Search in sources :

Example 31 with RegistryDirectory

use of com.alibaba.dubbo.registry.integration.RegistryDirectory in project dubbo by alibaba.

the class RegistryDirectoryTest method testDestroy_WithDestroyRegistry.

@Test
public void testDestroy_WithDestroyRegistry() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    CountDownLatch latch = new CountDownLatch(1);
    registryDirectory.setRegistry(new MockRegistry(latch));
    registryDirectory.subscribe(URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/DemoService?category=providers"));
    registryDirectory.destroy();
    Assert.assertEquals(0, latch.getCount());
}
Also used : RegistryDirectory(com.alibaba.dubbo.registry.integration.RegistryDirectory) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 32 with RegistryDirectory

use of com.alibaba.dubbo.registry.integration.RegistryDirectory in project dubbo by alibaba.

the class RegistryDirectoryTest method testNotifyoverrideUrls_afterInvoker.

/**
     * 测试override规则是否优先
     * 场景:先推送override,后推送invoker
     */
@Test
public void testNotifyoverrideUrls_afterInvoker() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    //在推送两个provider,directory状态恢复为true
    List<URL> serviceUrls = new ArrayList<URL>();
    serviceUrls.add(SERVICEURL.addParameter("timeout", "1000"));
    serviceUrls.add(SERVICEURL2.addParameter("timeout", "1000").addParameter("connections", "10"));
    registryDirectory.notify(serviceUrls);
    Assert.assertEquals(true, registryDirectory.isAvailable());
    List<URL> overrideUrls = new ArrayList<URL>();
    overrideUrls.add(URL.valueOf("override://0.0.0.0?timeout=1&connections=5"));
    registryDirectory.notify(overrideUrls);
    //开始验证参数值
    invocation = new RpcInvocation();
    List<Invoker<?>> invokers = registryDirectory.list(invocation);
    Assert.assertEquals(2, invokers.size());
    Assert.assertEquals("override rute must be first priority", "1", invokers.get(0).getUrl().getParameter("timeout"));
    Assert.assertEquals("override rute must be first priority", "5", invokers.get(0).getUrl().getParameter("connections"));
}
Also used : RegistryDirectory(com.alibaba.dubbo.registry.integration.RegistryDirectory) RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) Invoker(com.alibaba.dubbo.rpc.Invoker) ArrayList(java.util.ArrayList) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 33 with RegistryDirectory

use of com.alibaba.dubbo.registry.integration.RegistryDirectory in project dubbo by alibaba.

the class RegistryDirectoryTest method testNotifyRouterUrls.

/**
     * 1. notify twice, the second time notified router rules should completely replace the former one. 2. notify with
     * no router url, do nothing to current routers 3. notify with only one router url, with router=clean, clear all
     * current routers
     */
@Test
public void testNotifyRouterUrls() {
    if (isScriptUnsupported)
        return;
    RegistryDirectory registryDirectory = getRegistryDirectory();
    URL routerurl = URL.valueOf(Constants.ROUTE_PROTOCOL + "://127.0.0.1:9096/");
    URL routerurl2 = URL.valueOf(Constants.ROUTE_PROTOCOL + "://127.0.0.1:9097/");
    List<URL> serviceUrls = new ArrayList<URL>();
    // without ROUTER_KEY, the first router should not be created.
    serviceUrls.add(routerurl.addParameter(Constants.CATEGORY_KEY, Constants.ROUTERS_CATEGORY).addParameter(Constants.TYPE_KEY, "javascript").addParameter(Constants.ROUTER_KEY, "notsupported").addParameter(Constants.RULE_KEY, "function test1(){}"));
    serviceUrls.add(routerurl2.addParameter(Constants.CATEGORY_KEY, Constants.ROUTERS_CATEGORY).addParameter(Constants.TYPE_KEY, "javascript").addParameter(Constants.ROUTER_KEY, ScriptRouterFactory.NAME).addParameter(Constants.RULE_KEY, "function test1(){}"));
    registryDirectory.notify(serviceUrls);
    List<Router> routers = registryDirectory.getRouters();
    //default invocation selector
    Assert.assertEquals(1 + 1, routers.size());
    Assert.assertTrue(ScriptRouter.class == routers.get(1).getClass() || ScriptRouter.class == routers.get(0).getClass());
    registryDirectory.notify(new ArrayList<URL>());
    routers = registryDirectory.getRouters();
    Assert.assertEquals(1 + 1, routers.size());
    Assert.assertTrue(ScriptRouter.class == routers.get(1).getClass() || ScriptRouter.class == routers.get(0).getClass());
    serviceUrls.clear();
    serviceUrls.add(routerurl.addParameter(Constants.ROUTER_KEY, Constants.ROUTER_TYPE_CLEAR));
    registryDirectory.notify(serviceUrls);
    routers = registryDirectory.getRouters();
    Assert.assertEquals(0 + 1, routers.size());
}
Also used : RegistryDirectory(com.alibaba.dubbo.registry.integration.RegistryDirectory) ArrayList(java.util.ArrayList) Router(com.alibaba.dubbo.rpc.cluster.Router) ScriptRouter(com.alibaba.dubbo.rpc.cluster.router.script.ScriptRouter) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Aggregations

RegistryDirectory (com.alibaba.dubbo.registry.integration.RegistryDirectory)33 Test (org.junit.Test)31 URL (com.alibaba.dubbo.common.URL)28 ArrayList (java.util.ArrayList)28 RpcInvocation (com.alibaba.dubbo.rpc.RpcInvocation)22 Invoker (com.alibaba.dubbo.rpc.Invoker)19 List (java.util.List)9 RpcException (com.alibaba.dubbo.rpc.RpcException)2 RegistryService (com.alibaba.dubbo.registry.RegistryService)1 Router (com.alibaba.dubbo.rpc.cluster.Router)1 ScriptRouter (com.alibaba.dubbo.rpc.cluster.router.script.ScriptRouter)1 Field (java.lang.reflect.Field)1 Map (java.util.Map)1 CountDownLatch (java.util.concurrent.CountDownLatch)1