Search in sources :

Example 91 with Result

use of org.apache.dubbo.rpc.Result in project dubbo by alibaba.

the class GenericFilterTest method testInvokeWithMethodNamtNot$Invoke.

@Test
public void testInvokeWithMethodNamtNot$Invoke() {
    Method genericInvoke = GenericService.class.getMethods()[0];
    Map<String, Object> person = new HashMap<String, Object>();
    person.put("name", "dubbo");
    person.put("age", 10);
    RpcInvocation invocation = new RpcInvocation("sayHi", GenericService.class.getName(), "", genericInvoke.getParameterTypes(), new Object[] { "getPerson", new String[] { Person.class.getCanonicalName() }, new Object[] { person } });
    URL url = URL.valueOf("test://test:11/org.apache.dubbo.rpc.support.DemoService?" + "accesslog=true&group=dubbo&version=1.1");
    Invoker invoker = Mockito.mock(Invoker.class);
    when(invoker.invoke(any(Invocation.class))).thenReturn(new AppResponse(new Person("person", 10)));
    when(invoker.getUrl()).thenReturn(url);
    when(invoker.getInterface()).thenReturn(DemoService.class);
    Result result = genericFilter.invoke(invoker, invocation);
    Assertions.assertEquals(Person.class, result.getValue().getClass());
    Assertions.assertEquals(10, ((Person) (result.getValue())).getAge());
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) GenericService(org.apache.dubbo.rpc.service.GenericService) Invocation(org.apache.dubbo.rpc.Invocation) RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) HashMap(java.util.HashMap) Method(java.lang.reflect.Method) URL(org.apache.dubbo.common.URL) AsyncRpcResult(org.apache.dubbo.rpc.AsyncRpcResult) Result(org.apache.dubbo.rpc.Result) Invoker(org.apache.dubbo.rpc.Invoker) AppResponse(org.apache.dubbo.rpc.AppResponse) Person(org.apache.dubbo.rpc.support.Person) Test(org.junit.jupiter.api.Test)

Example 92 with Result

use of org.apache.dubbo.rpc.Result in project dubbo by alibaba.

the class GenericFilterTest method testInvokeWithMethodArgumentSizeIsNot3.

@Test
public void testInvokeWithMethodArgumentSizeIsNot3() {
    Method genericInvoke = GenericService.class.getMethods()[0];
    Map<String, Object> person = new HashMap<String, Object>();
    person.put("name", "dubbo");
    person.put("age", 10);
    RpcInvocation invocation = new RpcInvocation($INVOKE, GenericService.class.getName(), "", genericInvoke.getParameterTypes(), new Object[] { "getPerson", new String[] { Person.class.getCanonicalName() } });
    URL url = URL.valueOf("test://test:11/org.apache.dubbo.rpc.support.DemoService?" + "accesslog=true&group=dubbo&version=1.1");
    Invoker invoker = Mockito.mock(Invoker.class);
    when(invoker.invoke(any(Invocation.class))).thenReturn(new AppResponse(new Person("person", 10)));
    when(invoker.getUrl()).thenReturn(url);
    when(invoker.getInterface()).thenReturn(DemoService.class);
    Result result = genericFilter.invoke(invoker, invocation);
    Assertions.assertEquals(Person.class, result.getValue().getClass());
    Assertions.assertEquals(10, ((Person) (result.getValue())).getAge());
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) GenericService(org.apache.dubbo.rpc.service.GenericService) Invocation(org.apache.dubbo.rpc.Invocation) RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) HashMap(java.util.HashMap) Method(java.lang.reflect.Method) URL(org.apache.dubbo.common.URL) AsyncRpcResult(org.apache.dubbo.rpc.AsyncRpcResult) Result(org.apache.dubbo.rpc.Result) Invoker(org.apache.dubbo.rpc.Invoker) AppResponse(org.apache.dubbo.rpc.AppResponse) Person(org.apache.dubbo.rpc.support.Person) Test(org.junit.jupiter.api.Test)

Example 93 with Result

use of org.apache.dubbo.rpc.Result in project dubbo by alibaba.

the class TimeoutFilterTest method testInvokeWithTimeout.

@Test
public void testInvokeWithTimeout() throws Exception {
    int timeout = 100;
    URL url = URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1&timeout=" + timeout);
    Invoker invoker = new BlockMyInvoker(url, (timeout + 100));
    Invocation invocation = Mockito.mock(Invocation.class);
    when(invocation.getMethodName()).thenReturn("testInvokeWithTimeout");
    Result result = timeoutFilter.invoke(invoker, invocation);
    Assertions.assertEquals("Dubbo", result.getValue());
}
Also used : BlockMyInvoker(org.apache.dubbo.rpc.support.BlockMyInvoker) BlockMyInvoker(org.apache.dubbo.rpc.support.BlockMyInvoker) Invoker(org.apache.dubbo.rpc.Invoker) Invocation(org.apache.dubbo.rpc.Invocation) URL(org.apache.dubbo.common.URL) Result(org.apache.dubbo.rpc.Result) Test(org.junit.jupiter.api.Test)

Example 94 with Result

use of org.apache.dubbo.rpc.Result in project dubbo by alibaba.

the class TokenFilterTest method testInvokeWithToken.

@Test
public void testInvokeWithToken() throws Exception {
    String token = "token";
    Invoker invoker = Mockito.mock(Invoker.class);
    URL url = URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1&token=" + token);
    when(invoker.getUrl()).thenReturn(url);
    when(invoker.invoke(any(Invocation.class))).thenReturn(new AppResponse("result"));
    Map<String, Object> attachments = new HashMap<>();
    attachments.put(TOKEN_KEY, token);
    Invocation invocation = Mockito.mock(Invocation.class);
    when(invocation.getObjectAttachments()).thenReturn(attachments);
    Result result = tokenFilter.invoke(invoker, invocation);
    Assertions.assertEquals("result", result.getValue());
}
Also used : Invoker(org.apache.dubbo.rpc.Invoker) Invocation(org.apache.dubbo.rpc.Invocation) HashMap(java.util.HashMap) AppResponse(org.apache.dubbo.rpc.AppResponse) URL(org.apache.dubbo.common.URL) Result(org.apache.dubbo.rpc.Result) Test(org.junit.jupiter.api.Test)

Example 95 with Result

use of org.apache.dubbo.rpc.Result in project dubbo by alibaba.

the class CacheFilterTest method testNonArgsMethod.

@ParameterizedTest
@MethodSource("cacheFactories")
public void testNonArgsMethod(String cacheType, CacheFactory cacheFactory) {
    setUp(cacheType, cacheFactory);
    invocation.setMethodName("echo");
    invocation.setParameterTypes(new Class<?>[] {});
    invocation.setArguments(new Object[] {});
    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)

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