From 124fbf45dfbb4e171d9b520f68dcdbb5f91e6075 Mon Sep 17 00:00:00 2001 From: linxin Date: Mon, 20 May 2019 17:16:00 +0800 Subject: [PATCH] version 1.5.5 (#158) * upgrade version to 1.5.5 and fix reconnect bug --- pom.xml | 2 +- .../com/alipay/remoting/rpc/RpcClient.java | 6 ++++++ .../ReconnectManagerTest.java | 21 ++++++++++++++++++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 949b9491..cd171e02 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ 4.0.0 com.alipay.sofa bolt - 1.5.4 + 1.5.5 jar ${project.groupId}:${project.artifactId} diff --git a/src/main/java/com/alipay/remoting/rpc/RpcClient.java b/src/main/java/com/alipay/remoting/rpc/RpcClient.java index aa73a404..e2c6e6eb 100644 --- a/src/main/java/com/alipay/remoting/rpc/RpcClient.java +++ b/src/main/java/com/alipay/remoting/rpc/RpcClient.java @@ -809,6 +809,9 @@ public boolean checkConnection(String addr) { */ public void closeConnection(String addr) { Url url = this.addressParser.parse(addr); + if (switches().isOn(GlobalSwitch.CONN_RECONNECT_SWITCH) && reconnectManager != null) { + reconnectManager.addCancelUrl(url); + } this.connectionManager.remove(url.getUniqueKey()); } @@ -818,6 +821,9 @@ public void closeConnection(String addr) { * @param url */ public void closeConnection(Url url) { + if (switches().isOn(GlobalSwitch.CONN_RECONNECT_SWITCH) && reconnectManager != null) { + reconnectManager.addCancelUrl(url); + } this.connectionManager.remove(url.getUniqueKey()); } diff --git a/src/test/java/com/alipay/remoting/rpc/connectionmanage/ReconnectManagerTest.java b/src/test/java/com/alipay/remoting/rpc/connectionmanage/ReconnectManagerTest.java index 4f1ad244..1c5e71f7 100644 --- a/src/test/java/com/alipay/remoting/rpc/connectionmanage/ReconnectManagerTest.java +++ b/src/test/java/com/alipay/remoting/rpc/connectionmanage/ReconnectManagerTest.java @@ -105,11 +105,30 @@ public void testReconnectionByUserSetting() throws InterruptedException, Remotin Assert.assertEquals(0, clientDisConnectProcessor.getDisConnectTimes()); Assert.assertEquals(1, clientConnectProcessor.getConnectTimes()); connection.close(); - Thread.sleep(1000); + Thread.sleep(2000); Assert.assertEquals(1, clientDisConnectProcessor.getDisConnectTimes()); Assert.assertEquals(2, clientConnectProcessor.getConnectTimes()); } + @Test + public void testCancelReConnection() throws InterruptedException, RemotingException { + doInit(false, true); + client.enableReconnectSwitch(); + + String addr = "127.0.0.1:2014?zone=RZONE&_CONNECTIONNUM=1"; + Url url = addressParser.parse(addr); + + client.getConnection(url, 1000); + Assert.assertEquals(0, clientDisConnectProcessor.getDisConnectTimes()); + Assert.assertEquals(1, clientConnectProcessor.getConnectTimes()); + + client.closeConnection(url); + + Thread.sleep(1000); + Assert.assertEquals(1, clientDisConnectProcessor.getDisConnectTimes()); + Assert.assertEquals(1, clientConnectProcessor.getConnectTimes()); + } + private void doInit(boolean enableSystem, boolean enableUser) { if (enableSystem) { System.setProperty(Configs.CONN_RECONNECT_SWITCH, "true");