Search in sources :

Example 16 with RegistryDirectory

use of org.apache.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();
    Assertions.assertEquals(0, latch.getCount());
}
Also used : RegistryDirectory(org.apache.dubbo.registry.integration.RegistryDirectory) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Example 17 with RegistryDirectory

use of org.apache.dubbo.registry.integration.RegistryDirectory in project dubbo by alibaba.

the class RegistryDirectoryTest method testNofityOverrideUrls_CleanOnly.

/**
 * The test clears the override rule and only sends the override cleanup rules
 * Whether the test can be restored to the providerUrl when it is pushed
 */
@Test
public void testNofityOverrideUrls_CleanOnly() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    invocation = new RpcInvocation();
    List<URL> durls = new ArrayList<URL>();
    durls.add(SERVICEURL.setHost("10.20.30.140").addParameter("timeout", "1"));
    registryDirectory.notify(durls);
    Assertions.assertNull(((InvokerWrapper<?>) registryDirectory.getInvokers().get(0)).getUrl().getParameter("mock"));
    // override
    durls = new ArrayList<URL>();
    durls.add(URL.valueOf("override://0.0.0.0?timeout=1000&mock=fail"));
    registryDirectory.notify(durls);
    List<Invoker<?>> invokers = registryDirectory.list(invocation);
    Invoker<?> aInvoker = invokers.get(0);
    Assertions.assertEquals("1000", aInvoker.getUrl().getParameter("timeout"));
    Assertions.assertEquals("fail", ((InvokerWrapper<?>) registryDirectory.getInvokers().get(0)).getUrl().getParameter("mock"));
    // override clean
    durls = new ArrayList<URL>();
    durls.add(URL.valueOf("override://0.0.0.0/dubbo.test.api.HelloService"));
    registryDirectory.notify(durls);
    invokers = registryDirectory.list(invocation);
    aInvoker = invokers.get(0);
    // Need to be restored to the original providerUrl
    Assertions.assertEquals("1", aInvoker.getUrl().getParameter("timeout"));
    Assertions.assertNull(((InvokerWrapper<?>) registryDirectory.getInvokers().get(0)).getUrl().getParameter("mock"));
}
Also used : RegistryDirectory(org.apache.dubbo.registry.integration.RegistryDirectory) RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) MockClusterInvoker(org.apache.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker) Invoker(org.apache.dubbo.rpc.Invoker) ArrayList(java.util.ArrayList) InvokerWrapper(org.apache.dubbo.rpc.protocol.InvokerWrapper) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 18 with RegistryDirectory

use of org.apache.dubbo.registry.integration.RegistryDirectory in project dubbo by alibaba.

the class RegistryDirectoryTest method testNotifyRouterUrls_Clean.

@Test
public void testNotifyRouterUrls_Clean() {
    if (isScriptUnsupported)
        return;
    RegistryDirectory registryDirectory = getRegistryDirectory();
    URL routerurl = URL.valueOf(ROUTE_PROTOCOL + "://127.0.0.1:9096/").addParameter(ROUTER_KEY, "javascript").addParameter(RULE_KEY, "function test1(){}").addParameter(ROUTER_KEY, // FIX
    "script");
    // BAD
    List<URL> serviceUrls = new ArrayList<URL>();
    // without ROUTER_KEY, the first router should not be created.
    serviceUrls.add(routerurl);
    registryDirectory.notify(serviceUrls);
// FIXME
/* List routers = registryDirectory.getRouters();
        Assertions.assertEquals(1 + 1, routers.size());

        serviceUrls.clear();
        serviceUrls.add(routerurl.addParameter(Constants.ROUTER_KEY, Constants.ROUTER_TYPE_CLEAR));
        registryDirectory.notify(serviceUrls);
        routers = registryDirectory.getRouters();
        Assertions.assertEquals(0 + 1, routers.size());*/
}
Also used : RegistryDirectory(org.apache.dubbo.registry.integration.RegistryDirectory) ArrayList(java.util.ArrayList) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 19 with RegistryDirectory

use of org.apache.dubbo.registry.integration.RegistryDirectory in project dubbo by alibaba.

the class RegistryDirectoryTest method getRegistryDirectory.

private RegistryDirectory getRegistryDirectory(URL url) {
    RegistryDirectory registryDirectory = new RegistryDirectory(URL.class, url);
    registryDirectory.setProtocol(protocol);
    registryDirectory.setRegistry(registry);
    registryDirectory.setRouterChain(RouterChain.buildChain(url));
    Map<String, String> queryMap = StringUtils.parseQueryString(url.getParameterAndDecoded(REFER_KEY));
    URL subscribeUrl = new URL(CONSUMER_PROTOCOL, "10.20.30.40", 0, url.getServiceInterface(), queryMap);
    registryDirectory.subscribe(subscribeUrl);
    // asert empty
    List invokers = registryDirectory.list(invocation);
    Assertions.assertEquals(0, invokers.size());
    Assertions.assertFalse(registryDirectory.isAvailable());
    return registryDirectory;
}
Also used : RegistryDirectory(org.apache.dubbo.registry.integration.RegistryDirectory) List(java.util.List) ArrayList(java.util.ArrayList) URL(org.apache.dubbo.common.URL)

Example 20 with RegistryDirectory

use of org.apache.dubbo.registry.integration.RegistryDirectory in project dubbo by alibaba.

the class RegistryDirectoryTest method testDestroy_WithDestroyRegistry_WithError.

@Test
public void testDestroy_WithDestroyRegistry_WithError() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    registryDirectory.setRegistry(new MockRegistry(true));
    registryDirectory.destroy();
}
Also used : RegistryDirectory(org.apache.dubbo.registry.integration.RegistryDirectory) Test(org.junit.jupiter.api.Test)

Aggregations

RegistryDirectory (org.apache.dubbo.registry.integration.RegistryDirectory)34 Test (org.junit.jupiter.api.Test)32 URL (org.apache.dubbo.common.URL)30 ArrayList (java.util.ArrayList)29 RpcInvocation (org.apache.dubbo.rpc.RpcInvocation)23 Invoker (org.apache.dubbo.rpc.Invoker)20 MockClusterInvoker (org.apache.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker)20 List (java.util.List)7 HashMap (java.util.HashMap)2 RpcException (org.apache.dubbo.rpc.RpcException)2 Field (java.lang.reflect.Field)1 Map (java.util.Map)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 RegistryService (org.apache.dubbo.registry.RegistryService)1 InvokerWrapper (org.apache.dubbo.rpc.protocol.InvokerWrapper)1 Disabled (org.junit.jupiter.api.Disabled)1