Search in sources :

Example 1 with Person

use of org.apache.dubbo.rpc.support.Person 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 2 with Person

use of org.apache.dubbo.rpc.support.Person 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 3 with Person

use of org.apache.dubbo.rpc.support.Person 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 4 with Person

use of org.apache.dubbo.rpc.support.Person in project dubbo by alibaba.

the class GenericImplFilterTest method testInvokeWith$Invoke.

@Test
public void testInvokeWith$Invoke() 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(), "org.apache.dubbo.rpc.support.DemoService:dubbo", 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&generic=true");
    Invoker invoker = Mockito.mock(Invoker.class);
    when(invoker.invoke(any(Invocation.class))).thenReturn(new AppResponse(new Person("person", 10)));
    when(invoker.getUrl()).thenReturn(url);
    genericImplFilter.invoke(invoker, invocation);
    Assertions.assertEquals("true", invocation.getAttachment(GENERIC_KEY));
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) GenericService(org.apache.dubbo.rpc.service.GenericService) 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) Method(java.lang.reflect.Method) Person(org.apache.dubbo.rpc.support.Person) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 5 with Person

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

Aggregations

URL (org.apache.dubbo.common.URL)7 AppResponse (org.apache.dubbo.rpc.AppResponse)7 Invocation (org.apache.dubbo.rpc.Invocation)7 Invoker (org.apache.dubbo.rpc.Invoker)7 RpcInvocation (org.apache.dubbo.rpc.RpcInvocation)7 Person (org.apache.dubbo.rpc.support.Person)7 Test (org.junit.jupiter.api.Test)7 HashMap (java.util.HashMap)6 Method (java.lang.reflect.Method)5 AsyncRpcResult (org.apache.dubbo.rpc.AsyncRpcResult)5 Result (org.apache.dubbo.rpc.Result)5 GenericService (org.apache.dubbo.rpc.service.GenericService)5 GenericException (com.alibaba.dubbo.rpc.service.GenericException)1