use of com.alibaba.dubbo.rpc.Invocation in project dubbo by alibaba.
the class RpcUtilsTest method testAttachInvocationIdIfAsync_forceAttache.
/**
* 场景:强制设置为添加
* 验证:acctachment中有添加id属性
*/
@Test
public void testAttachInvocationIdIfAsync_forceAttache() {
URL url = URL.valueOf("dubbo://localhost/?" + Constants.AUTO_ATTACH_INVOCATIONID_KEY + "=true");
Invocation inv = new RpcInvocation("test", new Class[] {}, new String[] {});
RpcUtils.attachInvocationIdIfAsync(url, inv);
Assert.assertNotNull(RpcUtils.getInvocationId(inv));
}
use of com.alibaba.dubbo.rpc.Invocation in project dubbo by alibaba.
the class AbstractProxyProtocol method refer.
public <T> Invoker<T> refer(final Class<T> type, final URL url) throws RpcException {
final Invoker<T> tagert = 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 = tagert.invoke(invocation);
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);
}
}
};
invokers.add(invoker);
return invoker;
}
use of com.alibaba.dubbo.rpc.Invocation in project dubbo by alibaba.
the class AccessLogFilterTest method testDefault.
// TODO how to assert thread action
@Test
public void testDefault() {
URL url = URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1");
Invoker<AccessLogFilterTest> invoker = new MyInvoker<AccessLogFilterTest>(url);
Invocation invocation = new MockInvocation();
accessLogFilter.invoke(invoker, invocation);
}
use of com.alibaba.dubbo.rpc.Invocation in project dubbo by alibaba.
the class AccessLogFilterTest method testCustom.
@Test
public void testCustom() {
URL url = URL.valueOf("test://test:11/test?accesslog=alibaba");
Invoker<AccessLogFilterTest> invoker = new MyInvoker<AccessLogFilterTest>(url);
Invocation invocation = new MockInvocation();
accessLogFilter.invoke(invoker, invocation);
}
use of com.alibaba.dubbo.rpc.Invocation in project dubbo by alibaba.
the class AccessLogFilterTest method testInvokeException.
// 测试filter不会抛出异常
@Test
public void testInvokeException() {
Invoker<AccessLogFilterTest> invoker = new MyInvoker<AccessLogFilterTest>(null);
Invocation invocation = new MockInvocation();
LogUtil.start();
accessLogFilter.invoke(invoker, invocation);
assertEquals(1, LogUtil.findMessage("Exception in AcessLogFilter of service"));
LogUtil.stop();
}
Aggregations