Search in sources :

Example 31 with RegistryDirectory

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

the class RegistryDirectoryTest method testDestroy.

/**
 * When destroying, RegistryDirectory should: 1. be disconnected from Registry 2. destroy all invokers
 */
@Test
public void testDestroy() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    List<URL> serviceUrls = new ArrayList<URL>();
    serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1"));
    serviceUrls.add(SERVICEURL2.addParameter("methods", "getXXX1,getXXX2"));
    serviceUrls.add(SERVICEURL3.addParameter("methods", "getXXX1,getXXX2,getXXX3"));
    registryDirectory.notify(serviceUrls);
    List<Invoker> invokers = registryDirectory.list(invocation);
    Assertions.assertTrue(registryDirectory.isAvailable());
    Assertions.assertTrue(invokers.get(0).isAvailable());
    registryDirectory.destroy();
    Assertions.assertFalse(registryDirectory.isAvailable());
    Assertions.assertFalse(invokers.get(0).isAvailable());
    registryDirectory.destroy();
    List<Invoker<RegistryDirectoryTest>> cachedInvokers = registryDirectory.getInvokers();
    Map<URL, Invoker<RegistryDirectoryTest>> urlInvokerMap = registryDirectory.getUrlInvokerMap();
    Assertions.assertNull(cachedInvokers);
    Assertions.assertEquals(0, urlInvokerMap.size());
    // List<U> urls = mockRegistry.getSubscribedUrls();
    RpcInvocation inv = new RpcInvocation();
    try {
        registryDirectory.list(inv);
        fail();
    } catch (RpcException e) {
        Assertions.assertTrue(e.getMessage().contains("already destroyed"));
    }
}
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) RpcException(org.apache.dubbo.rpc.RpcException) ArrayList(java.util.ArrayList) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 32 with RegistryDirectory

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

the class RegistryDirectoryTest method test_Notified_acceptProtocol2.

// Test the matching of protocol and select only the matched protocol for refer
@Test
public void test_Notified_acceptProtocol2() {
    URL errorPathUrl = URL.valueOf("notsupport:/xxx");
    errorPathUrl = errorPathUrl.addParameterAndEncoded(REFER_KEY, "interface=" + service + "&protocol=dubbo,injvm");
    RegistryDirectory registryDirectory = getRegistryDirectory(errorPathUrl);
    List<URL> serviceUrls = new ArrayList<URL>();
    URL dubbo1URL = URL.valueOf("dubbo://127.0.0.1:9098?lazy=true&methods=getXXX");
    URL dubbo2URL = URL.valueOf("injvm://127.0.0.1:9099?lazy=true&methods=getXXX");
    serviceUrls.add(dubbo1URL);
    serviceUrls.add(dubbo2URL);
    registryDirectory.notify(serviceUrls);
    invocation = new RpcInvocation();
    List<Invoker<DemoService>> invokers = registryDirectory.list(invocation);
    Assertions.assertEquals(2, invokers.size());
}
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) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 33 with RegistryDirectory

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

the class RegistryDirectoryTest method testNotifyoverrideUrls_beforeInvoker.

/**
 * Test whether the override rule have a high priority
 * Scene: first push override , then push invoker
 */
@Test
public void testNotifyoverrideUrls_beforeInvoker() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    List<URL> overrideUrls = new ArrayList<URL>();
    overrideUrls.add(URL.valueOf("override://0.0.0.0?timeout=1&connections=5"));
    registryDirectory.notify(overrideUrls);
    // The registry is initially pushed to override only, and the dirctory state should be false because there is no invoker.
    Assertions.assertFalse(registryDirectory.isAvailable());
    // After pushing two provider, the directory state is restored to 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);
    Assertions.assertTrue(registryDirectory.isAvailable());
    // Start validation of parameter values
    invocation = new RpcInvocation();
    List<Invoker<?>> invokers = registryDirectory.list(invocation);
    Assertions.assertEquals(2, invokers.size());
    Assertions.assertEquals("1", invokers.get(0).getUrl().getParameter("timeout"), "override rute must be first priority");
    Assertions.assertEquals("5", invokers.get(0).getUrl().getParameter("connections"), "override rute must be first priority");
}
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) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 34 with RegistryDirectory

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

the class RegistryDirectoryTest method test_Constructor_CheckStatus.

@Test
public void test_Constructor_CheckStatus() throws Exception {
    URL url = URL.valueOf("notsupported://10.20.30.40/" + service + "?a=b").addParameterAndEncoded(REFER_KEY, "foo=bar&" + REGISTER_IP_KEY + "=10.20.30.40&" + INTERFACE_KEY + "=" + service);
    RegistryDirectory reg = getRegistryDirectory(url);
    Field field = reg.getClass().getSuperclass().getSuperclass().getDeclaredField("queryMap");
    ReflectUtils.makeAccessible(field);
    Map<String, String> queryMap = (Map<String, String>) field.get(reg);
    Assertions.assertEquals("bar", queryMap.get("foo"));
    URL expected = url.setProtocol(DUBBO_PROTOCOL).clearParameters().addParameter("foo", "bar").addParameter(REGISTER_IP_KEY, "10.20.30.40").addParameter(INTERFACE_KEY, service);
    Assertions.assertEquals(expected, reg.getConsumerUrl());
}
Also used : RegistryDirectory(org.apache.dubbo.registry.integration.RegistryDirectory) Field(java.lang.reflect.Field) Map(java.util.Map) HashMap(java.util.HashMap) URL(org.apache.dubbo.common.URL) 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