@Test
    public void testConnectionException() throws RemotingException, InterruptedException {
        CONNECTEventProcessor serverConnectProcessor = new CONNECTEventProcessor();

        BoltServer boltServer = new BoltServer(1024);
        boltServer.addConnectionEventProcessor(ConnectionEventType.CONNECT, serverConnectProcessor);
        boltServer.start();

        final String[] closedUrl = new String[1];
        RpcClient client = new RpcClient();
        client.enableReconnectSwitch();
        client.addConnectionEventProcessor(ConnectionEventType.CLOSE,
            new ConnectionEventProcessor() {
                @Override
                public void onEvent(String remoteAddr, Connection conn) {
                    closedUrl[0] = remoteAddr;
                }
            });
        client.init();

        Connection connection = client.getConnection("127.0.0.1:1024", 1000);
        Thread.sleep(10);
        Assert.assertEquals(1, serverConnectProcessor.getConnectTimes());

        connection.getChannel().close();

        Thread.sleep(100);
        Assert.assertEquals("127.0.0.1:1024", closedUrl[0]);

        // connection has been created by ReconnectManager
        Thread.sleep(1000 * 2);
        Assert.assertEquals(2, serverConnectProcessor.getConnectTimes());
        connection = client.getConnection("127.0.0.1:1024", 1000);
        Assert.assertTrue(connection.isFine());
        Assert.assertEquals(2, serverConnectProcessor.getConnectTimes());

        boltServer.stop();
    }
@author chengyi (mark.lx@antfin.com) 2019-06-27 13:49
src/test/java/com/alipay/remoting/rpc/connectionmanage/ConnectionExceptionTest.java