use of org.apache.dubbo.rpc.Result in project dubbo by alibaba.
the class CompatibleFilterFilterTest method testInvokerNonJsonPojoSerialization.
@Test
public void testInvokerNonJsonPojoSerialization() {
invocation = mock(Invocation.class);
given(invocation.getMethodName()).willReturn("echo");
given(invocation.getParameterTypes()).willReturn(new Class<?>[] { String.class });
given(invocation.getArguments()).willReturn(new Object[] { "hello" });
invoker = mock(Invoker.class);
given(invoker.isAvailable()).willReturn(true);
given(invoker.getInterface()).willReturn(DemoService.class);
AppResponse result = new AppResponse();
result.setValue("hello");
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 = compatibleFilter.invoke(invoker, invocation);
assertEquals("hello", filterResult.getValue());
}
use of org.apache.dubbo.rpc.Result in project dubbo by alibaba.
the class CompatibleFilterFilterTest method testResulthasException.
@Test
public void testResulthasException() {
invocation = mock(Invocation.class);
given(invocation.getMethodName()).willReturn("enumlength");
given(invocation.getParameterTypes()).willReturn(new Class<?>[] { Enum.class });
given(invocation.getArguments()).willReturn(new Object[] { "hello" });
invoker = mock(Invoker.class);
given(invoker.isAvailable()).willReturn(true);
given(invoker.getInterface()).willReturn(DemoService.class);
AppResponse result = new AppResponse();
result.setException(new RuntimeException());
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 = compatibleFilter.invoke(invoker, invocation);
assertEquals(filterResult, result);
}
use of org.apache.dubbo.rpc.Result in project dubbo by alibaba.
the class ExceptionFilterTest method testRuntimeException.
@SuppressWarnings("unchecked")
@Test
public void testRuntimeException() {
ExceptionFilter exceptionFilter = new ExceptionFilter();
RpcInvocation invocation = new RpcInvocation("sayHello", DemoService.class.getName(), "", new Class<?>[] { String.class }, new Object[] { "world" });
AppResponse appResponse = new AppResponse();
appResponse.setException(new LocalException("localException"));
Invoker<DemoService> invoker = mock(Invoker.class);
when(invoker.invoke(invocation)).thenReturn(appResponse);
when(invoker.getInterface()).thenReturn(DemoService.class);
Result newResult = exceptionFilter.invoke(invoker, invocation);
Assertions.assertEquals(appResponse.getException(), newResult.getException());
}
use of org.apache.dubbo.rpc.Result in project dubbo by alibaba.
the class ExceptionFilterTest method testJavaException.
@SuppressWarnings("unchecked")
@Test
public void testJavaException() {
ExceptionFilter exceptionFilter = new ExceptionFilter();
RpcInvocation invocation = new RpcInvocation("sayHello", DemoService.class.getName(), "", new Class<?>[] { String.class }, new Object[] { "world" });
AppResponse appResponse = new AppResponse();
appResponse.setException(new IllegalArgumentException("java"));
Invoker<DemoService> invoker = mock(Invoker.class);
when(invoker.invoke(invocation)).thenReturn(appResponse);
when(invoker.getInterface()).thenReturn(DemoService.class);
Result newResult = exceptionFilter.invoke(invoker, invocation);
Assertions.assertEquals(appResponse.getException(), newResult.getException());
}
use of org.apache.dubbo.rpc.Result in project dubbo by alibaba.
the class AbstractProxyProtocol method protocolBindingRefer.
@Override
protected <T> Invoker<T> protocolBindingRefer(final Class<T> type, final URL url) throws RpcException {
final Invoker<T> target = proxyFactory.getInvoker(doRefer(type, url), type, url);
Invoker<T> invoker = new AbstractInvoker<T>(type, url) {
@Override
protected Result doInvoke(Invocation invocation) throws Throwable {
try {
Result result = target.invoke(invocation);
// FIXME result is an AsyncRpcResult instance.
Throwable e = result.getException();
if (e != null) {
for (Class<?> rpcException : rpcExceptions) {
if (rpcException.isAssignableFrom(e.getClass())) {
throw getRpcException(type, url, invocation, e);
}
}
}
return result;
} catch (RpcException e) {
if (e.getCode() == RpcException.UNKNOWN_EXCEPTION) {
e.setCode(getErrorCode(e.getCause()));
}
throw e;
} catch (Throwable e) {
throw getRpcException(type, url, invocation, e);
}
}
@Override
public void destroy() {
super.destroy();
target.destroy();
invokers.remove(this);
}
};
invokers.add(invoker);
return invoker;
}
Aggregations