Search in sources :

Example 51 with Invoker

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

the class ConditionRouterTest method testRoute_False_HostFilter.

@Test
public void testRoute_False_HostFilter() {
    Router router = new ConditionRouterFactory().getRouter(getRouteUrl("true => " + " host = " + LOCAL_HOST));
    List<Invoker<String>> invokers = new ArrayList<Invoker<String>>();
    Invoker<String> invoker1 = new MockInvoker<String>(URL.valueOf("dubbo://10.20.3.3:20880/com.foo.BarService"));
    Invoker<String> invoker2 = new MockInvoker<String>(URL.valueOf("dubbo://" + LOCAL_HOST + ":20880/com.foo.BarService"));
    Invoker<String> invoker3 = new MockInvoker<String>(URL.valueOf("dubbo://" + LOCAL_HOST + ":20880/com.foo.BarService"));
    invokers.add(invoker1);
    invokers.add(invoker2);
    invokers.add(invoker3);
    List<Invoker<String>> filteredInvokers = router.route(invokers, URL.valueOf("consumer://" + LOCAL_HOST + "/com.foo.BarService"), new RpcInvocation());
    Assertions.assertEquals(2, filteredInvokers.size());
    Assertions.assertEquals(invoker2, filteredInvokers.get(0));
    Assertions.assertEquals(invoker3, filteredInvokers.get(1));
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) Invoker(org.apache.dubbo.rpc.Invoker) MockInvoker(org.apache.dubbo.rpc.cluster.router.MockInvoker) MockInvoker(org.apache.dubbo.rpc.cluster.router.MockInvoker) ArrayList(java.util.ArrayList) Router(org.apache.dubbo.rpc.cluster.Router) Test(org.junit.jupiter.api.Test)

Example 52 with Invoker

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

the class ScriptRouterTest method testRouteReturnAll.

@Test
public void testRouteReturnAll() {
    Router router = new ScriptRouterFactory().getRouter(getRouteUrl("function route(op1,op2){return op1} route(invokers)"));
    List<Invoker<String>> invokers = new ArrayList<Invoker<String>>();
    invokers.add(new MockInvoker<String>());
    invokers.add(new MockInvoker<String>());
    invokers.add(new MockInvoker<String>());
    List<Invoker<String>> filteredInvokers = router.route(invokers, invokers.get(0).getUrl(), new RpcInvocation());
    Assertions.assertEquals(invokers, filteredInvokers);
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) Invoker(org.apache.dubbo.rpc.Invoker) MockInvoker(org.apache.dubbo.rpc.cluster.router.MockInvoker) ArrayList(java.util.ArrayList) Router(org.apache.dubbo.rpc.cluster.Router) Test(org.junit.jupiter.api.Test)

Example 53 with Invoker

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

the class FailoverClusterInvokerTest method testInvokerDestroyAndReList.

/**
 * When invokers in directory changes after a failed request but just before a retry effort,
 * then we should reselect from the latest invokers before retry.
 */
@Test
public void testInvokerDestroyAndReList() {
    final URL url = URL.valueOf("test://localhost/" + Demo.class.getName() + "?loadbalance=roundrobin&retries=" + retries);
    RpcException exception = new RpcException(RpcException.TIMEOUT_EXCEPTION);
    MockInvoker<Demo> invoker1 = new MockInvoker<Demo>(Demo.class, url);
    invoker1.setException(exception);
    MockInvoker<Demo> invoker2 = new MockInvoker<Demo>(Demo.class, url);
    invoker2.setException(exception);
    final List<Invoker<Demo>> invokers = new ArrayList<Invoker<Demo>>();
    invokers.add(invoker1);
    invokers.add(invoker2);
    Callable<Object> callable = () -> {
        // Simulation: all invokers are destroyed
        for (Invoker<Demo> invoker : invokers) {
            invoker.destroy();
        }
        invokers.clear();
        MockInvoker<Demo> invoker3 = new MockInvoker<Demo>(Demo.class, url);
        invoker3.setResult(AsyncRpcResult.newDefaultAsyncResult(null));
        invokers.add(invoker3);
        return null;
    };
    invoker1.setCallable(callable);
    invoker2.setCallable(callable);
    RpcInvocation inv = new RpcInvocation();
    inv.setMethodName("test");
    Directory<Demo> dic = new MockDirectory<Demo>(url, invokers);
    FailoverClusterInvoker<Demo> clusterinvoker = new FailoverClusterInvoker<Demo>(dic);
    clusterinvoker.invoke(inv);
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) ArrayList(java.util.ArrayList) URL(org.apache.dubbo.common.URL) AbstractInvoker(org.apache.dubbo.rpc.protocol.AbstractInvoker) Invoker(org.apache.dubbo.rpc.Invoker) RpcException(org.apache.dubbo.rpc.RpcException) Test(org.junit.jupiter.api.Test)

Example 54 with Invoker

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

the class LoadBalanceBaseTest method getInvokeCounter.

public Map<Invoker, AtomicLong> getInvokeCounter(int runs, String loadbalanceName) {
    Map<Invoker, AtomicLong> counter = new ConcurrentHashMap<Invoker, AtomicLong>();
    LoadBalance lb = getLoadBalance(loadbalanceName);
    for (Invoker invoker : invokers) {
        counter.put(invoker, new AtomicLong(0));
    }
    URL url = invokers.get(0).getUrl();
    for (int i = 0; i < runs; i++) {
        Invoker sinvoker = lb.select(invokers, url, invocation);
        counter.get(sinvoker).incrementAndGet();
    }
    return counter;
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) Invoker(org.apache.dubbo.rpc.Invoker) LoadBalance(org.apache.dubbo.rpc.cluster.LoadBalance) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) URL(org.apache.dubbo.common.URL)

Example 55 with Invoker

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

the class LoadBalanceBaseTest method getWeightedInvokeResult.

protected Map<Invoker, InvokeResult> getWeightedInvokeResult(int runs, String loadbalanceName) {
    Map<Invoker, InvokeResult> counter = new ConcurrentHashMap<Invoker, InvokeResult>();
    AbstractLoadBalance lb = getLoadBalance(loadbalanceName);
    int totalWeight = 0;
    for (int i = 0; i < weightInvokers.size(); i++) {
        InvokeResult invokeResult = new InvokeResult(lb.getWeight(weightInvokers.get(i), weightTestInvocation));
        counter.put(weightInvokers.get(i), invokeResult);
        totalWeight += invokeResult.getWeight();
    }
    for (InvokeResult invokeResult : counter.values()) {
        invokeResult.setTotalWeight(totalWeight);
    }
    URL url = weightInvokers.get(0).getUrl();
    for (int i = 0; i < runs; i++) {
        Invoker sinvoker = lb.select(weightInvokers, url, weightTestInvocation);
        counter.get(sinvoker).getCount().incrementAndGet();
    }
    return counter;
}
Also used : Invoker(org.apache.dubbo.rpc.Invoker) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) URL(org.apache.dubbo.common.URL)

Aggregations

Invoker (org.apache.dubbo.rpc.Invoker)128 Test (org.junit.jupiter.api.Test)104 URL (org.apache.dubbo.common.URL)74 RpcInvocation (org.apache.dubbo.rpc.RpcInvocation)66 ArrayList (java.util.ArrayList)48 Invocation (org.apache.dubbo.rpc.Invocation)42 Result (org.apache.dubbo.rpc.Result)26 AppResponse (org.apache.dubbo.rpc.AppResponse)21 MockClusterInvoker (org.apache.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker)21 RegistryDirectory (org.apache.dubbo.registry.integration.RegistryDirectory)20 Router (org.apache.dubbo.rpc.cluster.Router)18 MockInvoker (org.apache.dubbo.rpc.cluster.router.MockInvoker)18 HashMap (java.util.HashMap)13 LoadBalance (org.apache.dubbo.rpc.cluster.LoadBalance)13 AsyncRpcResult (org.apache.dubbo.rpc.AsyncRpcResult)12 RpcException (org.apache.dubbo.rpc.RpcException)12 LeastActiveLoadBalance (org.apache.dubbo.rpc.cluster.loadbalance.LeastActiveLoadBalance)8 RandomLoadBalance (org.apache.dubbo.rpc.cluster.loadbalance.RandomLoadBalance)8 RoundRobinLoadBalance (org.apache.dubbo.rpc.cluster.loadbalance.RoundRobinLoadBalance)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8