Search in sources :

Example 91 with Invocation

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

the class TimeoutFilterTest method testInvokeWithTimeout.

@Test
public void testInvokeWithTimeout() throws Exception {
    int timeout = 100;
    URL url = URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1&timeout=" + timeout);
    Invoker invoker = new BlockMyInvoker(url, (timeout + 100));
    Invocation invocation = Mockito.mock(Invocation.class);
    when(invocation.getMethodName()).thenReturn("testInvokeWithTimeout");
    Result result = timeoutFilter.invoke(invoker, invocation);
    Assertions.assertEquals("Dubbo", result.getValue());
}
Also used : BlockMyInvoker(org.apache.dubbo.rpc.support.BlockMyInvoker) BlockMyInvoker(org.apache.dubbo.rpc.support.BlockMyInvoker) Invoker(org.apache.dubbo.rpc.Invoker) Invocation(org.apache.dubbo.rpc.Invocation) URL(org.apache.dubbo.common.URL) Result(org.apache.dubbo.rpc.Result) Test(org.junit.jupiter.api.Test)

Example 92 with Invocation

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

the class DefaultTPSLimiterTest method testIsAllowable.

@Test
public void testIsAllowable() 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));
    }
}
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 93 with Invocation

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

the class DefaultTPSLimiterTest method testIsNotAllowable.

@Test
public void testIsNotAllowable() 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 + 1; i++) {
        if (i == TEST_LIMIT_RATE + 1) {
            Assertions.assertFalse(defaultTPSLimiter.isAllowable(url, invocation));
        } else {
            Assertions.assertTrue(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 94 with Invocation

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

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

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