Search in sources :

Example 11 with Invocation

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));
}
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 12 with Invocation

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

Example 13 with Invocation

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

Example 14 with 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);
}
Also used : MockInvocation(com.alibaba.dubbo.rpc.support.MockInvocation) Invocation(com.alibaba.dubbo.rpc.Invocation) MockInvocation(com.alibaba.dubbo.rpc.support.MockInvocation) MyInvoker(com.alibaba.dubbo.rpc.support.MyInvoker) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 15 with 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();
}
Also used : MockInvocation(com.alibaba.dubbo.rpc.support.MockInvocation) Invocation(com.alibaba.dubbo.rpc.Invocation) MockInvocation(com.alibaba.dubbo.rpc.support.MockInvocation) MyInvoker(com.alibaba.dubbo.rpc.support.MyInvoker) 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