use of com.alibaba.dubbo.registry.integration.RegistryDirectory in project dubbo by alibaba.
the class RegistryDirectoryTest method testNofityOverrideUrls_disabled_allProvider.
/**
* Test override disables all service providers through enable=false
* Expectation: all service providers can not be disabled through 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);
// All service providers can not be disabled through override.
Assert.assertEquals(2, invokers.size());
}
use of com.alibaba.dubbo.registry.integration.RegistryDirectory in project dubbo by alibaba.
the class RegistryDirectoryTest method testNotified_Normal.
@Test
public void testNotified_Normal() {
RegistryDirectory registryDirectory = getRegistryDirectory();
test_Notified2invokers(registryDirectory);
test_Notified1invokers(registryDirectory);
test_Notified3invokers(registryDirectory);
testforbid(registryDirectory);
}
use of com.alibaba.dubbo.registry.integration.RegistryDirectory in project dubbo by alibaba.
the class RegistryDirectoryTest method test_Notified_acceptProtocol0.
// mock protocol
// Test the matching of protocol and select only the matched protocol for refer
@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());
}
use of com.alibaba.dubbo.registry.integration.RegistryDirectory in project dubbo by alibaba.
the class RegistryDirectoryTest method testNotifyoverrideUrls_Nouse.
/**
* Test whether the override rule have a high priority
* Scene: the rules of the push are the same as the parameters of the provider
* Expectation: no need to be re-referenced
*/
@Test
public void testNotifyoverrideUrls_Nouse() {
RegistryDirectory registryDirectory = getRegistryDirectory();
invocation = new RpcInvocation();
List<URL> durls = new ArrayList<URL>();
// One is the same, one is different
durls.add(SERVICEURL.addParameter("timeout", "1"));
durls.add(SERVICEURL2.addParameter("timeout", "1").addParameter("connections", "5"));
registryDirectory.notify(durls);
List<Invoker<?>> invokers = registryDirectory.list(invocation);
Assert.assertEquals(2, invokers.size());
Invoker<?> a1Invoker = invokers.get(0);
Invoker<?> b1Invoker = invokers.get(1);
durls = new ArrayList<URL>();
durls.add(URL.valueOf("override://0.0.0.0?timeout=1&connections=5"));
registryDirectory.notify(durls);
Assert.assertEquals(true, registryDirectory.isAvailable());
invokers = registryDirectory.list(invocation);
Assert.assertEquals(2, invokers.size());
Invoker<?> a2Invoker = invokers.get(0);
Invoker<?> b2Invoker = invokers.get(1);
// The parameters are different and must be rereferenced.
Assert.assertFalse("object not same", a1Invoker == a2Invoker);
// The parameters can not be rereferenced
Assert.assertTrue("object same", b1Invoker == b2Invoker);
}
use of com.alibaba.dubbo.registry.integration.RegistryDirectory in project dubbo by alibaba.
the class RegistryDirectoryTest method testParametersMerge.
@Test
public void testParametersMerge() {
RegistryDirectory registryDirectory = getRegistryDirectory();
URL regurl = noMeaningUrl.addParameter("test", "reg").addParameterAndEncoded(Constants.REFER_KEY, "key=query&" + Constants.LOADBALANCE_KEY + "=" + LeastActiveLoadBalance.NAME);
RegistryDirectory<RegistryDirectoryTest> registryDirectory2 = new RegistryDirectory(RegistryDirectoryTest.class, regurl);
registryDirectory2.setProtocol(protocol);
List<URL> serviceUrls = new ArrayList<URL>();
// The parameters of the inspection registry need to be cleared
{
serviceUrls.clear();
serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1"));
registryDirectory.notify(serviceUrls);
invocation = new RpcInvocation();
List invokers = registryDirectory.list(invocation);
Invoker invoker = (Invoker) invokers.get(0);
URL url = invoker.getUrl();
Assert.assertEquals(null, url.getParameter("key"));
}
// The parameters of the provider for the inspection service need merge
{
serviceUrls.clear();
serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX2").addParameter("key", "provider"));
registryDirectory.notify(serviceUrls);
invocation = new RpcInvocation();
List invokers = registryDirectory.list(invocation);
Invoker invoker = (Invoker) invokers.get(0);
URL url = invoker.getUrl();
Assert.assertEquals("provider", url.getParameter("key"));
}
// The parameters of the test service query need to be with the providermerge.
{
serviceUrls.clear();
serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX3").addParameter("key", "provider"));
registryDirectory2.notify(serviceUrls);
invocation = new RpcInvocation();
List invokers = registryDirectory2.list(invocation);
Invoker invoker = (Invoker) invokers.get(0);
URL url = invoker.getUrl();
Assert.assertEquals("query", url.getParameter("key"));
}
{
serviceUrls.clear();
serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1"));
registryDirectory.notify(serviceUrls);
invocation = new RpcInvocation();
List invokers = registryDirectory.list(invocation);
Invoker invoker = (Invoker) invokers.get(0);
URL url = invoker.getUrl();
Assert.assertEquals(false, url.getParameter(Constants.CHECK_KEY, false));
}
{
serviceUrls.clear();
serviceUrls.add(SERVICEURL.addParameter(Constants.LOADBALANCE_KEY, RoundRobinLoadBalance.NAME));
registryDirectory2.notify(serviceUrls);
invocation = new RpcInvocation();
invocation.setMethodName("get");
List invokers = registryDirectory2.list(invocation);
Invoker invoker = (Invoker) invokers.get(0);
URL url = invoker.getUrl();
Assert.assertEquals(LeastActiveLoadBalance.NAME, url.getMethodParameter("get", Constants.LOADBALANCE_KEY));
}
// test geturl
{
Assert.assertEquals(null, registryDirectory2.getUrl().getParameter("mock"));
serviceUrls.clear();
serviceUrls.add(SERVICEURL.addParameter(Constants.MOCK_KEY, "true"));
registryDirectory2.notify(serviceUrls);
Assert.assertEquals("true", registryDirectory2.getUrl().getParameter("mock"));
}
}
Aggregations