Source:
<code>public void testObjectsAreNotCreatedWhenThereAreNoWaiters(int numberOfCheckouts, int poolSize, int concurrency) { CreationBlockableSynchronousLifecycle blockableObjectCreator = new CreationBlockableSynchronousLifecycle(numberOfCheckouts, concurrency); ScheduledExecutorService executor = Executors.newScheduledThreadPool(500); RateLimiter rateLimiter = new ExponentialBackOffRateLimiter(0, 5000, 10, executor, concurrency); final AsyncPool<Object> pool = new AsyncPoolImpl<Object>("object pool", blockableObjectCreator, poolSize, Integer.MAX_VALUE, _executor, Integer.MAX_VALUE, AsyncPoolImpl.Strategy.MRU, 0, rateLimiter ); pool.start(); List<Object> checkedOutObjects = performCheckout(numberOfCheckouts, pool); blockableObjectCreator.blockCreation(); Future<None> future = performUnblockingCheckout(numberOfCheckouts, numberOfCheckouts, pool); blockableObjectCreator.waitUntilAllBlocked(); for (Object checkedOutObject : checkedOutObjects) { pool.put(checkedOutObject); } blockableObjectCreator.unblockCreation(); try { future.get(5, TimeUnit.SECONDS); } catch (Exception e) { <START> Assert.fail("Unexpected interruption", e); <END> } while (rateLimiter.numberOfPendingTasks() > 0) { try { Thread.sleep(1); } catch (Exception e) { Assert.fail("Unexpected interruption", e); } } executor.shutdown(); try { if (!executor.awaitTermination(10, TimeUnit.SECONDS)) { Assert.fail("Too long to finish"); } } catch (Exception ex) { Assert.fail("Unexpected interruption", ex); } PoolStats stats = pool.getStats(); Assert.assertEquals(stats.getTotalCreationIgnored(), numberOfCheckouts-concurrency); Assert.assertEquals(stats.getCheckedOut(), numberOfCheckouts); Assert.assertEquals(stats.getIdleCount(), concurrency); Assert.assertEquals(stats.getTotalCreated(), numberOfCheckouts+concurrency); Assert.assertEquals(stats.getPoolSize(), numberOfCheckouts+concurrency); Assert.assertEquals(stats.getTotalDestroyed(), 0); Assert.assertEquals(stats.getTotalBadDestroyed(), 0); Assert.assertEquals(stats.getTotalTimedOut(), 0); }</code><technical_language>add in is unexpected</technical_language>

Target:
public void testObjectsAreNotCreatedWhenThereAreNoWaiters(int numberOfCheckouts, int poolSize, int concurrency) throws Exception { CreationBlockableSynchronousLifecycle blockableObjectCreator = new CreationBlockableSynchronousLifecycle(numberOfCheckouts, concurrency); ScheduledExecutorService executor = Executors.newScheduledThreadPool(500); ExponentialBackOffRateLimiter rateLimiter = new ExponentialBackOffRateLimiter(0, 5000, 10, executor, concurrency); final AsyncPool<Object> pool = new AsyncPoolImpl<Object>("object pool", blockableObjectCreator, poolSize, Integer.MAX_VALUE, _executor, Integer.MAX_VALUE, AsyncPoolImpl.Strategy.MRU, 0, rateLimiter ); pool.start(); List<Object> checkedOutObjects = performCheckout(numberOfCheckouts, pool); blockableObjectCreator.blockCreation(); Future<None> future = performUnblockingCheckout(numberOfCheckouts, numberOfCheckouts, pool); blockableObjectCreator.waitUntilAllBlocked(); for (Object checkedOutObject : checkedOutObjects) { pool.put(checkedOutObject); } blockableObjectCreator.unblockCreation(); try { future.get(5, TimeUnit.SECONDS); } catch (Exception e) { Assert.fail("Did not complete unblocked object creations on time, Unexpected interruption", e); } AssertionMethods.assertWithTimeout(5000, ()-> Assert.assertEquals(rateLimiter.numberOfPendingTasks(),0,"Number of tasks has to drop to 0")); executor.shutdown(); try { if (!executor.awaitTermination(10, TimeUnit.SECONDS)) { Assert.fail("Executor took too long to shutdown"); } } catch (Exception ex) { Assert.fail("Unexpected interruption while shutting down executor", ex); } PoolStats stats = pool.getStats(); Assert.assertEquals(stats.getTotalCreationIgnored(), numberOfCheckouts-concurrency); Assert.assertEquals(stats.getCheckedOut(), numberOfCheckouts); Assert.assertEquals(stats.getIdleCount(), concurrency); Assert.assertEquals(stats.getTotalCreated(), numberOfCheckouts+concurrency); Assert.assertEquals(stats.getPoolSize(), numberOfCheckouts+concurrency); Assert.assertEquals(stats.getTotalDestroyed(), 0); Assert.assertEquals(stats.getTotalBadDestroyed(), 0); Assert.assertEquals(stats.getTotalTimedOut(), 0); }