public void testBlockingStore() throws Exception
{
final BlockingCallbackStore store = new BlockingCallbackStore();
new Thread(new Runnable() {
public void run()
{
for(int x = 0; x < 100; x++)
{
try
{
store.add(new Holder(x));
}
catch (IOException e)
{
failure = true;
e.printStackTrace();
}
}
}
}).start();
new Thread(new Runnable() {
public void run()
{
for(int i = 500; i < 600; i++)
{
try
{
store.add(new Holder(i));
}
catch (IOException e)
{
failure = true;
e.printStackTrace();
}
}
}
}).start();
Thread.sleep(1000);
Holder holder = (Holder)store.getNext();
while(holder != null)
{
int num = holder.getNum();
if(num <= 100)
{
System.out.println("lowCounter = " + lowCounter + ", num = " + num);
assertEquals(lowCounter, num);
lowCounter++;
}
else
{
System.out.println("highCounter = " + highCounter + ", num = " + num);
assertEquals(highCounter, num);
highCounter++;
}
Thread.sleep(100);
holder = (Holder)store.getNext();
}
assertFalse(failure);
}