Search in sources :

Example 6 with RegistryDirectory

use of com.alibaba.dubbo.registry.integration.RegistryDirectory in project dubbo by alibaba.

the class RegistryDirectoryTest method testNofity_To_Decrease_provider.

/**
     * 测试override通过enable=false,禁用指定服务提供者
     * 预期:可以禁用指定的服务提供者。
     */
@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);
    Assert.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);
    Assert.assertEquals(1, invokers2.size());
    Assert.assertEquals("10.20.30.140", invokers.get(0).getUrl().getHost());
    durls = new ArrayList<URL>();
    durls.add(URL.valueOf("empty://0.0.0.0?" + Constants.DISABLED_KEY + "=true&" + Constants.CATEGORY_KEY + "=" + Constants.CONFIGURATORS_CATEGORY));
    registryDirectory.notify(durls);
    List<Invoker<?>> invokers3 = registryDirectory.list(invocation);
    Assert.assertEquals(1, invokers3.size());
}
Also used : RegistryDirectory(com.alibaba.dubbo.registry.integration.RegistryDirectory) RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) Invoker(com.alibaba.dubbo.rpc.Invoker) ArrayList(java.util.ArrayList) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 7 with RegistryDirectory

use of com.alibaba.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(Constants.REFER_KEY, "foo=bar");
    RegistryDirectory reg = getRegistryDirectory(url);
    Field field = reg.getClass().getDeclaredField("queryMap");
    field.setAccessible(true);
    Map<String, String> queryMap = (Map<String, String>) field.get(reg);
    Assert.assertEquals("bar", queryMap.get("foo"));
    Assert.assertEquals(url.clearParameters().addParameter("foo", "bar"), reg.getUrl());
}
Also used : RegistryDirectory(com.alibaba.dubbo.registry.integration.RegistryDirectory) Field(java.lang.reflect.Field) Map(java.util.Map) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 8 with RegistryDirectory

use of com.alibaba.dubbo.registry.integration.RegistryDirectory in project dubbo by alibaba.

the class RegistryDirectoryTest method testNofityOverrideUrls_CleanNOverride.

/**
     * 测试同时推送清除override和针对某个provider的override
     * 看override是否能够生效
     */
@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);
    Assert.assertEquals("4", aInvoker.getUrl().getParameter("timeout"));
}
Also used : RegistryDirectory(com.alibaba.dubbo.registry.integration.RegistryDirectory) RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) Invoker(com.alibaba.dubbo.rpc.Invoker) ArrayList(java.util.ArrayList) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 9 with RegistryDirectory

use of com.alibaba.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);
    Assert.assertEquals(true, registryDirectory.isAvailable());
    List invokers = registryDirectory.list(invocation);
    Assert.assertEquals(1, invokers.size());
}
Also used : RegistryDirectory(com.alibaba.dubbo.registry.integration.RegistryDirectory) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 10 with RegistryDirectory

use of com.alibaba.dubbo.registry.integration.RegistryDirectory in project dubbo by alibaba.

the class RegistryDirectoryTest method testNotify_MockProviderOnly.

// mock protocol
/**
     * 测试mock provider下发
     */
@Test
public void testNotify_MockProviderOnly() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    List<URL> serviceUrls = new ArrayList<URL>();
    serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1"));
    serviceUrls.add(SERVICEURL2.addParameter("methods", "getXXX1,getXXX2"));
    serviceUrls.add(SERVICEURL.setProtocol(Constants.MOCK_PROTOCOL));
    registryDirectory.notify(serviceUrls);
    Assert.assertEquals(true, registryDirectory.isAvailable());
    invocation = new RpcInvocation();
    List invokers = registryDirectory.list(invocation);
    Assert.assertEquals(2, invokers.size());
    RpcInvocation mockinvocation = new RpcInvocation();
    mockinvocation.setAttachment(Constants.INVOCATION_NEED_MOCK, "true");
    invokers = registryDirectory.list(mockinvocation);
    Assert.assertEquals(1, invokers.size());
}
Also used : RegistryDirectory(com.alibaba.dubbo.registry.integration.RegistryDirectory) RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Aggregations

RegistryDirectory (com.alibaba.dubbo.registry.integration.RegistryDirectory)33 Test (org.junit.Test)31 URL (com.alibaba.dubbo.common.URL)28 ArrayList (java.util.ArrayList)28 RpcInvocation (com.alibaba.dubbo.rpc.RpcInvocation)22 Invoker (com.alibaba.dubbo.rpc.Invoker)19 List (java.util.List)9 RpcException (com.alibaba.dubbo.rpc.RpcException)2 RegistryService (com.alibaba.dubbo.registry.RegistryService)1 Router (com.alibaba.dubbo.rpc.cluster.Router)1 ScriptRouter (com.alibaba.dubbo.rpc.cluster.router.script.ScriptRouter)1 Field (java.lang.reflect.Field)1 Map (java.util.Map)1 CountDownLatch (java.util.concurrent.CountDownLatch)1