Search in sources :

Example 1 with ConditionRouterFactory

use of org.apache.dubbo.rpc.cluster.router.condition.ConditionRouterFactory in project dubbo by alibaba.

the class StaticDirectoryTest method testStaticDirectory.

@Test
public void testStaticDirectory() {
    Router router = new ConditionRouterFactory().getRouter(getRouteUrl(" => " + " host = " + NetUtils.getLocalHost()));
    List<Router> routers = new ArrayList<Router>();
    routers.add(router);
    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>> filteredInvokers = router.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
    StaticDirectory<String> staticDirectory = new StaticDirectory<>(filteredInvokers);
    boolean isAvailable = staticDirectory.isAvailable();
    Assertions.assertTrue(!isAvailable);
    List<Invoker<String>> newInvokers = staticDirectory.list(new MockDirInvocation());
    Assertions.assertTrue(newInvokers.size() > 0);
    staticDirectory.destroy();
    Assertions.assertEquals(0, newInvokers.size());
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) ArrayList(java.util.ArrayList) Router(org.apache.dubbo.rpc.cluster.Router) Invoker(org.apache.dubbo.rpc.Invoker) MockInvoker(org.apache.dubbo.rpc.cluster.router.MockInvoker) MockInvoker(org.apache.dubbo.rpc.cluster.router.MockInvoker) ConditionRouterFactory(org.apache.dubbo.rpc.cluster.router.condition.ConditionRouterFactory) Test(org.junit.jupiter.api.Test)

Aggregations

ArrayList (java.util.ArrayList)1 Invoker (org.apache.dubbo.rpc.Invoker)1 RpcInvocation (org.apache.dubbo.rpc.RpcInvocation)1 Router (org.apache.dubbo.rpc.cluster.Router)1 MockInvoker (org.apache.dubbo.rpc.cluster.router.MockInvoker)1 ConditionRouterFactory (org.apache.dubbo.rpc.cluster.router.condition.ConditionRouterFactory)1 Test (org.junit.jupiter.api.Test)1