use of com.alibaba.dubbo.common.URL in project dubbo by alibaba.
the class MockClusterInvokerTest method testMockInvokerInvoke_forcemock.
/**
* 测试mock策略是否正常-force-mork
*/
@Test
public void testMockInvokerInvoke_forcemock() {
URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName());
url = url.addParameter(Constants.MOCK_KEY, "force:return null");
Invoker<IHelloService> cluster = getClusterInvoker(url);
URL mockUrl = URL.valueOf("mock://localhost/" + IHelloService.class.getName() + "?getSomething.mock=return aa&getSomething3xx.mock=return xx").addParameters(url.getParameters());
Protocol protocol = new MockProtocol();
Invoker<IHelloService> mInvoker1 = protocol.refer(IHelloService.class, mockUrl);
invokers.add(mInvoker1);
//方法配置了mock
RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("getSomething");
Result ret = cluster.invoke(invocation);
Assert.assertEquals("aa", ret.getValue());
//如果没有配置mock,则直接返回null
invocation = new RpcInvocation();
invocation.setMethodName("getSomething2");
ret = cluster.invoke(invocation);
Assert.assertEquals(null, ret.getValue());
//如果没有配置mock,则直接返回null
invocation = new RpcInvocation();
invocation.setMethodName("sayHello");
ret = cluster.invoke(invocation);
Assert.assertEquals(null, ret.getValue());
}
use of com.alibaba.dubbo.common.URL in project dubbo by alibaba.
the class AbsentConfiguratorTest method testOverride_Host.
@Test
public void testOverride_Host() {
AbsentConfigurator configurator = new AbsentConfigurator(URL.valueOf("override://10.20.153.10/com.foo.BarService?timeout=200"));
URL url = configurator.configure(URL.valueOf("dubbo://10.20.153.10:20880/com.foo.BarService?application=foo"));
Assert.assertEquals("200", url.getParameter("timeout"));
url = configurator.configure(URL.valueOf("dubbo://10.20.153.10:20880/com.foo.BarService?application=foo&timeout=1000"));
Assert.assertEquals("1000", url.getParameter("timeout"));
url = configurator.configure(URL.valueOf("dubbo://10.20.153.11:20880/com.foo.BarService?application=bar"));
Assert.assertNull(url.getParameter("timeout"));
url = configurator.configure(URL.valueOf("dubbo://10.20.153.11:20880/com.foo.BarService?application=bar&timeout=1000"));
Assert.assertEquals("1000", url.getParameter("timeout"));
}
use of com.alibaba.dubbo.common.URL in project dubbo by alibaba.
the class OverrideConfiguratorTest method testOverride_Host.
@Test
public void testOverride_Host() {
OverrideConfigurator configurator = new OverrideConfigurator(URL.valueOf("override://10.20.153.10/com.foo.BarService?timeout=200"));
URL url = configurator.configure(URL.valueOf("dubbo://10.20.153.10:20880/com.foo.BarService?application=foo"));
Assert.assertEquals("200", url.getParameter("timeout"));
url = configurator.configure(URL.valueOf("dubbo://10.20.153.10:20880/com.foo.BarService?application=foo&timeout=1000"));
Assert.assertEquals("200", url.getParameter("timeout"));
url = configurator.configure(URL.valueOf("dubbo://10.20.153.11:20880/com.foo.BarService?application=bar"));
Assert.assertNull(url.getParameter("timeout"));
url = configurator.configure(URL.valueOf("dubbo://10.20.153.11:20880/com.foo.BarService?application=bar&timeout=1000"));
Assert.assertEquals("1000", url.getParameter("timeout"));
}
use of com.alibaba.dubbo.common.URL in project dubbo by alibaba.
the class FileRouterEngineTest method testRouteAvailable.
@Test
public void testRouteAvailable() {
if (isScriptUnsupported)
return;
URL url = initUrl("availablerule.javascript");
initInvocation("method1");
initDic(url);
initInvokers(url);
MockClusterInvoker<FileRouterEngineTest> sinvoker = new MockClusterInvoker<FileRouterEngineTest>(dic, url);
for (int i = 0; i < 100; i++) {
sinvoker.invoke(invocation);
Invoker<FileRouterEngineTest> invoker = sinvoker.getSelectedInvoker();
Assert.assertEquals(invoker1, invoker);
}
}
use of com.alibaba.dubbo.common.URL in project dubbo by alibaba.
the class AbstractClusterInvokerTest method testTimeoutExceptionCode.
@Test()
public void testTimeoutExceptionCode() {
List<Invoker<DemoService>> invokers = new ArrayList<Invoker<DemoService>>();
invokers.add(new Invoker<DemoService>() {
public Class<DemoService> getInterface() {
return DemoService.class;
}
public URL getUrl() {
return URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/" + DemoService.class.getName());
}
public boolean isAvailable() {
return false;
}
public Result invoke(Invocation invocation) throws RpcException {
throw new RpcException(RpcException.TIMEOUT_EXCEPTION, "test timeout");
}
public void destroy() {
}
});
Directory<DemoService> directory = new StaticDirectory<DemoService>(invokers);
FailoverClusterInvoker<DemoService> failoverClusterInvoker = new FailoverClusterInvoker<DemoService>(directory);
try {
failoverClusterInvoker.invoke(new RpcInvocation("sayHello", new Class<?>[0], new Object[0]));
Assert.fail();
} catch (RpcException e) {
Assert.assertEquals(RpcException.TIMEOUT_EXCEPTION, e.getCode());
}
ForkingClusterInvoker<DemoService> forkingClusterInvoker = new ForkingClusterInvoker<DemoService>(directory);
try {
forkingClusterInvoker.invoke(new RpcInvocation("sayHello", new Class<?>[0], new Object[0]));
Assert.fail();
} catch (RpcException e) {
Assert.assertEquals(RpcException.TIMEOUT_EXCEPTION, e.getCode());
}
FailfastClusterInvoker<DemoService> failfastClusterInvoker = new FailfastClusterInvoker<DemoService>(directory);
try {
failfastClusterInvoker.invoke(new RpcInvocation("sayHello", new Class<?>[0], new Object[0]));
Assert.fail();
} catch (RpcException e) {
Assert.assertEquals(RpcException.TIMEOUT_EXCEPTION, e.getCode());
}
}
Aggregations