com.alibaba.dubbo.registry.integration.RegistryDirectory Java Examples

The following examples show how to use com.alibaba.dubbo.registry.integration.RegistryDirectory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RegistryDirectoryTest.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
/**
 * When the first arg of a method is String or Enum, Registry server can do parameter-value-based routing.
 */
@Test
public void testParmeterRoute() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    List<URL> serviceUrls = new ArrayList<URL>();
    serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1.napoli"));
    serviceUrls.add(SERVICEURL2.addParameter("methods", "getXXX1.MORGAN,getXXX2"));
    serviceUrls.add(SERVICEURL3.addParameter("methods", "getXXX1.morgan,getXXX2,getXXX3"));

    registryDirectory.notify(serviceUrls);

    invocation = new RpcInvocation(
                                   Constants.$INVOKE,
                                   new Class[] { String.class, String[].class, Object[].class },
                                   new Object[] { "getXXX1", new String[] { "Enum" }, new Object[] { Param.MORGAN } });

    List invokers = registryDirectory.list(invocation);
    Assert.assertEquals(1, invokers.size());
}
 
Example #2
Source File: RegistryDirectoryTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
/**
 * 测试override通过enable=false,禁用指定服务提供者
 * 预期:可以禁用指定的服务提供者。
 */
@Test
public void testNofity_disabled_specifiedProvider(){
	RegistryDirectory registryDirectory = getRegistryDirectory();
    invocation = new RpcInvocation();
    
    // 初始就禁用
    List<URL> durls = new ArrayList<URL>();
    durls.add(SERVICEURL.setHost("10.20.30.140").addParameter(Constants.ENABLED_KEY, "false"));
    durls.add(SERVICEURL.setHost("10.20.30.141"));
    registryDirectory.notify(durls);
    
    List<Invoker<?>> invokers = registryDirectory.list(invocation);
    Assert.assertEquals(1,invokers.size());
    Assert.assertEquals("10.20.30.141", invokers.get(0).getUrl().getHost());
    
    // 通过覆盖规则启用
    durls = new ArrayList<URL>();
    durls.add(URL.valueOf("override://10.20.30.140?"+Constants.DISABLED_KEY+"=false"));
    registryDirectory.notify(durls);
    List<Invoker<?>> invokers2 = registryDirectory.list(invocation);
    Assert.assertEquals(2,invokers2.size());
}
 
Example #3
Source File: RegistryDirectoryTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@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);
    Assert.assertEquals(2, invokers.size());
}
 
Example #4
Source File: RegistryDirectoryTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #5
Source File: RegistryDirectoryTest.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@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);
    Assert.assertEquals(true, registryDirectory.isAvailable());

    invocation = new RpcInvocation();

    List<Invoker<DemoService>> invokers = registryDirectory.list(invocation);
    Assert.assertEquals(1, invokers.size());

    invocation.setMethodName("getXXX");
    invokers = registryDirectory.list(invocation);
    Assert.assertEquals(1, invokers.size());
    Assert.assertEquals(DemoService.class.getName(), invokers.get(0).getUrl().getPath());
}
 
Example #6
Source File: RegistryDirectoryTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
/**
 * 测试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());
}
 
Example #7
Source File: RegistryDirectoryTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
private void test_Notified2invokers(RegistryDirectory registryDirectory) {
    List<URL> serviceUrls = new ArrayList<URL>();
    serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1"));
    serviceUrls.add(SERVICEURL2.addParameter("methods", "getXXX1,getXXX2"));
    serviceUrls.add(SERVICEURL2.addParameter("methods", "getXXX1,getXXX2"));

    registryDirectory.notify(serviceUrls);
    Assert.assertEquals(true, registryDirectory.isAvailable());

    invocation = new RpcInvocation();

    List invokers = registryDirectory.list(invocation);
    Assert.assertEquals(2, invokers.size());

    invocation.setMethodName("getXXX");
    invokers = registryDirectory.list(invocation);
    Assert.assertEquals(2, invokers.size());

    invocation.setMethodName("getXXX1");
    invokers = registryDirectory.list(invocation);
    Assert.assertEquals(2, invokers.size());

    invocation.setMethodName("getXXX2");
    invokers = registryDirectory.list(invocation);
    Assert.assertEquals(1, invokers.size());
}
 
Example #8
Source File: RegistryDirectoryTest.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
/**
 * Test whether the override rule have a high priority
 * Scene: push override rules with invoker
 */
@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());

    //Start validation of parameter values

    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"));
}
 
Example #9
Source File: RegistryDirectoryTest.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
/**
 * 测试override通过enable=false,禁用所有服务提供者
 * 预期:不能通过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?"+Constants.ENABLED_KEY+"=false"));
    registryDirectory.notify(durls);
    
    List<Invoker<?>> invokers = registryDirectory.list(invocation);
    //不能通过override禁用所有服务提供者.
    Assert.assertEquals(2,invokers.size());
}
 
Example #10
Source File: RegistryDirectoryTest.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
/**
 * Test override rules for a certain provider
 */
@Test
public void testNofityOverrideUrls_Provider() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    invocation = new RpcInvocation();

    List<URL> durls = new ArrayList<URL>();
    durls.add(SERVICEURL.setHost("10.20.30.140").addParameter("timeout", "1").addParameter(Constants.SIDE_KEY, Constants.CONSUMER_SIDE));//One is the same, one is different
    durls.add(SERVICEURL2.setHost("10.20.30.141").addParameter("timeout", "2").addParameter(Constants.SIDE_KEY, Constants.CONSUMER_SIDE));
    registryDirectory.notify(durls);

    durls = new ArrayList<URL>();
    durls.add(URL.valueOf("override://0.0.0.0?timeout=3"));
    durls.add(URL.valueOf("override://10.20.30.141:9092?timeout=4"));
    registryDirectory.notify(durls);

    List<Invoker<?>> invokers = registryDirectory.list(invocation);
    Invoker<?> aInvoker = invokers.get(0);
    Invoker<?> bInvoker = invokers.get(1);
    Assert.assertEquals("3", aInvoker.getUrl().getParameter("timeout"));
    Assert.assertEquals("4", bInvoker.getUrl().getParameter("timeout"));
}
 
Example #11
Source File: RegistryDirectoryTest.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
@Test
public void testNotifyRouterUrls_Clean() {
    if (isScriptUnsupported) return;
    RegistryDirectory registryDirectory = getRegistryDirectory();
    URL routerurl = URL.valueOf(Constants.ROUTE_PROTOCOL + "://127.0.0.1:9096/").addParameter(Constants.ROUTER_KEY,
                                                                                                 "javascript").addParameter(Constants.RULE_KEY,
                                                                                                                            "function test1(){}").addParameter(Constants.ROUTER_KEY,
                                                                                                                                                               "script"); // FIX
                                                                                                                                                                          // BAD

    List<URL> serviceUrls = new ArrayList<URL>();
    // without ROUTER_KEY, the first router should not be created.
    serviceUrls.add(routerurl);
    registryDirectory.notify(serviceUrls);
    List routers = registryDirectory.getRouters();
    Assert.assertEquals(1 + 1, routers.size());

    serviceUrls.clear();
    serviceUrls.add(routerurl.addParameter(Constants.ROUTER_KEY, Constants.ROUTER_TYPE_CLEAR));
    registryDirectory.notify(serviceUrls);
    routers = registryDirectory.getRouters();
    Assert.assertEquals(0 + 1, routers.size());
}
 
Example #12
Source File: RegistryDirectoryTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
/**
 * 测试针对某个provider的Override规则
 */
@Test
public void testNofityOverrideUrls_Provider(){
    RegistryDirectory registryDirectory = getRegistryDirectory();
    invocation = new RpcInvocation();
    
    List<URL> durls = new ArrayList<URL>();
    durls.add(SERVICEURL.setHost("10.20.30.140").addParameter("timeout", "1"));//一个一样,一个不一样
    durls.add(SERVICEURL2.setHost("10.20.30.141").addParameter("timeout", "2"));
    registryDirectory.notify(durls);
    
    durls = new ArrayList<URL>();
    durls.add(URL.valueOf("override://0.0.0.0?timeout=3"));
    durls.add(URL.valueOf("override://10.20.30.141:9092?timeout=4"));
    registryDirectory.notify(durls);
    
    List<Invoker<?>> invokers = registryDirectory.list(invocation);
    Invoker<?> aInvoker = invokers.get(0);
    Invoker<?> bInvoker = invokers.get(1);
    Assert.assertEquals("3",aInvoker.getUrl().getParameter("timeout"));
    Assert.assertEquals("4",bInvoker.getUrl().getParameter("timeout"));
}
 
Example #13
Source File: RegistryDirectoryTest.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
/**
 * 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?" + Constants.DISABLED_KEY + "=true"));
    registryDirectory.notify(durls);

    List<Invoker<?>> invokers = registryDirectory.list(invocation);
    Assert.assertEquals(1, invokers.size());
    Assert.assertEquals("10.20.30.141", 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<?>> invokers2 = registryDirectory.list(invocation);
    Assert.assertEquals(2, invokers2.size());
}
 
Example #14
Source File: DubboRegistryFactory.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public Registry createRegistry(URL url) {
    url = getRegistryURL(url);
    List<URL> urls = new ArrayList<URL>();
    urls.add(url.removeParameter(Constants.BACKUP_KEY));
    String backup = url.getParameter(Constants.BACKUP_KEY);
    if (backup != null && backup.length() > 0) {
        String[] addresses = Constants.COMMA_SPLIT_PATTERN.split(backup);
        for (String address : addresses) {
            urls.add(url.setAddress(address));
        }
    }
    RegistryDirectory<RegistryService> directory = new RegistryDirectory<RegistryService>(RegistryService.class, url.addParameter(Constants.INTERFACE_KEY, RegistryService.class.getName()).addParameterAndEncoded(Constants.REFER_KEY, url.toParameterString()));
    Invoker<RegistryService> registryInvoker = cluster.join(directory);
    RegistryService registryService = proxyFactory.getProxy(registryInvoker);
    DubboRegistry registry = new DubboRegistry(registryInvoker, registryService);
    directory.setRegistry(registry);
    directory.setProtocol(protocol);
    directory.notify(urls);
    directory.subscribe(new URL(Constants.CONSUMER_PROTOCOL, NetUtils.getLocalHost(), 0, RegistryService.class.getName(), url.getParameters()));
    return registry;
}
 
Example #15
Source File: RegistryDirectoryTest.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
/**
 * 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_disabled_specifiedProvider() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    invocation = new RpcInvocation();

    // Initially disable
    List<URL> durls = new ArrayList<URL>();
    durls.add(SERVICEURL.setHost("10.20.30.140").addParameter(Constants.ENABLED_KEY, "false"));
    durls.add(SERVICEURL.setHost("10.20.30.141"));
    registryDirectory.notify(durls);

    List<Invoker<?>> invokers = registryDirectory.list(invocation);
    Assert.assertEquals(1, invokers.size());
    Assert.assertEquals("10.20.30.141", invokers.get(0).getUrl().getHost());

    //Enabled by override rule
    durls = new ArrayList<URL>();
    durls.add(URL.valueOf("override://10.20.30.140:9091?" + Constants.DISABLED_KEY + "=false"));
    registryDirectory.notify(durls);
    List<Invoker<?>> invokers2 = registryDirectory.list(invocation);
    Assert.assertEquals(2, invokers2.size());
}
 
Example #16
Source File: RegistryDirectoryTest.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
/**
 * 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
    Assert.assertEquals("1", aInvoker.getUrl().getParameter("timeout"));
}
 
Example #17
Source File: RegistryDirectoryTest.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
private void test_Notified1invokers(RegistryDirectory registryDirectory) {

        List<URL> serviceUrls = new ArrayList<URL>();
        serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1"));// .addParameter("refer.autodestroy", "true")
        registryDirectory.notify(serviceUrls);
        Assert.assertEquals(true, registryDirectory.isAvailable());

        invocation = new RpcInvocation();

        List invokers = registryDirectory.list(invocation);
        Assert.assertEquals(1, invokers.size());

        invocation.setMethodName("getXXX");
        invokers = registryDirectory.list(invocation);
        Assert.assertEquals(1, invokers.size());

        invocation.setMethodName("getXXX1");
        invokers = registryDirectory.list(invocation);
        Assert.assertEquals(1, invokers.size());

        invocation.setMethodName("getXXX2");
        invokers = registryDirectory.list(invocation);
        Assert.assertEquals(1, invokers.size());
    }
 
Example #18
Source File: RegistryDirectoryTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
/**
 * When the first arg of a method is String or Enum, Registry server can do parameter-value-based routing.
 */
@Test
public void testParmeterRoute() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    List<URL> serviceUrls = new ArrayList<URL>();
    serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1.napoli"));
    serviceUrls.add(SERVICEURL2.addParameter("methods", "getXXX1.MORGAN,getXXX2"));
    serviceUrls.add(SERVICEURL3.addParameter("methods", "getXXX1.morgan,getXXX2,getXXX3"));

    registryDirectory.notify(serviceUrls);

    invocation = new RpcInvocation(
                                   Constants.$INVOKE,
                                   new Class[] { String.class, String[].class, Object[].class },
                                   new Object[] { "getXXX1", new String[] { "Enum" }, new Object[] { Param.MORGAN } });

    List invokers = registryDirectory.list(invocation);
    Assert.assertEquals(1, invokers.size());
}
 
Example #19
Source File: RegistryDirectoryTest.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #20
Source File: RegistryDirectoryTest.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Test
public void test_Notified_acceptProtocol2() {
    URL errorPathUrl = URL.valueOf("notsupport:/xxx");
    errorPathUrl = errorPathUrl.addParameterAndEncoded(Constants.REFER_KEY, "interface=" + service + "&protocol=dubbo,injvm");
    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);
    Assert.assertEquals(2, invokers.size());
}
 
Example #21
Source File: RegistryDirectoryTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@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);
    Assert.assertEquals(true, registryDirectory.isAvailable());

    invocation = new RpcInvocation();

    List<Invoker<DemoService>> invokers = registryDirectory.list(invocation);
    Assert.assertEquals(1, invokers.size());

    invocation.setMethodName("getXXX");
    invokers = registryDirectory.list(invocation);
    Assert.assertEquals(1, invokers.size());
    Assert.assertEquals(DemoService.class.getName(), invokers.get(0).getUrl().getPath());
}
 
Example #22
Source File: RegistryDirectoryTest.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
private void test_Notified2invokers(RegistryDirectory registryDirectory) {
    List<URL> serviceUrls = new ArrayList<URL>();
    serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1"));
    serviceUrls.add(SERVICEURL2.addParameter("methods", "getXXX1,getXXX2"));
    serviceUrls.add(SERVICEURL2.addParameter("methods", "getXXX1,getXXX2"));

    registryDirectory.notify(serviceUrls);
    Assert.assertEquals(true, registryDirectory.isAvailable());

    invocation = new RpcInvocation();

    List invokers = registryDirectory.list(invocation);
    Assert.assertEquals(2, invokers.size());

    invocation.setMethodName("getXXX");
    invokers = registryDirectory.list(invocation);
    Assert.assertEquals(2, invokers.size());

    invocation.setMethodName("getXXX1");
    invokers = registryDirectory.list(invocation);
    Assert.assertEquals(2, invokers.size());

    invocation.setMethodName("getXXX2");
    invokers = registryDirectory.list(invocation);
    Assert.assertEquals(1, invokers.size());
}
 
Example #23
Source File: DubboRegistryFactory.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public Registry createRegistry(URL url) {
    url = getRegistryURL(url);
    List<URL> urls = new ArrayList<URL>();
    urls.add(url.removeParameter(Constants.BACKUP_KEY));
    String backup = url.getParameter(Constants.BACKUP_KEY);
    if (backup != null && backup.length() > 0) {
        String[] addresses = Constants.COMMA_SPLIT_PATTERN.split(backup);
        for (String address : addresses) {
            urls.add(url.setAddress(address));
        }
    }
    RegistryDirectory<RegistryService> directory = new RegistryDirectory<RegistryService>(RegistryService.class, url.addParameter(Constants.INTERFACE_KEY, RegistryService.class.getName()).addParameterAndEncoded(Constants.REFER_KEY, url.toParameterString()));
    Invoker<RegistryService> registryInvoker = cluster.join(directory);
    RegistryService registryService = proxyFactory.getProxy(registryInvoker);
    DubboRegistry registry = new DubboRegistry(registryInvoker, registryService);
    directory.setRegistry(registry);
    directory.setProtocol(protocol);
    directory.notify(urls);
    directory.subscribe(new URL(Constants.CONSUMER_PROTOCOL, NetUtils.getLocalHost(), 0, RegistryService.class.getName(), url.getParameters()));
    return registry;
}
 
Example #24
Source File: RegistryDirectoryTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
/**
 * When the first arg of a method is String or Enum, Registry server can do parameter-value-based routing.
 */
@Test
public void testParmeterRoute() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    List<URL> serviceUrls = new ArrayList<URL>();
    serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1.napoli"));
    serviceUrls.add(SERVICEURL2.addParameter("methods", "getXXX1.MORGAN,getXXX2"));
    serviceUrls.add(SERVICEURL3.addParameter("methods", "getXXX1.morgan,getXXX2,getXXX3"));

    registryDirectory.notify(serviceUrls);

    invocation = new RpcInvocation(
                                   Constants.$INVOKE,
                                   new Class[] { String.class, String[].class, Object[].class },
                                   new Object[] { "getXXX1", new String[] { "Enum" }, new Object[] { Param.MORGAN } });

    List invokers = registryDirectory.list(invocation);
    Assert.assertEquals(1, invokers.size());
}
 
Example #25
Source File: RegistryDirectoryTest.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
/**
 * 测试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"));
}
 
Example #26
Source File: RegistryDirectoryTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@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);
    Assert.assertEquals(true, registryDirectory.isAvailable());

    invocation = new RpcInvocation();

    List<Invoker<DemoService>> invokers = registryDirectory.list(invocation);
    Assert.assertEquals(1, invokers.size());

    invocation.setMethodName("getXXX");
    invokers = registryDirectory.list(invocation);
    Assert.assertEquals(1, invokers.size());
    Assert.assertEquals(DemoService.class.getName(), invokers.get(0).getUrl().getPath());
}
 
Example #27
Source File: RegistryDirectoryTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
/**
 * When the first arg of a method is String or Enum, Registry server can do parameter-value-based routing.
 */
@Test
public void testParmeterRoute() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    List<URL> serviceUrls = new ArrayList<URL>();
    serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1.napoli"));
    serviceUrls.add(SERVICEURL2.addParameter("methods", "getXXX1.MORGAN,getXXX2"));
    serviceUrls.add(SERVICEURL3.addParameter("methods", "getXXX1.morgan,getXXX2,getXXX3"));

    registryDirectory.notify(serviceUrls);

    invocation = new RpcInvocation(
                                   Constants.$INVOKE,
                                   new Class[] { String.class, String[].class, Object[].class },
                                   new Object[] { "getXXX1", new String[] { "Enum" }, new Object[] { Param.MORGAN } });

    List invokers = registryDirectory.list(invocation);
    Assert.assertEquals(1, invokers.size());
}
 
Example #28
Source File: RegistryDirectoryTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@Test
public void testNotifyRouterUrls_Clean() {
    if (isScriptUnsupported) return;
    RegistryDirectory registryDirectory = getRegistryDirectory();
    URL routerurl = URL.valueOf(Constants.ROUTE_PROTOCOL + "://127.0.0.1:9096/").addParameter(Constants.ROUTER_KEY,
                                                                                                 "javascript").addParameter(Constants.RULE_KEY,
                                                                                                                            "function test1(){}").addParameter(Constants.ROUTER_KEY,
                                                                                                                                                               "script"); // FIX
                                                                                                                                                                          // BAD

    List<URL> serviceUrls = new ArrayList<URL>();
    // without ROUTER_KEY, the first router should not be created.
    serviceUrls.add(routerurl);
    registryDirectory.notify(serviceUrls);
    List routers = registryDirectory.getRouters();
    Assert.assertEquals(1 + 1, routers.size());

    serviceUrls.clear();
    serviceUrls.add(routerurl.addParameter(Constants.ROUTER_KEY, Constants.ROUTER_TYPE_CLEAR));
    registryDirectory.notify(serviceUrls);
    routers = registryDirectory.getRouters();
    Assert.assertEquals(0 + 1, routers.size());
}
 
Example #29
Source File: RegistryDirectoryTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@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);
    Assert.assertEquals(true, registryDirectory.isAvailable());

    invocation = new RpcInvocation();

    List<Invoker<DemoService>> invokers = registryDirectory.list(invocation);
    Assert.assertEquals(1, invokers.size());

    invocation.setMethodName("getXXX");
    invokers = registryDirectory.list(invocation);
    Assert.assertEquals(1, invokers.size());
    Assert.assertEquals(DemoService.class.getName(), invokers.get(0).getUrl().getPath());
}
 
Example #30
Source File: RegistryDirectoryTest.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
@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);
    Assert.assertEquals(2, invokers.size());
}