Search in sources :

Example 26 with Invocation

use of com.alibaba.dubbo.rpc.Invocation in project dubbo by alibaba.

the class ProtocolFilterWrapper method buildInvokerChain.

private static <T> Invoker<T> buildInvokerChain(final Invoker<T> invoker, String key, String group) {
    Invoker<T> last = invoker;
    List<Filter> filters = ExtensionLoader.getExtensionLoader(Filter.class).getActivateExtension(invoker.getUrl(), key, group);
    if (filters.size() > 0) {
        for (int i = filters.size() - 1; i >= 0; i--) {
            final Filter filter = filters.get(i);
            final Invoker<T> next = last;
            last = new Invoker<T>() {

                public Class<T> getInterface() {
                    return invoker.getInterface();
                }

                public URL getUrl() {
                    return invoker.getUrl();
                }

                public boolean isAvailable() {
                    return invoker.isAvailable();
                }

                public Result invoke(Invocation invocation) throws RpcException {
                    return filter.invoke(next, invocation);
                }

                public void destroy() {
                    invoker.destroy();
                }

                @Override
                public String toString() {
                    return invoker.toString();
                }
            };
        }
    }
    return last;
}
Also used : Invocation(com.alibaba.dubbo.rpc.Invocation) Filter(com.alibaba.dubbo.rpc.Filter) RpcException(com.alibaba.dubbo.rpc.RpcException) URL(com.alibaba.dubbo.common.URL) Result(com.alibaba.dubbo.rpc.Result)

Example 27 with Invocation

use of com.alibaba.dubbo.rpc.Invocation in project dubbo by alibaba.

the class CompatibleFilterFilterTest method testInvokerNonJsonPojoSerialization.

@Test
public void testInvokerNonJsonPojoSerialization() {
    invocation = EasyMock.createMock(Invocation.class);
    EasyMock.expect(invocation.getMethodName()).andReturn("echo").anyTimes();
    EasyMock.expect(invocation.getParameterTypes()).andReturn(new Class<?>[] { String.class }).anyTimes();
    EasyMock.expect(invocation.getArguments()).andReturn(new Object[] { "hello" }).anyTimes();
    EasyMock.replay(invocation);
    invoker = EasyMock.createMock(Invoker.class);
    EasyMock.expect(invoker.isAvailable()).andReturn(true).anyTimes();
    EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class).anyTimes();
    RpcResult result = new RpcResult();
    result.setValue("hello");
    EasyMock.expect(invoker.invoke(invocation)).andReturn(result).anyTimes();
    URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
    EasyMock.expect(invoker.getUrl()).andReturn(url).anyTimes();
    EasyMock.replay(invoker);
    Result filterResult = compatibleFilter.invoke(invoker, invocation);
    assertEquals("hello", filterResult.getValue());
}
Also used : Invocation(com.alibaba.dubbo.rpc.Invocation) Invoker(com.alibaba.dubbo.rpc.Invoker) RpcResult(com.alibaba.dubbo.rpc.RpcResult) DemoService(com.alibaba.dubbo.rpc.support.DemoService) URL(com.alibaba.dubbo.common.URL) Result(com.alibaba.dubbo.rpc.Result) RpcResult(com.alibaba.dubbo.rpc.RpcResult) Test(org.junit.Test)

Example 28 with Invocation

use of com.alibaba.dubbo.rpc.Invocation in project dubbo by alibaba.

the class CompatibleFilterFilterTest method testInvokerNonJsonEnumSerialization.

@Test
public void testInvokerNonJsonEnumSerialization() {
    invocation = EasyMock.createMock(Invocation.class);
    EasyMock.expect(invocation.getMethodName()).andReturn("enumlength").anyTimes();
    EasyMock.expect(invocation.getParameterTypes()).andReturn(new Class<?>[] { Type[].class }).anyTimes();
    EasyMock.expect(invocation.getArguments()).andReturn(new Object[] { "hello" }).anyTimes();
    EasyMock.replay(invocation);
    invoker = EasyMock.createMock(Invoker.class);
    EasyMock.expect(invoker.isAvailable()).andReturn(true).anyTimes();
    EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class).anyTimes();
    RpcResult result = new RpcResult();
    result.setValue("High");
    EasyMock.expect(invoker.invoke(invocation)).andReturn(result).anyTimes();
    URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
    EasyMock.expect(invoker.getUrl()).andReturn(url).anyTimes();
    EasyMock.replay(invoker);
    Result filterResult = compatibleFilter.invoke(invoker, invocation);
    assertEquals(Type.High, filterResult.getValue());
}
Also used : Invocation(com.alibaba.dubbo.rpc.Invocation) Invoker(com.alibaba.dubbo.rpc.Invoker) RpcResult(com.alibaba.dubbo.rpc.RpcResult) DemoService(com.alibaba.dubbo.rpc.support.DemoService) URL(com.alibaba.dubbo.common.URL) Result(com.alibaba.dubbo.rpc.Result) RpcResult(com.alibaba.dubbo.rpc.RpcResult) Test(org.junit.Test)

Example 29 with Invocation

use of com.alibaba.dubbo.rpc.Invocation in project dubbo by alibaba.

the class CompatibleFilterFilterTest method testInvokerGeneric.

@Test
public void testInvokerGeneric() {
    invocation = EasyMock.createMock(Invocation.class);
    EasyMock.expect(invocation.getMethodName()).andReturn("$enumlength").anyTimes();
    EasyMock.expect(invocation.getParameterTypes()).andReturn(new Class<?>[] { Enum.class }).anyTimes();
    EasyMock.expect(invocation.getArguments()).andReturn(new Object[] { "hello" }).anyTimes();
    EasyMock.replay(invocation);
    invoker = EasyMock.createMock(Invoker.class);
    EasyMock.expect(invoker.isAvailable()).andReturn(true).anyTimes();
    EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class).anyTimes();
    RpcResult result = new RpcResult();
    result.setValue("High");
    EasyMock.expect(invoker.invoke(invocation)).andReturn(result).anyTimes();
    URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
    EasyMock.expect(invoker.getUrl()).andReturn(url).anyTimes();
    EasyMock.replay(invoker);
    Result filterResult = compatibleFilter.invoke(invoker, invocation);
    assertEquals(filterResult, result);
}
Also used : Invocation(com.alibaba.dubbo.rpc.Invocation) Invoker(com.alibaba.dubbo.rpc.Invoker) RpcResult(com.alibaba.dubbo.rpc.RpcResult) DemoService(com.alibaba.dubbo.rpc.support.DemoService) URL(com.alibaba.dubbo.common.URL) Result(com.alibaba.dubbo.rpc.Result) RpcResult(com.alibaba.dubbo.rpc.RpcResult) Test(org.junit.Test)

Example 30 with Invocation

use of com.alibaba.dubbo.rpc.Invocation in project dubbo by alibaba.

the class CompatibleFilterFilterTest method testInvokerJsonPojoSerialization.

@Test
public void testInvokerJsonPojoSerialization() {
    invocation = EasyMock.createMock(Invocation.class);
    EasyMock.expect(invocation.getMethodName()).andReturn("enumlength").anyTimes();
    EasyMock.expect(invocation.getParameterTypes()).andReturn(new Class<?>[] { Type[].class }).anyTimes();
    EasyMock.expect(invocation.getArguments()).andReturn(new Object[] { "hello" }).anyTimes();
    EasyMock.replay(invocation);
    invoker = EasyMock.createMock(Invoker.class);
    EasyMock.expect(invoker.isAvailable()).andReturn(true).anyTimes();
    EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class).anyTimes();
    RpcResult result = new RpcResult();
    result.setValue("High");
    EasyMock.expect(invoker.invoke(invocation)).andReturn(result).anyTimes();
    URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1&serialization=json");
    EasyMock.expect(invoker.getUrl()).andReturn(url).anyTimes();
    EasyMock.replay(invoker);
    Result filterResult = compatibleFilter.invoke(invoker, invocation);
    assertEquals(Type.High, filterResult.getValue());
}
Also used : Invocation(com.alibaba.dubbo.rpc.Invocation) Invoker(com.alibaba.dubbo.rpc.Invoker) RpcResult(com.alibaba.dubbo.rpc.RpcResult) DemoService(com.alibaba.dubbo.rpc.support.DemoService) URL(com.alibaba.dubbo.common.URL) Result(com.alibaba.dubbo.rpc.Result) RpcResult(com.alibaba.dubbo.rpc.RpcResult) 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