Search in sources :

Example 11 with RegistryDirectory

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

the class RegistryDirectoryTest method testNotified_WithDuplicateUrls.

@Test
public void testNotified_WithDuplicateUrls() {
    List<URL> serviceUrls = new ArrayList<URL>();
    // ignore error log
    serviceUrls.add(SERVICEURL);
    serviceUrls.add(SERVICEURL);
    RegistryDirectory registryDirectory = getRegistryDirectory();
    registryDirectory.notify(serviceUrls);
    List invokers = registryDirectory.list(invocation);
    Assertions.assertEquals(1, invokers.size());
}
Also used : RegistryDirectory(org.apache.dubbo.registry.integration.RegistryDirectory) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 12 with RegistryDirectory

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

the class RegistryDirectoryTest method testNofityOverrideUrls_disabled_specifiedProvider.

/**
 * Test override disables a specified service provider through enable=false
 * It is expected that a specified service provider can be disable.
 */
@Test
public void testNofityOverrideUrls_disabled_specifiedProvider() {
    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);
    durls = new ArrayList<URL>();
    durls.add(URL.valueOf("override://10.20.30.140:9091?" + DISABLED_KEY + "=true"));
    registryDirectory.notify(durls);
    List<Invoker<?>> invokers = registryDirectory.list(invocation);
    Assertions.assertEquals(1, invokers.size());
    Assertions.assertEquals("10.20.30.141", invokers.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<?>> invokers2 = registryDirectory.list(invocation);
    Assertions.assertEquals(2, invokers2.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 13 with RegistryDirectory

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

the class RegistryDirectoryTest method test_Notified_withGroupFilter.

@Test
public void test_Notified_withGroupFilter() {
    URL directoryUrl = noMeaningUrl.addParameterAndEncoded(REFER_KEY, "interface" + service + "&group=group1,group2");
    RegistryDirectory directory = this.getRegistryDirectory(directoryUrl);
    URL provider1 = URL.valueOf("dubbo://10.134.108.1:20880/" + service + "?methods=getXXX&group=group1&mock=false&application=mockApplication");
    URL provider2 = URL.valueOf("dubbo://10.134.108.1:20880/" + service + "?methods=getXXX&group=group2&mock=false&application=mockApplication");
    List<URL> providers = new ArrayList<>();
    providers.add(provider1);
    providers.add(provider2);
    directory.notify(providers);
    invocation = new RpcInvocation();
    invocation.setMethodName("getXXX");
    List<Invoker<DemoService>> invokers = directory.list(invocation);
    Assertions.assertEquals(2, invokers.size());
    Assertions.assertTrue(invokers.get(0) instanceof MockClusterInvoker);
    Assertions.assertTrue(invokers.get(1) instanceof MockClusterInvoker);
    directoryUrl = noMeaningUrl.addParameterAndEncoded(REFER_KEY, "interface" + service + "&group=group1");
    directory = this.getRegistryDirectory(directoryUrl);
    directory.notify(providers);
    invokers = directory.list(invocation);
    Assertions.assertEquals(2, invokers.size());
    Assertions.assertFalse(invokers.get(0) instanceof MockClusterInvoker);
    Assertions.assertFalse(invokers.get(1) instanceof MockClusterInvoker);
}
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) MockClusterInvoker(org.apache.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 14 with RegistryDirectory

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

the class RegistryDirectoryTest method testNotifyoverrideUrls_Nouse.

/**
 * Test whether the override rule have a high priority
 * Scene: the rules of the push are the same as the parameters of the provider
 * Expectation: no need to be re-referenced
 */
@Test
public void testNotifyoverrideUrls_Nouse() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    invocation = new RpcInvocation();
    List<URL> durls = new ArrayList<URL>();
    // One is the same, one is different
    durls.add(SERVICEURL.addParameter("timeout", "1"));
    durls.add(SERVICEURL2.addParameter("timeout", "1").addParameter("connections", "5"));
    registryDirectory.notify(durls);
    List<Invoker<?>> invokers = registryDirectory.list(invocation);
    Assertions.assertEquals(2, invokers.size());
    Map<String, Invoker<?>> map = new HashMap<>();
    map.put(invokers.get(0).getUrl().getAddress(), invokers.get(0));
    map.put(invokers.get(1).getUrl().getAddress(), invokers.get(1));
    durls = new ArrayList<URL>();
    durls.add(URL.valueOf("override://0.0.0.0?timeout=1&connections=5"));
    registryDirectory.notify(durls);
    Assertions.assertTrue(registryDirectory.isAvailable());
    invokers = registryDirectory.list(invocation);
    Assertions.assertEquals(2, invokers.size());
    Map<String, Invoker<?>> map2 = new HashMap<>();
    map2.put(invokers.get(0).getUrl().getAddress(), invokers.get(0));
    map2.put(invokers.get(1).getUrl().getAddress(), invokers.get(1));
    // The parameters are different and must be rereferenced.
    Assertions.assertNotSame(map.get(SERVICEURL.getAddress()), map2.get(SERVICEURL.getAddress()), "object should not same");
    // The parameters can not be rereferenced
    Assertions.assertSame(map.get(SERVICEURL2.getAddress()), map2.get(SERVICEURL2.getAddress()), "object should not same");
}
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) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 15 with RegistryDirectory

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

the class RegistryDirectoryTest method testNotified_Normal.

@Test
public void testNotified_Normal() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    test_Notified2invokers(registryDirectory);
    test_Notified1invokers(registryDirectory);
    test_Notified3invokers(registryDirectory);
    testforbid(registryDirectory);
}
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