From 86e8b369e63c9d8e00b8aa33803b9579ee18c92b Mon Sep 17 00:00:00 2001 From: lixiaojiee Date: Fri, 7 Dec 2018 19:51:44 +0800 Subject: [PATCH] enhance unit test --- .../registry/dubbo/RegistryDirectoryTest.java | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/RegistryDirectoryTest.java b/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/RegistryDirectoryTest.java index 95459b282b6..8c8b8ea6660 100644 --- a/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/RegistryDirectoryTest.java +++ b/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/RegistryDirectoryTest.java @@ -34,7 +34,7 @@ import org.apache.dubbo.rpc.cluster.loadbalance.RoundRobinLoadBalance; import org.apache.dubbo.rpc.cluster.router.script.ScriptRouter; import org.apache.dubbo.rpc.cluster.router.script.ScriptRouterFactory; - +import org.apache.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -1014,6 +1014,37 @@ public void test_Notified_acceptProtocol2() { List> invokers = registryDirectory.list(invocation); Assert.assertEquals(2, invokers.size()); } + + @Test + public void test_Notified_withGroupFilter() { + URL directoryUrl = noMeaningUrl.addParameterAndEncoded(Constants.REFER_KEY, "interface" + service + "&group=group1,group2"); + RegistryDirectory directory = this.getRegistryDirectory(directoryUrl); + URL provider1 = URL.valueOf("dubbo://10.134.108.1:20880?methods=getXXX&group=group1&mock=false"); + URL provider2 = URL.valueOf("dubbo://10.134.108.1:20880?methods=getXXX&group=group2&mock=false"); + + List providers = new ArrayList<>(); + providers.add(provider1); + providers.add(provider2); + directory.notify(providers); + + invocation = new RpcInvocation(); + invocation.setMethodName("getXXX"); + List> invokers = directory.list(invocation); + + Assert.assertEquals(2, invokers.size()); + Assert.assertTrue(invokers.get(0) instanceof MockClusterInvoker); + Assert.assertTrue(invokers.get(1) instanceof MockClusterInvoker); + + directoryUrl = noMeaningUrl.addParameterAndEncoded(Constants.REFER_KEY, "interface" + service + "&group=group1"); + directory = this.getRegistryDirectory(directoryUrl); + directory.notify(providers); + + invokers = directory.list(invocation); + + Assert.assertEquals(2, invokers.size()); + Assert.assertFalse(invokers.get(0) instanceof MockClusterInvoker); + Assert.assertFalse(invokers.get(1) instanceof MockClusterInvoker); + } enum Param { MORGAN,