From 8e6fb909d66bf7672ce504117566862f7fe4b6c7 Mon Sep 17 00:00:00 2001 From: "xiaochun.xxc" Date: Tue, 5 Mar 2019 11:44:54 +0800 Subject: [PATCH] add group test --- .../nacos/test/naming/MultiTenant_ITCase.java | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) 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 13f37e3fd..7c3dfc31d 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 @@ -326,6 +326,36 @@ public class MultiTenant_ITCase { Assert.assertTrue(verifyInstanceList(instances, naming1.getAllInstances(serviceName))); } + /** + * @TCDescription : 多租户多group订阅服务 + * @TestStep : + * @ExpectResult : + */ + @Test + public void multipleTenant_group_subscribe() throws Exception { + + String serviceName = randomDomainName(); + + naming1.subscribe(serviceName, TEST_GROUP_1, new EventListener() { + @Override + public void onEvent(Event event) { + instances = ((NamingEvent) event).getInstances(); + } + }); + + naming1.registerInstance(serviceName, "11.11.11.11", TEST_PORT, "c1"); + naming1.registerInstance(serviceName, TEST_GROUP_1,"33.33.33.33", TEST_PORT, "c1"); + + while (instances.size() == 0) { + TimeUnit.SECONDS.sleep(1L); + } + TimeUnit.SECONDS.sleep(2L); + Assert.assertEquals(1, instances.size()); + + TimeUnit.SECONDS.sleep(2L); + Assert.assertTrue(verifyInstanceList(instances, naming1.getAllInstances(serviceName, TEST_GROUP_1))); + } + /** * @TCDescription : 多租户取消订阅服务 * @TestStep : @@ -360,6 +390,74 @@ public class MultiTenant_ITCase { Assert.assertEquals(0, naming2.getSubscribeServices().size()); } + /** + * @TCDescription : 多租户,多group下, 没有对应的group订阅,取消订阅服务 + * @TestStep : + * @ExpectResult : + */ + @Test + public void multipleTenant_group_nosubscribe_unSubscribe() throws Exception { + + String serviceName = randomDomainName(); + EventListener listener = new EventListener() { + @Override + public void onEvent(Event event) { + System.out.println(((NamingEvent)event).getServiceName()); + instances = ((NamingEvent)event).getInstances(); + } + }; + + naming1.subscribe(serviceName, TEST_GROUP_1, listener); + naming1.registerInstance(serviceName, "11.11.11.11", TEST_PORT, "c1"); + naming1.registerInstance(serviceName, TEST_GROUP_2,"33.33.33.33", TEST_PORT, "c1"); + + while (instances.size() == 0) { + TimeUnit.SECONDS.sleep(1L); + } + Assert.assertEquals(serviceName, naming1.getSubscribeServices().get(0).getName()); + Assert.assertEquals(0, naming2.getSubscribeServices().size()); + + naming1.unsubscribe(serviceName, listener); + + TimeUnit.SECONDS.sleep(5L); + Assert.assertEquals(0, naming1.getSubscribeServices().size()); + Assert.assertEquals(0, naming2.getSubscribeServices().size()); + } + + /** + * @TCDescription : 多租户,多group下, 没有对应的group订阅,取消订阅服务 + * @TestStep : + * @ExpectResult : + */ + @Test + public void multipleTenant_group_unSubscribe() throws Exception { + + String serviceName = randomDomainName(); + EventListener listener = new EventListener() { + @Override + public void onEvent(Event event) { + System.out.println(((NamingEvent)event).getServiceName()); + instances = ((NamingEvent)event).getInstances(); + } + }; + + naming1.subscribe(serviceName, TEST_GROUP_1, listener); + naming1.registerInstance(serviceName, "11.11.11.11", TEST_PORT, "c1"); + naming1.registerInstance(serviceName, TEST_GROUP_2,"33.33.33.33", TEST_PORT, "c1"); + + while (instances.size() == 0) { + TimeUnit.SECONDS.sleep(1L); + } + Assert.assertEquals(serviceName, naming1.getSubscribeServices().get(0).getName()); + Assert.assertEquals(0, naming2.getSubscribeServices().size()); + + naming1.unsubscribe(serviceName, listener); + + TimeUnit.SECONDS.sleep(5L); + Assert.assertEquals(0, naming1.getSubscribeServices().size()); + Assert.assertEquals(0, naming2.getSubscribeServices().size()); + } + /** * @TCDescription : 多租户获取server状态 * @TestStep :