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