use of org.apache.dubbo.rpc.Invocation in project dubbo by alibaba.
the class ContextFilterTest method testWithAttachments.
@Test
public void testWithAttachments() {
URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
Invoker<DemoService> invoker = new MyInvoker<DemoService>(url);
Invocation invocation = new MockInvocation();
Result result = contextFilter.invoke(invoker, invocation);
assertNull(RpcContext.getContext().getInvoker());
}
use of org.apache.dubbo.rpc.Invocation in project dubbo by alibaba.
the class EchoFilterTest method testNonEcho.
@SuppressWarnings("unchecked")
@Test
public void testNonEcho() {
Invocation invocation = mock(Invocation.class);
given(invocation.getMethodName()).willReturn("echo");
given(invocation.getParameterTypes()).willReturn(new Class<?>[] { Enum.class });
given(invocation.getArguments()).willReturn(new Object[] { "hello" });
given(invocation.getObjectAttachments()).willReturn(null);
Invoker<DemoService> invoker = mock(Invoker.class);
given(invoker.isAvailable()).willReturn(true);
given(invoker.getInterface()).willReturn(DemoService.class);
AppResponse result = new AppResponse();
result.setValue("High");
given(invoker.invoke(invocation)).willReturn(result);
URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
given(invoker.getUrl()).willReturn(url);
Result filterResult = echoFilter.invoke(invoker, invocation);
assertEquals("High", filterResult.getValue());
}
use of org.apache.dubbo.rpc.Invocation in project dubbo by alibaba.
the class ExecuteLimitFilterTest method testNoExecuteLimitInvoke.
@Test
public void testNoExecuteLimitInvoke() throws Exception {
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"));
Invocation invocation = Mockito.mock(Invocation.class);
when(invocation.getMethodName()).thenReturn("testNoExecuteLimitInvoke");
Result result = executeLimitFilter.invoke(invoker, invocation);
Assertions.assertEquals("result", result.getValue());
}
use of org.apache.dubbo.rpc.Invocation in project dubbo by alibaba.
the class ExecuteLimitFilterTest method testMoreThanExecuteLimitInvoke.
@Test
public void testMoreThanExecuteLimitInvoke() throws Exception {
int maxExecute = 10;
int totalExecute = 20;
final AtomicInteger failed = new AtomicInteger(0);
final Invocation invocation = Mockito.mock(Invocation.class);
when(invocation.getMethodName()).thenReturn("testMoreThanExecuteLimitInvoke");
URL url = URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1&executes=" + maxExecute);
final Invoker<ExecuteLimitFilter> invoker = new BlockMyInvoker<ExecuteLimitFilter>(url, 1000);
final CountDownLatch latch = new CountDownLatch(1);
for (int i = 0; i < totalExecute; i++) {
Thread thread = new Thread(new Runnable() {
public void run() {
try {
latch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
try {
executeLimitFilter.invoke(invoker, invocation);
} catch (RpcException expected) {
failed.incrementAndGet();
}
}
});
thread.start();
}
latch.countDown();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Assertions.assertEquals(totalExecute - maxExecute, failed.get());
}
use of org.apache.dubbo.rpc.Invocation in project dubbo by alibaba.
the class ExecuteLimitFilterTest method testExecuteLimitInvokeWitException.
@Test
public void testExecuteLimitInvokeWitException() throws Exception {
Invoker invoker = Mockito.mock(Invoker.class);
doThrow(new RpcException()).when(invoker).invoke(any(Invocation.class));
URL url = URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1&executes=10");
when(invoker.getUrl()).thenReturn(url);
Invocation invocation = Mockito.mock(Invocation.class);
when(invocation.getMethodName()).thenReturn("testExecuteLimitInvokeWitException");
try {
executeLimitFilter.invoke(invoker, invocation);
} catch (Exception e) {
Assertions.assertTrue(e instanceof RpcException);
executeLimitFilter.onError(e, invoker, invocation);
}
Assertions.assertEquals(1, RpcStatus.getStatus(url, invocation.getMethodName()).getFailed());
}
Aggregations