#269 fix test case bug

This commit is contained in:
nkorange 2019-03-05 15:58:51 +08:00
parent 42cd5395ac
commit a4155fd939
6 changed files with 17 additions and 43 deletions

View File

@ -21,7 +21,6 @@ import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.api.common.Constants; import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.naming.CommonParams; import com.alibaba.nacos.api.naming.CommonParams;
import com.alibaba.nacos.core.utils.WebUtils; import com.alibaba.nacos.core.utils.WebUtils;
import com.alibaba.nacos.naming.boot.RunningConfig;
import com.alibaba.nacos.naming.cluster.ServerMode; import com.alibaba.nacos.naming.cluster.ServerMode;
import com.alibaba.nacos.naming.core.DistroMapper; import com.alibaba.nacos.naming.core.DistroMapper;
import com.alibaba.nacos.naming.core.Instance; import com.alibaba.nacos.naming.core.Instance;
@ -29,7 +28,6 @@ import com.alibaba.nacos.naming.core.Service;
import com.alibaba.nacos.naming.core.ServiceManager; import com.alibaba.nacos.naming.core.ServiceManager;
import com.alibaba.nacos.naming.exception.NacosException; import com.alibaba.nacos.naming.exception.NacosException;
import com.alibaba.nacos.naming.healthcheck.RsInfo; import com.alibaba.nacos.naming.healthcheck.RsInfo;
import com.alibaba.nacos.naming.misc.HttpClient;
import com.alibaba.nacos.naming.misc.Loggers; import com.alibaba.nacos.naming.misc.Loggers;
import com.alibaba.nacos.naming.misc.SwitchDomain; import com.alibaba.nacos.naming.misc.SwitchDomain;
import com.alibaba.nacos.naming.misc.UtilsAndCommons; import com.alibaba.nacos.naming.misc.UtilsAndCommons;
@ -45,7 +43,6 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.*; import java.util.*;
@ -251,30 +248,7 @@ public class InstanceController {
throw new NacosException(NacosException.SERVER_ERROR, "service not found: " + serviceName + "@" + namespaceId); throw new NacosException(NacosException.SERVER_ERROR, "service not found: " + serviceName + "@" + namespaceId);
} }
if (!distroMapper.responsible(serviceName)) { service.processClientBeat(clientBeat);
String server = distroMapper.mapSrv(serviceName);
Loggers.EVT_LOG.info("I'm not responsible for {}, proxy it to {}", serviceName, server);
Map<String, String> proxyParams = new HashMap<>(16);
for (Map.Entry<String, String[]> entry : request.getParameterMap().entrySet()) {
String key = entry.getKey();
String value = entry.getValue()[0];
proxyParams.put(key, value);
}
if (!server.contains(UtilsAndCommons.IP_PORT_SPLITER)) {
server = server + UtilsAndCommons.IP_PORT_SPLITER + RunningConfig.getServerPort();
}
String url = "http://" + server + RunningConfig.getContextPath()
+ UtilsAndCommons.NACOS_NAMING_CONTEXT + "/instance/clientBeat";
HttpClient.HttpResult httpResult = HttpClient.httpGet(url, null, proxyParams);
if (httpResult.code != HttpURLConnection.HTTP_OK) {
throw new IllegalArgumentException("failed to proxy client beat to" + server + ", beat: " + beat);
}
} else {
service.processClientBeat(clientBeat);
}
return result; return result;
} }

View File

@ -32,6 +32,7 @@ import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -61,8 +62,8 @@ public class PartitionController {
@Autowired @Autowired
private SwitchDomain switchDomain; private SwitchDomain switchDomain;
@RequestMapping("/onSync") @RequestMapping(value = "/datum", method = RequestMethod.PUT)
public String onSync(HttpServletRequest request, HttpServletResponse response) throws Exception { public String onSyncDatum(HttpServletRequest request, HttpServletResponse response) throws Exception {
String entity = IOUtils.toString(request.getInputStream(), "UTF-8"); String entity = IOUtils.toString(request.getInputStream(), "UTF-8");
@ -88,7 +89,7 @@ public class PartitionController {
return "ok"; return "ok";
} }
@RequestMapping("/syncTimestamps") @RequestMapping(value = "/timestamps", method = RequestMethod.PUT)
public String syncTimestamps(HttpServletRequest request, HttpServletResponse response) throws Exception { public String syncTimestamps(HttpServletRequest request, HttpServletResponse response) throws Exception {
String source = WebUtils.required(request, "source"); String source = WebUtils.required(request, "source");
String entity = IOUtils.toString(request.getInputStream(), "UTF-8"); String entity = IOUtils.toString(request.getInputStream(), "UTF-8");
@ -109,7 +110,7 @@ public class PartitionController {
return "ok"; return "ok";
} }
@RequestMapping("/get") @RequestMapping(value = "/datum", method = RequestMethod.GET)
public void get(HttpServletRequest request, HttpServletResponse response) throws Exception { public void get(HttpServletRequest request, HttpServletResponse response) throws Exception {
String keys = WebUtils.required(request, "keys"); String keys = WebUtils.required(request, "keys");
String keySplitter = ","; String keySplitter = ",";

View File

@ -296,7 +296,7 @@ public class ServiceController {
return result; return result;
} }
@RequestMapping("/serviceStatus") @RequestMapping(value = "/status", method = RequestMethod.POST)
public String serviceStatus(HttpServletRequest request) { public String serviceStatus(HttpServletRequest request) {
//format: service1@@checksum@@@service2@@checksum //format: service1@@checksum@@@service2@@checksum
String statuses = WebUtils.required(request, "statuses"); String statuses = WebUtils.required(request, "statuses");

View File

@ -31,11 +31,11 @@ import java.util.*;
*/ */
public class NamingProxy { public class NamingProxy {
private static final String DATA_ON_SYNC_URL = "/partition/onSync"; private static final String DATA_ON_SYNC_URL = "/partition/datum";
private static final String DATA_GET_URL = "/partition/get"; private static final String DATA_GET_URL = "/partition/datum";
private static final String TIMESTAMP_SYNC_URL = "/partition/syncTimestamps"; private static final String TIMESTAMP_SYNC_URL = "/partition/timestamps";
public static void syncTimestamps(Map<String, String> timestamps, String server) { public static void syncTimestamps(Map<String, String> timestamps, String server) {

View File

@ -41,11 +41,11 @@ public class ServiceStatusSynchronizer implements Synchronizer {
String url = "http://" + serverIP + ":" + RunningConfig.getServerPort() + RunningConfig.getContextPath() + String url = "http://" + serverIP + ":" + RunningConfig.getServerPort() + RunningConfig.getContextPath() +
UtilsAndCommons.NACOS_NAMING_CONTEXT + "/service/serviceStatus"; UtilsAndCommons.NACOS_NAMING_CONTEXT + "/service/status";
if (serverIP.contains(UtilsAndCommons.IP_PORT_SPLITER)) { if (serverIP.contains(UtilsAndCommons.IP_PORT_SPLITER)) {
url = "http://" + serverIP + RunningConfig.getContextPath() + url = "http://" + serverIP + RunningConfig.getContextPath() +
UtilsAndCommons.NACOS_NAMING_CONTEXT + "/service/serviceStatus"; UtilsAndCommons.NACOS_NAMING_CONTEXT + "/service/status";
} }
try { try {

View File

@ -60,7 +60,7 @@ public class AutoDeregisterInstance_ITCase {
NamingBase.prepareServer(port); NamingBase.prepareServer(port);
if (naming == null) { if (naming == null) {
naming = NamingFactory.createNamingService("127.0.0.1" + ":" + port); naming = NamingFactory.createNamingService("127.0.0.1:" + port);
} }
while (true) { while (true) {
@ -174,7 +174,7 @@ public class AutoDeregisterInstance_ITCase {
Assert.assertEquals(instances.size(), 1); Assert.assertEquals(instances.size(), 1);
BeatInfo beatInfo = new BeatInfo(); BeatInfo beatInfo = new BeatInfo();
beatInfo.setServiceName(serviceName); beatInfo.setServiceName(Constants.DEFAULT_GROUP + Constants.SERVICE_INFO_SPLITER + serviceName);
beatInfo.setIp("127.0.0.1"); beatInfo.setIp("127.0.0.1");
beatInfo.setPort(TEST_PORT); beatInfo.setPort(TEST_PORT);
@ -220,12 +220,11 @@ public class AutoDeregisterInstance_ITCase {
Assert.assertEquals(1, instances.size()); Assert.assertEquals(1, instances.size());
BeatInfo beatInfo = new BeatInfo(); BeatInfo beatInfo = new BeatInfo();
beatInfo.setServiceName(serviceName); beatInfo.setServiceName(Constants.DEFAULT_GROUP + Constants.SERVICE_INFO_SPLITER + serviceName);
beatInfo.setIp("127.0.0.1"); beatInfo.setIp("127.0.0.1");
beatInfo.setPort(TEST_PORT); beatInfo.setPort(TEST_PORT);
beatInfo.setCluster("c1"); beatInfo.setCluster("c1");
namingServiceImpl.getBeatReactor(). namingServiceImpl.getBeatReactor().
addBeatInfo(Constants.DEFAULT_GROUP + Constants.SERVICE_INFO_SPLITER + serviceName, beatInfo); addBeatInfo(Constants.DEFAULT_GROUP + Constants.SERVICE_INFO_SPLITER + serviceName, beatInfo);
//TimeUnit.SECONDS.sleep(15); //TimeUnit.SECONDS.sleep(15);
@ -238,10 +237,10 @@ public class AutoDeregisterInstance_ITCase {
instances = naming.getAllInstances(serviceName, Arrays.asList("c2")); instances = naming.getAllInstances(serviceName, Arrays.asList("c2"));
Assert.assertEquals(1, instances.size()); Assert.assertEquals(1, instances.size());
TimeUnit.SECONDS.sleep(5);
instances = naming.getAllInstances(serviceName, Arrays.asList("c1")); instances = naming.getAllInstances(serviceName, Arrays.asList("c1"));
Assert.assertEquals(1, instances.size()); Assert.assertEquals(1, instances.size());
} }
public void verifyInstanceList(List<Instance> instances, int size, String serviceName) throws Exception { public void verifyInstanceList(List<Instance> instances, int size, String serviceName) throws Exception {