From dd9866a049b950384cc4ca0e3d211f57cc93c68a Mon Sep 17 00:00:00 2001 From: "xiaochun.xxc" Date: Tue, 5 Mar 2019 11:07:01 +0800 Subject: [PATCH] add group testcase --- .../nacos/test/naming/MultiTenant_ITCase.java | 116 +++++++++++++++++- .../alibaba/nacos/test/naming/NamingBase.java | 4 + 2 files changed, 118 insertions(+), 2 deletions(-) diff --git a/test/src/test/java/com/alibaba/nacos/test/naming/MultiTenant_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/naming/MultiTenant_ITCase.java index aeaaa4508..13f37e3fd 100644 --- a/test/src/test/java/com/alibaba/nacos/test/naming/MultiTenant_ITCase.java +++ b/test/src/test/java/com/alibaba/nacos/test/naming/MultiTenant_ITCase.java @@ -7,6 +7,7 @@ import java.util.Properties; import java.util.concurrent.TimeUnit; import com.alibaba.nacos.api.PropertyKeyConst; +import com.alibaba.nacos.api.common.Constants; import com.alibaba.nacos.api.naming.NamingFactory; import com.alibaba.nacos.api.naming.NamingService; import com.alibaba.nacos.api.naming.listener.Event; @@ -44,7 +45,7 @@ public class MultiTenant_ITCase { @Before public void init() throws Exception { - + Thread.sleep(6000L); NamingBase.prepareServer(port); naming = NamingFactory.createNamingService("127.0.0.1" + ":" + port); @@ -101,6 +102,38 @@ public class MultiTenant_ITCase { Assert.assertEquals(2, instances.size()); } + /** + * @TCDescription : 多Group注册实例 + * @TestStep : + * @ExpectResult : + */ + @Test + public void multipleTenant_multiGroup_registerInstance() throws Exception { + String serviceName = randomDomainName(); + + naming1.registerInstance(serviceName, TEST_GROUP_1,"11.11.11.11", 80); + + naming2.registerInstance(serviceName, TEST_GROUP_2,"22.22.22.22", 80); + + naming.registerInstance(serviceName, "33.33.33.33", 8888); + naming.registerInstance(serviceName, "44.44.44.44", 8888); + + TimeUnit.SECONDS.sleep(5L); + + List instances = naming1.getAllInstances(serviceName); + Assert.assertEquals(1, instances.size()); + Assert.assertEquals("11.11.11.11", instances.get(0).getIp()); + Assert.assertEquals(80, instances.get(0).getPort()); + + instances = naming2.getAllInstances(serviceName); + Assert.assertEquals(1, instances.size()); + Assert.assertEquals("22.22.22.22", instances.get(0).getIp()); + Assert.assertEquals(80, instances.get(0).getPort()); + + instances = naming.getAllInstances(serviceName); + Assert.assertEquals(2, instances.size()); + } + /** * @TCDescription : 多租户注册IP,port相同的实例 * @TestStep : @@ -109,7 +142,6 @@ public class MultiTenant_ITCase { @Test public void multipleTenant_equalIP() throws Exception { String serviceName = randomDomainName(); - System.out.println(serviceName); naming1.registerInstance(serviceName, "11.11.11.11", 80); naming2.registerInstance(serviceName, "11.11.11.11", 80); @@ -165,6 +197,64 @@ public class MultiTenant_ITCase { Assert.assertEquals(2, instances.size()); } + /** + * @TCDescription : 多租户,多Group注册IP,port相同的实例 + * @TestStep : + * @ExpectResult : + */ + @Test + public void multipleTenant_group_equalIP() throws Exception { + String serviceName = randomDomainName(); + System.out.println(serviceName); + naming1.registerInstance(serviceName, TEST_GROUP_1,"11.11.11.11", 80); + + naming2.registerInstance(serviceName, TEST_GROUP_2,"11.11.11.11", 80); + + naming.registerInstance(serviceName, Constants.DEFAULT_GROUP,"11.11.11.11", 80); + + TimeUnit.SECONDS.sleep(5L); + + List instances = naming1.getAllInstances(serviceName); + + Assert.assertEquals(1, instances.size()); + Assert.assertEquals("11.11.11.11", instances.get(0).getIp()); + Assert.assertEquals(80, instances.get(0).getPort()); + + instances = naming2.getAllInstances(serviceName); + + Assert.assertEquals(1, instances.size()); + Assert.assertEquals("11.11.11.11", instances.get(0).getIp()); + Assert.assertEquals(80, instances.get(0).getPort()); + + instances = naming.getAllInstances(serviceName); + Assert.assertEquals(1, instances.size()); + } + + /** + * @TCDescription : 多租户,多Group注册IP,port相同的实例, 通过group获取实例 + * @TestStep : + * @ExpectResult : + */ + @Test + public void multipleTenant_group_getInstances() throws Exception { + String serviceName = randomDomainName(); + naming1.registerInstance(serviceName, TEST_GROUP_1,"11.11.11.22", 80); + naming1.registerInstance(serviceName, TEST_GROUP_2,"11.11.11.11", 80); + + naming.registerInstance(serviceName, Constants.DEFAULT_GROUP,"11.11.11.33", 80); + + TimeUnit.SECONDS.sleep(5L); + + List instances = naming1.getAllInstances(serviceName); + + Assert.assertEquals(1, instances.size()); + Assert.assertEquals("11.11.11.11", instances.get(0).getIp()); + Assert.assertEquals(80, instances.get(0).getPort()); + + instances = naming.getAllInstances(serviceName); + Assert.assertEquals(1, instances.size()); + } + /** * @TCDescription : 多租户同服务获取实例 * @TestStep : @@ -185,6 +275,28 @@ public class MultiTenant_ITCase { Assert.assertEquals(listView.getCount(), listView1.getCount()); } + /** + * @TCDescription : 多租户, 多group,同服务获取实例 + * @TestStep : + * @ExpectResult : + */ + @Test + public void multipleTenant_group_getServicesOfServer() throws Exception { + + String serviceName = randomDomainName(); + naming1.registerInstance(serviceName, "11.11.11.11", TEST_GROUP_1, TEST_PORT, "c1"); + naming1.registerInstance(serviceName, "22.22.22.22", TEST_GROUP_2, TEST_PORT, "c1"); + TimeUnit.SECONDS.sleep(5L); + + ListView listView = naming1.getServicesOfServer(1, 20); + Assert.assertEquals(0, listView.getCount()); + + naming2.registerInstance(serviceName, "33.33.33.33", TEST_PORT, "c1"); + TimeUnit.SECONDS.sleep(5L); + ListView listView1 = naming1.getServicesOfServer(1, 20, TEST_GROUP_1); + Assert.assertEquals(listView.getCount(), listView1.getCount()); + } + /** * @TCDescription : 多租户订阅服务 * @TestStep : diff --git a/test/src/test/java/com/alibaba/nacos/test/naming/NamingBase.java b/test/src/test/java/com/alibaba/nacos/test/naming/NamingBase.java index 30a5afa54..9f83f8916 100644 --- a/test/src/test/java/com/alibaba/nacos/test/naming/NamingBase.java +++ b/test/src/test/java/com/alibaba/nacos/test/naming/NamingBase.java @@ -44,6 +44,10 @@ public class NamingBase { public static final String TETS_TOKEN_4_DOM_2 = "xyz"; public static final String TEST_SERVER_STATUS = "UP"; + public static final String TEST_GROUP = "group"; + public static final String TEST_GROUP_1 = "group1"; + public static final String TEST_GROUP_2 = "group2"; + static final String NAMING_CONTROLLER_PATH = "/nacos/v1/ns"; public static final int TEST_PORT = 8080;