use of org.apache.dubbo.rpc.RpcInvocation in project dubbo by alibaba.
the class MockClusterInvokerTest method testMockInvokerFromOverride_Invoke_checkCompatible_ImplMock.
/**
* Test if mock policy works fine: fail-mock
*/
@Test
public void testMockInvokerFromOverride_Invoke_checkCompatible_ImplMock() {
URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()).addParameter("mock", "true").addParameter(REFER_KEY, URL.encode(PATH_KEY + "=" + IHelloService.class.getName())).addParameter("invoke_return_error", "true");
Invoker<IHelloService> cluster = getClusterInvoker(url);
// Configured with mock
RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("getSomething");
Result ret = cluster.invoke(invocation);
Assertions.assertEquals("somethingmock", ret.getValue());
}
use of org.apache.dubbo.rpc.RpcInvocation in project dubbo by alibaba.
the class MockClusterInvokerTest method testMockInvokerFromOverride_Invoke_check_ListPojo.
@SuppressWarnings("unchecked")
@Test
public void testMockInvokerFromOverride_Invoke_check_ListPojo() {
URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()).addParameter("getUsers.mock", "force:return [{id:1, name:\"hi1\"}, {id:2, name:\"hi2\"}]").addParameter(REFER_KEY, URL.encode(PATH_KEY + "=" + IHelloService.class.getName())).addParameter("invoke_return_error", "true");
Invoker<IHelloService> cluster = getClusterInvoker(url);
// Configured with mock
RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("getUsers");
Result ret = cluster.invoke(invocation);
List<User> rl = (List<User>) ret.getValue();
System.out.println(rl);
Assertions.assertEquals(2, rl.size());
Assertions.assertEquals("hi1", ((User) rl.get(0)).getName());
}
use of org.apache.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(REFER_KEY, URL.encode(PATH_KEY + "=" + IHelloService.class.getName())).addParameter("invoke_return_error", "true");
Invoker<IHelloService> cluster = getClusterInvoker(url);
// Configured with mock
RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("getUsers");
try {
cluster.invoke(invocation);
} catch (RpcException e) {
}
}
use of org.apache.dubbo.rpc.RpcInvocation in project dubbo by alibaba.
the class MockClusterInvokerTest method testMockInvokerFromOverride_Invoke_force_throwCustemException.
@Test
public void testMockInvokerFromOverride_Invoke_force_throwCustemException() throws Throwable {
URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()).addParameter("getBoolean2.mock", "force:throw org.apache.dubbo.rpc.cluster.support.wrapper.MyMockException").addParameter(REFER_KEY, URL.encode(PATH_KEY + "=" + IHelloService.class.getName())).addParameter("invoke_return_error", "true");
Invoker<IHelloService> cluster = getClusterInvoker(url);
// Configured with mock
RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("getBoolean2");
try {
cluster.invoke(invocation).recreate();
Assertions.fail();
} catch (MyMockException e) {
}
}
use of org.apache.dubbo.rpc.RpcInvocation in project dubbo by alibaba.
the class MockClusterInvokerTest method testMockInvokerFromOverride_Invoke_checkCompatible_ImplMock2.
/**
* Test if mock policy works fine: fail-mock
*/
@Test
public void testMockInvokerFromOverride_Invoke_checkCompatible_ImplMock2() {
URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()).addParameter("mock", "fail").addParameter(REFER_KEY, URL.encode(PATH_KEY + "=" + IHelloService.class.getName())).addParameter("invoke_return_error", "true");
Invoker<IHelloService> cluster = getClusterInvoker(url);
// Configured with mock
RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("getSomething");
Result ret = cluster.invoke(invocation);
Assertions.assertEquals("somethingmock", ret.getValue());
}
Aggregations