From 4a2e1be84a127750b351e9910ed4c9465b32a9e6 Mon Sep 17 00:00:00 2001 From: "xiaochun.xxc" Date: Fri, 8 Mar 2019 16:52:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8E=A5=E5=8F=A3=E7=94=A8?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/naming/CPInstancesAPI_ITCase.java | 56 +++++++++++++++++-- 1 file changed, 51 insertions(+), 5 deletions(-) diff --git a/test/src/test/java/com/alibaba/nacos/test/naming/CPInstancesAPI_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/naming/CPInstancesAPI_ITCase.java index 05e1b3d67..03bff96a5 100644 --- a/test/src/test/java/com/alibaba/nacos/test/naming/CPInstancesAPI_ITCase.java +++ b/test/src/test/java/com/alibaba/nacos/test/naming/CPInstancesAPI_ITCase.java @@ -16,6 +16,7 @@ package com.alibaba.nacos.test.naming; import java.net.URL; +import java.util.List; import java.util.Properties; import java.util.concurrent.TimeUnit; @@ -28,6 +29,7 @@ import com.alibaba.nacos.api.naming.CommonParams; import com.alibaba.nacos.api.naming.NamingFactory; import com.alibaba.nacos.api.naming.NamingService; import com.alibaba.nacos.api.naming.pojo.Instance; +import com.alibaba.nacos.api.naming.pojo.ListView; import com.alibaba.nacos.naming.NamingApp; import org.junit.After; @@ -151,7 +153,7 @@ public class CPInstancesAPI_ITCase { instance.setPort(80); naming1.registerInstance(serviceName, TEST_GROUP_1, instance); naming1.deregisterInstance(serviceName, TEST_GROUP_1, "11.11.11.11", 80, "c1"); - + namingServiceDelete(serviceName, TEST_NAMESPACE_1, TEST_GROUP_1); } @@ -192,7 +194,7 @@ public class CPInstancesAPI_ITCase { } /** - * @TCDescription : 根据serviceName修改服务,并获取服务信息 + * @TCDescription : 根据serviceName修改服务,并通过HTTP接口获取服务信息 * @TestStep : * @ExpectResult : */ @@ -205,7 +207,7 @@ public class CPInstancesAPI_ITCase { Params.newParams() .appendParam("serviceName", serviceName) .appendParam("namespaceId", TEST_NAMESPACE_1) - .appendParam("protectThreshold", "9.0") + .appendParam("protectThreshold", "0.5") .done(), String.class, HttpMethod.PUT); @@ -224,7 +226,26 @@ public class CPInstancesAPI_ITCase { JSONObject json = JSON.parseObject(response.getBody()); Assert.assertEquals(serviceName, json.getString("name")); - Assert.assertEquals("9.0", json.getString("protectThreshold")); + Assert.assertEquals("0.5", json.getString("protectThreshold")); + + namingServiceDelete(serviceName, TEST_NAMESPACE_1); + } + + /** + * @TCDescription : 根据serviceName修改服务,并通过接口获取服务信息 + * @TestStep : + * @ExpectResult : + */ + @Test + public void getService_1() throws Exception { + String serviceName = NamingBase.randomDomainName(); + ListView listView = naming1.getServicesOfServer(1, 20); + + namingServiceCreate(serviceName, TEST_NAMESPACE_1); + TimeUnit.SECONDS.sleep(5L); + + ListView listView1 = naming1.getServicesOfServer(1, 20); + Assert.assertEquals(listView.getCount()+1, listView1.getCount()); namingServiceDelete(serviceName, TEST_NAMESPACE_1); } @@ -284,6 +305,31 @@ public class CPInstancesAPI_ITCase { namingServiceDelete(serviceName, Constants.DEFAULT_NAMESPACE_ID); } + /** + * @TCDescription : 根据serviceName创建服务,注册持久化实例, 查询实例,注销实例,删除服务 + * @TestStep : + * @ExpectResult : + */ + @Test + public void registerInstance_query() throws Exception { + String serviceName = NamingBase.randomDomainName(); + namingServiceCreate(serviceName, Constants.DEFAULT_NAMESPACE_ID); + + instanceRegister(serviceName, Constants.DEFAULT_NAMESPACE_ID, "33.33.33.33", TEST_PORT2_4_DOM_1); + + List instances = naming.getAllInstances(serviceName); + Assert.assertEquals(1, instances.size()); + Assert.assertEquals("33.33.33.33", instances.get(0).getIp()); + + instanceDeregister(serviceName, Constants.DEFAULT_NAMESPACE_ID, "33.33.33.33", TEST_PORT2_4_DOM_1); + + TimeUnit.SECONDS.sleep(3L); + instances = naming.getAllInstances(serviceName); + Assert.assertEquals(0, instances.size()); + + namingServiceDelete(serviceName, Constants.DEFAULT_NAMESPACE_ID); + } + /** * @TCDescription : 根据serviceName创建服务,注册不同group的2个持久化实例, 注销实例,删除服务 * @TestStep : @@ -358,7 +404,7 @@ public class CPInstancesAPI_ITCase { ResponseEntity response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service", Params.newParams() .appendParam("serviceName", serviceName) - .appendParam("protectThreshold", "3") + .appendParam("protectThreshold", "0.3") .appendParam("namespaceId", namespace) .appendParam("groupName", groupName) .done(),