use of org.apache.dubbo.rpc.Invoker in project dubbo by alibaba.
the class RegistryDirectoryTest method testNofityOverrideUrls_Provider.
/**
* Test override rules for a certain provider
*/
@Test
public void testNofityOverrideUrls_Provider() {
RegistryDirectory registryDirectory = getRegistryDirectory();
invocation = new RpcInvocation();
List<URL> durls = new ArrayList<URL>();
// One is the same, one is different
durls.add(SERVICEURL.setHost("10.20.30.140").addParameter("timeout", "1").addParameter(SIDE_KEY, CONSUMER_SIDE));
durls.add(SERVICEURL2.setHost("10.20.30.141").addParameter("timeout", "2").addParameter(SIDE_KEY, CONSUMER_SIDE));
registryDirectory.notify(durls);
durls = new ArrayList<URL>();
durls.add(URL.valueOf("override://0.0.0.0?timeout=3"));
durls.add(URL.valueOf("override://10.20.30.141:9092?timeout=4"));
registryDirectory.notify(durls);
List<Invoker<?>> invokers = registryDirectory.list(invocation);
URL aUrl = invokers.get(0).getUrl();
URL bUrl = invokers.get(1).getUrl();
Assertions.assertEquals(aUrl.getHost().equals("10.20.30.140") ? "3" : "4", aUrl.getParameter("timeout"));
Assertions.assertEquals(bUrl.getHost().equals("10.20.30.141") ? "4" : "3", bUrl.getParameter("timeout"));
}
use of org.apache.dubbo.rpc.Invoker in project dubbo by alibaba.
the class RegistryDirectoryTest method test_Notified_acceptProtocol1.
// Test the matching of protocol and select only the matched protocol for refer
@Test
public void test_Notified_acceptProtocol1() {
URL errorPathUrl = URL.valueOf("notsupport:/xxx");
errorPathUrl = errorPathUrl.addParameterAndEncoded(REFER_KEY, "interface=" + service + "&protocol=dubbo");
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:9098?lazy=true&methods=getXXX");
serviceUrls.add(dubbo1URL);
serviceUrls.add(dubbo2URL);
registryDirectory.notify(serviceUrls);
invocation = new RpcInvocation();
List<Invoker<DemoService>> invokers = registryDirectory.list(invocation);
Assertions.assertEquals(1, invokers.size());
}
use of org.apache.dubbo.rpc.Invoker in project dubbo by alibaba.
the class RegistryDirectoryTest method testDubbo1UrlWithGenericInvocation.
@Test
public void testDubbo1UrlWithGenericInvocation() {
RegistryDirectory registryDirectory = getRegistryDirectory();
List<URL> serviceUrls = new ArrayList<URL>();
URL serviceURL = SERVICEURL_DUBBO_NOPATH.addParameter("methods", "getXXX1,getXXX2,getXXX3");
serviceUrls.add(serviceURL);
registryDirectory.notify(serviceUrls);
// Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException;
invocation = new RpcInvocation($INVOKE, GenericService.class.getName(), "", new Class[] { String.class, String[].class, Object[].class }, new Object[] { "getXXX1", "", new Object[] {} });
List<Invoker> invokers = registryDirectory.list(invocation);
Assertions.assertEquals(1, invokers.size());
// Assertions.assertEquals(
// serviceURL.setPath(service).addParameters("check", "false", "interface", DemoService.class.getName(), REMOTE_APPLICATION_KEY, serviceURL.getParameter(APPLICATION_KEY))
// , invokers.get(0).getUrl()
// );
}
use of org.apache.dubbo.rpc.Invoker in project dubbo by alibaba.
the class RegistryDirectoryTest method testNotifyoverrideUrls_withInvoker.
/**
* Test whether the override rule have a high priority
* Scene: push override rules with invoker
*/
@Test
public void testNotifyoverrideUrls_withInvoker() {
RegistryDirectory registryDirectory = getRegistryDirectory();
List<URL> durls = new ArrayList<URL>();
durls.add(SERVICEURL.addParameter("timeout", "1000"));
durls.add(SERVICEURL2.addParameter("timeout", "1000").addParameter("connections", "10"));
durls.add(URL.valueOf("override://0.0.0.0?timeout=1&connections=5"));
registryDirectory.notify(durls);
Assertions.assertTrue(registryDirectory.isAvailable());
// Start validation of parameter values
invocation = new RpcInvocation();
List<Invoker<?>> invokers = registryDirectory.list(invocation);
Assertions.assertEquals(2, invokers.size());
Assertions.assertEquals("1", invokers.get(0).getUrl().getParameter("timeout"), "override rute must be first priority");
Assertions.assertEquals("5", invokers.get(0).getUrl().getParameter("connections"), "override rute must be first priority");
}
use of org.apache.dubbo.rpc.Invoker 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(ENABLED_KEY, "false"));
durls.add(SERVICEURL.setHost("10.20.30.141"));
registryDirectory.notify(durls);
List<Invoker<?>> invokers = registryDirectory.list(invocation);
Assertions.assertEquals(1, invokers.size());
Assertions.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?" + DISABLED_KEY + "=false"));
registryDirectory.notify(durls);
List<Invoker<?>> invokers2 = registryDirectory.list(invocation);
Assertions.assertEquals(2, invokers2.size());
}
Aggregations