@Test
public void testDelayedAllocation() throws Exception {

    BufferPool pool = new BufferPool(5 * 1024, 1024, metrics, time, metricGroup);
    ByteBuffer buffer = pool.allocate(1024, maxBlockTimeMs);
    CountDownLatch doDealloc = asyncDeallocate(pool, buffer);
    CountDownLatch allocation = asyncAllocate(pool, 5 * 1024);
    assertEquals("Allocation shouldn't have happened yet, waiting on memory.", 1L, allocation.getCount());
    doDealloc.countDown(); // return the memory
    assertTrue("Allocation should succeed soon after de-allocation", allocation.await(1, TimeUnit.SECONDS));
}