Search in sources :

Example 11 with Result

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");
}
Also used : AsyncRpcResult(org.apache.dubbo.rpc.AsyncRpcResult) Result(org.apache.dubbo.rpc.Result) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 12 with Result

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");
}
Also used : AsyncRpcResult(org.apache.dubbo.rpc.AsyncRpcResult) Result(org.apache.dubbo.rpc.Result) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 13 with Result

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());
}
Also used : AsyncRpcResult(org.apache.dubbo.rpc.AsyncRpcResult) Result(org.apache.dubbo.rpc.Result) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 14 with Result

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());
}
Also used : Invocation(org.apache.dubbo.rpc.Invocation) AppResponse(org.apache.dubbo.rpc.AppResponse) DemoService(org.apache.dubbo.rpc.support.DemoService) URL(org.apache.dubbo.common.URL) Result(org.apache.dubbo.rpc.Result) Test(org.junit.jupiter.api.Test)

Example 15 with Result

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());
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) Invoker(org.apache.dubbo.rpc.Invoker) Invocation(org.apache.dubbo.rpc.Invocation) RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) AppResponse(org.apache.dubbo.rpc.AppResponse) Person(org.apache.dubbo.rpc.support.Person) GenericException(com.alibaba.dubbo.rpc.service.GenericException) URL(org.apache.dubbo.common.URL) AsyncRpcResult(org.apache.dubbo.rpc.AsyncRpcResult) Result(org.apache.dubbo.rpc.Result) Test(org.junit.jupiter.api.Test)

Aggregations

Result (org.apache.dubbo.rpc.Result)97 Test (org.junit.jupiter.api.Test)74 URL (org.apache.dubbo.common.URL)55 RpcInvocation (org.apache.dubbo.rpc.RpcInvocation)39 Invocation (org.apache.dubbo.rpc.Invocation)33 AsyncRpcResult (org.apache.dubbo.rpc.AsyncRpcResult)31 AppResponse (org.apache.dubbo.rpc.AppResponse)28 Invoker (org.apache.dubbo.rpc.Invoker)27 RpcException (org.apache.dubbo.rpc.RpcException)22 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)7 RpcContext (org.apache.dubbo.rpc.RpcContext)7 BlockMyInvoker (org.apache.dubbo.rpc.support.BlockMyInvoker)6 DemoService (org.apache.dubbo.rpc.support.DemoService)6 List (java.util.List)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 Protocol (org.apache.dubbo.rpc.Protocol)5 Person (org.apache.dubbo.rpc.support.Person)5 Method (java.lang.reflect.Method)4 MockProtocol (org.apache.dubbo.rpc.support.MockProtocol)4