Parcourir la source

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

master
Jason Joo Eric Zhao il y a 5 ans
Parent
révision
78c0dd8f86
2 fichiers modifiés avec 60 ajouts et 2 suppressions
  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 Voir le fichier

@@ -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 Voir le fichier

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

Chargement…
Annuler
Enregistrer