Search in sources :

Example 16 with AppResponse

use of org.apache.dubbo.rpc.AppResponse 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 17 with AppResponse

use of org.apache.dubbo.rpc.AppResponse 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)

Example 18 with AppResponse

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

the class GenericImplFilterTest method testInvoke.

@Test
public void testInvoke() 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);
    Map<String, Object> person = new HashMap<String, Object>();
    person.put("name", "dubbo");
    person.put("age", 10);
    AppResponse mockRpcResult = new AppResponse(person);
    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(Person.class, result.getValue().getClass());
    Assertions.assertEquals(10, ((Person) result.getValue()).getAge());
}
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) HashMap(java.util.HashMap) AppResponse(org.apache.dubbo.rpc.AppResponse) Person(org.apache.dubbo.rpc.support.Person) URL(org.apache.dubbo.common.URL) AsyncRpcResult(org.apache.dubbo.rpc.AsyncRpcResult) Result(org.apache.dubbo.rpc.Result) Test(org.junit.jupiter.api.Test)

Example 19 with AppResponse

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

the class GenericFilterTest method testInvokeWithDefault.

@Test
public void testInvokeWithDefault() throws Exception {
    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() }, 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(AsyncRpcResult.newDefaultAsyncResult(new Person("person", 10), invocation));
    when(invoker.getUrl()).thenReturn(url);
    when(invoker.getInterface()).thenReturn(DemoService.class);
    Result asyncResult = genericFilter.invoke(invoker, invocation);
    AppResponse appResponse = (AppResponse) asyncResult.get();
    genericFilter.onResponse(appResponse, invoker, invocation);
    Assertions.assertEquals(HashMap.class, appResponse.getValue().getClass());
    Assertions.assertEquals(10, ((HashMap) appResponse.getValue()).get("age"));
}
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 20 with AppResponse

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

Aggregations

AppResponse (org.apache.dubbo.rpc.AppResponse)54 Test (org.junit.jupiter.api.Test)37 URL (org.apache.dubbo.common.URL)33 Invocation (org.apache.dubbo.rpc.Invocation)27 Result (org.apache.dubbo.rpc.Result)27 AsyncRpcResult (org.apache.dubbo.rpc.AsyncRpcResult)20 Invoker (org.apache.dubbo.rpc.Invoker)20 RpcInvocation (org.apache.dubbo.rpc.RpcInvocation)20 HashMap (java.util.HashMap)13 RpcException (org.apache.dubbo.rpc.RpcException)12 Method (java.lang.reflect.Method)8 Person (org.apache.dubbo.rpc.support.Person)7 TMessage (org.apache.thrift.protocol.TMessage)6 IMetricManager (com.alibaba.metrics.IMetricManager)5 DemoService (org.apache.dubbo.monitor.dubbo.service.DemoService)5 Request (org.apache.dubbo.remoting.exchange.Request)5 Response (org.apache.dubbo.remoting.exchange.Response)5 DemoService (org.apache.dubbo.rpc.support.DemoService)5 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)5 TIOStreamTransport (org.apache.thrift.transport.TIOStreamTransport)5