use of org.apache.dubbo.registry.integration.RegistryDirectory in project dubbo by alibaba.
the class RegistryDirectoryTest method testNotified_WithDuplicateUrls.
@Test
public void testNotified_WithDuplicateUrls() {
List<URL> serviceUrls = new ArrayList<URL>();
// ignore error log
serviceUrls.add(SERVICEURL);
serviceUrls.add(SERVICEURL);
RegistryDirectory registryDirectory = getRegistryDirectory();
registryDirectory.notify(serviceUrls);
List invokers = registryDirectory.list(invocation);
Assertions.assertEquals(1, invokers.size());
}
use of org.apache.dubbo.registry.integration.RegistryDirectory in project dubbo by alibaba.
the class RegistryDirectoryTest method testNofityOverrideUrls_disabled_specifiedProvider.
/**
* Test override disables a specified service provider through enable=false
* It is expected that a specified service provider can be disable.
*/
@Test
public void testNofityOverrideUrls_disabled_specifiedProvider() {
RegistryDirectory registryDirectory = getRegistryDirectory();
invocation = new RpcInvocation();
List<URL> durls = new ArrayList<URL>();
durls.add(SERVICEURL.setHost("10.20.30.140"));
durls.add(SERVICEURL.setHost("10.20.30.141"));
registryDirectory.notify(durls);
durls = new ArrayList<URL>();
durls.add(URL.valueOf("override://10.20.30.140:9091?" + DISABLED_KEY + "=true"));
registryDirectory.notify(durls);
List<Invoker<?>> invokers = registryDirectory.list(invocation);
Assertions.assertEquals(1, invokers.size());
Assertions.assertEquals("10.20.30.141", invokers.get(0).getUrl().getHost());
durls = new ArrayList<URL>();
durls.add(URL.valueOf("empty://0.0.0.0?" + DISABLED_KEY + "=true&" + CATEGORY_KEY + "=" + CONFIGURATORS_CATEGORY));
registryDirectory.notify(durls);
List<Invoker<?>> invokers2 = registryDirectory.list(invocation);
Assertions.assertEquals(2, invokers2.size());
}
use of org.apache.dubbo.registry.integration.RegistryDirectory in project dubbo by alibaba.
the class RegistryDirectoryTest method test_Notified_withGroupFilter.
@Test
public void test_Notified_withGroupFilter() {
URL directoryUrl = noMeaningUrl.addParameterAndEncoded(REFER_KEY, "interface" + service + "&group=group1,group2");
RegistryDirectory directory = this.getRegistryDirectory(directoryUrl);
URL provider1 = URL.valueOf("dubbo://10.134.108.1:20880/" + service + "?methods=getXXX&group=group1&mock=false&application=mockApplication");
URL provider2 = URL.valueOf("dubbo://10.134.108.1:20880/" + service + "?methods=getXXX&group=group2&mock=false&application=mockApplication");
List<URL> providers = new ArrayList<>();
providers.add(provider1);
providers.add(provider2);
directory.notify(providers);
invocation = new RpcInvocation();
invocation.setMethodName("getXXX");
List<Invoker<DemoService>> invokers = directory.list(invocation);
Assertions.assertEquals(2, invokers.size());
Assertions.assertTrue(invokers.get(0) instanceof MockClusterInvoker);
Assertions.assertTrue(invokers.get(1) instanceof MockClusterInvoker);
directoryUrl = noMeaningUrl.addParameterAndEncoded(REFER_KEY, "interface" + service + "&group=group1");
directory = this.getRegistryDirectory(directoryUrl);
directory.notify(providers);
invokers = directory.list(invocation);
Assertions.assertEquals(2, invokers.size());
Assertions.assertFalse(invokers.get(0) instanceof MockClusterInvoker);
Assertions.assertFalse(invokers.get(1) instanceof MockClusterInvoker);
}
use of org.apache.dubbo.registry.integration.RegistryDirectory in project dubbo by alibaba.
the class RegistryDirectoryTest method testNotifyoverrideUrls_Nouse.
/**
* Test whether the override rule have a high priority
* Scene: the rules of the push are the same as the parameters of the provider
* Expectation: no need to be re-referenced
*/
@Test
public void testNotifyoverrideUrls_Nouse() {
RegistryDirectory registryDirectory = getRegistryDirectory();
invocation = new RpcInvocation();
List<URL> durls = new ArrayList<URL>();
// One is the same, one is different
durls.add(SERVICEURL.addParameter("timeout", "1"));
durls.add(SERVICEURL2.addParameter("timeout", "1").addParameter("connections", "5"));
registryDirectory.notify(durls);
List<Invoker<?>> invokers = registryDirectory.list(invocation);
Assertions.assertEquals(2, invokers.size());
Map<String, Invoker<?>> map = new HashMap<>();
map.put(invokers.get(0).getUrl().getAddress(), invokers.get(0));
map.put(invokers.get(1).getUrl().getAddress(), invokers.get(1));
durls = new ArrayList<URL>();
durls.add(URL.valueOf("override://0.0.0.0?timeout=1&connections=5"));
registryDirectory.notify(durls);
Assertions.assertTrue(registryDirectory.isAvailable());
invokers = registryDirectory.list(invocation);
Assertions.assertEquals(2, invokers.size());
Map<String, Invoker<?>> map2 = new HashMap<>();
map2.put(invokers.get(0).getUrl().getAddress(), invokers.get(0));
map2.put(invokers.get(1).getUrl().getAddress(), invokers.get(1));
// The parameters are different and must be rereferenced.
Assertions.assertNotSame(map.get(SERVICEURL.getAddress()), map2.get(SERVICEURL.getAddress()), "object should not same");
// The parameters can not be rereferenced
Assertions.assertSame(map.get(SERVICEURL2.getAddress()), map2.get(SERVICEURL2.getAddress()), "object should not same");
}
use of org.apache.dubbo.registry.integration.RegistryDirectory in project dubbo by alibaba.
the class RegistryDirectoryTest method testNotified_Normal.
@Test
public void testNotified_Normal() {
RegistryDirectory registryDirectory = getRegistryDirectory();
test_Notified2invokers(registryDirectory);
test_Notified1invokers(registryDirectory);
test_Notified3invokers(registryDirectory);
testforbid(registryDirectory);
}
Aggregations