improved test

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2524 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Greg Wilkins 2010-11-17 00:28:47 +00:00
parent 6ca798c49a
commit ba5343fe12
1 changed files with 28 additions and 17 deletions

View File

@ -15,6 +15,7 @@ package org.eclipse.jetty.util.thread;
import static org.junit.Assert.assertEquals;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicIntegerArray;
import org.junit.Before;
@ -131,8 +132,8 @@ public class TimeoutTest
public void testStress() throws Exception
{
final int LOOP=250;
final boolean[] running = {true};
final AtomicIntegerArray count = new AtomicIntegerArray( 3 );
final AtomicBoolean running=new AtomicBoolean(true);
final AtomicIntegerArray count = new AtomicIntegerArray( 4 );
timeout.setNow(System.currentTimeMillis());
@ -144,7 +145,7 @@ public class TimeoutTest
@Override
public void run()
{
while (running[0])
while (running.get())
{
try
{
@ -199,18 +200,18 @@ public class TimeoutTest
// do the looping until we are stopped
int loop=0;
while (running[0])
while (running.get())
{
try
{
long delay=1000;
long wait=100-once;
if (loop++==once)
{
// THIS loop is the one time we wait 1000ms
// THIS loop is the one time we wait longer than the delay
count.incrementAndGet( 1 );
count.incrementAndGet( 1 );
delay=200;
wait=1000;
}
@ -228,25 +229,35 @@ public class TimeoutTest
e.printStackTrace();
}
}
count.incrementAndGet(3);
}
};
th.start();
}
// run test for 5s
Thread.sleep(8000);
synchronized (lock)
{
running[0]=false;
}
// give some time for test to stop
Thread.sleep(1000);
timeout.tick(System.currentTimeMillis());
Thread.sleep(500);
long start=System.currentTimeMillis();
// run test until all threads are started
while (count.get(0)<LOOP && (System.currentTimeMillis()-start)<20000)
Thread.sleep(50);
// run test until all expires initiated
while (count.get(1)<LOOP && (System.currentTimeMillis()-start)<20000)
Thread.sleep(50);
// run test until all expires initiated
while (count.get(2)<LOOP && (System.currentTimeMillis()-start)<20000)
Thread.sleep(50);
running.set(false);
// run test until all threads complete
while (count.get(3)<LOOP && (System.currentTimeMillis()-start)<20000)
Thread.sleep(50);
// check the counts
assertEquals("count threads", LOOP,count.get( 0 ));
assertEquals("count once waits",LOOP,count.get(1 ));
assertEquals("count expires",LOOP,count.get(2));
assertEquals("done",LOOP,count.get(3));
}
}