Search in sources :

Example 6 with Result

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

the class MockClusterInvoker method doMockInvoke.

@SuppressWarnings({ "unchecked", "rawtypes" })
private Result doMockInvoke(Invocation invocation, RpcException e) {
    Result result = null;
    Invoker<T> minvoker;
    List<Invoker<T>> mockInvokers = selectMockInvoker(invocation);
    if (CollectionUtils.isEmpty(mockInvokers)) {
        minvoker = (Invoker<T>) new MockInvoker(getUrl(), directory.getInterface());
    } else {
        minvoker = mockInvokers.get(0);
    }
    try {
        result = minvoker.invoke(invocation);
    } catch (RpcException me) {
        if (me.isBiz()) {
            result = AsyncRpcResult.newDefaultAsyncResult(me.getCause(), invocation);
        } else {
            throw new RpcException(me.getCode(), getMockExceptionMessage(e, me), me.getCause());
        }
    } catch (Throwable me) {
        throw new RpcException(getMockExceptionMessage(e, me), me.getCause());
    }
    return result;
}
Also used : Invoker(org.apache.dubbo.rpc.Invoker) ClusterInvoker(org.apache.dubbo.rpc.cluster.ClusterInvoker) MockInvoker(org.apache.dubbo.rpc.support.MockInvoker) MockInvoker(org.apache.dubbo.rpc.support.MockInvoker) RpcException(org.apache.dubbo.rpc.RpcException) AsyncRpcResult(org.apache.dubbo.rpc.AsyncRpcResult) Result(org.apache.dubbo.rpc.Result)

Example 7 with Result

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

the class GrpcInvoker method doInvoke.

@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) {
            throw getRpcException(getInterface(), getUrl(), 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(getInterface(), getUrl(), invocation, e);
    }
}
Also used : RpcException(org.apache.dubbo.rpc.RpcException) Result(org.apache.dubbo.rpc.Result)

Example 8 with Result

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

the class RestProtocolTest method testInvoke.

@Test
public void testInvoke() {
    DemoService server = new DemoServiceImpl();
    this.registerProvider(exportUrl, server, DemoService.class);
    Exporter<DemoService> exporter = protocol.export(proxy.getInvoker(server, DemoService.class, exportUrl));
    RpcInvocation rpcInvocation = new RpcInvocation("hello", DemoService.class.getName(), "", new Class[] { Integer.class, Integer.class }, new Integer[] { 2, 3 });
    Result result = exporter.getInvoker().invoke(rpcInvocation);
    assertThat(result.getValue(), CoreMatchers.<Object>is(5));
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) Result(org.apache.dubbo.rpc.Result) Test(org.junit.jupiter.api.Test)

Example 9 with Result

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

the class ValidationFilterTest method testItWhileMethodNameStartWithDollar.

@Test
public void testItWhileMethodNameStartWithDollar() throws Exception {
    URL url = URL.valueOf("test://test:11/test");
    given(validation.getValidator(url)).willReturn(validator);
    given(invoker.invoke(invocation)).willReturn(new AppResponse("success"));
    given(invoker.getUrl()).willReturn(url);
    given(invocation.getMethodName()).willReturn("$echo1");
    given(invocation.getParameterTypes()).willReturn(new Class<?>[] { String.class });
    given(invocation.getArguments()).willReturn(new Object[] { "arg1" });
    validationFilter.setValidation(validation);
    Result result = validationFilter.invoke(invoker, invocation);
    assertThat(String.valueOf(result.getValue()), is("success"));
}
Also used : AppResponse(org.apache.dubbo.rpc.AppResponse) URL(org.apache.dubbo.common.URL) Result(org.apache.dubbo.rpc.Result) Test(org.junit.jupiter.api.Test)

Example 10 with Result

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

the class ValidationFilterTest method testItWithExistClass.

@Test
public void testItWithExistClass() throws Exception {
    URL url = URL.valueOf("test://test:11/test?validation=true");
    given(validation.getValidator(url)).willReturn(validator);
    given(invoker.invoke(invocation)).willReturn(new AppResponse("success"));
    given(invoker.getUrl()).willReturn(url);
    given(invocation.getMethodName()).willReturn("echo1");
    given(invocation.getParameterTypes()).willReturn(new Class<?>[] { String.class });
    given(invocation.getArguments()).willReturn(new Object[] { "arg1" });
    validationFilter.setValidation(validation);
    Result result = validationFilter.invoke(invoker, invocation);
    assertThat(String.valueOf(result.getValue()), is("success"));
}
Also used : AppResponse(org.apache.dubbo.rpc.AppResponse) URL(org.apache.dubbo.common.URL) Result(org.apache.dubbo.rpc.Result) Test(org.junit.jupiter.api.Test)

Aggregations

Result (org.apache.dubbo.rpc.Result)97 Test (org.junit.jupiter.api.Test)74 URL (org.apache.dubbo.common.URL)55 RpcInvocation (org.apache.dubbo.rpc.RpcInvocation)39 Invocation (org.apache.dubbo.rpc.Invocation)33 AsyncRpcResult (org.apache.dubbo.rpc.AsyncRpcResult)31 AppResponse (org.apache.dubbo.rpc.AppResponse)28 Invoker (org.apache.dubbo.rpc.Invoker)27 RpcException (org.apache.dubbo.rpc.RpcException)22 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)7 RpcContext (org.apache.dubbo.rpc.RpcContext)7 BlockMyInvoker (org.apache.dubbo.rpc.support.BlockMyInvoker)6 DemoService (org.apache.dubbo.rpc.support.DemoService)6 List (java.util.List)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 Protocol (org.apache.dubbo.rpc.Protocol)5 Person (org.apache.dubbo.rpc.support.Person)5 Method (java.lang.reflect.Method)4 MockProtocol (org.apache.dubbo.rpc.support.MockProtocol)4