Search in sources :

Example 6 with MockInvocation

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

the class DeprecatedFilterTest method testDeprecatedFilter.

@Test
public void testDeprecatedFilter() {
    URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1&echo." + DEPRECATED_KEY + "=true");
    LogUtil.start();
    deprecatedFilter.invoke(new MyInvoker<DemoService>(url), new MockInvocation());
    assertEquals(1, LogUtil.findMessage("The service method org.apache.dubbo.rpc.support.DemoService.echo(String) is DEPRECATED"));
    LogUtil.stop();
}
Also used : DemoService(org.apache.dubbo.rpc.support.DemoService) MockInvocation(org.apache.dubbo.rpc.support.MockInvocation) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 7 with MockInvocation

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

the class TpsLimitFilterTest method testFail.

@Test
public void testFail() throws Exception {
    Assertions.assertThrows(RpcException.class, () -> {
        URL url = URL.valueOf("test://test");
        url = url.addParameter(INTERFACE_KEY, "org.apache.dubbo.rpc.file.TpsService");
        url = url.addParameter(TPS_LIMIT_RATE_KEY, 5);
        Invoker<TpsLimitFilterTest> invoker = new MyInvoker<TpsLimitFilterTest>(url);
        Invocation invocation = new MockInvocation();
        for (int i = 0; i < 10; i++) {
            try {
                filter.invoke(invoker, invocation);
            } catch (Exception e) {
                assertTrue(i >= 5);
                throw e;
            }
        }
    });
}
Also used : Invocation(org.apache.dubbo.rpc.Invocation) MockInvocation(org.apache.dubbo.rpc.support.MockInvocation) MockInvocation(org.apache.dubbo.rpc.support.MockInvocation) MyInvoker(org.apache.dubbo.rpc.support.MyInvoker) URL(org.apache.dubbo.common.URL) RpcException(org.apache.dubbo.rpc.RpcException) Test(org.junit.jupiter.api.Test)

Example 8 with MockInvocation

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

the class ActiveLimitFilterTest method testInvokeGreaterActives.

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

            public void run() {
                try {
                    latch.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                for (int i = 0; i < 100; i++) {
                    try {
                        activeLimitFilter.invoke(invoker, invocation);
                    } catch (RpcException expected) {
                        count.incrementAndGet();
                    }
                }
            }
        });
        thread.start();
    }
    latch.countDown();
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    assertNotSame(0, 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) 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 9 with MockInvocation

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

the class ActiveLimitFilterTest method testInvokeNotTimeOut.

@Test
public void testInvokeNotTimeOut() throws Exception {
    int totalThread = 100;
    int maxActives = 10;
    long timeout = 1000;
    long blockTime = 0;
    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();
    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();
                        activeLimitFilter.onError(expected, invoker, invocation);
                    } catch (Exception e) {
                        fail();
                    }
                } finally {
                    latchBlocking.countDown();
                }
            }
        });
        thread.start();
    }
    latch.countDown();
    try {
        latchBlocking.await();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    assertEquals(0, 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 10 with MockInvocation

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

the class ActiveLimitFilterTest method testInvokeRuntimeException.

@Test
public void testInvokeRuntimeException() {
    Assertions.assertThrows(RuntimeException.class, () -> {
        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();
        activeLimitFilter.invoke(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)

Aggregations

MockInvocation (org.apache.dubbo.rpc.support.MockInvocation)17 Test (org.junit.jupiter.api.Test)17 URL (org.apache.dubbo.common.URL)16 Invocation (org.apache.dubbo.rpc.Invocation)16 MyInvoker (org.apache.dubbo.rpc.support.MyInvoker)8 BlockMyInvoker (org.apache.dubbo.rpc.support.BlockMyInvoker)5 RpcException (org.apache.dubbo.rpc.RpcException)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Result (org.apache.dubbo.rpc.Result)3 RpcStatus (org.apache.dubbo.rpc.RpcStatus)2 DemoService (org.apache.dubbo.rpc.support.DemoService)2 RuntimeExceptionInvoker (org.apache.dubbo.rpc.support.RuntimeExceptionInvoker)2 Field (java.lang.reflect.Field)1 Map (java.util.Map)1 Queue (java.util.Queue)1 AccessLogData (org.apache.dubbo.rpc.support.AccessLogData)1