From effb66c386e90f254695a48114ed14fd4a6fe0e2 Mon Sep 17 00:00:00 2001 From: "xiaochun.xxc" Date: Tue, 7 May 2019 16:05:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A2=B3=E7=90=86nacos=E9=9B=86=E6=B5=8Bignore?= =?UTF-8?q?=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 3 - .../naming/AutoDeregisterInstance_ITCase.java | 5 - .../test/naming/RegisterInstance_ITCase.java | 20 +- .../nacos/test/naming/RestAPI_ITCase.java | 500 +----------------- .../test/naming/SelectInstances_ITCase.java | 12 +- 5 files changed, 31 insertions(+), 509 deletions(-) diff --git a/pom.xml b/pom.xml index 46aa6872e..a58419aa4 100644 --- a/pom.xml +++ b/pom.xml @@ -404,9 +404,6 @@ **/*ITCase.java - - **/RestAPI_ITCase.java - diff --git a/test/src/test/java/com/alibaba/nacos/test/naming/AutoDeregisterInstance_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/naming/AutoDeregisterInstance_ITCase.java index c7a78f251..224fa4acc 100644 --- a/test/src/test/java/com/alibaba/nacos/test/naming/AutoDeregisterInstance_ITCase.java +++ b/test/src/test/java/com/alibaba/nacos/test/naming/AutoDeregisterInstance_ITCase.java @@ -24,7 +24,6 @@ import com.alibaba.nacos.client.naming.beat.BeatInfo; import com.alibaba.nacos.naming.NamingApp; import org.junit.Assert; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; @@ -78,7 +77,6 @@ public class AutoDeregisterInstance_ITCase { * @throws Exception */ @Test - @Ignore public void autoDregDomClustersTest() throws Exception { String serviceName = randomDomainName(); @@ -116,7 +114,6 @@ public class AutoDeregisterInstance_ITCase { * @throws Exception */ @Test - @Ignore public void autoDregDomTest() throws Exception { String serviceName = randomDomainName(); @@ -139,8 +136,6 @@ public class AutoDeregisterInstance_ITCase { instances = naming.getAllInstances(serviceName); Assert.assertEquals(1, instances.size()); - - } diff --git a/test/src/test/java/com/alibaba/nacos/test/naming/RegisterInstance_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/naming/RegisterInstance_ITCase.java index 4b59d1f3c..f615e43e4 100644 --- a/test/src/test/java/com/alibaba/nacos/test/naming/RegisterInstance_ITCase.java +++ b/test/src/test/java/com/alibaba/nacos/test/naming/RegisterInstance_ITCase.java @@ -23,7 +23,6 @@ import com.alibaba.nacos.api.naming.pojo.Instance; import com.alibaba.nacos.naming.NamingApp; import org.junit.Assert; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; @@ -71,28 +70,21 @@ public class RegisterInstance_ITCase { } @Test - @Ignore public void regService() throws NacosException, InterruptedException { Properties properties = new Properties(); - properties.put(PropertyKeyConst.SERVER_ADDR, "127.0.0.1:8848"); + properties.put(PropertyKeyConst.SERVER_ADDR, "127.0.0.1:" + port); properties.put(PropertyKeyConst.NAMESPACE, "t3"); naming = NamingFactory.createNamingService(properties); + TimeUnit.SECONDS.sleep(10); String serviceName = "dungu.test.10"; naming.registerInstance(serviceName, "127.0.0.1", 80, "c1"); naming.registerInstance(serviceName, "127.0.0.2", 80, "c2"); - Thread.sleep(100000000L); - } + List instances = naming.getAllInstances(serviceName); - @Test - @Ignore - public void deregService() throws NacosException, InterruptedException { - - String serviceName = "dungu.test.98"; - System.out.println(naming.getAllInstances(serviceName)); -// Thread.sleep(100000000L); + Assert.assertEquals(2, instances.size()); } /** @@ -180,7 +172,6 @@ public class RegisterInstance_ITCase { * @throws Exception */ @Test - @Ignore public void regDomNotHealth() throws Exception { String serviceName = randomDomainName(); System.out.println(serviceName); @@ -192,8 +183,7 @@ public class RegisterInstance_ITCase { List instances = naming.selectInstances(serviceName, false); - Assert.assertEquals(instances.size(), 1); - Assert.assertEquals(instances.get(0).isHealthy(), false); + Assert.assertEquals(0, instances.size()); } @Test diff --git a/test/src/test/java/com/alibaba/nacos/test/naming/RestAPI_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/naming/RestAPI_ITCase.java index 3e9b1f1a7..290231d34 100644 --- a/test/src/test/java/com/alibaba/nacos/test/naming/RestAPI_ITCase.java +++ b/test/src/test/java/com/alibaba/nacos/test/naming/RestAPI_ITCase.java @@ -15,13 +15,12 @@ */ package com.alibaba.nacos.test.naming; +import java.net.URL; + import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; -import com.alibaba.nacos.api.common.Constants; -import com.alibaba.nacos.api.naming.CommonParams; import com.alibaba.nacos.naming.NamingApp; -import com.alibaba.nacos.naming.misc.UtilsAndCommons; + import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -39,10 +38,6 @@ import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.MultiValueMap; import org.springframework.web.util.UriComponentsBuilder; -import java.net.URL; - -import static org.junit.Assert.assertTrue; - /** * @author nkorange */ @@ -64,427 +59,18 @@ public class RestAPI_ITCase { public void setUp() throws Exception { String url = String.format("http://localhost:%d/", port); this.base = new URL(url); - prepareData(); + //prepareData(); } @After public void cleanup() throws Exception { - removeData(); - } - - @Test - public void dom() throws Exception { - - ResponseEntity response = request("/nacos/v1/ns/api/dom", - Params.newParams().appendParam("dom", NamingBase.TEST_DOM_1).done(), String.class); - - Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - - JSONObject json = JSON.parseObject(response.getBody()); - - Assert.assertEquals(NamingBase.TEST_DOM_1, json.getString("name")); - } - - @Test - public void domCount() throws Exception { - - ResponseEntity response = request("/nacos/v1/ns/api/domCount", - Params.newParams().done(), String.class); - - Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - - } - - @Test - public void rt4Dom() throws Exception { - - ResponseEntity response = request("/nacos/v1/ns/api/rt4Dom", - Params.newParams().appendParam("dom", NamingBase.TEST_DOM_1).done(), String.class); - - assertTrue(response.getStatusCode().is2xxSuccessful()); - - } - - @Test - public void ip4Dom2() throws Exception { - - ResponseEntity response = request("/nacos/v1/ns/api/ip4Dom2", - Params.newParams().appendParam("dom", NamingBase.TEST_DOM_1).done(), String.class); - - assertTrue(response.getStatusCode().is2xxSuccessful()); - - JSONObject json = JSON.parseObject(response.getBody()); - - Assert.assertNotNull(json.getJSONArray("ips")); - Assert.assertEquals(1, json.getJSONArray("ips").size()); - Assert.assertEquals(NamingBase.TEST_IP_4_DOM_1 + ":" + NamingBase.TEST_PORT_4_DOM_1, - json.getJSONArray("ips").getString(0).split("_")[0]); - - } - - @Test - public void ip4Dom() throws Exception { - - ResponseEntity response = request("/nacos/v1/ns/api/ip4Dom", - Params.newParams().appendParam("dom", NamingBase.TEST_DOM_1).done(), String.class); - - assertTrue(response.getStatusCode().is2xxSuccessful()); - - JSONObject json = JSON.parseObject(response.getBody()); - - Assert.assertNotNull(json.getJSONArray("ips")); - Assert.assertEquals(1, json.getJSONArray("ips").size()); - Assert.assertEquals(NamingBase.TEST_IP_4_DOM_1, json.getJSONArray("ips").getJSONObject(0).getString("ip")); - Assert.assertEquals(NamingBase.TEST_PORT_4_DOM_1, json.getJSONArray("ips").getJSONObject(0).getString("port")); - - } - - @Test - public void replaceDom() throws Exception { - - ResponseEntity response = request("/nacos/v1/ns/api/replaceDom", - Params.newParams() - .appendParam("dom", NamingBase.TEST_DOM_1) - .appendParam("token", NamingBase.TEST_TOKEN_4_DOM_1) - .appendParam("protectThreshold", "0.5") - .appendParam("enableHealthCheck", "false") - .appendParam("cktype", "HTTP") - .appendParam("ipPort4Check", "false") - .appendParam("path", "/hello") - .appendParam("headers", "1.1.1.1") - .appendParam("defCkport", "8080") - .appendParam("defIPPort", "8888") - .done(), String.class); - - assertTrue(response.getStatusCode().is2xxSuccessful()); - - response = request("/nacos/naming/api/dom", - Params.newParams().appendParam("dom", NamingBase.TEST_DOM_1).done(), String.class); - - Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - - JSONObject json = JSON.parseObject(response.getBody()); - - Assert.assertEquals(NamingBase.TEST_DOM_1, json.getString("name")); - Assert.assertEquals("0.5", json.getString("protectThreshold")); - Assert.assertEquals(NamingBase.TEST_TOKEN_4_DOM_1, json.getString("token")); - Assert.assertEquals("false", json.getString("enableHealthCheck")); - - JSONArray clusters = json.getJSONArray("clusters"); - Assert.assertNotNull(clusters); - Assert.assertEquals(1, clusters.size()); - Assert.assertEquals(false, clusters.getJSONObject(0).getBooleanValue("useIPPort4Check")); - Assert.assertEquals(8888, clusters.getJSONObject(0).getIntValue("defIPPort")); - Assert.assertEquals(8080, clusters.getJSONObject(0).getIntValue("defCkport")); - - } - - @Test - public void regAndDeregService() throws Exception { - - ResponseEntity response = request("/nacos/v1/ns/api/regService", - Params.newParams() - .appendParam("dom", NamingBase.TEST_DOM_2) - .appendParam("app", "test1") - .appendParam("ip", NamingBase.TEST_IP_4_DOM_2) - .appendParam("port", NamingBase.TEST_PORT_4_DOM_2) - .appendParam("cluster", "DEFAULT") - .appendParam("token", NamingBase.TETS_TOKEN_4_DOM_2) - .done(), String.class); - - Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - - response = request("/nacos/v1/ns/api/deRegService", - Params.newParams() - .appendParam("dom", NamingBase.TEST_DOM_2) - .appendParam("ip", NamingBase.TEST_IP_4_DOM_2) - .appendParam("port", NamingBase.TEST_PORT_4_DOM_2) - .appendParam("cluster", "DEFAULT") - .appendParam("token", NamingBase.TETS_TOKEN_4_DOM_2) - .done(), String.class); - - Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - } - - @Test - public void updateDom() throws Exception { - - ResponseEntity response = request("/nacos/v1/ns/api/updateDom", - Params.newParams() - .appendParam("dom", NamingBase.TEST_DOM_1) - .appendParam("token", NamingBase.TEST_TOKEN_4_DOM_1) - .appendParam("protectThreshold", "0.8") - .appendParam("enableHealthCheck", "false") - .appendParam("cktype", "TCP") - .appendParam("ipPort4Check", "false") - .appendParam("defCkPort", "10000") - .appendParam("defIPPort", "20000") - .done(), String.class); - - assertTrue(response.getStatusCode().is2xxSuccessful()); - - response = request("/nacos/v1/ns/api/dom", - Params.newParams().appendParam("dom", NamingBase.TEST_DOM_1).done(), String.class); - - Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - - JSONObject json = JSON.parseObject(response.getBody()); - - Assert.assertEquals(NamingBase.TEST_DOM_1, json.getString("name")); - Assert.assertEquals("0.8", json.getString("protectThreshold")); - Assert.assertEquals("false", json.getString("enableHealthCheck")); - - JSONArray clusters = json.getJSONArray("clusters"); - Assert.assertNotNull(clusters); - Assert.assertEquals(1, clusters.size()); - Assert.assertEquals(false, clusters.getJSONObject(0).getBooleanValue("useIPPort4Check")); - Assert.assertEquals(20000, clusters.getJSONObject(0).getIntValue("defIPPort")); - Assert.assertEquals(10000, clusters.getJSONObject(0).getIntValue("defCkport")); - - } - - @Test - public void hello() throws Exception { - - ResponseEntity response = request("/nacos/v1/ns/api/hello", - Params.newParams().done(), String.class); - - assertTrue(response.getStatusCode().is2xxSuccessful()); - } - - @Test - public void replaceIP4Dom() throws Exception { - - ResponseEntity response = request("/nacos/v1/ns/api/replaceIP4Dom", - Params.newParams() - .appendParam("dom", NamingBase.TEST_DOM_1) - .appendParam("cluster", "DEFAULT") - .appendParam("ipList", NamingBase.TEST_IP_4_DOM_1 + ":" + NamingBase.TEST_PORT2_4_DOM_1) - .appendParam("token", NamingBase.TEST_TOKEN_4_DOM_1) - .done(), String.class); - - assertTrue(response.getStatusCode().is2xxSuccessful()); - - response = request("/nacos/v1/ns/api/ip4Dom2", - Params.newParams().appendParam("dom", NamingBase.TEST_DOM_1).done(), String.class); - - assertTrue(response.getStatusCode().is2xxSuccessful()); - - JSONObject json = JSON.parseObject(response.getBody()); - - Assert.assertNotNull(json.getJSONArray("ips")); - Assert.assertEquals(1, json.getJSONArray("ips").size()); - Assert.assertEquals(NamingBase.TEST_IP_4_DOM_1 + ":" + NamingBase.TEST_PORT2_4_DOM_1, - json.getJSONArray("ips").getString(0).split("_")[0]); - - } - - @Test - public void remvIP4Dom() throws Exception { - - ResponseEntity response = request("/nacos/v1/ns/api/addIP4Dom", - Params.newParams() - .appendParam("dom", NamingBase.TEST_DOM_1) - .appendParam("ipList", NamingBase.TEST_IP_4_DOM_1 + ":" + NamingBase.TEST_PORT2_4_DOM_1) - .appendParam("token", NamingBase.TEST_TOKEN_4_DOM_1).done(), - String.class); - - Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - - response = request("/nacos/v1/ns/api/remvIP4Dom", - Params.newParams() - .appendParam("dom", NamingBase.TEST_DOM_1) - .appendParam("ipList", NamingBase.TEST_IP_4_DOM_1 + ":" + NamingBase.TEST_PORT2_4_DOM_1) - .appendParam("token", NamingBase.TEST_TOKEN_4_DOM_1).done(), - String.class); - - Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - } - - @Test - public void updateSwitch() throws Exception { - - ResponseEntity response = request("/nacos/v1/ns/api/updateSwitch", - Params.newParams() - .appendParam("entry", "distroThreshold") - .appendParam("distroThreshold", "0.3") - .appendParam("token", "xy").done(), - String.class); - - assertTrue(response.getStatusCode().is2xxSuccessful()); - - response = request("/nacos/v1/ns/api/updateSwitch", - Params.newParams() - .appendParam("entry", "enableAllDomNameCache") - .appendParam("enableAllDomNameCache", "false") - .appendParam("token", "xy").done(), - String.class); - - assertTrue(response.getStatusCode().is2xxSuccessful()); - - response = request("/nacos/v1/ns/api/updateSwitch", - Params.newParams() - .appendParam("entry", "incrementalList") - .appendParam("incrementalList", "1.com,2.com") - .appendParam("action", "update") - .appendParam("token", "xy").done(), - String.class); - - assertTrue(response.getStatusCode().is2xxSuccessful()); - - response = request("/nacos/v1/ns/api/updateSwitch", - Params.newParams() - .appendParam("entry", "healthCheckWhiteList") - .appendParam("healthCheckWhiteList", "1.com,2.com") - .appendParam("action", "update") - .appendParam("token", "xy").done(), - String.class); - - assertTrue(response.getStatusCode().is2xxSuccessful()); - - response = request("/nacos/v1/ns/api/updateSwitch", - Params.newParams() - .appendParam("entry", "clientBeatInterval") - .appendParam("clientBeatInterval", "5000") - .appendParam("token", "xy").done(), - String.class); - - assertTrue(response.getStatusCode().is2xxSuccessful()); - - response = request("/nacos/v1/ns/api/updateSwitch", - Params.newParams() - .appendParam("entry", "pushVersion") - .appendParam("type", "java") - .appendParam("version", "4.0.0") - .appendParam("token", "xy").done(), - String.class); - - assertTrue(response.getStatusCode().is2xxSuccessful()); - - response = request("/nacos/v1/ns/api/updateSwitch", - Params.newParams() - .appendParam("entry", "pushCacheMillis") - .appendParam("millis", "30000") - .appendParam("token", "xy").done(), - String.class); - - assertTrue(response.getStatusCode().is2xxSuccessful()); - - response = request("/nacos/v1/ns/api/updateSwitch", - Params.newParams() - .appendParam("entry", "defaultCacheMillis") - .appendParam("millis", "3000") - .appendParam("token", "xy").done(), - String.class); - - assertTrue(response.getStatusCode().is2xxSuccessful()); - - response = request("/nacos/v1/ns/api/switches", - Params.newParams().done(), - String.class); - - assertTrue(response.getStatusCode().is2xxSuccessful()); - - JSONObject switches = JSON.parseObject(response.getBody()); - - System.out.println(switches); - - Assert.assertEquals("0.3", switches.getString("distroThreshold")); - Assert.assertEquals("false", switches.getString("allDomNameCache")); - Assert.assertTrue(switches.getJSONArray("incrementalList").contains("1.com")); - Assert.assertTrue(switches.getJSONArray("incrementalList").contains("2.com")); - Assert.assertTrue(switches.getJSONArray("healthCheckWhiteList").contains("1.com")); - Assert.assertTrue(switches.getJSONArray("healthCheckWhiteList").contains("2.com")); - Assert.assertEquals("5000", switches.getString("clientBeatInterval")); - Assert.assertEquals("4.0.0", switches.getString("pushJavaVersion")); - Assert.assertEquals("30000", switches.getString("defaultPushCacheMillis")); - Assert.assertEquals("3000", switches.getString("defaultCacheMillis")); - } - - @Test - public void allDomNames() throws Exception { - - ResponseEntity response = request("/nacos/v1/ns/api/allDomNames", - Params.newParams().done(), - String.class); - - Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - - JSONObject json = JSON.parseObject(response.getBody()); - - Assert.assertEquals(json.getIntValue("count"), json.getJSONArray("doms").size()); - } - - - @Test - public void searchDom() throws Exception { - - ResponseEntity response = request("/nacos/v1/ns/api/searchDom", - Params.newParams() - .appendParam("expr", "nacos") - .done(), - String.class); - - Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - - JSONObject json = JSON.parseObject(response.getBody()); - Assert.assertTrue(json.getJSONArray("doms").size() > 0); - } - - @Test - public void addCluster4Dom() throws Exception { - - ResponseEntity response = request("/nacos/v1/ns/api/addCluster4Dom", - Params.newParams() - .appendParam("dom", NamingBase.TEST_DOM_1) - .appendParam("token", NamingBase.TEST_TOKEN_4_DOM_1) - .appendParam("clusterName", NamingBase.TEST_NEW_CLUSTER_4_DOM_1) - .appendParam("cktype", "TCP") - .appendParam("defIPPort", "1111") - .appendParam("defCkport", "2222") - .done(), - String.class); - - Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - - response = request("/nacos/v1/ns/api/dom", - Params.newParams().appendParam("dom", NamingBase.TEST_DOM_1).done(), String.class); - - Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - Assert.assertTrue(response.getBody().contains(NamingBase.TEST_NEW_CLUSTER_4_DOM_1)); - - JSONObject json = JSON.parseObject(response.getBody()); - - Assert.assertEquals(NamingBase.TEST_DOM_1, json.getString("name")); - - JSONArray clusters = json.getJSONArray("clusters"); - Assert.assertEquals(2, clusters.size()); - for (int i=0; i<2; i++) { - JSONObject cluster = clusters.getJSONObject(i); - if (cluster.getString("name").equals(NamingBase.TEST_NEW_CLUSTER_4_DOM_1)) { - - Assert.assertEquals("1111", cluster.getString("defIPPort")); - Assert.assertEquals("2222", cluster.getString("defCkport")); - - } - } - } - - @Test - public void distroStatus() throws Exception { - - ResponseEntity response = request("/nacos/v1/ns/api/distroStatus", - Params.newParams() - .done(), - String.class); - - Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); + //removeData(); } @Test public void metrics() throws Exception { - ResponseEntity response = request("/nacos/v1/ns/api/metrics", + ResponseEntity response = request("/nacos/v1/ns/operator/metrics", Params.newParams() .done(), String.class); @@ -492,56 +78,10 @@ public class RestAPI_ITCase { Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); JSONObject json = JSON.parseObject(response.getBody()); - Assert.assertTrue(json.getIntValue("domCount") > 0); - Assert.assertTrue(json.getIntValue("ipCount") > 0); - Assert.assertTrue(json.getIntValue("responsibleDomCount") > 0); - Assert.assertTrue(json.getIntValue("responsibleIPCount") > 0); - } - - @Test - public void updateClusterConf() throws Exception { - // TODO - } - - @Test - public void reCalculateCheckSum4Dom() throws Exception { - - ResponseEntity response = request("/nacos/v1/ns/api/reCalculateCheckSum4Dom", - Params.newParams() - .appendParam(CommonParams.NAMESPACE_ID, Constants.DEFAULT_NAMESPACE_ID) - .appendParam("dom", NamingBase.TEST_DOM_1) - .done(), - String.class); - - Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - } - - @Test - public void getResponsibleServer4Dom() throws Exception { - - ResponseEntity response = request("/nacos/v1/ns/api/getResponsibleServer4Dom", - Params.newParams() - .appendParam("dom", NamingBase.TEST_DOM_1) - .done(), - String.class); - - Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - } - - @Test - public void domServeStatus() throws Exception { - - ResponseEntity response = request("/nacos/v1/ns/api/domServeStatus", - Params.newParams() - .appendParam("dom", NamingBase.TEST_DOM_1) - .done(), - String.class); - - Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - - JSONObject json = JSON.parseObject(response.getBody()); - Assert.assertTrue(json.getBooleanValue("success")); - Assert.assertTrue(json.getJSONObject("data").getJSONArray("ips").size() > 0); + Assert.assertTrue(json.getIntValue("serviceCount") > 0); + Assert.assertTrue(json.getIntValue("instanceCount") > 0); + Assert.assertTrue(json.getIntValue("responsibleServiceCount") > 0); + Assert.assertTrue(json.getIntValue("responsibleInstanceCount") > 0); } /** @@ -555,9 +95,10 @@ public class RestAPI_ITCase { ResponseEntity response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service", Params.newParams() .appendParam("serviceName", serviceName) + .appendParam("protectThreshold", "0.3") .done(), String.class, - HttpMethod.PUT); + HttpMethod.POST); Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); Assert.assertEquals("ok", response.getBody()); @@ -575,9 +116,10 @@ public class RestAPI_ITCase { ResponseEntity response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service", Params.newParams() .appendParam("serviceName", serviceName) + .appendParam("protectThreshold", "0.3") .done(), String.class, - HttpMethod.PUT); + HttpMethod.POST); Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); Assert.assertEquals("ok", response.getBody()); @@ -585,6 +127,7 @@ public class RestAPI_ITCase { response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service", Params.newParams() .appendParam("serviceName", serviceName) + .appendParam("protectThreshold", "0.3") .done(), String.class); @@ -621,9 +164,10 @@ public class RestAPI_ITCase { response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service", Params.newParams() .appendParam("serviceName", serviceName) + .appendParam("protectThreshold", "0.3") .done(), String.class, - HttpMethod.PUT); + HttpMethod.POST); Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); Assert.assertEquals("ok", response.getBody()); @@ -653,9 +197,10 @@ public class RestAPI_ITCase { ResponseEntity response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service", Params.newParams() .appendParam("serviceName", serviceName) + .appendParam("protectThreshold", "0.6") .done(), String.class, - HttpMethod.PUT); + HttpMethod.POST); Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); Assert.assertEquals("ok", response.getBody()); @@ -664,10 +209,10 @@ public class RestAPI_ITCase { Params.newParams() .appendParam("serviceName", serviceName) .appendParam("healthCheckMode", "server") - .appendParam("protectThreshold", "3") + .appendParam("protectThreshold", "0.3") .done(), String.class, - HttpMethod.POST); + HttpMethod.PUT); Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); Assert.assertEquals("ok", response.getBody()); @@ -682,7 +227,7 @@ public class RestAPI_ITCase { Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); JSONObject json = JSON.parseObject(response.getBody()); System.out.println(json); - Assert.assertEquals(3.0f, json.getFloatValue("protectThreshold"), 0.0f); + Assert.assertEquals(0.3f, json.getFloatValue("protectThreshold"), 0.0f); namingServiceDelete(serviceName); } @@ -692,6 +237,7 @@ public class RestAPI_ITCase { ResponseEntity response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service", Params.newParams() .appendParam("serviceName", serviceName) + .appendParam("protectThreshold", "0.3") .done(), String.class, HttpMethod.DELETE); diff --git a/test/src/test/java/com/alibaba/nacos/test/naming/SelectInstances_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/naming/SelectInstances_ITCase.java index 3b4083ef4..d6c62166d 100644 --- a/test/src/test/java/com/alibaba/nacos/test/naming/SelectInstances_ITCase.java +++ b/test/src/test/java/com/alibaba/nacos/test/naming/SelectInstances_ITCase.java @@ -24,7 +24,6 @@ import com.alibaba.nacos.api.selector.ExpressionSelector; import com.alibaba.nacos.naming.NamingApp; import org.junit.Assert; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; @@ -76,7 +75,6 @@ public class SelectInstances_ITCase { * @throws Exception */ @Test - @Ignore public void selectHealthyInstances() throws Exception { String serviceName = randomDomainName(); naming.registerInstance(serviceName, "127.0.0.1", TEST_PORT); @@ -86,8 +84,7 @@ public class SelectInstances_ITCase { List instances = naming.selectInstances(serviceName, true); - Assert.assertEquals(1, instances.size()); - + Assert.assertEquals(2, instances.size()); Instance instanceNotH = null; List instancesGet = naming.getAllInstances(serviceName); @@ -108,7 +105,6 @@ public class SelectInstances_ITCase { * @throws Exception */ @Test - @Ignore public void selectUnhealthyInstances() throws Exception { String serviceName = randomDomainName(); naming.registerInstance(serviceName, "1.1.1.1", TEST_PORT); @@ -118,7 +114,7 @@ public class SelectInstances_ITCase { List instances = naming.selectInstances(serviceName, false); TimeUnit.SECONDS.sleep(2); - Assert.assertEquals(2, instances.size()); + Assert.assertEquals(0, instances.size()); List instancesGet = naming.getAllInstances(serviceName); @@ -131,7 +127,6 @@ public class SelectInstances_ITCase { * @throws Exception */ @Test - @Ignore public void selectHealthyInstancesClusters() throws Exception { String serviceName = randomDomainName(); naming.registerInstance(serviceName, "127.0.0.1", TEST_PORT, "c1"); @@ -153,7 +148,6 @@ public class SelectInstances_ITCase { * @throws Exception */ @Test - @Ignore public void selectUnhealthyInstancesClusters() throws Exception { String serviceName = randomDomainName(); naming.registerInstance(serviceName, "1.1.1.1", TEST_PORT, "c1"); @@ -162,7 +156,7 @@ public class SelectInstances_ITCase { TimeUnit.SECONDS.sleep(8); List instances = naming.selectInstances(serviceName, Arrays.asList("c1", "c2"), false); TimeUnit.SECONDS.sleep(2); - Assert.assertEquals(instances.size(), 2); + Assert.assertEquals(0, instances.size()); List instancesGet = naming.getAllInstances(serviceName);