use of com.alibaba.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(Constants.EMPTY_PROTOCOL, Constants.ANYHOST_VALUE, 0, service, Constants.CATEGORY_KEY, Constants.PROVIDERS_CATEGORY));
registryDirectory.notify(serviceUrls);
Assert.assertEquals("invokers size=0 ,then the registry directory is not available", false, registryDirectory.isAvailable());
try {
registryDirectory.list(invocation);
fail("forbid must throw RpcException");
} catch (RpcException e) {
Assert.assertEquals(RpcException.FORBIDDEN_EXCEPTION, e.getCode());
}
}
use of com.alibaba.dubbo.rpc.RpcInvocation in project dubbo by alibaba.
the class RegistryDirectoryTest method testParmeterRoute.
/**
* When the first arg of a method is String or Enum, Registry server can do parameter-value-based routing.
*/
@Test
public void testParmeterRoute() {
RegistryDirectory registryDirectory = getRegistryDirectory();
List<URL> serviceUrls = new ArrayList<URL>();
serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1.napoli"));
serviceUrls.add(SERVICEURL2.addParameter("methods", "getXXX1.MORGAN,getXXX2"));
serviceUrls.add(SERVICEURL3.addParameter("methods", "getXXX1.morgan,getXXX2,getXXX3"));
registryDirectory.notify(serviceUrls);
invocation = new RpcInvocation(Constants.$INVOKE, new Class[] { String.class, String[].class, Object[].class }, new Object[] { "getXXX1", new String[] { "Enum" }, new Object[] { Param.MORGAN } });
List invokers = registryDirectory.list(invocation);
Assert.assertEquals(1, invokers.size());
}
use of com.alibaba.dubbo.rpc.RpcInvocation in project dubbo by alibaba.
the class RegistryDirectoryTest method test_Notified1invokers.
// notify one invoker
private void test_Notified1invokers(RegistryDirectory registryDirectory) {
List<URL> serviceUrls = new ArrayList<URL>();
// .addParameter("refer.autodestroy", "true")
serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1"));
registryDirectory.notify(serviceUrls);
Assert.assertEquals(true, registryDirectory.isAvailable());
invocation = new RpcInvocation();
List invokers = registryDirectory.list(invocation);
Assert.assertEquals(1, invokers.size());
invocation.setMethodName("getXXX");
invokers = registryDirectory.list(invocation);
Assert.assertEquals(1, invokers.size());
invocation.setMethodName("getXXX1");
invokers = registryDirectory.list(invocation);
Assert.assertEquals(1, invokers.size());
invocation.setMethodName("getXXX2");
invokers = registryDirectory.list(invocation);
Assert.assertEquals(1, invokers.size());
}
use of com.alibaba.dubbo.rpc.RpcInvocation in project dubbo by alibaba.
the class RegistryDirectoryTest method testNofityOverrideUrls_Clean1.
/**
* Test cleanup override rules, and sent remove rules and other override rules
* Whether the test can be restored to the providerUrl when it is pushed
*/
@Test
public void testNofityOverrideUrls_Clean1() {
RegistryDirectory registryDirectory = getRegistryDirectory();
invocation = new RpcInvocation();
List<URL> durls = new ArrayList<URL>();
durls.add(SERVICEURL.setHost("10.20.30.140").addParameter("timeout", "1"));
registryDirectory.notify(durls);
durls = new ArrayList<URL>();
durls.add(URL.valueOf("override://0.0.0.0?timeout=1000"));
registryDirectory.notify(durls);
durls = new ArrayList<URL>();
durls.add(URL.valueOf("override://0.0.0.0?timeout=3"));
durls.add(URL.valueOf("override://0.0.0.0"));
registryDirectory.notify(durls);
List<Invoker<?>> invokers = registryDirectory.list(invocation);
Invoker<?> aInvoker = invokers.get(0);
// Need to be restored to the original providerUrl
Assert.assertEquals("1", aInvoker.getUrl().getParameter("timeout"));
}
use of com.alibaba.dubbo.rpc.RpcInvocation in project dubbo by alibaba.
the class RegistryDirectoryTest method testNofityOverrideUrls_Provider.
/**
* Test override rules for a certain provider
*/
@Test
public void testNofityOverrideUrls_Provider() {
RegistryDirectory registryDirectory = getRegistryDirectory();
invocation = new RpcInvocation();
List<URL> durls = new ArrayList<URL>();
// One is the same, one is different
durls.add(SERVICEURL.setHost("10.20.30.140").addParameter("timeout", "1").addParameter(Constants.SIDE_KEY, Constants.CONSUMER_SIDE));
durls.add(SERVICEURL2.setHost("10.20.30.141").addParameter("timeout", "2").addParameter(Constants.SIDE_KEY, Constants.CONSUMER_SIDE));
registryDirectory.notify(durls);
durls = new ArrayList<URL>();
durls.add(URL.valueOf("override://0.0.0.0?timeout=3"));
durls.add(URL.valueOf("override://10.20.30.141:9092?timeout=4"));
registryDirectory.notify(durls);
List<Invoker<?>> invokers = registryDirectory.list(invocation);
Invoker<?> aInvoker = invokers.get(0);
Invoker<?> bInvoker = invokers.get(1);
Assert.assertEquals("3", aInvoker.getUrl().getParameter("timeout"));
Assert.assertEquals("4", bInvoker.getUrl().getParameter("timeout"));
}
Aggregations