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());
}
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));
}
}
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));
}
}
}
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));
}
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);
}
Aggregations