NotReusableClientTransportHolder implements ClientTransportHolder { @Override public ClientTransport getClientTransport(ClientTransportConfig config) { ClientTransport transport = allTransports.get(config); if (transport == null) { transport = ExtensionLoaderFactory.getExtensionLoader(ClientTransport.class) .getExtension(config.getContainer(), new Class[] { ClientTransportConfig.class }, new Object[] { config }); ClientTransport old = allTransports.putIfAbsent(config, transport); if (old != null) { if (LOGGER.isWarnEnabled()) { LOGGER.warn("Multiple threads init ClientTransport with same ClientTransportConfig!"); } transport.destroy(); transport = old; } } return transport; }  @Override ClientTransport getClientTransport(ClientTransportConfig config); @Override boolean removeClientTransport(ClientTransport clientTransport); @Override int size(); @Override void destroy(); @Override void destroy(DestroyHook hook);  }
@Test public void getClientTransport() { NotReusableClientTransportHolder holder = new NotReusableClientTransportHolder(); ClientTransportConfig config = new ClientTransportConfig(); config.setProviderInfo(new ProviderInfo().setHost("127.0.0.1").setPort(12222)) .setContainer("test"); TestClientTransport clientTransport = (TestClientTransport) holder.getClientTransport(config); ClientTransportConfig config2 = new ClientTransportConfig(); config2.setProviderInfo(new ProviderInfo().setHost("127.0.0.1").setPort(12222)) .setContainer("test"); TestClientTransport clientTransport2 = (TestClientTransport) holder.getClientTransport(config2); Assert.assertFalse(clientTransport == clientTransport2); ClientTransportConfig config3 = new ClientTransportConfig(); config3.setProviderInfo(new ProviderInfo().setHost("127.0.0.1").setPort(12223)) .setContainer("test"); TestClientTransport clientTransport3 = (TestClientTransport) holder.getClientTransport(config3); Assert.assertFalse(clientTransport2 == clientTransport3); Assert.assertFalse(holder.removeClientTransport(null)); clientTransport.setRequest(4); Assert.assertTrue(holder.removeClientTransport(clientTransport)); Assert.assertEquals(2, holder.size()); clientTransport2.setRequest(0); Assert.assertTrue(holder.removeClientTransport(clientTransport2)); Assert.assertEquals(1, holder.size()); holder.destroy(); Assert.assertEquals(0, holder.size()); }