Search in sources :

Example 11 with Router

use of com.alibaba.dubbo.rpc.cluster.Router in project dubbo by alibaba.

the class ConditionRouterTest method testRoute_ReturnFalse.

@Test
public void testRoute_ReturnFalse() {
    Router router = new ConditionRouterFactory().getRouter(getRouteUrl("host = " + NetUtils.getLocalHost() + " => false"));
    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, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
    Assert.assertEquals(0, fileredInvokers.size());
}
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 12 with Router

use of com.alibaba.dubbo.rpc.cluster.Router in project dubbo by alibaba.

the class ConditionRouterTest method testRoute_ReturnAll.

@Test
public void testRoute_ReturnAll() {
    Router router = new ConditionRouterFactory().getRouter(getRouteUrl("host = " + NetUtils.getLocalHost() + " => " + " host = " + NetUtils.getLocalHost()));
    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, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), 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 13 with Router

use of com.alibaba.dubbo.rpc.cluster.Router in project dubbo by alibaba.

the class ConditionRouterTest method testRoute_Force.

@Test
public void testRoute_Force() {
    Router router = new ConditionRouterFactory().getRouter(getRouteUrl("host = " + NetUtils.getLocalHost() + " => " + " host = 1.2.3.4").addParameter(Constants.FORCE_KEY, String.valueOf(true)));
    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(0, fileredInvokers.size());
}
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 14 with Router

use of com.alibaba.dubbo.rpc.cluster.Router 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 15 with Router

use of com.alibaba.dubbo.rpc.cluster.Router 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)

Aggregations

Router (com.alibaba.dubbo.rpc.cluster.Router)18 RpcInvocation (com.alibaba.dubbo.rpc.RpcInvocation)15 ArrayList (java.util.ArrayList)15 Test (org.junit.Test)15 Invoker (com.alibaba.dubbo.rpc.Invoker)14 MockInvoker (com.alibaba.dubbo.rpc.cluster.router.MockInvoker)13 Invocation (com.alibaba.dubbo.rpc.Invocation)3 URL (com.alibaba.dubbo.common.URL)2 RegistryDirectory (com.alibaba.dubbo.registry.integration.RegistryDirectory)1 RpcException (com.alibaba.dubbo.rpc.RpcException)1 Configurator (com.alibaba.dubbo.rpc.cluster.Configurator)1 ScriptRouter (com.alibaba.dubbo.rpc.cluster.router.script.ScriptRouter)1