use of org.apache.dubbo.rpc.Result in project dubbo by alibaba.
the class ExceptionFilterTest method testConvertToRunTimeException.
@SuppressWarnings("unchecked")
@Test
public void testConvertToRunTimeException() throws Exception {
ExceptionFilter exceptionFilter = new ExceptionFilter();
RpcInvocation invocation = new RpcInvocation("sayHello", DemoService.class.getName(), "", new Class<?>[] { String.class }, new Object[] { "world" });
AppResponse mockRpcResult = new AppResponse();
mockRpcResult.setException(new HessianException("hessian"));
Result mockAsyncResult = AsyncRpcResult.newDefaultAsyncResult(mockRpcResult, invocation);
Invoker<DemoService> invoker = mock(Invoker.class);
when(invoker.invoke(invocation)).thenReturn(mockAsyncResult);
when(invoker.getInterface()).thenReturn(DemoService.class);
Result asyncResult = exceptionFilter.invoke(invoker, invocation);
AppResponse appResponse = (AppResponse) asyncResult.get();
exceptionFilter.onResponse(appResponse, invoker, invocation);
Assertions.assertFalse(appResponse.getException() instanceof HessianException);
Assertions.assertEquals(appResponse.getException().getClass(), RuntimeException.class);
}
use of org.apache.dubbo.rpc.Result in project dubbo by alibaba.
the class TimeoutFilterTest method testInvokeWithoutTimeout.
@Test
public void testInvokeWithoutTimeout() throws Exception {
int timeout = 3000;
Invoker invoker = Mockito.mock(Invoker.class);
when(invoker.invoke(any(Invocation.class))).thenReturn(new AppResponse("result"));
when(invoker.getUrl()).thenReturn(URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1&timeout=" + timeout));
Invocation invocation = Mockito.mock(Invocation.class);
when(invocation.getMethodName()).thenReturn("testInvokeWithoutTimeout");
Result result = timeoutFilter.invoke(invoker, invocation);
Assertions.assertEquals("result", result.getValue());
}
use of org.apache.dubbo.rpc.Result in project dubbo by alibaba.
the class MockClusterInvokerTest method testMockInvokerFromOverride_Invoke_check_ListString.
@SuppressWarnings("unchecked")
@Test
public void testMockInvokerFromOverride_Invoke_check_ListString() {
URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()).addParameter("getListString.mock", "force:return [\"hi\",\"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("getListString");
Result ret = cluster.invoke(invocation);
List<String> rl = (List<String>) ret.getValue();
Assertions.assertEquals(2, rl.size());
Assertions.assertEquals("hi", rl.get(0));
}
use of org.apache.dubbo.rpc.Result 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(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);
Assertions.assertEquals(0, ((List<User>) ret.getValue()).size());
}
use of org.apache.dubbo.rpc.Result in project dubbo by alibaba.
the class MockClusterInvokerTest method testMockInvokerFromOverride_Invoke_check_boolean.
@Test
public void testMockInvokerFromOverride_Invoke_check_boolean() {
URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()).addParameter(REFER_KEY, URL.encode(PATH_KEY + "=" + IHelloService.class.getName())).addParameter("getBoolean1.mock", "force:return true").addParameter("invoke_return_error", "true");
Invoker<IHelloService> cluster = getClusterInvoker(url);
// Configured with mock
RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("getBoolean1");
Result ret = cluster.invoke(invocation);
Assertions.assertTrue(ret.getValue() instanceof Boolean, "result type must be Boolean but was : " + ret.getValue().getClass());
Assertions.assertTrue(Boolean.parseBoolean(ret.getValue().toString()));
}
Aggregations