use of org.apache.dubbo.rpc.RpcInvocation in project dubbo by alibaba.
the class RegistryDirectoryTest method testParametersMerge.
@Test
public void testParametersMerge() {
RegistryDirectory registryDirectory = getRegistryDirectory();
URL regurl = noMeaningUrl.addParameter("test", "reg").addParameterAndEncoded(REFER_KEY, "key=query&" + LOADBALANCE_KEY + "=" + LeastActiveLoadBalance.NAME);
RegistryDirectory<RegistryDirectoryTest> registryDirectory2 = new RegistryDirectory(RegistryDirectoryTest.class, regurl);
registryDirectory2.setProtocol(protocol);
List<URL> serviceUrls = new ArrayList<URL>();
// The parameters of the inspection registry need to be cleared
{
serviceUrls.clear();
serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1"));
registryDirectory.notify(serviceUrls);
invocation = new RpcInvocation();
List invokers = registryDirectory.list(invocation);
Invoker invoker = (Invoker) invokers.get(0);
URL url = invoker.getUrl();
Assertions.assertNull(url.getParameter("key"));
}
// The parameters of the provider for the inspection service need merge
{
serviceUrls.clear();
serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX2").addParameter("key", "provider"));
registryDirectory.notify(serviceUrls);
invocation = new RpcInvocation();
List invokers = registryDirectory.list(invocation);
Invoker invoker = (Invoker) invokers.get(0);
URL url = invoker.getUrl();
Assertions.assertEquals("provider", url.getParameter("key"));
}
// The parameters of the test service query need to be with the providermerge.
{
serviceUrls.clear();
serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX3").addParameter("key", "provider"));
registryDirectory2.setRegistry(registry);
registryDirectory2.setRouterChain(RouterChain.buildChain(noMeaningUrl));
registryDirectory2.subscribe(noMeaningUrl);
registryDirectory2.notify(serviceUrls);
invocation = new RpcInvocation();
List invokers = registryDirectory2.list(invocation);
Invoker invoker = (Invoker) invokers.get(0);
URL url = invoker.getUrl();
Assertions.assertEquals("query", url.getParameter("key"));
}
{
serviceUrls.clear();
serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1"));
registryDirectory.notify(serviceUrls);
invocation = new RpcInvocation();
List invokers = registryDirectory.list(invocation);
Invoker invoker = (Invoker) invokers.get(0);
URL url = invoker.getUrl();
Assertions.assertFalse(url.getParameter(Constants.CHECK_KEY, false));
}
{
serviceUrls.clear();
serviceUrls.add(SERVICEURL.addParameter(LOADBALANCE_KEY, RoundRobinLoadBalance.NAME));
registryDirectory2.notify(serviceUrls);
invocation = new RpcInvocation();
invocation.setMethodName("get");
List invokers = registryDirectory2.list(invocation);
Invoker invoker = (Invoker) invokers.get(0);
URL url = invoker.getUrl();
Assertions.assertEquals(LeastActiveLoadBalance.NAME, url.getMethodParameter("get", LOADBALANCE_KEY));
}
// test geturl
{
Assertions.assertNull(registryDirectory2.getUrl().getParameter("mock"));
serviceUrls.clear();
serviceUrls.add(SERVICEURL.addParameter(MOCK_KEY, "true"));
registryDirectory2.notify(serviceUrls);
Assertions.assertEquals("true", ((InvokerWrapper<?>) registryDirectory2.getInvokers().get(0)).getUrl().getParameter("mock"));
}
}
use of org.apache.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.
*/
@Disabled("Parameter routing is not available at present.")
@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($INVOKE, GenericService.class.getName(), "", new Class[] { String.class, String[].class, Object[].class }, new Object[] { "getXXX1", new String[] { "Enum" }, new Object[] { Param.MORGAN } });
List invokers = registryDirectory.list(invocation);
Assertions.assertEquals(1, invokers.size());
}
use of org.apache.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(SIDE_KEY, CONSUMER_SIDE));
durls.add(SERVICEURL2.setHost("10.20.30.141").addParameter("timeout", "2").addParameter(SIDE_KEY, 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);
URL aUrl = invokers.get(0).getUrl();
URL bUrl = invokers.get(1).getUrl();
Assertions.assertEquals(aUrl.getHost().equals("10.20.30.140") ? "3" : "4", aUrl.getParameter("timeout"));
Assertions.assertEquals(bUrl.getHost().equals("10.20.30.141") ? "4" : "3", bUrl.getParameter("timeout"));
}
use of org.apache.dubbo.rpc.RpcInvocation in project dubbo by alibaba.
the class RegistryDirectoryTest method test_Notified2invokers.
// 2 invokers===================================
private void test_Notified2invokers(RegistryDirectory registryDirectory) {
List<URL> serviceUrls = new ArrayList<URL>();
serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1"));
serviceUrls.add(SERVICEURL2.addParameter("methods", "getXXX1,getXXX2"));
serviceUrls.add(SERVICEURL2.addParameter("methods", "getXXX1,getXXX2"));
registryDirectory.notify(serviceUrls);
Assertions.assertTrue(registryDirectory.isAvailable());
invocation = new RpcInvocation();
List invokers = registryDirectory.list(invocation);
Assertions.assertEquals(2, invokers.size());
invocation.setMethodName("getXXX");
invokers = registryDirectory.list(invocation);
Assertions.assertEquals(2, invokers.size());
invocation.setMethodName("getXXX1");
invokers = registryDirectory.list(invocation);
Assertions.assertEquals(2, invokers.size());
}
use of org.apache.dubbo.rpc.RpcInvocation in project dubbo by alibaba.
the class RegistryDirectoryTest method test_Notified_acceptProtocol1.
// Test the matching of protocol and select only the matched protocol for refer
@Test
public void test_Notified_acceptProtocol1() {
URL errorPathUrl = URL.valueOf("notsupport:/xxx");
errorPathUrl = errorPathUrl.addParameterAndEncoded(REFER_KEY, "interface=" + service + "&protocol=dubbo");
RegistryDirectory registryDirectory = getRegistryDirectory(errorPathUrl);
List<URL> serviceUrls = new ArrayList<URL>();
URL dubbo1URL = URL.valueOf("dubbo://127.0.0.1:9098?lazy=true&methods=getXXX");
URL dubbo2URL = URL.valueOf("injvm://127.0.0.1:9098?lazy=true&methods=getXXX");
serviceUrls.add(dubbo1URL);
serviceUrls.add(dubbo2URL);
registryDirectory.notify(serviceUrls);
invocation = new RpcInvocation();
List<Invoker<DemoService>> invokers = registryDirectory.list(invocation);
Assertions.assertEquals(1, invokers.size());
}
Aggregations