Search in sources :

Example 1 with AbstractClusterInvoker

use of com.alibaba.dubbo.rpc.cluster.support.AbstractClusterInvoker in project dubbo by alibaba.

the class MockClusterInvokerTest method getClusterInvoker.

@SuppressWarnings({ "unchecked", "rawtypes" })
private Invoker<IHelloService> getClusterInvoker(URL url) {
    // As `javassist` have a strict restriction of argument types, request will fail if Invocation do not contains complete parameter type information
    final URL durl = url.addParameter("proxy", "jdk");
    invokers.clear();
    ProxyFactory proxy = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getExtension("jdk");
    Invoker<IHelloService> invoker1 = proxy.getInvoker(new HelloService(), IHelloService.class, durl);
    invokers.add(invoker1);
    Directory<IHelloService> dic = new StaticDirectory<IHelloService>(durl, invokers, null);
    AbstractClusterInvoker<IHelloService> cluster = new AbstractClusterInvoker(dic) {

        @Override
        protected Result doInvoke(Invocation invocation, List invokers, LoadBalance loadbalance) throws RpcException {
            if (durl.getParameter("invoke_return_error", false)) {
                throw new RpcException(RpcException.TIMEOUT_EXCEPTION, "test rpc exception");
            } else {
                return ((Invoker<?>) invokers.get(0)).invoke(invocation);
            }
        }
    };
    return new MockClusterInvoker<IHelloService>(dic, cluster);
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) Invocation(com.alibaba.dubbo.rpc.Invocation) ProxyFactory(com.alibaba.dubbo.rpc.ProxyFactory) AbstractClusterInvoker(com.alibaba.dubbo.rpc.cluster.support.AbstractClusterInvoker) URL(com.alibaba.dubbo.common.URL) StaticDirectory(com.alibaba.dubbo.rpc.cluster.directory.StaticDirectory) Invoker(com.alibaba.dubbo.rpc.Invoker) AbstractClusterInvoker(com.alibaba.dubbo.rpc.cluster.support.AbstractClusterInvoker) LoadBalance(com.alibaba.dubbo.rpc.cluster.LoadBalance) RpcException(com.alibaba.dubbo.rpc.RpcException) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

URL (com.alibaba.dubbo.common.URL)1 Invocation (com.alibaba.dubbo.rpc.Invocation)1 Invoker (com.alibaba.dubbo.rpc.Invoker)1 ProxyFactory (com.alibaba.dubbo.rpc.ProxyFactory)1 RpcException (com.alibaba.dubbo.rpc.RpcException)1 RpcInvocation (com.alibaba.dubbo.rpc.RpcInvocation)1 LoadBalance (com.alibaba.dubbo.rpc.cluster.LoadBalance)1 StaticDirectory (com.alibaba.dubbo.rpc.cluster.directory.StaticDirectory)1 AbstractClusterInvoker (com.alibaba.dubbo.rpc.cluster.support.AbstractClusterInvoker)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1