use of com.alibaba.dubbo.rpc.Invocation in project dubbo by alibaba.
the class MonitorFilterTest method testGenericFilter.
@Test
public void testGenericFilter() throws Exception {
MonitorFilter monitorFilter = new MonitorFilter();
monitorFilter.setMonitorFactory(monitorFactory);
Invocation invocation = new RpcInvocation("$invoke", new Class<?>[] { String.class, String[].class, Object[].class }, new Object[] { "xxx", new String[] {}, new Object[] {} });
RpcContext.getContext().setRemoteAddress(NetUtils.getLocalHost(), 20880).setLocalAddress(NetUtils.getLocalHost(), 2345);
monitorFilter.invoke(serviceInvoker, invocation);
while (lastStatistics == null) {
Thread.sleep(10);
}
Assert.assertEquals("abc", lastStatistics.getParameter(MonitorService.APPLICATION));
Assert.assertEquals(MonitorService.class.getName(), lastStatistics.getParameter(MonitorService.INTERFACE));
Assert.assertEquals("xxx", lastStatistics.getParameter(MonitorService.METHOD));
Assert.assertEquals(NetUtils.getLocalHost() + ":20880", lastStatistics.getParameter(MonitorService.PROVIDER));
Assert.assertEquals(NetUtils.getLocalHost(), lastStatistics.getAddress());
Assert.assertEquals(null, lastStatistics.getParameter(MonitorService.CONSUMER));
Assert.assertEquals(1, lastStatistics.getParameter(MonitorService.SUCCESS, 0));
Assert.assertEquals(0, lastStatistics.getParameter(MonitorService.FAILURE, 0));
Assert.assertEquals(1, lastStatistics.getParameter(MonitorService.CONCURRENT, 0));
Assert.assertEquals(invocation, lastInvocation);
}
use of com.alibaba.dubbo.rpc.Invocation in project dubbo by alibaba.
the class RegistryDirectory method route.
private List<Invoker<T>> route(List<Invoker<T>> invokers, String method) {
Invocation invocation = new RpcInvocation(method, new Class<?>[0], new Object[0]);
List<Router> routers = getRouters();
if (routers != null) {
for (Router router : routers) {
if (router.getUrl() != null && !router.getUrl().getParameter(Constants.RUNTIME_KEY, true)) {
invokers = router.route(invokers, getConsumerUrl(), invocation);
}
}
}
return invokers;
}
use of com.alibaba.dubbo.rpc.Invocation in project dubbo by alibaba.
the class RpcUtilsTest method testAttachInvocationIdIfAsync_sync.
/**
* 场景:同步调用,不默认添加acctachment
* 验证:acctachment中没有添加id属性
*/
@Test
public void testAttachInvocationIdIfAsync_sync() {
URL url = URL.valueOf("dubbo://localhost/");
Invocation inv = new RpcInvocation("test", new Class[] {}, new String[] {});
RpcUtils.attachInvocationIdIfAsync(url, inv);
Assert.assertNull(RpcUtils.getInvocationId(inv));
}
use of com.alibaba.dubbo.rpc.Invocation in project dubbo by alibaba.
the class RpcUtilsTest method testAttachInvocationIdIfAsync_forceNotAttache.
/**
* 场景:强制设置为不添加
* 验证:acctachment中没有添加id属性
*/
@Test
public void testAttachInvocationIdIfAsync_forceNotAttache() {
URL url = URL.valueOf("dubbo://localhost/?test.async=true&" + Constants.AUTO_ATTACH_INVOCATIONID_KEY + "=false");
Invocation inv = new RpcInvocation("test", new Class[] {}, new String[] {});
RpcUtils.attachInvocationIdIfAsync(url, inv);
Assert.assertNull(RpcUtils.getInvocationId(inv));
}
use of com.alibaba.dubbo.rpc.Invocation in project dubbo by alibaba.
the class RpcUtilsTest method testAttachInvocationIdIfAsync_nullAttachments.
/**
* 场景:异步调用,默认添加attachement
* 验证:当原始acctachment为null时,不能报错.
*/
@Test
public void testAttachInvocationIdIfAsync_nullAttachments() {
URL url = URL.valueOf("dubbo://localhost/?test.async=true");
Invocation inv = new RpcInvocation("test", new Class[] {}, new String[] {});
RpcUtils.attachInvocationIdIfAsync(url, inv);
Assert.assertTrue(RpcUtils.getInvocationId(inv) >= 0l);
}
Aggregations