Search in sources :

Example 36 with Invocation

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

the class ActiveLimitFilterTest method testInvokeTimeOut.

@Test
public void testInvokeTimeOut() throws Exception {
    int totalThread = 100;
    int maxActives = 10;
    long timeout = 1;
    long blockTime = 100;
    AtomicInteger count = new AtomicInteger(0);
    final CountDownLatch latch = new CountDownLatch(1);
    final CountDownLatch latchBlocking = new CountDownLatch(totalThread);
    URL url = URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1&actives=" + maxActives + "&timeout=" + timeout);
    final Invoker<ActiveLimitFilterTest> invoker = new BlockMyInvoker<ActiveLimitFilterTest>(url, blockTime);
    final Invocation invocation = new MockInvocation();
    RpcStatus.removeStatus(url);
    RpcStatus.removeStatus(url, invocation.getMethodName());
    for (int i = 0; i < totalThread; i++) {
        Thread thread = new Thread(new Runnable() {

            public void run() {
                try {
                    try {
                        latch.await();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    try {
                        Result asyncResult = activeLimitFilter.invoke(invoker, invocation);
                        Result result = asyncResult.get();
                        activeLimitFilter.onResponse(result, invoker, invocation);
                    } catch (RpcException expected) {
                        count.incrementAndGet();
                    } catch (Exception e) {
                        fail();
                    }
                } finally {
                    latchBlocking.countDown();
                }
            }
        });
        thread.start();
    }
    latch.countDown();
    try {
        latchBlocking.await();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    assertEquals(90, count.intValue());
}
Also used : Invocation(org.apache.dubbo.rpc.Invocation) MockInvocation(org.apache.dubbo.rpc.support.MockInvocation) CountDownLatch(java.util.concurrent.CountDownLatch) URL(org.apache.dubbo.common.URL) RpcException(org.apache.dubbo.rpc.RpcException) Result(org.apache.dubbo.rpc.Result) BlockMyInvoker(org.apache.dubbo.rpc.support.BlockMyInvoker) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RpcException(org.apache.dubbo.rpc.RpcException) MockInvocation(org.apache.dubbo.rpc.support.MockInvocation) Test(org.junit.jupiter.api.Test)

Example 37 with Invocation

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

the class ActiveLimitFilterTest method testInvokeLessActives.

@Test
public void testInvokeLessActives() {
    URL url = URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1&actives=10");
    Invoker<ActiveLimitFilterTest> invoker = new MyInvoker<ActiveLimitFilterTest>(url);
    Invocation invocation = new MockInvocation();
    activeLimitFilter.invoke(invoker, invocation);
}
Also used : Invocation(org.apache.dubbo.rpc.Invocation) MockInvocation(org.apache.dubbo.rpc.support.MockInvocation) MockInvocation(org.apache.dubbo.rpc.support.MockInvocation) BlockMyInvoker(org.apache.dubbo.rpc.support.BlockMyInvoker) MyInvoker(org.apache.dubbo.rpc.support.MyInvoker) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 38 with Invocation

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

the class ActiveLimitFilterTest method testInvokeRuntimeExceptionWithActiveCountMatch.

@Test
public void testInvokeRuntimeExceptionWithActiveCountMatch() {
    URL url = URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1&actives=0");
    Invoker<ActiveLimitFilterTest> invoker = new RuntimeExceptionInvoker(url);
    Invocation invocation = new MockInvocation();
    RpcStatus count = RpcStatus.getStatus(invoker.getUrl(), invocation.getMethodName());
    int beforeExceptionActiveCount = count.getActive();
    try {
        activeLimitFilter.invoke(invoker, invocation);
    } catch (RuntimeException ex) {
        activeLimitFilter.onError(ex, invoker, invocation);
        int afterExceptionActiveCount = count.getActive();
        assertEquals(beforeExceptionActiveCount, afterExceptionActiveCount, "After exception active count should be same");
    }
}
Also used : Invocation(org.apache.dubbo.rpc.Invocation) MockInvocation(org.apache.dubbo.rpc.support.MockInvocation) RuntimeExceptionInvoker(org.apache.dubbo.rpc.support.RuntimeExceptionInvoker) MockInvocation(org.apache.dubbo.rpc.support.MockInvocation) RpcStatus(org.apache.dubbo.rpc.RpcStatus) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 39 with Invocation

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

the class CompatibleFilterFilterTest method testInvokerGeneric.

@Test
public void testInvokerGeneric() {
    invocation = mock(Invocation.class);
    given(invocation.getMethodName()).willReturn("$enumlength");
    given(invocation.getParameterTypes()).willReturn(new Class<?>[] { Enum.class });
    given(invocation.getArguments()).willReturn(new Object[] { "hello" });
    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 = compatibleFilter.invoke(invoker, invocation);
    assertEquals(filterResult, result);
}
Also used : Invocation(org.apache.dubbo.rpc.Invocation) Invoker(org.apache.dubbo.rpc.Invoker) AppResponse(org.apache.dubbo.rpc.AppResponse) 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 40 with Invocation

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

the class CompatibleFilterFilterTest method testInvokerJsonPojoSerialization.

@Test
public void testInvokerJsonPojoSerialization() throws Exception {
    invocation = mock(Invocation.class);
    given(invocation.getMethodName()).willReturn("enumlength");
    given(invocation.getParameterTypes()).willReturn(new Class<?>[] { Type[].class });
    given(invocation.getArguments()).willReturn(new Object[] { "hello" });
    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(AsyncRpcResult.newDefaultAsyncResult(result, invocation));
    URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1&serialization=json");
    given(invoker.getUrl()).willReturn(url);
    Result asyncResult = compatibleFilter.invoke(invoker, invocation);
    AppResponse appResponse = (AppResponse) asyncResult.get();
    compatibleFilter.onResponse(appResponse, invoker, invocation);
    assertEquals(Type.High, appResponse.getValue());
}
Also used : Type(org.apache.dubbo.rpc.support.Type) Invocation(org.apache.dubbo.rpc.Invocation) Invoker(org.apache.dubbo.rpc.Invoker) AppResponse(org.apache.dubbo.rpc.AppResponse) URL(org.apache.dubbo.common.URL) AsyncRpcResult(org.apache.dubbo.rpc.AsyncRpcResult) Result(org.apache.dubbo.rpc.Result) 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