@Test public void testConnectionFailureCases() throws InterruptedException, ConnectionPoolTimeoutException, IOException { int port = 6680; String host = "127.0.0.1"; SocketServer server = startServer(port); Properties props = new Properties(); props.setProperty("clustermap.cluster.name", "test"); props.setProperty("clustermap.datacenter.name", "dc1"); props.setProperty("clustermap.host.name", "localhost"); 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); 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()); }
@Override public void shutdown() { logger.info("Shutting down the BlockingChannelConnectionPool"); for (Map.Entry<String, BlockingChannelInfo> channels : connections.entrySet()) { channels.getValue().cleanup(); } }
BlockingChannelConnectionPool implements ConnectionPool { @Override public void shutdown() { logger.info("Shutting down the BlockingChannelConnectionPool"); for (Map.Entry<String, BlockingChannelInfo> channels : connections.entrySet()) { channels.getValue().cleanup(); } } }
BlockingChannelConnectionPool implements ConnectionPool { @Override public void shutdown() { logger.info("Shutting down the BlockingChannelConnectionPool"); for (Map.Entry<String, BlockingChannelInfo> channels : connections.entrySet()) { channels.getValue().cleanup(); } } BlockingChannelConnectionPool(ConnectionPoolConfig config, SSLConfig sslConfig,
      ClusterMapConfig clusterMapConfig, MetricRegistry registry); }
BlockingChannelConnectionPool implements ConnectionPool { @Override public void shutdown() { logger.info("Shutting down the BlockingChannelConnectionPool"); for (Map.Entry<String, BlockingChannelInfo> channels : connections.entrySet()) { channels.getValue().cleanup(); } } BlockingChannelConnectionPool(ConnectionPoolConfig config, SSLConfig sslConfig,
      ClusterMapConfig clusterMapConfig, MetricRegistry registry); @Override void start(); @Override void shutdown(); @Override ConnectedChannel checkOutConnection(String host, Port port, long timeoutInMs); @Override void checkInConnection(ConnectedChannel connectedChannel); @Override void destroyConnection(ConnectedChannel connectedChannel); }
BlockingChannelConnectionPool implements ConnectionPool { @Override public void shutdown() { logger.info("Shutting down the BlockingChannelConnectionPool"); for (Map.Entry<String, BlockingChannelInfo> channels : connections.entrySet()) { channels.getValue().cleanup(); } } BlockingChannelConnectionPool(ConnectionPoolConfig config, SSLConfig sslConfig,
      ClusterMapConfig clusterMapConfig, MetricRegistry registry); @Override void start(); @Override void shutdown(); @Override ConnectedChannel checkOutConnection(String host, Port port, long timeoutInMs); @Override void checkInConnection(ConnectedChannel connectedChannel); @Override void destroyConnection(ConnectedChannel connectedChannel); public Gauge<Integer> totalNumberOfConnections; public Gauge<Integer> requestsWaitingToCheckoutConnection; public Counter sslSocketFactoryClientInitializationCount; public Counter sslSocketFactoryClientInitializationErrorCount; }