use of org.apache.dubbo.rpc.Result in project dubbo by alibaba.
the class CacheFilterTest method testException.
@ParameterizedTest
@MethodSource("cacheFactories")
public void testException(String cacheType, CacheFactory cacheFactory) {
setUp(cacheType, cacheFactory);
invocation.setMethodName("echo1");
invocation.setParameterTypes(new Class<?>[] { String.class });
invocation.setArguments(new Object[] { "arg2" });
cacheFilter.invoke(invoker3, invocation);
cacheFilter.invoke(invoker3, invocation);
Result rpcResult = cacheFilter.invoke(invoker2, invocation);
Assertions.assertEquals(rpcResult.getValue(), "value2");
}
use of org.apache.dubbo.rpc.Result in project dubbo by alibaba.
the class CacheFilterTest method testMethodWithArgs.
@ParameterizedTest
@MethodSource("cacheFactories")
public void testMethodWithArgs(String cacheType, CacheFactory cacheFactory) {
setUp(cacheType, cacheFactory);
invocation.setMethodName("echo1");
invocation.setParameterTypes(new Class<?>[] { String.class });
invocation.setArguments(new Object[] { "arg1" });
cacheFilter.invoke(invoker, invocation);
cacheFilter.invoke(invoker, invocation);
Result rpcResult1 = cacheFilter.invoke(invoker1, invocation);
Result rpcResult2 = cacheFilter.invoke(invoker2, invocation);
Assertions.assertEquals(rpcResult1.getValue(), rpcResult2.getValue());
Assertions.assertEquals(rpcResult1.getValue(), "value");
}
use of org.apache.dubbo.rpc.Result in project dubbo by alibaba.
the class CacheFilterTest method testNull.
@ParameterizedTest
@MethodSource("cacheFactories")
public void testNull(String cacheType, CacheFactory cacheFactory) {
setUp(cacheType, cacheFactory);
invocation.setMethodName("echo1");
invocation.setParameterTypes(new Class<?>[] { String.class });
invocation.setArguments(new Object[] { "arg3" });
cacheFilter.invoke(invoker4, invocation);
cacheFilter.invoke(invoker4, invocation);
Result result1 = cacheFilter.invoke(invoker1, invocation);
Result result2 = cacheFilter.invoke(invoker2, invocation);
Assertions.assertNull(result1.getValue());
Assertions.assertNull(result2.getValue());
}
use of org.apache.dubbo.rpc.Result in project dubbo by alibaba.
the class EchoFilterTest method testEcho.
@SuppressWarnings("unchecked")
@Test
public void testEcho() {
Invocation invocation = mock(Invocation.class);
given(invocation.getMethodName()).willReturn("$echo");
given(invocation.getParameterTypes()).willReturn(new Class<?>[] { Enum.class });
given(invocation.getArguments()).willReturn(new Object[] { "hello" });
given(invocation.getObjectAttachments()).willReturn(null);
Invoker<DemoService> invoker = mock(Invoker.class);
given(invoker.isAvailable()).willReturn(true);
given(invoker.getInterface()).willReturn(DemoService.class);
AppResponse result = new AppResponse();
result.setValue("High");
given(invoker.invoke(invocation)).willReturn(result);
URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
given(invoker.getUrl()).willReturn(url);
Result filterResult = echoFilter.invoke(invoker, invocation);
assertEquals("hello", filterResult.getValue());
}
use of org.apache.dubbo.rpc.Result in project dubbo by alibaba.
the class GenericImplFilterTest method testInvokeWithException.
@Test
public void testInvokeWithException() throws Exception {
RpcInvocation invocation = new RpcInvocation("getPerson", "org.apache.dubbo.rpc.support.DemoService", "org.apache.dubbo.rpc.support.DemoService:dubbo", new Class[] { Person.class }, new Object[] { new Person("dubbo", 10) });
URL url = URL.valueOf("test://test:11/org.apache.dubbo.rpc.support.DemoService?" + "accesslog=true&group=dubbo&version=1.1&generic=true");
Invoker invoker = Mockito.mock(Invoker.class);
AppResponse mockRpcResult = new AppResponse(new GenericException(new RuntimeException("failed")));
when(invoker.invoke(any(Invocation.class))).thenReturn(AsyncRpcResult.newDefaultAsyncResult(mockRpcResult, invocation));
when(invoker.getUrl()).thenReturn(url);
when(invoker.getInterface()).thenReturn(DemoService.class);
Result asyncResult = genericImplFilter.invoke(invoker, invocation);
Result result = asyncResult.get();
genericImplFilter.onResponse(result, invoker, invocation);
Assertions.assertEquals(RuntimeException.class, result.getException().getClass());
}
Aggregations