private void overSubscriptionTest(Properties props, String host, Port port, int maxConnectionsPerHost,
      boolean destroyConnection) throws Exception {
    AtomicReference<Exception> exception = new AtomicReference<Exception>();
    BlockingChannelInfo channelInfo =
        new BlockingChannelInfo(new ConnectionPoolConfig(new VerifiableProperties(props)), host, port,
            new MetricRegistry(), sslSocketFactory, sslConfig);

    CountDownLatch channelCount = new CountDownLatch(maxConnectionsPerHost);
    CountDownLatch shouldRelease = new CountDownLatch(1);
    CountDownLatch releaseComplete = new CountDownLatch(2 * maxConnectionsPerHost);
    for (int i = 0; i < maxConnectionsPerHost; i++) {
      BlockingChannelInfoThread infoThread =
          new BlockingChannelInfoThread(channelInfo, channelCount, shouldRelease, releaseComplete, destroyConnection,
              exception);
      Thread t = new Thread(infoThread);
      t.start();
    }
    awaitCountdown(channelCount, 1000, exception,
        "Timed out while waiting for channel count to reach " + maxConnectionsPerHost);
    Assert.assertEquals(channelInfo.getNumberOfConnections(), maxConnectionsPerHost);

    // try "maxConnectionsPerHost" more connections
    channelCount = new CountDownLatch(maxConnectionsPerHost);
    for (int i = 0; i < maxConnectionsPerHost; i++) {
      BlockingChannelInfoThread infoThread =
          new BlockingChannelInfoThread(channelInfo, channelCount, shouldRelease, releaseComplete, destroyConnection,
              exception);
      Thread t = new Thread(infoThread);
      t.start();
    }
    Assert.assertEquals(channelInfo.getNumberOfConnections(), maxConnectionsPerHost);
    shouldRelease.countDown();
    awaitCountdown(channelCount, 1000, exception,
        "Timed out while waiting for channel count to reach " + maxConnectionsPerHost);
    Assert.assertEquals(channelInfo.getNumberOfConnections(), maxConnectionsPerHost);
    awaitCountdown(releaseComplete, 2000, exception, "Timed out while waiting for channels to be released");
    channelInfo.cleanup();
    Assert.assertEquals(channelInfo.getNumberOfConnections(), 0);
  }
Tests how connection failures are handled by BlockingChannelInfo.
ambry-network/src/test/java/com/github/ambry/network/BlockingChannelConnectionPoolTest.java