Skip to content

Commit

Permalink
transport: netty-http revert the default port to 80 of console.server…
Browse files Browse the repository at this point in the history
… and add unit test (alibaba#567)
  • Loading branch information
jasonjoo2010 authored and sczyh30 committed Mar 14, 2019
1 parent 1a482b1 commit 78c0dd8
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public HttpHeartbeatSender() {
}
}

private List<Tuple2<String, Integer>> parseDashboardList() {
protected static List<Tuple2<String, Integer>> parseDashboardList() {
List<Tuple2<String, Integer>> list = new ArrayList<Tuple2<String, Integer>>();
try {
String ipsStr = TransportConfig.getConsoleServer();
Expand All @@ -86,7 +86,7 @@ private List<Tuple2<String, Integer>> parseDashboardList() {
continue;
}
String[] ipPort = ipPortStr.trim().split(":");
int port = 8080;
int port = 80;
if (ipPort.length > 1) {
port = Integer.parseInt(ipPort[1].trim());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Tuple2<String, Integer>> 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);
}
}

0 comments on commit 78c0dd8

Please sign in to comment.