Search in sources :

Example 61 with RpcInvocation

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

the class ConditionRouterTest method testRoute_matchWhen.

@Test
public void testRoute_matchWhen() {
    Invocation invocation = new RpcInvocation();
    Router router = new ConditionRouterFactory().getRouter(getRouteUrl(" => host = 1.2.3.4"));
    boolean matchWhen = ((ConditionRouter) router).matchWhen(URL.valueOf("consumer://1.1.1.1/com.foo.BarService"), invocation);
    Assert.assertEquals(true, matchWhen);
    router = new ConditionRouterFactory().getRouter(getRouteUrl("host = 2.2.2.2,1.1.1.1,3.3.3.3 => host = 1.2.3.4"));
    matchWhen = ((ConditionRouter) router).matchWhen(URL.valueOf("consumer://1.1.1.1/com.foo.BarService"), invocation);
    Assert.assertEquals(true, matchWhen);
    router = new ConditionRouterFactory().getRouter(getRouteUrl("host = 2.2.2.2,1.1.1.1,3.3.3.3 & host !=1.1.1.1 => host = 1.2.3.4"));
    matchWhen = ((ConditionRouter) router).matchWhen(URL.valueOf("consumer://1.1.1.1/com.foo.BarService"), invocation);
    Assert.assertEquals(false, matchWhen);
    router = new ConditionRouterFactory().getRouter(getRouteUrl("host !=4.4.4.4 & host = 2.2.2.2,1.1.1.1,3.3.3.3 => host = 1.2.3.4"));
    matchWhen = ((ConditionRouter) router).matchWhen(URL.valueOf("consumer://1.1.1.1/com.foo.BarService"), invocation);
    Assert.assertEquals(true, matchWhen);
    router = new ConditionRouterFactory().getRouter(getRouteUrl("host !=4.4.4.* & host = 2.2.2.2,1.1.1.1,3.3.3.3 => host = 1.2.3.4"));
    matchWhen = ((ConditionRouter) router).matchWhen(URL.valueOf("consumer://1.1.1.1/com.foo.BarService"), invocation);
    Assert.assertEquals(true, matchWhen);
    router = new ConditionRouterFactory().getRouter(getRouteUrl("host = 2.2.2.2,1.1.1.*,3.3.3.3 & host != 1.1.1.1 => host = 1.2.3.4"));
    matchWhen = ((ConditionRouter) router).matchWhen(URL.valueOf("consumer://1.1.1.1/com.foo.BarService"), invocation);
    Assert.assertEquals(false, matchWhen);
    router = new ConditionRouterFactory().getRouter(getRouteUrl("host = 2.2.2.2,1.1.1.*,3.3.3.3 & host != 1.1.1.2 => host = 1.2.3.4"));
    matchWhen = ((ConditionRouter) router).matchWhen(URL.valueOf("consumer://1.1.1.1/com.foo.BarService"), invocation);
    Assert.assertEquals(true, matchWhen);
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) Invocation(com.alibaba.dubbo.rpc.Invocation) Router(com.alibaba.dubbo.rpc.cluster.Router) Test(org.junit.Test)

Example 62 with RpcInvocation

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

the class FileRouterEngineTest method initInvocation.

private void initInvocation(String methodName) {
    invocation = new RpcInvocation();
    ((RpcInvocation) invocation).setMethodName(methodName);
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation)

Example 63 with RpcInvocation

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

the class ScriptRouterTest method testRoute_ReturnAll.

@Test
public void testRoute_ReturnAll() {
    Router router = new ScriptRouterFactory().getRouter(getRouteUrl("function route(op1,op2){return op1} route(invokers)"));
    List<Invoker<String>> invokers = new ArrayList<Invoker<String>>();
    invokers.add(new MockInvoker<String>());
    invokers.add(new MockInvoker<String>());
    invokers.add(new MockInvoker<String>());
    List<Invoker<String>> fileredInvokers = router.route(invokers, invokers.get(0).getUrl(), new RpcInvocation());
    Assert.assertEquals(invokers, fileredInvokers);
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) Invoker(com.alibaba.dubbo.rpc.Invoker) MockInvoker(com.alibaba.dubbo.rpc.cluster.router.MockInvoker) ArrayList(java.util.ArrayList) Router(com.alibaba.dubbo.rpc.cluster.Router) Test(org.junit.Test)

Example 64 with RpcInvocation

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

the class ScriptRouterTest method testRoute_PickInvokers.

@Test
public void testRoute_PickInvokers() {
    String rule = "var result = new java.util.ArrayList(invokers.size());" + "for (i=0;i<invokers.size(); i++){ " + "if (invokers.get(i).isAvailable()) {" + "result.add(invokers.get(i)) ;" + "}" + "} ; " + "return result;";
    String script = "function route(invokers,invocation,context){" + rule + "} route(invokers,invocation,context)";
    Router router = new ScriptRouterFactory().getRouter(getRouteUrl(script));
    List<Invoker<String>> invokers = new ArrayList<Invoker<String>>();
    Invoker<String> invoker1 = new MockInvoker<String>(false);
    Invoker<String> invoker2 = new MockInvoker<String>(true);
    Invoker<String> invoker3 = new MockInvoker<String>(true);
    invokers.add(invoker1);
    invokers.add(invoker2);
    invokers.add(invoker3);
    List<Invoker<String>> fileredInvokers = router.route(invokers, invokers.get(0).getUrl(), 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 65 with RpcInvocation

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

the class AbstractClusterInvokerTest method testMockedInvokerSelect.

/**
 * Test mock invoker selector works as expected
 */
@Test
public void testMockedInvokerSelect() {
    initlistsize5();
    invokers.add(mockedInvoker1);
    RpcInvocation mockedInvocation = new RpcInvocation();
    mockedInvocation.setMethodName("sayHello");
    mockedInvocation.setAttachment(Constants.INVOCATION_NEED_MOCK, "true");
    List<Invoker<IHelloService>> mockedInvokers = dic.list(mockedInvocation);
    Assert.assertEquals(1, mockedInvokers.size());
    List<Invoker<IHelloService>> invokers = dic.list(invocation);
    Assert.assertEquals(5, invokers.size());
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) Invoker(com.alibaba.dubbo.rpc.Invoker) Test(org.junit.Test)

Aggregations

RpcInvocation (com.alibaba.dubbo.rpc.RpcInvocation)104 Test (org.junit.Test)77 URL (com.alibaba.dubbo.common.URL)62 ArrayList (java.util.ArrayList)45 Invoker (com.alibaba.dubbo.rpc.Invoker)37 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)15 MockInvoker (com.alibaba.dubbo.rpc.cluster.router.MockInvoker)13 Invocation (com.alibaba.dubbo.rpc.Invocation)12 List (java.util.List)10 RpcResult (com.alibaba.dubbo.rpc.RpcResult)9 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 Request (com.alibaba.dubbo.remoting.exchange.Request)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3