use of org.apache.dubbo.rpc.Invocation in project dubbo by alibaba.
the class TimeoutFilterTest method testInvokeWithoutTimeout.
@Test
public void testInvokeWithoutTimeout() throws Exception {
int timeout = 3000;
Invoker invoker = Mockito.mock(Invoker.class);
when(invoker.invoke(any(Invocation.class))).thenReturn(new AppResponse("result"));
when(invoker.getUrl()).thenReturn(URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1&timeout=" + timeout));
Invocation invocation = Mockito.mock(Invocation.class);
when(invocation.getMethodName()).thenReturn("testInvokeWithoutTimeout");
Result result = timeoutFilter.invoke(invoker, invocation);
Assertions.assertEquals("result", result.getValue());
}
use of org.apache.dubbo.rpc.Invocation 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;
}
}
});
}
use of org.apache.dubbo.rpc.Invocation in project dubbo by alibaba.
the class TokenFilterTest method testInvokeWithoutToken.
@Test
public void testInvokeWithoutToken() throws Exception {
Assertions.assertThrows(RpcException.class, () -> {
String token = "token";
Invoker invoker = Mockito.mock(Invoker.class);
URL url = URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1&token=" + token);
when(invoker.getUrl()).thenReturn(url);
when(invoker.invoke(any(Invocation.class))).thenReturn(new AppResponse("result"));
Invocation invocation = Mockito.mock(Invocation.class);
tokenFilter.invoke(invoker, invocation);
});
}
use of org.apache.dubbo.rpc.Invocation in project dubbo by alibaba.
the class TokenFilterTest method testInvokeWithWrongToken.
@Test
public void testInvokeWithWrongToken() throws Exception {
Assertions.assertThrows(RpcException.class, () -> {
String token = "token";
Invoker invoker = Mockito.mock(Invoker.class);
URL url = URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1&token=" + token);
when(invoker.getUrl()).thenReturn(url);
when(invoker.invoke(any(Invocation.class))).thenReturn(new AppResponse("result"));
Map<String, Object> attachments = new HashMap<>();
attachments.put(TOKEN_KEY, "wrongToken");
Invocation invocation = Mockito.mock(Invocation.class);
when(invocation.getObjectAttachments()).thenReturn(attachments);
tokenFilter.invoke(invoker, invocation);
});
}
use of org.apache.dubbo.rpc.Invocation in project dubbo by alibaba.
the class AddressRouterTest method testAddressRouteSelector.
@Test
public void testAddressRouteSelector() {
Router router = new AddressRouterFactory().getRouter(URL.valueOf("url"));
List<Invoker<String>> invokers = new ArrayList<Invoker<String>>();
invokers.add(new MockInvoker<>(new URL("dubbo", "129.34.56.7", 8809), true));
invokers.add(new MockInvoker<>(new URL("dubbo", "129.34.56.8", 8809), true));
invokers.add(new MockInvoker<>(new URL("dubbo", "129.34.56.9", 8809), true));
Invocation invocation = new RpcInvocation();
Address address = new Address("129.34.56.9", 8809);
invocation.setObjectAttachment("address", address);
List<Invoker<String>> list = router.route(invokers, URL.valueOf("url"), invocation);
Assertions.assertEquals(address.getIp(), list.get(0).getUrl().getHost());
}
Aggregations