Java Code Examples for com.alibaba.dubbo.registry.integration.RegistryDirectory#getRouters()

The following examples show how to use com.alibaba.dubbo.registry.integration.RegistryDirectory#getRouters() . 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 dubbo-2.6.5 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 2
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 3
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 4
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 5
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 6
Source File: RegistryDirectoryTest.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
/**
 * 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(Constants.ROUTE_PROTOCOL + "://127.0.0.1:9096/");
    URL routerurl2 = URL.valueOf(Constants.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(Constants.CATEGORY_KEY, Constants.ROUTERS_CATEGORY).addParameter(Constants.TYPE_KEY, "javascript").addParameter(Constants.ROUTER_KEY,
            "notsupported").addParameter(Constants.RULE_KEY,
            "function test1(){}"));
    serviceUrls.add(routerurl2.addParameter(Constants.CATEGORY_KEY, Constants.ROUTERS_CATEGORY).addParameter(Constants.TYPE_KEY, "javascript").addParameter(Constants.ROUTER_KEY,
            ScriptRouterFactory.NAME).addParameter(Constants.RULE_KEY,
            "function test1(){}"));

    registryDirectory.notify(serviceUrls);
    List<Router> routers = registryDirectory.getRouters();
    //default invocation selector
    Assert.assertEquals(1 + 1, routers.size());
    Assert.assertTrue(ScriptRouter.class == routers.get(1).getClass() || ScriptRouter.class == routers.get(0).getClass());

    registryDirectory.notify(new ArrayList<URL>());
    routers = registryDirectory.getRouters();
    Assert.assertEquals(1 + 1, routers.size());
    Assert.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();
    Assert.assertEquals(0 + 1, routers.size());
}
 
Example 7
Source File: RegistryDirectoryTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
/**
 * 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(Constants.ROUTE_PROTOCOL + "://127.0.0.1:9096/");
    URL routerurl2 = URL.valueOf(Constants.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(Constants.CATEGORY_KEY, Constants.ROUTERS_CATEGORY).addParameter(Constants.TYPE_KEY, "javascript").addParameter(Constants.ROUTER_KEY,
                                                                                             "notsupported").addParameter(Constants.RULE_KEY,
                                                                                                                          "function test1(){}"));
    serviceUrls.add(routerurl2.addParameter(Constants.CATEGORY_KEY, Constants.ROUTERS_CATEGORY).addParameter(Constants.TYPE_KEY, "javascript").addParameter(Constants.ROUTER_KEY,
                                                                                              ScriptRouterFactory.NAME).addParameter(Constants.RULE_KEY,
                                                                                                                                     "function test1(){}"));

    registryDirectory.notify(serviceUrls);
    List<Router> routers = registryDirectory.getRouters();
    //default invocation selector
    Assert.assertEquals(1+1, routers.size());
    Assert.assertEquals(ScriptRouter.class, routers.get(1).getClass());

    registryDirectory.notify(new ArrayList<URL>());
    routers = registryDirectory.getRouters();
    Assert.assertEquals(1 + 1, routers.size());
    Assert.assertEquals(ScriptRouter.class, routers.get(1).getClass());

    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 8
Source File: RegistryDirectoryTest.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
/**
 * 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(Constants.ROUTE_PROTOCOL + "://127.0.0.1:9096/");
    URL routerurl2 = URL.valueOf(Constants.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(Constants.CATEGORY_KEY, Constants.ROUTERS_CATEGORY).addParameter(Constants.TYPE_KEY, "javascript").addParameter(Constants.ROUTER_KEY,
                                                                                             "notsupported").addParameter(Constants.RULE_KEY,
                                                                                                                          "function test1(){}"));
    serviceUrls.add(routerurl2.addParameter(Constants.CATEGORY_KEY, Constants.ROUTERS_CATEGORY).addParameter(Constants.TYPE_KEY, "javascript").addParameter(Constants.ROUTER_KEY,
                                                                                              ScriptRouterFactory.NAME).addParameter(Constants.RULE_KEY,
                                                                                                                                     "function test1(){}"));

    registryDirectory.notify(serviceUrls);
    List<Router> routers = registryDirectory.getRouters();
    //default invocation selector
    Assert.assertEquals(1+1, routers.size());
    Assert.assertEquals(ScriptRouter.class, routers.get(1).getClass());

    registryDirectory.notify(new ArrayList<URL>());
    routers = registryDirectory.getRouters();
    Assert.assertEquals(1 + 1, routers.size());
    Assert.assertEquals(ScriptRouter.class, routers.get(1).getClass());

    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 9
Source File: RegistryDirectoryTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
/**
 * 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(Constants.ROUTE_PROTOCOL + "://127.0.0.1:9096/");
    URL routerurl2 = URL.valueOf(Constants.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(Constants.CATEGORY_KEY, Constants.ROUTERS_CATEGORY).addParameter(Constants.TYPE_KEY, "javascript").addParameter(Constants.ROUTER_KEY,
                                                                                             "notsupported").addParameter(Constants.RULE_KEY,
                                                                                                                          "function test1(){}"));
    serviceUrls.add(routerurl2.addParameter(Constants.CATEGORY_KEY, Constants.ROUTERS_CATEGORY).addParameter(Constants.TYPE_KEY, "javascript").addParameter(Constants.ROUTER_KEY,
                                                                                              ScriptRouterFactory.NAME).addParameter(Constants.RULE_KEY,
                                                                                                                                     "function test1(){}"));

    registryDirectory.notify(serviceUrls);
    List<Router> routers = registryDirectory.getRouters();
    //default invocation selector
    Assert.assertEquals(1+1, routers.size());
    Assert.assertTrue(ScriptRouter.class == routers.get(1).getClass() || ScriptRouter.class == routers.get(0).getClass());

    registryDirectory.notify(new ArrayList<URL>());
    routers = registryDirectory.getRouters();
    Assert.assertEquals(1 + 1, routers.size());
    Assert.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();
    Assert.assertEquals(0 + 1, routers.size());
}
 
Example 10
Source File: RegistryDirectoryTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
/**
 * 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(Constants.ROUTE_PROTOCOL + "://127.0.0.1:9096/");
    URL routerurl2 = URL.valueOf(Constants.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(Constants.CATEGORY_KEY, Constants.ROUTERS_CATEGORY).addParameter(Constants.TYPE_KEY, "javascript").addParameter(Constants.ROUTER_KEY,
                                                                                             "notsupported").addParameter(Constants.RULE_KEY,
                                                                                                                          "function test1(){}"));
    serviceUrls.add(routerurl2.addParameter(Constants.CATEGORY_KEY, Constants.ROUTERS_CATEGORY).addParameter(Constants.TYPE_KEY, "javascript").addParameter(Constants.ROUTER_KEY,
                                                                                              ScriptRouterFactory.NAME).addParameter(Constants.RULE_KEY,
                                                                                                                                     "function test1(){}"));

    registryDirectory.notify(serviceUrls);
    List<Router> routers = registryDirectory.getRouters();
    //default invocation selector
    Assert.assertEquals(1+1, routers.size());
    Assert.assertEquals(ScriptRouter.class, routers.get(1).getClass());

    registryDirectory.notify(new ArrayList<URL>());
    routers = registryDirectory.getRouters();
    Assert.assertEquals(1 + 1, routers.size());
    Assert.assertEquals(ScriptRouter.class, routers.get(1).getClass());

    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());
}