Search in sources :

Example 21 with RpcInvocation

use of com.alibaba.dubbo.rpc.RpcInvocation in project dubbo by alibaba.

the class ConditionRouterTest method testRoute_HostFilter.

@Test
public void testRoute_HostFilter() {
    Router router = new ConditionRouterFactory().getRouter(getRouteUrl("host = " + NetUtils.getLocalHost() + " => " + " host = " + NetUtils.getLocalHost()));
    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>> fileredInvokers = router.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
    Assert.assertEquals(2, fileredInvokers.size());
    Assert.assertEquals(invoker2, fileredInvokers.get(0));
    Assert.assertEquals(invoker3, fileredInvokers.get(1));
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) Invoker(com.alibaba.dubbo.rpc.Invoker) MockInvoker(com.alibaba.dubbo.rpc.cluster.router.MockInvoker) MockInvoker(com.alibaba.dubbo.rpc.cluster.router.MockInvoker) ArrayList(java.util.ArrayList) Router(com.alibaba.dubbo.rpc.cluster.Router) Test(org.junit.Test)

Example 22 with RpcInvocation

use of com.alibaba.dubbo.rpc.RpcInvocation in project dubbo by alibaba.

the class RegistryDirectoryTest method testNofityOverrideUrls_Provider.

/**
     * 测试针对某个provider的Override规则
     */
@Test
public void testNofityOverrideUrls_Provider() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    invocation = new RpcInvocation();
    List<URL> durls = new ArrayList<URL>();
    //一个一样,一个不一样
    durls.add(SERVICEURL.setHost("10.20.30.140").addParameter("timeout", "1"));
    durls.add(SERVICEURL2.setHost("10.20.30.141").addParameter("timeout", "2"));
    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"));
}
Also used : RegistryDirectory(com.alibaba.dubbo.registry.integration.RegistryDirectory) RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) Invoker(com.alibaba.dubbo.rpc.Invoker) ArrayList(java.util.ArrayList) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 23 with RpcInvocation

use of com.alibaba.dubbo.rpc.RpcInvocation in project dubbo by alibaba.

the class RegistryDirectoryTest method test_NotifiedDubbo1.

//测试调用和registry url的path无关
@Test
public void test_NotifiedDubbo1() {
    URL errorPathUrl = URL.valueOf("notsupport:/" + "xxx" + "?refer=" + URL.encode("interface=" + service));
    RegistryDirectory registryDirectory = getRegistryDirectory(errorPathUrl);
    List<URL> serviceUrls = new ArrayList<URL>();
    URL Dubbo1URL = URL.valueOf("dubbo://127.0.0.1:9098?lazy=true");
    serviceUrls.add(Dubbo1URL.addParameter("methods", "getXXX"));
    registryDirectory.notify(serviceUrls);
    Assert.assertEquals(true, registryDirectory.isAvailable());
    invocation = new RpcInvocation();
    List<Invoker<DemoService>> invokers = registryDirectory.list(invocation);
    Assert.assertEquals(1, invokers.size());
    invocation.setMethodName("getXXX");
    invokers = registryDirectory.list(invocation);
    Assert.assertEquals(1, invokers.size());
    Assert.assertEquals(DemoService.class.getName(), invokers.get(0).getUrl().getPath());
}
Also used : RegistryDirectory(com.alibaba.dubbo.registry.integration.RegistryDirectory) RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) Invoker(com.alibaba.dubbo.rpc.Invoker) ArrayList(java.util.ArrayList) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 24 with RpcInvocation

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());
}
Also used : RegistryDirectory(com.alibaba.dubbo.registry.integration.RegistryDirectory) RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 25 with RpcInvocation

use of com.alibaba.dubbo.rpc.RpcInvocation in project dubbo by alibaba.

the class RegistryDirectoryTest method testNofity_To_Decrease_provider.

/**
     * 测试override通过enable=false,禁用指定服务提供者
     * 预期:可以禁用指定的服务提供者。
     */
@Test
public void testNofity_To_Decrease_provider() {
    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);
    List<Invoker<?>> invokers = registryDirectory.list(invocation);
    Assert.assertEquals(2, invokers.size());
    durls = new ArrayList<URL>();
    durls.add(SERVICEURL.setHost("10.20.30.140"));
    registryDirectory.notify(durls);
    List<Invoker<?>> invokers2 = registryDirectory.list(invocation);
    Assert.assertEquals(1, invokers2.size());
    Assert.assertEquals("10.20.30.140", invokers.get(0).getUrl().getHost());
    durls = new ArrayList<URL>();
    durls.add(URL.valueOf("empty://0.0.0.0?" + Constants.DISABLED_KEY + "=true&" + Constants.CATEGORY_KEY + "=" + Constants.CONFIGURATORS_CATEGORY));
    registryDirectory.notify(durls);
    List<Invoker<?>> invokers3 = registryDirectory.list(invocation);
    Assert.assertEquals(1, invokers3.size());
}
Also used : RegistryDirectory(com.alibaba.dubbo.registry.integration.RegistryDirectory) RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) Invoker(com.alibaba.dubbo.rpc.Invoker) ArrayList(java.util.ArrayList) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Aggregations

RpcInvocation (com.alibaba.dubbo.rpc.RpcInvocation)99 Test (org.junit.Test)73 URL (com.alibaba.dubbo.common.URL)60 ArrayList (java.util.ArrayList)43 Invoker (com.alibaba.dubbo.rpc.Invoker)35 Result (com.alibaba.dubbo.rpc.Result)29 RegistryDirectory (com.alibaba.dubbo.registry.integration.RegistryDirectory)22 RpcException (com.alibaba.dubbo.rpc.RpcException)22 Router (com.alibaba.dubbo.rpc.cluster.Router)12 MockInvoker (com.alibaba.dubbo.rpc.cluster.router.MockInvoker)11 List (java.util.List)10 Invocation (com.alibaba.dubbo.rpc.Invocation)9 RpcResult (com.alibaba.dubbo.rpc.RpcResult)8 Method (java.lang.reflect.Method)6 Protocol (com.alibaba.dubbo.rpc.Protocol)4 MockProtocol (com.alibaba.dubbo.rpc.support.MockProtocol)4 RemotingException (com.alibaba.dubbo.remoting.RemotingException)3 TimeoutException (com.alibaba.dubbo.remoting.TimeoutException)3 ExchangeClient (com.alibaba.dubbo.remoting.exchange.ExchangeClient)3 Request (com.alibaba.dubbo.remoting.exchange.Request)3