use of com.alibaba.dubbo.rpc.RpcInvocation in project dubbo by alibaba.
the class RegistryDirectoryTest method testNofity_disabled_specifiedProvider.
/**
* 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());
}
use of com.alibaba.dubbo.rpc.RpcInvocation 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.rpc.RpcInvocation 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.rpc.RpcInvocation 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.rpc.RpcInvocation in project dubbo by alibaba.
the class RegistryDirectoryTest method test_Notified2invokers.
// 2 invokers===================================
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());
}
Aggregations