public void testConcurrentBag() throws InterruptedException
{
ConcurrentBag<PoolBagEntry> bag = new ConcurrentBag<PoolBagEntry>(null);
Assert.assertEquals(0, bag.values(8).size());
PoolBagEntry reserved = new PoolBagEntry(null, 0);
bag.add(reserved);
bag.reserve(reserved); // reserved
PoolBagEntry inuse = new PoolBagEntry(null, 0);
bag.add(inuse);
bag.borrow(2L, TimeUnit.SECONDS); // in use
PoolBagEntry notinuse = new PoolBagEntry(null, 0);
bag.add(notinuse); // not in use
bag.dumpState();
try {
bag.requite(reserved);
Assert.fail();
}
catch (IllegalStateException e) {
// pass
}
try {
bag.remove(notinuse);
Assert.fail();
}
catch (IllegalStateException e) {
// pass
}
try {
bag.unreserve(notinuse);
Assert.fail();
}
catch (IllegalStateException e) {
// pass
}
try {
bag.remove(inuse);
bag.remove(inuse);
Assert.fail();
}
catch (IllegalStateException e) {
// pass
}
bag.close();
try {
bag.add(new PoolBagEntry(null, 0));
Assert.fail();
}
catch (IllegalStateException e) {
// pass
}
Assert.assertNotNull(notinuse.toString());
}