From 78c0dd8f863090dc7a0f3d27c96f0e995290ae52 Mon Sep 17 00:00:00 2001 From: Jason Joo Date: Thu, 14 Mar 2019 10:25:01 +0800 Subject: [PATCH] transport: netty-http revert the default port to 80 of console.server and add unit test (#567) --- .../heartbeat/HttpHeartbeatSender.java | 4 +- .../heartbeat/HttpHeartbeatSenderTest.java | 58 +++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 sentinel-transport/sentinel-transport-netty-http/src/test/java/com/alibaba/csp/sentinel/transport/heartbeat/HttpHeartbeatSenderTest.java diff --git a/sentinel-transport/sentinel-transport-netty-http/src/main/java/com/alibaba/csp/sentinel/transport/heartbeat/HttpHeartbeatSender.java b/sentinel-transport/sentinel-transport-netty-http/src/main/java/com/alibaba/csp/sentinel/transport/heartbeat/HttpHeartbeatSender.java index 96cf4327..138d92a5 100755 --- a/sentinel-transport/sentinel-transport-netty-http/src/main/java/com/alibaba/csp/sentinel/transport/heartbeat/HttpHeartbeatSender.java +++ b/sentinel-transport/sentinel-transport-netty-http/src/main/java/com/alibaba/csp/sentinel/transport/heartbeat/HttpHeartbeatSender.java @@ -65,7 +65,7 @@ public class HttpHeartbeatSender implements HeartbeatSender { } } - private List> parseDashboardList() { + protected static List> parseDashboardList() { List> list = new ArrayList>(); try { String ipsStr = TransportConfig.getConsoleServer(); @@ -86,7 +86,7 @@ public class HttpHeartbeatSender implements HeartbeatSender { continue; } String[] ipPort = ipPortStr.trim().split(":"); - int port = 8080; + int port = 80; if (ipPort.length > 1) { port = Integer.parseInt(ipPort[1].trim()); } diff --git a/sentinel-transport/sentinel-transport-netty-http/src/test/java/com/alibaba/csp/sentinel/transport/heartbeat/HttpHeartbeatSenderTest.java b/sentinel-transport/sentinel-transport-netty-http/src/test/java/com/alibaba/csp/sentinel/transport/heartbeat/HttpHeartbeatSenderTest.java new file mode 100644 index 00000000..1d270d9a --- /dev/null +++ b/sentinel-transport/sentinel-transport-netty-http/src/test/java/com/alibaba/csp/sentinel/transport/heartbeat/HttpHeartbeatSenderTest.java @@ -0,0 +1,58 @@ +package com.alibaba.csp.sentinel.transport.heartbeat; + +import static org.junit.Assert.assertEquals; + +import java.util.List; + +import org.junit.Test; + +import com.alibaba.csp.sentinel.config.SentinelConfig; +import com.alibaba.csp.sentinel.transport.config.TransportConfig; +import com.alibaba.csp.sentinel.util.function.Tuple2; + +public class HttpHeartbeatSenderTest { + + private void setAddr(String serverList) { + SentinelConfig.setConfig(TransportConfig.CONSOLE_SERVER, serverList); + } + + @Test + public void testAddr() { + setAddr(""); + assertEquals(0, HttpHeartbeatSender.parseDashboardList().size()); + + setAddr("a.com"); + List> list = HttpHeartbeatSender.parseDashboardList(); + assertEquals(1, list.size()); + assertEquals("a.com", list.get(0).r1); + assertEquals(Integer.valueOf(80), list.get(0).r2); + + setAddr("a.com:88"); + list = HttpHeartbeatSender.parseDashboardList(); + assertEquals(1, list.size()); + assertEquals("a.com", list.get(0).r1); + assertEquals(Integer.valueOf(88), list.get(0).r2); + + setAddr("a.com:88,,,,"); + list = HttpHeartbeatSender.parseDashboardList(); + assertEquals(1, list.size()); + assertEquals("a.com", list.get(0).r1); + assertEquals(Integer.valueOf(88), list.get(0).r2); + + setAddr("a.com:88,b.com"); + list = HttpHeartbeatSender.parseDashboardList(); + assertEquals(2, list.size()); + assertEquals("a.com", list.get(0).r1); + assertEquals(Integer.valueOf(88), list.get(0).r2); + assertEquals("b.com", list.get(1).r1); + assertEquals(Integer.valueOf(80), list.get(1).r2); + + setAddr("a.com:88,b.com:99999"); + list = HttpHeartbeatSender.parseDashboardList(); + assertEquals(2, list.size()); + assertEquals("a.com", list.get(0).r1); + assertEquals(Integer.valueOf(88), list.get(0).r2); + assertEquals("b.com", list.get(1).r1); + assertEquals(Integer.valueOf(99999), list.get(1).r2); + } +}