Search in sources :

Example 86 with Invocation

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

the class ExecuteLimitFilterTest method testExecuteLimitInvoke.

@Test
public void testExecuteLimitInvoke() throws Exception {
    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&executes=10"));
    Invocation invocation = Mockito.mock(Invocation.class);
    when(invocation.getMethodName()).thenReturn("testExecuteLimitInvoke");
    Result result = executeLimitFilter.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)

Example 87 with Invocation

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

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

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

the class GenericFilterTest method testInvokeWithJavaException.

@Test
public void testInvokeWithJavaException() throws Exception {
    // temporary enable native java generic serialize
    System.setProperty(CommonConstants.ENABLE_NATIVE_JAVA_GENERIC_SERIALIZE, "true");
    Assertions.assertThrows(RpcException.class, () -> {
        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 } });
        invocation.setAttachment(GENERIC_KEY, GENERIC_SERIALIZATION_NATIVE_JAVA);
        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);
        genericFilter.invoke(invoker, invocation);
    });
    System.clearProperty(CommonConstants.ENABLE_NATIVE_JAVA_GENERIC_SERIALIZE);
}
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 90 with Invocation

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

Aggregations

Invocation (org.apache.dubbo.rpc.Invocation)98 Test (org.junit.jupiter.api.Test)78 URL (org.apache.dubbo.common.URL)77 Invoker (org.apache.dubbo.rpc.Invoker)44 RpcInvocation (org.apache.dubbo.rpc.RpcInvocation)44 Result (org.apache.dubbo.rpc.Result)33 AppResponse (org.apache.dubbo.rpc.AppResponse)29 RpcException (org.apache.dubbo.rpc.RpcException)18 MockInvocation (org.apache.dubbo.rpc.support.MockInvocation)17 HashMap (java.util.HashMap)16 AsyncRpcResult (org.apache.dubbo.rpc.AsyncRpcResult)13 BlockMyInvoker (org.apache.dubbo.rpc.support.BlockMyInvoker)11 MyInvoker (org.apache.dubbo.rpc.support.MyInvoker)10 ArrayList (java.util.ArrayList)8 Person (org.apache.dubbo.rpc.support.Person)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 IMetricManager (com.alibaba.metrics.IMetricManager)5 Method (java.lang.reflect.Method)5 DemoService (org.apache.dubbo.monitor.dubbo.service.DemoService)5 FastCompass (com.alibaba.metrics.FastCompass)4