ソースを参照

transport: netty-http revert the default port to 80 of console.server and add unit test (#567)

master
Jason Joo Eric Zhao 5年前
コミット
78c0dd8f86
2個のファイルの変更60行の追加2行の削除
  1. +2
    -2
      sentinel-transport/sentinel-transport-netty-http/src/main/java/com/alibaba/csp/sentinel/transport/heartbeat/HttpHeartbeatSender.java
  2. +58
    -0
      sentinel-transport/sentinel-transport-netty-http/src/test/java/com/alibaba/csp/sentinel/transport/heartbeat/HttpHeartbeatSenderTest.java

+ 2
- 2
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<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();
@@ -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());
}


+ 58
- 0
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<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);
}
}

読み込み中…
キャンセル
保存