Search in sources :

Example 16 with MockInvocation

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

the class DefaultTPSLimiterTest method testConfigChange.

@Test
public void testConfigChange() throws Exception {
    Invocation invocation = new MockInvocation();
    URL url = URL.valueOf("test://test");
    url = url.addParameter(INTERFACE_KEY, "org.apache.dubbo.rpc.file.TpsService");
    url = url.addParameter(TPS_LIMIT_RATE_KEY, TEST_LIMIT_RATE);
    url = url.addParameter(TPS_LIMIT_INTERVAL_KEY, 1000);
    for (int i = 1; i <= TEST_LIMIT_RATE; i++) {
        Assertions.assertTrue(defaultTPSLimiter.isAllowable(url, invocation));
    }
    final int tenTimesLimitRate = TEST_LIMIT_RATE * 10;
    url = url.addParameter(TPS_LIMIT_RATE_KEY, tenTimesLimitRate);
    for (int i = 1; i <= tenTimesLimitRate; i++) {
        Assertions.assertTrue(defaultTPSLimiter.isAllowable(url, invocation));
    }
    Assertions.assertFalse(defaultTPSLimiter.isAllowable(url, invocation));
}
Also used : Invocation(org.apache.dubbo.rpc.Invocation) MockInvocation(org.apache.dubbo.rpc.support.MockInvocation) MockInvocation(org.apache.dubbo.rpc.support.MockInvocation) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 17 with MockInvocation

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

the class TpsLimitFilterTest method testWithoutCount.

@Test
public void testWithoutCount() throws Exception {
    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();
    filter.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) MyInvoker(org.apache.dubbo.rpc.support.MyInvoker) 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