Integer[] ia = new Integer[num];
for(int i = 0; i < num; i++) {
ia[i] = new Integer(i);
}
InstancePool pool = new InstancePool(ia);
Assert.assertEquals("available size of pool", num, pool.getAvailable());
Integer[] integers = new Integer[num];
for(int i = 0; i < num; i++) {
Assert.assertEquals("loop: available size of pool #" + i,
num - i,
pool.getAvailable());
integers[i] = (Integer)pool.getObject();
Assert.assertEquals("loop: integer ", ia[i], integers[i]);
}
Assert.assertEquals("available size of pool after loop",
0,
pool.getAvailable());
long t1 = System.currentTimeMillis();
new Releaser(pool, integers[0], 3000);
integers[0] = (Integer)pool.getObject();
long t2 = System.currentTimeMillis();
Assert.assertTrue("wait()-period", (t2 - t1) > 2500 && (t2 - t1) < 3500);
Assert.assertEquals("object after release", integers[0], ia[0]);
Assert.assertEquals("capacity after release", 0, pool.getAvailable());
}