public void requestStatsTester()
{
CWConfig config=new CWConfig();
config.setLogger(Log.instance());
CWThreadExecutor executor = new CWThreadExecutor("test", config, 1, 5, 100, TimeUnit.SECONDS, 10, 500);
final RequestStats stats = new RequestStats();
int numRequests=500;
for(int i=0;i<numRequests;i++)
{
executor.execute(new Runnable(){
@Override
public void run()
{
final long startTime=System.nanoTime();
try
{
stats.startProcessing();
try{Thread.sleep(random.nextInt(10));}catch(Exception e){}
}
finally
{
stats.endProcessing(System.nanoTime()-startTime);
}
}
});
}
boolean success=false;
for(int i=1;i<8000;i++)
{
if((stats.getAverageEllapsedNanos()>0)
&&(stats.getNumberOfRequestsInProcess()>0))
{
success=true;
break;
}
try
{
Thread.sleep(1);
}
catch (InterruptedException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
if(!success)
{
fail("FAIL, nothing is in progress: "+stats.getAverageEllapsedNanos()+"/"+stats.getNumberOfRequestsInProcess());
}
while(executor.getQueue().size()>0)
try{Thread.sleep(100);}catch(Exception e){}
try{Thread.sleep(1000);}catch(Exception e){}
if((stats.getAverageEllapsedNanos()==0)
||(stats.getNumberOfRequests()!=numRequests))
{
fail("FAIL, num requests = "+stats.getNumberOfRequests());
}
System.out.println("Stats smoke test: PASS");
}