@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: 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: 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: 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: 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: 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: 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: invocation); Assert.assertEquals(true, matchWhen); }
boolean matchWhen(URL url, Invocation invocation) { return whenCondition == null || whenCondition.isEmpty() || matchCondition(whenCondition, url, null, invocation); }
ConditionRouter extends AbstractRouter { boolean matchWhen(URL url, Invocation invocation) { return whenCondition == null || whenCondition.isEmpty() || matchCondition(whenCondition, url, null, invocation); } }
ConditionRouter extends AbstractRouter { boolean matchWhen(URL url, Invocation invocation) { return whenCondition == null || whenCondition.isEmpty() || matchCondition(whenCondition, url, null, invocation); } ConditionRouter(URL url); }
ConditionRouter extends AbstractRouter { boolean matchWhen(URL url, Invocation invocation) { return whenCondition == null || whenCondition.isEmpty() || matchCondition(whenCondition, url, null, invocation); } ConditionRouter(URL url); @Override List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation); @Override URL getUrl(); @Override int compareTo(Router o); }
ConditionRouter extends AbstractRouter { boolean matchWhen(URL url, Invocation invocation) { return whenCondition == null || whenCondition.isEmpty() || matchCondition(whenCondition, url, null, invocation); } ConditionRouter(URL url); @Override List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation); @Override URL getUrl(); @Override int compareTo(Router o);  }