Source:
public void testConnectionFailureCases() throws InterruptedException, ConnectionPoolTimeoutException, IOException { int port = 6680; Properties props = new Properties(); String maxConnectFailuresToCleanUp = "2"; props.put("connectionpool.max.connect.failures.to.clean.up.available.pool", maxConnectFailuresToCleanUp); String host = "127.0.0.1"; SocketServer server = startServer(port); BlockingChannelInfo channelInfo = new BlockingChannelInfo(new ConnectionPoolConfig(new VerifiableProperties(props)), host, new Port(port, PortType.PLAINTEXT), new MetricRegistry(), sslSocketFactory, sslConfig); Assert.assertEquals(channelInfo.getNumberOfConnections(), 0); BlockingChannel blockingChannel1 = channelInfo.getBlockingChannel(1000); Assert.assertEquals(channelInfo.getNumberOfConnections(), 1); BlockingChannel blockingChannel2 = channelInfo.getBlockingChannel(1000); Assert.assertEquals(channelInfo.getNumberOfConnections(), 2); BlockingChannel blockingChannel3 = channelInfo.getBlockingChannel(1000); Assert.assertEquals(channelInfo.getNumberOfConnections(), 3); BlockingChannel blockingChannel4 = channelInfo.getBlockingChannel(1000); Assert.assertEquals(channelInfo.getNumberOfConnections(), 4); BlockingChannel blockingChannel5 = channelInfo.getBlockingChannel(1000); Assert.assertEquals(channelInfo.getNumberOfConnections(), 5); channelInfo.releaseBlockingChannel(blockingChannel3); channelInfo.releaseBlockingChannel(blockingChannel4); channelInfo.releaseBlockingChannel(blockingChannel5); Assert.assertEquals("Available connections count mismatch ", 3, channelInfo.availableConnections.getValue().intValue()); server.shutdown(); channelInfo.destroyBlockingChannel(blockingChannel1); Assert.assertEquals("Available connections should have not been cleaned up", 3, channelInfo.availableConnections.getValue().intValue()); server = startServer(port); channelInfo.destroyBlockingChannel(blockingChannel2); Assert.assertEquals("Available connections should not have been cleaned up", 4, channelInfo.availableConnections.getValue().intValue()); server.shutdown(); BlockingChannel blockingChannel = channelInfo.getBlockingChannel(1000); channelInfo.destroyBlockingChannel(blockingChannel); blockingChannel = channelInfo.getBlockingChannel(1000); channelInfo.destroyBlockingChannel(blockingChannel); Assert.assertEquals("Available connections should have been cleaned up", 0, channelInfo.availableConnections.getValue().intValue()); }

Target:
public void testConnectionFailureCases() throws InterruptedException, ConnectionPoolTimeoutException, IOException { int port = 6680; String host = "127.0.0.1"; SocketServer server = startServer(port); BlockingChannelInfo channelInfo = new BlockingChannelInfo(new ConnectionPoolConfig(new VerifiableProperties(new Properties())), host, new Port(port, PortType.PLAINTEXT), new MetricRegistry(), sslSocketFactory, sslConfig); Assert.assertEquals(channelInfo.getNumberOfConnections(), 0); BlockingChannel blockingChannel1 = channelInfo.getBlockingChannel(1000); Assert.assertEquals(channelInfo.getNumberOfConnections(), 1); BlockingChannel blockingChannel2 = channelInfo.getBlockingChannel(1000); Assert.assertEquals(channelInfo.getNumberOfConnections(), 2); BlockingChannel blockingChannel3 = channelInfo.getBlockingChannel(1000); Assert.assertEquals(channelInfo.getNumberOfConnections(), 3); channelInfo.releaseBlockingChannel(blockingChannel2); channelInfo.releaseBlockingChannel(blockingChannel3); Assert.assertEquals("Available connections count mismatch ", 2, channelInfo.availableConnections.getValue().intValue()); server.shutdown(); channelInfo.destroyBlockingChannel(blockingChannel1); Assert.assertEquals("Available connections should have not been cleaned up", 0, channelInfo.availableConnections.getValue().intValue()); startServer(port); BlockingChannel blockingChannel4 = channelInfo.getBlockingChannel(1000); Assert.assertEquals(channelInfo.getNumberOfConnections(), 1); BlockingChannel blockingChannel5 = channelInfo.getBlockingChannel(1000); Assert.assertEquals(channelInfo.getNumberOfConnections(), 2); channelInfo.releaseBlockingChannel(blockingChannel4); channelInfo.destroyBlockingChannel(blockingChannel5); Assert.assertEquals("Available connections should not have been cleaned up", 2, channelInfo.availableConnections.getValue().intValue()); }