use of org.apache.dubbo.rpc.Result in project dubbo by alibaba.
the class FilterNode method invoke.
@Override
public Result invoke(Invocation invocation) throws RpcException {
Result asyncResult;
try {
asyncResult = filter.invoke(next, invocation);
} catch (Exception e) {
if (filter instanceof ListenableFilter) {
ListenableFilter listenableFilter = ((ListenableFilter) filter);
try {
Filter.Listener listener = listenableFilter.listener(invocation);
if (listener != null) {
listener.onError(e, invoker, invocation);
}
} finally {
listenableFilter.removeListener(invocation);
}
} else if (filter instanceof Filter.Listener) {
Filter.Listener listener = (Filter.Listener) filter;
listener.onError(e, invoker, invocation);
}
throw e;
} finally {
}
return asyncResult.whenCompleteWithContext((r, t) -> {
if (filter instanceof ListenableFilter) {
ListenableFilter listenableFilter = ((ListenableFilter) filter);
Filter.Listener listener = listenableFilter.listener(invocation);
try {
if (listener != null) {
if (t == null) {
listener.onResponse(r, invoker, invocation);
} else {
listener.onError(t, invoker, invocation);
}
}
} finally {
listenableFilter.removeListener(invocation);
}
} else if (filter instanceof Filter.Listener) {
Filter.Listener listener = (Filter.Listener) filter;
if (t == null) {
listener.onResponse(r, invoker, invocation);
} else {
listener.onError(t, invoker, invocation);
}
}
});
}
use of org.apache.dubbo.rpc.Result in project dubbo by alibaba.
the class ConsumerContextClusterInterceptorTest method testOnMessage.
@Test
public void testOnMessage() {
RpcContext serverContext = RpcContext.getServerContext();
Result mockResult = Mockito.mock(Result.class);
Map<String, Object> map = Collections.singletonMap("key", "value");
Mockito.when(mockResult.getObjectAttachments()).thenReturn(map);
interceptor.onMessage(mockResult, null, null);
Map<String, Object> objectAttachments = serverContext.getObjectAttachments();
Assertions.assertNotNull(objectAttachments);
Assertions.assertTrue(objectAttachments.size() == 1);
Assertions.assertEquals("value", objectAttachments.get("key"));
}
use of org.apache.dubbo.rpc.Result in project dubbo by alibaba.
the class FailSafeClusterInvokerTest method testInvokeNoExceptoin.
@Test()
public void testInvokeNoExceptoin() {
resetInvokerToNoException();
FailsafeClusterInvoker<DemoService> invoker = new FailsafeClusterInvoker<DemoService>(dic);
Result ret = invoker.invoke(invocation);
Assertions.assertSame(result, ret);
}
use of org.apache.dubbo.rpc.Result in project dubbo by alibaba.
the class FailbackClusterInvokerTest method testInvokeNoException.
@Test
@Order(2)
public void testInvokeNoException() {
resetInvokerToNoException();
FailbackClusterInvoker<FailbackClusterInvokerTest> invoker = new FailbackClusterInvoker<FailbackClusterInvokerTest>(dic);
Result ret = invoker.invoke(invocation);
Assertions.assertSame(result, ret);
}
use of org.apache.dubbo.rpc.Result in project dubbo by alibaba.
the class FailoverClusterInvokerTest method testInvokeWithRPCException.
@Test()
public void testInvokeWithRPCException() {
given(invoker1.invoke(invocation)).willThrow(new RpcException());
given(invoker1.isAvailable()).willReturn(true);
given(invoker1.getUrl()).willReturn(url);
given(invoker1.getInterface()).willReturn(FailoverClusterInvokerTest.class);
given(invoker2.invoke(invocation)).willReturn(result);
given(invoker2.isAvailable()).willReturn(true);
given(invoker2.getUrl()).willReturn(url);
given(invoker2.getInterface()).willReturn(FailoverClusterInvokerTest.class);
FailoverClusterInvoker<FailoverClusterInvokerTest> invoker = new FailoverClusterInvoker<FailoverClusterInvokerTest>(dic);
for (int i = 0; i < 100; i++) {
Result ret = invoker.invoke(invocation);
assertSame(result, ret);
}
}
Aggregations