Search in sources :

Example 1 with MockInvoker

use of org.apache.dubbo.rpc.support.MockInvoker 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)

Aggregations

AsyncRpcResult (org.apache.dubbo.rpc.AsyncRpcResult)1 Invoker (org.apache.dubbo.rpc.Invoker)1 Result (org.apache.dubbo.rpc.Result)1 RpcException (org.apache.dubbo.rpc.RpcException)1 ClusterInvoker (org.apache.dubbo.rpc.cluster.ClusterInvoker)1 MockInvoker (org.apache.dubbo.rpc.support.MockInvoker)1