/** @throws Exception */
@Test
public void notify1() throws Exception
{
ByteBufferPool p = new ByteBufferPool( 1024, 1, 1, 0, 0 );
MyNotify n1 = new MyNotify();
MyNotify n2 = new MyNotify();
ByteBuffer b1 = p.alloc( n1 );
assertNotNull( b1 );
assertEquals( 1, p.used() );
Thread.sleep( 15 );
assertFalse( n1.available );
assertFalse( n2.available );
ByteBuffer b2 = p.alloc( n2 );
assertNull( b2 );
assertEquals( 1, p.used() );
Thread.sleep( 15 );
assertFalse( n1.available );
assertFalse( n2.available );
// the alloc of b2 failed, but n2 should be registered to be notified
// when a block is freed. release of b1 should notify n2 of availability
p.release( b1 );
b1 = null;
assertEquals( 0, p.used() );
Thread.sleep( 15 );
assertFalse( n1.available );
assertTrue( n2.available );
n2.available = false;
b2 = p.alloc( n2 );
assertNotNull( b2 );
assertEquals( 1, p.used() );
Thread.sleep( 15 );
assertFalse( n1.available );
assertFalse( n2.available );
p.release( b2 );
b2 = null;
assertEquals( 0, p.used() );
Thread.sleep( 15 );
assertFalse( n1.available );
assertFalse( n2.available );
}