Search in sources :

Example 11 with RegistryDirectory

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

the class RegistryDirectoryTest method testNofityOverrideUrls_Clean1.

/**
     * 测试清除override规则,同时下发清除规则和其他override规则
     * 测试是否能够恢复到推送时的providerUrl
     */
@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);
    //需要恢复到最初的providerUrl
    Assert.assertEquals("1", 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 12 with RegistryDirectory

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

the class RegistryDirectoryTest method testNotifyoverrideUrls_withInvoker.

/**
     * 测试override规则是否优先
     * 场景:与invoker 一起推override规则
     */
@Test
public void testNotifyoverrideUrls_withInvoker() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    List<URL> durls = new ArrayList<URL>();
    durls.add(SERVICEURL.addParameter("timeout", "1000"));
    durls.add(SERVICEURL2.addParameter("timeout", "1000").addParameter("connections", "10"));
    durls.add(URL.valueOf("override://0.0.0.0?timeout=1&connections=5"));
    registryDirectory.notify(durls);
    Assert.assertEquals(true, registryDirectory.isAvailable());
    //开始验证参数值
    invocation = new RpcInvocation();
    List<Invoker<?>> invokers = registryDirectory.list(invocation);
    Assert.assertEquals(2, invokers.size());
    Assert.assertEquals("override rute must be first priority", "1", invokers.get(0).getUrl().getParameter("timeout"));
    Assert.assertEquals("override rute must be first priority", "5", invokers.get(0).getUrl().getParameter("connections"));
}
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 13 with RegistryDirectory

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

the class RegistryDirectoryTest method getRegistryDirectory.

private RegistryDirectory getRegistryDirectory(URL url) {
    RegistryDirectory registryDirectory = new RegistryDirectory(URL.class, url);
    registryDirectory.setProtocol(protocol);
    // asert empty
    List invokers = registryDirectory.list(invocation);
    Assert.assertEquals(0, invokers.size());
    Assert.assertEquals(false, registryDirectory.isAvailable());
    return registryDirectory;
}
Also used : RegistryDirectory(com.alibaba.dubbo.registry.integration.RegistryDirectory) ArrayList(java.util.ArrayList) List(java.util.List)

Example 14 with RegistryDirectory

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

the class RegistryDirectoryTest method testNotified_Normal_withRouters.

/**
     * 测试推送只有router的情况
     */
@Test
public void testNotified_Normal_withRouters() {
    LogUtil.start();
    RegistryDirectory registryDirectory = getRegistryDirectory();
    test_Notified1invokers(registryDirectory);
    test_Notified_only_routers(registryDirectory);
    Assert.assertEquals(true, registryDirectory.isAvailable());
    Assert.assertTrue("notify no invoker urls ,should not error", LogUtil.checkNoError());
    LogUtil.stop();
    test_Notified2invokers(registryDirectory);
}
Also used : RegistryDirectory(com.alibaba.dubbo.registry.integration.RegistryDirectory) Test(org.junit.Test)

Example 15 with RegistryDirectory

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

the class RegistryDirectoryTest method test_Notified_acceptProtocol1.

//测试protocol匹配,只选择匹配的protocol进行refer
@Test
public void test_Notified_acceptProtocol1() {
    URL errorPathUrl = URL.valueOf("notsupport:/xxx");
    errorPathUrl = errorPathUrl.addParameterAndEncoded(Constants.REFER_KEY, "interface=" + service + "&protocol=dubbo");
    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:9098?lazy=true&methods=getXXX");
    serviceUrls.add(dubbo1URL);
    serviceUrls.add(dubbo2URL);
    registryDirectory.notify(serviceUrls);
    invocation = new RpcInvocation();
    List<Invoker<DemoService>> invokers = registryDirectory.list(invocation);
    Assert.assertEquals(1, invokers.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)

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