public void testPutAndTake()
throws Exception
{
final FunkyTwoThreadBlockingQueue twoThreadBlockingQueue = new FunkyTwoThreadBlockingQueue();
Callable<String> consumer = new Callable<String>()
{
public String call()
throws Exception
{
int num = 0;
String taken;
do
{
taken = twoThreadBlockingQueue.take();
if ( taken != TwoThreadBlockingQueue.poison )
{
Assert.assertEquals( "item" + num++, taken );
}
}
while ( taken != TwoThreadBlockingQueue.poison );
return taken;
}
};
FutureTask<String> futureTask = new FutureTask<String>( consumer );
Thread thread = new Thread( futureTask );
thread.start();
String[] items = generate( num );
//long start = System.currentTimeMillis();
for ( String item : items )
{
twoThreadBlockingQueue.put( item );
}
twoThreadBlockingQueue.put( TwoThreadBlockingQueue.poison );
//long elapsed = System.currentTimeMillis() - start;
futureTask.get();
// System.out.println( "TwoThreadBlockingQueue produced and taken " + num + " elements in = " + elapsed );