Search in sources :

Example 51 with Invocation

use of org.apache.dubbo.rpc.Invocation in project dubbo by alibaba.

the class CompatibleFilterFilterTest method testInvokerNonJsonEnumSerialization.

@Test
public void testInvokerNonJsonEnumSerialization() throws Exception {
    invocation = mock(Invocation.class);
    given(invocation.getMethodName()).willReturn("enumlength");
    given(invocation.getParameterTypes()).willReturn(new Class<?>[] { Type[].class });
    given(invocation.getArguments()).willReturn(new Object[] { "hello" });
    invoker = mock(Invoker.class);
    given(invoker.isAvailable()).willReturn(true);
    given(invoker.getInterface()).willReturn(DemoService.class);
    AppResponse result = new AppResponse();
    result.setValue("High");
    given(invoker.invoke(invocation)).willReturn(AsyncRpcResult.newDefaultAsyncResult(result, invocation));
    URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
    given(invoker.getUrl()).willReturn(url);
    Result asyncResult = compatibleFilter.invoke(invoker, invocation);
    AppResponse appResponse = (AppResponse) asyncResult.get();
    compatibleFilter.onResponse(appResponse, invoker, invocation);
    assertEquals(Type.High, appResponse.getValue());
}
Also used : Type(org.apache.dubbo.rpc.support.Type) Invocation(org.apache.dubbo.rpc.Invocation) Invoker(org.apache.dubbo.rpc.Invoker) AppResponse(org.apache.dubbo.rpc.AppResponse) URL(org.apache.dubbo.common.URL) AsyncRpcResult(org.apache.dubbo.rpc.AsyncRpcResult) Result(org.apache.dubbo.rpc.Result) Test(org.junit.jupiter.api.Test)

Example 52 with Invocation

use of org.apache.dubbo.rpc.Invocation in project dubbo by alibaba.

the class CompatibleFilterFilterTest method testInvokerNonJsonNonPojoSerialization.

@Test
public void testInvokerNonJsonNonPojoSerialization() {
    invocation = mock(Invocation.class);
    given(invocation.getMethodName()).willReturn("echo");
    given(invocation.getParameterTypes()).willReturn(new Class<?>[] { String.class });
    given(invocation.getArguments()).willReturn(new Object[] { "hello" });
    invoker = mock(Invoker.class);
    given(invoker.isAvailable()).willReturn(true);
    given(invoker.getInterface()).willReturn(DemoService.class);
    AppResponse result = new AppResponse();
    result.setValue(new String[] { "High" });
    given(invoker.invoke(invocation)).willReturn(result);
    URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
    given(invoker.getUrl()).willReturn(url);
    Result filterResult = compatibleFilter.invoke(invoker, invocation);
    assertArrayEquals(new String[] { "High" }, (String[]) filterResult.getValue());
}
Also used : Invocation(org.apache.dubbo.rpc.Invocation) Invoker(org.apache.dubbo.rpc.Invoker) AppResponse(org.apache.dubbo.rpc.AppResponse) URL(org.apache.dubbo.common.URL) AsyncRpcResult(org.apache.dubbo.rpc.AsyncRpcResult) Result(org.apache.dubbo.rpc.Result) Test(org.junit.jupiter.api.Test)

Example 53 with Invocation

use of org.apache.dubbo.rpc.Invocation in project dubbo by alibaba.

the class CompatibleFilterFilterTest method testInvokerNonJsonPojoSerialization.

@Test
public void testInvokerNonJsonPojoSerialization() {
    invocation = mock(Invocation.class);
    given(invocation.getMethodName()).willReturn("echo");
    given(invocation.getParameterTypes()).willReturn(new Class<?>[] { String.class });
    given(invocation.getArguments()).willReturn(new Object[] { "hello" });
    invoker = mock(Invoker.class);
    given(invoker.isAvailable()).willReturn(true);
    given(invoker.getInterface()).willReturn(DemoService.class);
    AppResponse result = new AppResponse();
    result.setValue("hello");
    given(invoker.invoke(invocation)).willReturn(result);
    URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
    given(invoker.getUrl()).willReturn(url);
    Result filterResult = compatibleFilter.invoke(invoker, invocation);
    assertEquals("hello", filterResult.getValue());
}
Also used : Invocation(org.apache.dubbo.rpc.Invocation) Invoker(org.apache.dubbo.rpc.Invoker) AppResponse(org.apache.dubbo.rpc.AppResponse) URL(org.apache.dubbo.common.URL) AsyncRpcResult(org.apache.dubbo.rpc.AsyncRpcResult) Result(org.apache.dubbo.rpc.Result) Test(org.junit.jupiter.api.Test)

Example 54 with Invocation

use of org.apache.dubbo.rpc.Invocation in project dubbo by alibaba.

the class CompatibleFilterFilterTest method testResulthasException.

@Test
public void testResulthasException() {
    invocation = mock(Invocation.class);
    given(invocation.getMethodName()).willReturn("enumlength");
    given(invocation.getParameterTypes()).willReturn(new Class<?>[] { Enum.class });
    given(invocation.getArguments()).willReturn(new Object[] { "hello" });
    invoker = mock(Invoker.class);
    given(invoker.isAvailable()).willReturn(true);
    given(invoker.getInterface()).willReturn(DemoService.class);
    AppResponse result = new AppResponse();
    result.setException(new RuntimeException());
    result.setValue("High");
    given(invoker.invoke(invocation)).willReturn(result);
    URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
    given(invoker.getUrl()).willReturn(url);
    Result filterResult = compatibleFilter.invoke(invoker, invocation);
    assertEquals(filterResult, result);
}
Also used : Invocation(org.apache.dubbo.rpc.Invocation) Invoker(org.apache.dubbo.rpc.Invoker) AppResponse(org.apache.dubbo.rpc.AppResponse) URL(org.apache.dubbo.common.URL) AsyncRpcResult(org.apache.dubbo.rpc.AsyncRpcResult) Result(org.apache.dubbo.rpc.Result) Test(org.junit.jupiter.api.Test)

Example 55 with Invocation

use of org.apache.dubbo.rpc.Invocation in project dubbo by alibaba.

the class AbstractProxyProtocol method protocolBindingRefer.

@Override
protected <T> Invoker<T> protocolBindingRefer(final Class<T> type, final URL url) throws RpcException {
    final Invoker<T> target = 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 = target.invoke(invocation);
                // FIXME result is an AsyncRpcResult instance.
                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);
            }
        }

        @Override
        public void destroy() {
            super.destroy();
            target.destroy();
            invokers.remove(this);
        }
    };
    invokers.add(invoker);
    return invoker;
}
Also used : Invocation(org.apache.dubbo.rpc.Invocation) RpcException(org.apache.dubbo.rpc.RpcException) Result(org.apache.dubbo.rpc.Result)

Aggregations

Invocation (org.apache.dubbo.rpc.Invocation)98 Test (org.junit.jupiter.api.Test)78 URL (org.apache.dubbo.common.URL)77 Invoker (org.apache.dubbo.rpc.Invoker)44 RpcInvocation (org.apache.dubbo.rpc.RpcInvocation)44 Result (org.apache.dubbo.rpc.Result)33 AppResponse (org.apache.dubbo.rpc.AppResponse)29 RpcException (org.apache.dubbo.rpc.RpcException)18 MockInvocation (org.apache.dubbo.rpc.support.MockInvocation)17 HashMap (java.util.HashMap)16 AsyncRpcResult (org.apache.dubbo.rpc.AsyncRpcResult)13 BlockMyInvoker (org.apache.dubbo.rpc.support.BlockMyInvoker)11 MyInvoker (org.apache.dubbo.rpc.support.MyInvoker)10 ArrayList (java.util.ArrayList)8 Person (org.apache.dubbo.rpc.support.Person)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 IMetricManager (com.alibaba.metrics.IMetricManager)5 Method (java.lang.reflect.Method)5 DemoService (org.apache.dubbo.monitor.dubbo.service.DemoService)5 FastCompass (com.alibaba.metrics.FastCompass)4