Search in sources :

Example 6 with Invocation

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);
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) Invocation(com.alibaba.dubbo.rpc.Invocation) MonitorService(com.alibaba.dubbo.monitor.MonitorService) MonitorFilter(com.alibaba.dubbo.monitor.support.MonitorFilter) Test(org.junit.Test)

Example 7 with Invocation

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;
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) Invocation(com.alibaba.dubbo.rpc.Invocation) RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) Router(com.alibaba.dubbo.rpc.cluster.Router)

Example 8 with Invocation

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));
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) Invocation(com.alibaba.dubbo.rpc.Invocation) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 9 with Invocation

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));
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) Invocation(com.alibaba.dubbo.rpc.Invocation) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 10 with Invocation

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);
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) Invocation(com.alibaba.dubbo.rpc.Invocation) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Aggregations

Invocation (com.alibaba.dubbo.rpc.Invocation)37 URL (com.alibaba.dubbo.common.URL)28 Test (org.junit.Test)27 Result (com.alibaba.dubbo.rpc.Result)13 RpcResult (com.alibaba.dubbo.rpc.RpcResult)12 Invoker (com.alibaba.dubbo.rpc.Invoker)11 RpcInvocation (com.alibaba.dubbo.rpc.RpcInvocation)11 DemoService (com.alibaba.dubbo.rpc.support.DemoService)11 MockInvocation (com.alibaba.dubbo.rpc.support.MockInvocation)11 MyInvoker (com.alibaba.dubbo.rpc.support.MyInvoker)11 RpcException (com.alibaba.dubbo.rpc.RpcException)9 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 MonitorService (com.alibaba.dubbo.monitor.MonitorService)2 MonitorFilter (com.alibaba.dubbo.monitor.support.MonitorFilter)2 LoadBalance (com.alibaba.dubbo.rpc.cluster.LoadBalance)2 StaticDirectory (com.alibaba.dubbo.rpc.cluster.directory.StaticDirectory)2 AbstractInvoker (com.alibaba.dubbo.rpc.protocol.AbstractInvoker)2 SocketTimeoutException (java.net.SocketTimeoutException)2 HashMap (java.util.HashMap)2