use of org.apache.dubbo.rpc.RpcInvocation in project dubbo by alibaba.
the class RegistryDirectoryTest method testEmptyNotifyCauseForbidden.
/**
* Empty notify cause forbidden, non-empty notify cancels forbidden state
*/
@Test
public void testEmptyNotifyCauseForbidden() {
RegistryDirectory registryDirectory = getRegistryDirectory();
List invokers = null;
List<URL> serviceUrls = new ArrayList<URL>();
registryDirectory.notify(serviceUrls);
RpcInvocation inv = new RpcInvocation();
try {
invokers = registryDirectory.list(inv);
} catch (RpcException e) {
Assertions.assertEquals(RpcException.FORBIDDEN_EXCEPTION, e.getCode());
Assertions.assertFalse(registryDirectory.isAvailable());
}
serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1"));
serviceUrls.add(SERVICEURL2.addParameter("methods", "getXXX1,getXXX2"));
serviceUrls.add(SERVICEURL3.addParameter("methods", "getXXX1,getXXX2,getXXX3"));
registryDirectory.notify(serviceUrls);
inv.setMethodName("getXXX2");
invokers = registryDirectory.list(inv);
Assertions.assertTrue(registryDirectory.isAvailable());
Assertions.assertEquals(3, invokers.size());
}
use of org.apache.dubbo.rpc.RpcInvocation in project dubbo by alibaba.
the class RegistryDirectoryTest method testDubbo1UrlWithGenericInvocation.
@Test
public void testDubbo1UrlWithGenericInvocation() {
RegistryDirectory registryDirectory = getRegistryDirectory();
List<URL> serviceUrls = new ArrayList<URL>();
URL serviceURL = SERVICEURL_DUBBO_NOPATH.addParameter("methods", "getXXX1,getXXX2,getXXX3");
serviceUrls.add(serviceURL);
registryDirectory.notify(serviceUrls);
// Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException;
invocation = new RpcInvocation($INVOKE, GenericService.class.getName(), "", new Class[] { String.class, String[].class, Object[].class }, new Object[] { "getXXX1", "", new Object[] {} });
List<Invoker> invokers = registryDirectory.list(invocation);
Assertions.assertEquals(1, invokers.size());
// Assertions.assertEquals(
// serviceURL.setPath(service).addParameters("check", "false", "interface", DemoService.class.getName(), REMOTE_APPLICATION_KEY, serviceURL.getParameter(APPLICATION_KEY))
// , invokers.get(0).getUrl()
// );
}
use of org.apache.dubbo.rpc.RpcInvocation in project dubbo by alibaba.
the class RegistryDirectoryTest method testNotifyoverrideUrls_withInvoker.
/**
* Test whether the override rule have a high priority
* Scene: push override rules with invoker
*/
@Test
public void testNotifyoverrideUrls_withInvoker() {
RegistryDirectory registryDirectory = getRegistryDirectory();
List<URL> durls = new ArrayList<URL>();
durls.add(SERVICEURL.addParameter("timeout", "1000"));
durls.add(SERVICEURL2.addParameter("timeout", "1000").addParameter("connections", "10"));
durls.add(URL.valueOf("override://0.0.0.0?timeout=1&connections=5"));
registryDirectory.notify(durls);
Assertions.assertTrue(registryDirectory.isAvailable());
// Start validation of parameter values
invocation = new RpcInvocation();
List<Invoker<?>> invokers = registryDirectory.list(invocation);
Assertions.assertEquals(2, invokers.size());
Assertions.assertEquals("1", invokers.get(0).getUrl().getParameter("timeout"), "override rute must be first priority");
Assertions.assertEquals("5", invokers.get(0).getUrl().getParameter("connections"), "override rute must be first priority");
}
use of org.apache.dubbo.rpc.RpcInvocation in project dubbo by alibaba.
the class RegistryDirectoryTest method testNofity_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 testNofity_disabled_specifiedProvider() {
RegistryDirectory registryDirectory = getRegistryDirectory();
invocation = new RpcInvocation();
// Initially disable
List<URL> durls = new ArrayList<URL>();
durls.add(SERVICEURL.setHost("10.20.30.140").addParameter(ENABLED_KEY, "false"));
durls.add(SERVICEURL.setHost("10.20.30.141"));
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());
// Enabled by override rule
durls = new ArrayList<URL>();
durls.add(URL.valueOf("override://10.20.30.140:9091?" + DISABLED_KEY + "=false"));
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 testNotify_MockProviderOnly.
/**
* Test mock provider distribution
*/
@Test
public void testNotify_MockProviderOnly() {
RegistryDirectory registryDirectory = getRegistryDirectory();
List<URL> serviceUrls = new ArrayList<URL>();
serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1"));
serviceUrls.add(SERVICEURL2.addParameter("methods", "getXXX1,getXXX2"));
serviceUrls.add(SERVICEURL.setProtocol(MOCK_PROTOCOL));
registryDirectory.notify(serviceUrls);
Assertions.assertTrue(registryDirectory.isAvailable());
invocation = new RpcInvocation();
List invokers = registryDirectory.list(invocation);
Assertions.assertEquals(2, invokers.size());
RpcInvocation mockinvocation = new RpcInvocation();
mockinvocation.setAttachment(INVOCATION_NEED_MOCK, "true");
invokers = registryDirectory.list(mockinvocation);
Assertions.assertEquals(1, invokers.size());
}
Aggregations