use of org.apache.dubbo.rpc.RpcInvocation 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.rpc.RpcInvocation 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.rpc.RpcInvocation 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.rpc.RpcInvocation in project dubbo by alibaba.
the class RegistryDirectoryTest method testforbid.
// forbid
private void testforbid(RegistryDirectory registryDirectory) {
invocation = new RpcInvocation();
List<URL> serviceUrls = new ArrayList<URL>();
serviceUrls.add(new URL(EMPTY_PROTOCOL, ANYHOST_VALUE, 0, service, CATEGORY_KEY, PROVIDERS_CATEGORY));
registryDirectory.notify(serviceUrls);
Assertions.assertFalse(registryDirectory.isAvailable(), "invokers size=0 ,then the registry directory is not available");
try {
registryDirectory.list(invocation);
fail("forbid must throw RpcException");
} catch (RpcException e) {
Assertions.assertEquals(RpcException.FORBIDDEN_EXCEPTION, e.getCode());
}
}
use of org.apache.dubbo.rpc.RpcInvocation in project dubbo by alibaba.
the class StaticDirectoryTest method testStaticDirectory.
@Test
public void testStaticDirectory() {
Router router = new ConditionRouterFactory().getRouter(getRouteUrl(" => " + " host = " + NetUtils.getLocalHost()));
List<Router> routers = new ArrayList<Router>();
routers.add(router);
List<Invoker<String>> invokers = new ArrayList<Invoker<String>>();
Invoker<String> invoker1 = new MockInvoker<String>(URL.valueOf("dubbo://10.20.3.3:20880/com.foo.BarService"));
Invoker<String> invoker2 = new MockInvoker<String>(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService"));
Invoker<String> invoker3 = new MockInvoker<String>(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService"));
invokers.add(invoker1);
invokers.add(invoker2);
invokers.add(invoker3);
List<Invoker<String>> filteredInvokers = router.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
StaticDirectory<String> staticDirectory = new StaticDirectory<>(filteredInvokers);
boolean isAvailable = staticDirectory.isAvailable();
Assertions.assertTrue(!isAvailable);
List<Invoker<String>> newInvokers = staticDirectory.list(new MockDirInvocation());
Assertions.assertTrue(newInvokers.size() > 0);
staticDirectory.destroy();
Assertions.assertEquals(0, newInvokers.size());
}
Aggregations