Search in sources :

Example 81 with Invocation

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

the class ContextFilterTest method testWithAttachments.

@Test
public void testWithAttachments() {
    URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
    Invoker<DemoService> invoker = new MyInvoker<DemoService>(url);
    Invocation invocation = new MockInvocation();
    Result result = contextFilter.invoke(invoker, invocation);
    assertNull(RpcContext.getContext().getInvoker());
}
Also used : Invocation(org.apache.dubbo.rpc.Invocation) MockInvocation(org.apache.dubbo.rpc.support.MockInvocation) DemoService(org.apache.dubbo.rpc.support.DemoService) MockInvocation(org.apache.dubbo.rpc.support.MockInvocation) MyInvoker(org.apache.dubbo.rpc.support.MyInvoker) URL(org.apache.dubbo.common.URL) Result(org.apache.dubbo.rpc.Result) Test(org.junit.jupiter.api.Test)

Example 82 with Invocation

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

the class EchoFilterTest method testNonEcho.

@SuppressWarnings("unchecked")
@Test
public void testNonEcho() {
    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("High", 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 83 with Invocation

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

the class ExecuteLimitFilterTest method testNoExecuteLimitInvoke.

@Test
public void testNoExecuteLimitInvoke() 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"));
    Invocation invocation = Mockito.mock(Invocation.class);
    when(invocation.getMethodName()).thenReturn("testNoExecuteLimitInvoke");
    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 84 with Invocation

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

the class ExecuteLimitFilterTest method testMoreThanExecuteLimitInvoke.

@Test
public void testMoreThanExecuteLimitInvoke() throws Exception {
    int maxExecute = 10;
    int totalExecute = 20;
    final AtomicInteger failed = new AtomicInteger(0);
    final Invocation invocation = Mockito.mock(Invocation.class);
    when(invocation.getMethodName()).thenReturn("testMoreThanExecuteLimitInvoke");
    URL url = URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1&executes=" + maxExecute);
    final Invoker<ExecuteLimitFilter> invoker = new BlockMyInvoker<ExecuteLimitFilter>(url, 1000);
    final CountDownLatch latch = new CountDownLatch(1);
    for (int i = 0; i < totalExecute; i++) {
        Thread thread = new Thread(new Runnable() {

            public void run() {
                try {
                    latch.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                try {
                    executeLimitFilter.invoke(invoker, invocation);
                } catch (RpcException expected) {
                    failed.incrementAndGet();
                }
            }
        });
        thread.start();
    }
    latch.countDown();
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    Assertions.assertEquals(totalExecute - maxExecute, failed.get());
}
Also used : BlockMyInvoker(org.apache.dubbo.rpc.support.BlockMyInvoker) Invocation(org.apache.dubbo.rpc.Invocation) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RpcException(org.apache.dubbo.rpc.RpcException) CountDownLatch(java.util.concurrent.CountDownLatch) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 85 with Invocation

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

the class ExecuteLimitFilterTest method testExecuteLimitInvokeWitException.

@Test
public void testExecuteLimitInvokeWitException() throws Exception {
    Invoker invoker = Mockito.mock(Invoker.class);
    doThrow(new RpcException()).when(invoker).invoke(any(Invocation.class));
    URL url = URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1&executes=10");
    when(invoker.getUrl()).thenReturn(url);
    Invocation invocation = Mockito.mock(Invocation.class);
    when(invocation.getMethodName()).thenReturn("testExecuteLimitInvokeWitException");
    try {
        executeLimitFilter.invoke(invoker, invocation);
    } catch (Exception e) {
        Assertions.assertTrue(e instanceof RpcException);
        executeLimitFilter.onError(e, invoker, invocation);
    }
    Assertions.assertEquals(1, RpcStatus.getStatus(url, invocation.getMethodName()).getFailed());
}
Also used : BlockMyInvoker(org.apache.dubbo.rpc.support.BlockMyInvoker) Invoker(org.apache.dubbo.rpc.Invoker) Invocation(org.apache.dubbo.rpc.Invocation) RpcException(org.apache.dubbo.rpc.RpcException) URL(org.apache.dubbo.common.URL) RpcException(org.apache.dubbo.rpc.RpcException) 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