Search in sources :

Example 26 with RegistryDirectory

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

the class RegistryDirectoryTest method testNofityOverrideUrls_disabled_allProvider.

/**
 * Test override disables all service providers through enable=false
 * Expectation: all service providers can not be disabled through override.
 */
@Test
public void testNofityOverrideUrls_disabled_allProvider() {
    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://0.0.0.0?" + ENABLED_KEY + "=false"));
    registryDirectory.notify(durls);
    List<Invoker<?>> invokers = registryDirectory.list(invocation);
    // All service providers can not be disabled through override.
    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 27 with RegistryDirectory

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

the class RegistryDirectoryTest method test_Notified_acceptProtocol0.

// mock protocol
// Test the matching of protocol and select only the matched protocol for refer
@Test
public void test_Notified_acceptProtocol0() {
    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&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 28 with RegistryDirectory

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

the class RegistryDirectoryTest method testNotified_WithError.

@Test
public void testNotified_WithError() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    List<URL> serviceUrls = new ArrayList<URL>();
    // ignore error log
    URL badurl = URL.valueOf("notsupported://127.0.0.1/" + service);
    serviceUrls.add(badurl);
    serviceUrls.add(SERVICEURL);
    registryDirectory.notify(serviceUrls);
    Assertions.assertTrue(registryDirectory.isAvailable());
    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 29 with RegistryDirectory

use of org.apache.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(ROUTE_PROTOCOL + "://127.0.0.1:9096/");
    URL routerurl2 = URL.valueOf(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(CATEGORY_KEY, ROUTERS_CATEGORY).addParameter(TYPE_KEY, "javascript").addParameter(ROUTER_KEY, "notsupported").addParameter(RULE_KEY, "function test1(){}"));
    serviceUrls.add(routerurl2.addParameter(CATEGORY_KEY, ROUTERS_CATEGORY).addParameter(TYPE_KEY, "javascript").addParameter(ROUTER_KEY, ScriptRouterFactory.NAME).addParameter(RULE_KEY, "function test1(){}"));
// FIXME
/*registryDirectory.notify(serviceUrls);
        RouterChain routerChain = registryDirectory.getRouterChain();
        //default invocation selector
        Assertions.assertEquals(1 + 1, routers.size());
        Assertions.assertTrue(ScriptRouter.class == routers.get(1).getClass() || ScriptRouter.class == routers.get(0).getClass());

        registryDirectory.notify(new ArrayList<URL>());
        routers = registryDirectory.getRouters();
        Assertions.assertEquals(1 + 1, routers.size());
        Assertions.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();
        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 30 with RegistryDirectory

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

the class RegistryDirectoryTest method testNotified_Normal_withRouters.

/**
 * Test push only router
 */
@Test
public void testNotified_Normal_withRouters() {
    LogUtil.start();
    RegistryDirectory registryDirectory = getRegistryDirectory();
    test_Notified1invokers(registryDirectory);
    test_Notified_only_routers(registryDirectory);
    Assertions.assertTrue(registryDirectory.isAvailable());
    Assertions.assertTrue(LogUtil.checkNoError(), "notify no invoker urls ,should not error");
    LogUtil.stop();
    test_Notified2invokers(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