@Test
public void testStressfulSituation() throws Exception {

    int numThreads = 10;
    final int iterations = 50000;
    final int poolableSize = 1024;
    final long totalMemory = numThreads / 2 * poolableSize;
    final BufferPool pool = new BufferPool(totalMemory, poolableSize, metrics, time, metricGroup);
    List<StressTestThread> threads = new ArrayList<StressTestThread>();
    for (int i = 0; i < numThreads; i++)
        threads.add(new StressTestThread(pool, iterations));
    for (StressTestThread thread : threads)
        thread.start();
    for (StressTestThread thread : threads)
        thread.join();
    for (StressTestThread thread : threads)
        assertTrue("Thread should have completed all iterations successfully.", thread.success.get());
    assertEquals(totalMemory, pool.availableMemory());
}