com.alibaba.dubbo.rpc.cluster.router.MockInvoker Java Examples

The following examples show how to use com.alibaba.dubbo.rpc.cluster.router.MockInvoker. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ScriptRouterTest.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example #2
Source File: ScriptRouterTest.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example #3
Source File: ScriptRouterTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example #4
Source File: ScriptRouterTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example #5
Source File: ScriptRouterTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example #6
Source File: ScriptRouterTest.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example #7
Source File: ScriptRouterTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #8
Source File: ConditionRouterTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example #9
Source File: ConditionRouterTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void testRoute_NoForce(){
    Router router = new ConditionRouterFactory().getRouter(getRouteUrl("host = " + NetUtils.getLocalHost() + " => " + " host = 1.2.3.4"));
    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(invokers, fileredInvokers);
}
 
Example #10
Source File: ConditionRouterTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #11
Source File: ConditionRouterTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void testRoute_Placeholder(){
    Router router = new ConditionRouterFactory().getRouter(getRouteUrl("host = " + NetUtils.getLocalHost() + " => " + " host = $host"));
    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));
}
 
Example #12
Source File: ConditionRouterTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example #13
Source File: ConditionRouterTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #14
Source File: ConditionRouterTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void testRoute_ReturnEmpty(){
    Router router = new ConditionRouterFactory().getRouter(getRouteUrl("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(0, fileredInvokers.size());
}
 
Example #15
Source File: ConditionRouterTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #16
Source File: ConditionRouterTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void testRoute_False_HostFilter(){
    Router router = new ConditionRouterFactory().getRouter(getRouteUrl("true => " + " 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));
}
 
Example #17
Source File: ScriptRouterTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #18
Source File: ConditionRouterTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #19
Source File: ScriptRouterTest.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #20
Source File: ConditionRouterTest.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #21
Source File: ConditionRouterTest.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@Test
public void testRoute_NoForce(){
    Router router = new ConditionRouterFactory().getRouter(getRouteUrl("host = " + NetUtils.getLocalHost() + " => " + " host = 1.2.3.4"));
    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(invokers, fileredInvokers);
}
 
Example #22
Source File: ConditionRouterTest.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@Test
public void testRoute_Placeholder(){
    Router router = new ConditionRouterFactory().getRouter(getRouteUrl("host = " + NetUtils.getLocalHost() + " => " + " host = $host"));
    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));
}
 
Example #23
Source File: ConditionRouterTest.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@Test
public void testRoute_False_HostFilter(){
    Router router = new ConditionRouterFactory().getRouter(getRouteUrl("true => " + " 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));
}
 
Example #24
Source File: ConditionRouterTest.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@Test
public void testRoute_Empty_HostFilter(){
    Router router = new ConditionRouterFactory().getRouter(getRouteUrl(" => " + " 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));
}
 
Example #25
Source File: ConditionRouterTest.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example #26
Source File: ConditionRouterTest.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #27
Source File: ConditionRouterTest.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@Test
public void testRoute_ReturnEmpty(){
    Router router = new ConditionRouterFactory().getRouter(getRouteUrl("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(0, fileredInvokers.size());
}
 
Example #28
Source File: ConditionRouterTest.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #29
Source File: ConditionRouterTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #30
Source File: ConditionRouterTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void testRoute_ReturnEmpty(){
    Router router = new ConditionRouterFactory().getRouter(getRouteUrl("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(0, fileredInvokers.size());
}