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