Skip to content

Commit

Permalink
#269 fix test case bug
Browse files Browse the repository at this point in the history
  • Loading branch information
nkorange committed Mar 5, 2019
1 parent 42cd539 commit a4155fd
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.naming.CommonParams;
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.core.DistroMapper;
import com.alibaba.nacos.naming.core.Instance;
import com.alibaba.nacos.naming.core.Service;
import com.alibaba.nacos.naming.core.ServiceManager;
import com.alibaba.nacos.naming.exception.NacosException;
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.SwitchDomain;
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
Expand All @@ -45,7 +43,6 @@
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.util.*;

Expand Down Expand Up @@ -251,30 +248,7 @@ public JSONObject beat(HttpServletRequest request) throws Exception {
throw new NacosException(NacosException.SERVER_ERROR, "service not found: " + serviceName + "@" + namespaceId);
}

if (!distroMapper.responsible(serviceName)) {
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);
}
service.processClientBeat(clientBeat);

return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -61,8 +62,8 @@ public class PartitionController {
@Autowired
private SwitchDomain switchDomain;

@RequestMapping("/onSync")
public String onSync(HttpServletRequest request, HttpServletResponse response) throws Exception {
@RequestMapping(value = "/datum", method = RequestMethod.PUT)
public String onSyncDatum(HttpServletRequest request, HttpServletResponse response) throws Exception {

String entity = IOUtils.toString(request.getInputStream(), "UTF-8");

Expand All @@ -88,7 +89,7 @@ public String onSync(HttpServletRequest request, HttpServletResponse response) t
return "ok";
}

@RequestMapping("/syncTimestamps")
@RequestMapping(value = "/timestamps", method = RequestMethod.PUT)
public String syncTimestamps(HttpServletRequest request, HttpServletResponse response) throws Exception {
String source = WebUtils.required(request, "source");
String entity = IOUtils.toString(request.getInputStream(), "UTF-8");
Expand All @@ -109,7 +110,7 @@ public String syncTimestamps(HttpServletRequest request, HttpServletResponse res
return "ok";
}

@RequestMapping("/get")
@RequestMapping(value = "/datum", method = RequestMethod.GET)
public void get(HttpServletRequest request, HttpServletResponse response) throws Exception {
String keys = WebUtils.required(request, "keys");
String keySplitter = ",";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ public JSONObject searchService(HttpServletRequest request) {
return result;
}

@RequestMapping("/serviceStatus")
@RequestMapping(value = "/status", method = RequestMethod.POST)
public String serviceStatus(HttpServletRequest request) {
//format: service1@@checksum@@@service2@@checksum
String statuses = WebUtils.required(request, "statuses");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
*/
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) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ public void send(final String serverIP, Message msg) {


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)) {
url = "http://" + serverIP + RunningConfig.getContextPath() +
UtilsAndCommons.NACOS_NAMING_CONTEXT + "/service/serviceStatus";
UtilsAndCommons.NACOS_NAMING_CONTEXT + "/service/status";
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void init() throws Exception {
NamingBase.prepareServer(port);

if (naming == null) {
naming = NamingFactory.createNamingService("127.0.0.1" + ":" + port);
naming = NamingFactory.createNamingService("127.0.0.1:" + port);
}

while (true) {
Expand Down Expand Up @@ -174,7 +174,7 @@ public void autoRegDomTest() throws Exception {

Assert.assertEquals(instances.size(), 1);
BeatInfo beatInfo = new BeatInfo();
beatInfo.setServiceName(serviceName);
beatInfo.setServiceName(Constants.DEFAULT_GROUP + Constants.SERVICE_INFO_SPLITER + serviceName);
beatInfo.setIp("127.0.0.1");
beatInfo.setPort(TEST_PORT);

Expand Down Expand Up @@ -220,12 +220,11 @@ public void autoRegDomClustersTest() throws Exception {

Assert.assertEquals(1, instances.size());
BeatInfo beatInfo = new BeatInfo();
beatInfo.setServiceName(serviceName);
beatInfo.setServiceName(Constants.DEFAULT_GROUP + Constants.SERVICE_INFO_SPLITER + serviceName);
beatInfo.setIp("127.0.0.1");
beatInfo.setPort(TEST_PORT);
beatInfo.setCluster("c1");


namingServiceImpl.getBeatReactor().
addBeatInfo(Constants.DEFAULT_GROUP + Constants.SERVICE_INFO_SPLITER + serviceName, beatInfo);
//TimeUnit.SECONDS.sleep(15);
Expand All @@ -238,10 +237,10 @@ public void autoRegDomClustersTest() throws Exception {
instances = naming.getAllInstances(serviceName, Arrays.asList("c2"));
Assert.assertEquals(1, instances.size());

TimeUnit.SECONDS.sleep(5);

instances = naming.getAllInstances(serviceName, Arrays.asList("c1"));
Assert.assertEquals(1, instances.size());


}

public void verifyInstanceList(List<Instance> instances, int size, String serviceName) throws Exception {
Expand Down

0 comments on commit a4155fd

Please sign in to comment.