@Test
    public void doReuseTest() {

        ServerConfig serverConfig = new ServerConfig().setPort(12222).setProtocol(RpcConstants.PROTOCOL_TYPE_BOLT);
        serverConfig.buildIfAbsent().start();

        ServerConfig serverConfig2 = new ServerConfig().setPort(12223).setProtocol(RpcConstants.PROTOCOL_TYPE_BOLT);
        serverConfig2.buildIfAbsent().start();

        ClientTransportConfig clientTransportConfig = new ClientTransportConfig();
        ProviderInfo providerInfo = ProviderHelper.toProviderInfo("127.0.0.1:12222");
        clientTransportConfig.setProviderInfo(providerInfo);

        BoltClientTransport clientTransport = new BoltClientTransport(clientTransportConfig);
        clientTransport.disconnect();
        final BoltClientConnectionManager connectionManager = BoltClientTransport.connectionManager;

        if (connectionManager instanceof ReuseBoltClientConnectionManager) {
            Assert.assertTrue(((ReuseBoltClientConnectionManager) connectionManager).urlConnectionMap.size() == 0);
            Assert.assertTrue(((ReuseBoltClientConnectionManager) connectionManager).connectionRefCounter.size() == 0);
        } else {
            Assert.fail();
        }

        ClientTransportConfig config1 = new ClientTransportConfig();
        config1.setProviderInfo(new ProviderInfo().setHost("127.0.0.1").setPort(12222))
            .setContainer("bolt");

        BoltClientTransport clientTransport1 = (BoltClientTransport) ClientTransportFactory
            .getClientTransport(config1);
        clientTransport1.connect();

        ClientTransportConfig config2 = new ClientTransportConfig();
        config2.setProviderInfo(new ProviderInfo().setHost("127.0.0.1").setPort(12222))
            .setContainer("bolt");
        BoltClientTransport clientTransport2 = (BoltClientTransport) ClientTransportFactory
            .getClientTransport(config2);
        clientTransport2.connect();
        Assert.assertFalse(clientTransport1 == clientTransport2);
        Assert.assertTrue(clientTransport1.fetchConnection() == clientTransport2.fetchConnection());

        ClientTransportConfig config3 = new ClientTransportConfig();
        config3.setProviderInfo(new ProviderInfo().setHost("127.0.0.1").setPort(12223))
            .setContainer("bolt");
        BoltClientTransport clientTransport3 = (BoltClientTransport) ClientTransportFactory
            .getClientTransport(config3);
        clientTransport3.connect();
        Assert.assertFalse(clientTransport1 == clientTransport3);
        Assert.assertFalse(clientTransport1.fetchConnection() == clientTransport3.fetchConnection());

        ClientTransportFactory.releaseTransport(null, 500);

        clientTransport1.currentRequests.set(4);
        ClientTransportFactory.releaseTransport(clientTransport1, 500);

        clientTransport2.currentRequests.set(0);
        ClientTransportFactory.releaseTransport(clientTransport2, 500);

        ClientTransportFactory.closeAll();
    }
@author <a href="mailto:zhanggeng.zg@antfin.com">GengZhang</a>
remoting/remoting-bolt/src/test/java/com/alipay/sofa/rpc/transport/bolt/BoltClientTransportTest.java