use of org.apache.dubbo.registry.integration.RegistryDirectory in project dubbo by alibaba.
the class RegistryDirectoryTest method testDestroy_WithDestroyRegistry.
@Test
public void testDestroy_WithDestroyRegistry() {
RegistryDirectory registryDirectory = getRegistryDirectory();
CountDownLatch latch = new CountDownLatch(1);
registryDirectory.setRegistry(new MockRegistry(latch));
registryDirectory.subscribe(URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/DemoService?category=providers"));
registryDirectory.destroy();
Assertions.assertEquals(0, latch.getCount());
}
use of org.apache.dubbo.registry.integration.RegistryDirectory in project dubbo by alibaba.
the class RegistryDirectoryTest method testNofityOverrideUrls_CleanOnly.
/**
* The test clears the override rule and only sends the override cleanup rules
* Whether the test can be restored to the providerUrl when it is pushed
*/
@Test
public void testNofityOverrideUrls_CleanOnly() {
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);
Assertions.assertNull(((InvokerWrapper<?>) registryDirectory.getInvokers().get(0)).getUrl().getParameter("mock"));
// override
durls = new ArrayList<URL>();
durls.add(URL.valueOf("override://0.0.0.0?timeout=1000&mock=fail"));
registryDirectory.notify(durls);
List<Invoker<?>> invokers = registryDirectory.list(invocation);
Invoker<?> aInvoker = invokers.get(0);
Assertions.assertEquals("1000", aInvoker.getUrl().getParameter("timeout"));
Assertions.assertEquals("fail", ((InvokerWrapper<?>) registryDirectory.getInvokers().get(0)).getUrl().getParameter("mock"));
// override clean
durls = new ArrayList<URL>();
durls.add(URL.valueOf("override://0.0.0.0/dubbo.test.api.HelloService"));
registryDirectory.notify(durls);
invokers = registryDirectory.list(invocation);
aInvoker = invokers.get(0);
// Need to be restored to the original providerUrl
Assertions.assertEquals("1", aInvoker.getUrl().getParameter("timeout"));
Assertions.assertNull(((InvokerWrapper<?>) registryDirectory.getInvokers().get(0)).getUrl().getParameter("mock"));
}
use of org.apache.dubbo.registry.integration.RegistryDirectory in project dubbo by alibaba.
the class RegistryDirectoryTest method testNotifyRouterUrls_Clean.
@Test
public void testNotifyRouterUrls_Clean() {
if (isScriptUnsupported)
return;
RegistryDirectory registryDirectory = getRegistryDirectory();
URL routerurl = URL.valueOf(ROUTE_PROTOCOL + "://127.0.0.1:9096/").addParameter(ROUTER_KEY, "javascript").addParameter(RULE_KEY, "function test1(){}").addParameter(ROUTER_KEY, // FIX
"script");
// BAD
List<URL> serviceUrls = new ArrayList<URL>();
// without ROUTER_KEY, the first router should not be created.
serviceUrls.add(routerurl);
registryDirectory.notify(serviceUrls);
// FIXME
/* List routers = registryDirectory.getRouters();
Assertions.assertEquals(1 + 1, routers.size());
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());*/
}
use of org.apache.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);
registryDirectory.setRegistry(registry);
registryDirectory.setRouterChain(RouterChain.buildChain(url));
Map<String, String> queryMap = StringUtils.parseQueryString(url.getParameterAndDecoded(REFER_KEY));
URL subscribeUrl = new URL(CONSUMER_PROTOCOL, "10.20.30.40", 0, url.getServiceInterface(), queryMap);
registryDirectory.subscribe(subscribeUrl);
// asert empty
List invokers = registryDirectory.list(invocation);
Assertions.assertEquals(0, invokers.size());
Assertions.assertFalse(registryDirectory.isAvailable());
return registryDirectory;
}
use of org.apache.dubbo.registry.integration.RegistryDirectory in project dubbo by alibaba.
the class RegistryDirectoryTest method testDestroy_WithDestroyRegistry_WithError.
@Test
public void testDestroy_WithDestroyRegistry_WithError() {
RegistryDirectory registryDirectory = getRegistryDirectory();
registryDirectory.setRegistry(new MockRegistry(true));
registryDirectory.destroy();
}
Aggregations