use of com.alibaba.dubbo.rpc.RpcInvocation in project dubbo by alibaba.
the class MockClusterInvokerTest method testMockInvokerFromOverride_Invoke_check_int.
@Test
public void testMockInvokerFromOverride_Invoke_check_int() {
URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()).addParameter("getInt1.mock", "force:return 1688").addParameter("invoke_return_error", "true");
Invoker<IHelloService> cluster = getClusterInvoker(url);
//方法配置了mock
RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("getInt1");
Result ret = cluster.invoke(invocation);
Assert.assertTrue("result type must be integer but was : " + ret.getValue().getClass(), ret.getValue() instanceof Integer);
Assert.assertEquals(new Integer(1688), (Integer) ret.getValue());
}
use of com.alibaba.dubbo.rpc.RpcInvocation in project dubbo by alibaba.
the class MockClusterInvokerTest method testMockInvokerFromOverride_Invoke_check_ListPojo_empty.
@SuppressWarnings("unchecked")
@Test
public void testMockInvokerFromOverride_Invoke_check_ListPojo_empty() {
URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()).addParameter("getUsers.mock", "force:return empty").addParameter("invoke_return_error", "true");
Invoker<IHelloService> cluster = getClusterInvoker(url);
//方法配置了mock
RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("getUsers");
Result ret = cluster.invoke(invocation);
Assert.assertEquals(0, ((List<User>) ret.getValue()).size());
}
use of com.alibaba.dubbo.rpc.RpcInvocation in project dubbo by alibaba.
the class MockClusterInvokerTest method testMockInvokerFromOverride_Invoke_check_ListPojo_error.
@Test
public void testMockInvokerFromOverride_Invoke_check_ListPojo_error() {
URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()).addParameter("getUsers.mock", "force:return [{id:x, name:\"hi1\"}]").addParameter("invoke_return_error", "true");
Invoker<IHelloService> cluster = getClusterInvoker(url);
//方法配置了mock
RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("getUsers");
try {
cluster.invoke(invocation);
} catch (RpcException e) {
}
}
use of com.alibaba.dubbo.rpc.RpcInvocation in project dubbo by alibaba.
the class MockClusterInvokerTest method testMockInvokerFromOverride_Invoke_force_throw.
@Test
public void testMockInvokerFromOverride_Invoke_force_throw() {
URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()).addParameter("getBoolean2.mock", "force:throw ").addParameter("invoke_return_error", "true");
Invoker<IHelloService> cluster = getClusterInvoker(url);
//方法配置了mock
RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("getBoolean2");
try {
cluster.invoke(invocation);
Assert.fail();
} catch (RpcException e) {
Assert.assertFalse("not custem exception", e.isBiz());
}
}
use of com.alibaba.dubbo.rpc.RpcInvocation in project dubbo by alibaba.
the class MockClusterInvokerTest method testMockInvokerFromOverride_Invoke_Fock_WithDefault.
/**
* 测试mock策略是否正常-fail-mock
*/
@Test
public void testMockInvokerFromOverride_Invoke_Fock_WithDefault() {
URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()).addParameter("mock", "fail:return null").addParameter("getSomething.mock", "fail:return x").addParameter("getSomething2.mock", "force:return y").addParameter("invoke_return_error", "true");
Invoker<IHelloService> cluster = getClusterInvoker(url);
//方法配置了mock
RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("getSomething");
Result ret = cluster.invoke(invocation);
Assert.assertEquals("x", ret.getValue());
//如果没有配置mock,则直接返回null
invocation = new RpcInvocation();
invocation.setMethodName("getSomething2");
ret = cluster.invoke(invocation);
Assert.assertEquals("y", ret.getValue());
//如果没有配置mock,则直接返回null
invocation = new RpcInvocation();
invocation.setMethodName("getSomething3");
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());
}
Aggregations