Search in sources :

Example 21 with RegistryDirectory

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

the class RegistryDirectoryTest method testNotifyoverrideUrls_afterInvoker.

/**
 * Test whether the override rule have a high priority
 * Scene: first push override , then push invoker
 */
@Test
public void testNotifyoverrideUrls_afterInvoker() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    // 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());
    List<URL> overrideUrls = new ArrayList<URL>();
    overrideUrls.add(URL.valueOf("override://0.0.0.0?timeout=1&connections=5"));
    registryDirectory.notify(overrideUrls);
    // 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 22 with RegistryDirectory

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

the class RegistryDirectoryTest method testNofityOverrideUrls_CleanNOverride.

/**
 * Test the simultaneous push to clear the override and the override for a certain provider
 * See if override can take effect
 */
@Test
public void testNofityOverrideUrls_CleanNOverride() {
    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);
    durls = new ArrayList<URL>();
    durls.add(URL.valueOf("override://0.0.0.0?timeout=3"));
    durls.add(URL.valueOf("override://0.0.0.0"));
    durls.add(URL.valueOf("override://10.20.30.140:9091?timeout=4"));
    registryDirectory.notify(durls);
    List<Invoker<?>> invokers = registryDirectory.list(invocation);
    Invoker<?> aInvoker = invokers.get(0);
    Assertions.assertEquals("4", aInvoker.getUrl().getParameter("timeout"));
}
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 23 with RegistryDirectory

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

the class RegistryDirectoryTest method testNofity_To_Decrease_provider.

/**
 * Test override disables a specified service provider through enable=false
 * It is expected that a specified service provider can be disable.
 */
@Test
public void testNofity_To_Decrease_provider() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    invocation = new RpcInvocation();
    List<URL> durls = new ArrayList<URL>();
    durls.add(SERVICEURL.setHost("10.20.30.140"));
    durls.add(SERVICEURL.setHost("10.20.30.141"));
    registryDirectory.notify(durls);
    List<Invoker<?>> invokers = registryDirectory.list(invocation);
    Assertions.assertEquals(2, invokers.size());
    durls = new ArrayList<URL>();
    durls.add(SERVICEURL.setHost("10.20.30.140"));
    registryDirectory.notify(durls);
    List<Invoker<?>> invokers2 = registryDirectory.list(invocation);
    Assertions.assertEquals(1, invokers2.size());
    Assertions.assertEquals("10.20.30.140", invokers2.get(0).getUrl().getHost());
    durls = new ArrayList<URL>();
    durls.add(URL.valueOf("empty://0.0.0.0?" + DISABLED_KEY + "=true&" + CATEGORY_KEY + "=" + CONFIGURATORS_CATEGORY));
    registryDirectory.notify(durls);
    List<Invoker<?>> invokers3 = registryDirectory.list(invocation);
    Assertions.assertEquals(1, invokers3.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 24 with RegistryDirectory

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

the class RegistryDirectoryTest method test_NotifiedDubbo1.

// The test call is independent of the path of the registry url
@Test
public void test_NotifiedDubbo1() {
    URL errorPathUrl = URL.valueOf("notsupport:/" + "xxx" + "?refer=" + URL.encode("interface=" + service));
    RegistryDirectory registryDirectory = getRegistryDirectory(errorPathUrl);
    List<URL> serviceUrls = new ArrayList<URL>();
    URL Dubbo1URL = URL.valueOf("dubbo://127.0.0.1:9098?lazy=true");
    serviceUrls.add(Dubbo1URL.addParameter("methods", "getXXX"));
    registryDirectory.notify(serviceUrls);
    Assertions.assertTrue(registryDirectory.isAvailable());
    invocation = new RpcInvocation();
    List<Invoker<DemoService>> invokers = registryDirectory.list(invocation);
    Assertions.assertEquals(1, invokers.size());
    invocation.setMethodName("getXXX");
    invokers = registryDirectory.list(invocation);
    Assertions.assertEquals(1, invokers.size());
    Assertions.assertEquals(DemoService.class.getName(), invokers.get(0).getUrl().getPath());
}
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 25 with RegistryDirectory

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

the class RegistryDirectoryTest method testNofityOverrideUrls_Clean1.

/**
 * Test cleanup override rules, and sent remove rules and other override rules
 * Whether the test can be restored to the providerUrl when it is pushed
 */
@Test
public void testNofityOverrideUrls_Clean1() {
    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);
    durls = new ArrayList<URL>();
    durls.add(URL.valueOf("override://0.0.0.0?timeout=1000"));
    registryDirectory.notify(durls);
    durls = new ArrayList<URL>();
    durls.add(URL.valueOf("override://0.0.0.0?timeout=3"));
    durls.add(URL.valueOf("override://0.0.0.0"));
    registryDirectory.notify(durls);
    List<Invoker<?>> invokers = registryDirectory.list(invocation);
    Invoker<?> aInvoker = invokers.get(0);
    // Need to be restored to the original providerUrl
    Assertions.assertEquals("3", aInvoker.getUrl().getParameter("timeout"));
}
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)

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