Search in sources :

Example 41 with Invoker

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

the class AbstractClusterInvokerTest method testSelectAgainAndCheckAvailable.

@Test
public void testSelectAgainAndCheckAvailable() {
    LoadBalance lb = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(RoundRobinLoadBalance.NAME);
    initlistsize5();
    {
        // Boundary condition test .
        selectedInvokers.clear();
        selectedInvokers.add(invoker1);
        selectedInvokers.add(invoker2);
        selectedInvokers.add(invoker3);
        selectedInvokers.add(invoker5);
        Invoker sinvoker = cluster.select(lb, invocation, invokers, selectedInvokers);
        Assertions.assertSame(sinvoker, invoker4);
    }
    {
        // Boundary condition test .
        selectedInvokers.clear();
        selectedInvokers.add(invoker2);
        selectedInvokers.add(invoker3);
        selectedInvokers.add(invoker4);
        selectedInvokers.add(invoker5);
        Invoker sinvoker = cluster.select(lb, invocation, invokers, selectedInvokers);
        Assertions.assertTrue(sinvoker == invoker2 || sinvoker == invoker4);
    }
    {
        // Boundary condition test .
        for (int i = 0; i < 100; i++) {
            selectedInvokers.clear();
            Invoker sinvoker = cluster.select(lb, invocation, invokers, selectedInvokers);
            Assertions.assertTrue(sinvoker == invoker2 || sinvoker == invoker4);
        }
    }
    {
        // Boundary condition test .
        for (int i = 0; i < 100; i++) {
            selectedInvokers.clear();
            selectedInvokers.add(invoker1);
            selectedInvokers.add(invoker3);
            selectedInvokers.add(invoker5);
            Invoker sinvoker = cluster.select(lb, invocation, invokers, selectedInvokers);
            Assertions.assertTrue(sinvoker == invoker2 || sinvoker == invoker4);
        }
    }
    {
        // Boundary condition test .
        for (int i = 0; i < 100; i++) {
            selectedInvokers.clear();
            selectedInvokers.add(invoker1);
            selectedInvokers.add(invoker3);
            selectedInvokers.add(invoker2);
            selectedInvokers.add(invoker4);
            selectedInvokers.add(invoker5);
            Invoker sinvoker = cluster.select(lb, invocation, invokers, selectedInvokers);
            Assertions.assertTrue(sinvoker == invoker2 || sinvoker == invoker4);
        }
    }
}
Also used : Invoker(org.apache.dubbo.rpc.Invoker) LoadBalance(org.apache.dubbo.rpc.cluster.LoadBalance) RoundRobinLoadBalance(org.apache.dubbo.rpc.cluster.loadbalance.RoundRobinLoadBalance) LeastActiveLoadBalance(org.apache.dubbo.rpc.cluster.loadbalance.LeastActiveLoadBalance) RandomLoadBalance(org.apache.dubbo.rpc.cluster.loadbalance.RandomLoadBalance) Test(org.junit.jupiter.api.Test)

Example 42 with Invoker

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

the class AbstractClusterInvokerTest method testSelect_Invokersize1.

@Test
public void testSelect_Invokersize1() throws Exception {
    invokers.clear();
    invokers.add(invoker1);
    LoadBalance l = cluster.initLoadBalance(invokers, invocation);
    Assertions.assertNotNull(l, "cluster.initLoadBalance returns null!");
    Invoker invoker = cluster.select(l, null, invokers, null);
    Assertions.assertEquals(invoker1, invoker);
}
Also used : Invoker(org.apache.dubbo.rpc.Invoker) LoadBalance(org.apache.dubbo.rpc.cluster.LoadBalance) RoundRobinLoadBalance(org.apache.dubbo.rpc.cluster.loadbalance.RoundRobinLoadBalance) LeastActiveLoadBalance(org.apache.dubbo.rpc.cluster.loadbalance.LeastActiveLoadBalance) RandomLoadBalance(org.apache.dubbo.rpc.cluster.loadbalance.RandomLoadBalance) Test(org.junit.jupiter.api.Test)

Example 43 with Invoker

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

the class AbstractClusterInvokerTest method testSelect_multiInvokers.

public void testSelect_multiInvokers(String lbname) throws Exception {
    int min = 1000, max = 5000;
    Double d = (Math.random() * (max - min + 1) + min);
    int runs = d.intValue();
    Assertions.assertTrue(runs >= min);
    LoadBalance lb = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(lbname);
    initlistsize5();
    for (int i = 0; i < runs; i++) {
        Invoker sinvoker = cluster.select(lb, invocation, invokers, selectedInvokers);
        Assertions.assertTrue(sinvoker.isAvailable());
        Mockito.clearInvocations(invoker1, invoker2, invoker3, invoker4, invoker5);
    }
    for (int i = 0; i < runs; i++) {
        selectedInvokers.clear();
        selectedInvokers.add(invoker1);
        Invoker sinvoker = cluster.select(lb, invocation, invokers, selectedInvokers);
        Assertions.assertTrue(sinvoker.isAvailable());
        Mockito.clearInvocations(invoker1, invoker2, invoker3, invoker4, invoker5);
    }
    for (int i = 0; i < runs; i++) {
        selectedInvokers.clear();
        selectedInvokers.add(invoker2);
        Invoker sinvoker = cluster.select(lb, invocation, invokers, selectedInvokers);
        Assertions.assertTrue(sinvoker.isAvailable());
        Mockito.clearInvocations(invoker1, invoker2, invoker3, invoker4, invoker5);
    }
    for (int i = 0; i < runs; i++) {
        selectedInvokers.clear();
        selectedInvokers.add(invoker2);
        selectedInvokers.add(invoker4);
        Invoker sinvoker = cluster.select(lb, invocation, invokers, selectedInvokers);
        Assertions.assertTrue(sinvoker.isAvailable());
        Mockito.clearInvocations(invoker1, invoker2, invoker3, invoker4, invoker5);
    }
    for (int i = 0; i < runs; i++) {
        selectedInvokers.clear();
        selectedInvokers.add(invoker1);
        selectedInvokers.add(invoker3);
        selectedInvokers.add(invoker5);
        Invoker sinvoker = cluster.select(lb, invocation, invokers, selectedInvokers);
        Assertions.assertTrue(sinvoker.isAvailable());
        Mockito.clearInvocations(invoker1, invoker2, invoker3, invoker4, invoker5);
    }
    for (int i = 0; i < runs; i++) {
        selectedInvokers.clear();
        selectedInvokers.add(invoker1);
        selectedInvokers.add(invoker2);
        selectedInvokers.add(invoker3);
        Invoker sinvoker = cluster.select(lb, invocation, invokers, selectedInvokers);
        Assertions.assertTrue(sinvoker.isAvailable());
        Mockito.clearInvocations(invoker1, invoker2, invoker3, invoker4, invoker5);
    }
}
Also used : Invoker(org.apache.dubbo.rpc.Invoker) LoadBalance(org.apache.dubbo.rpc.cluster.LoadBalance) RoundRobinLoadBalance(org.apache.dubbo.rpc.cluster.loadbalance.RoundRobinLoadBalance) LeastActiveLoadBalance(org.apache.dubbo.rpc.cluster.loadbalance.LeastActiveLoadBalance) RandomLoadBalance(org.apache.dubbo.rpc.cluster.loadbalance.RandomLoadBalance)

Example 44 with Invoker

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

the class ShortestResponseLoadBalanceTest method testSelectByWeight.

@Test
public void testSelectByWeight() {
    int sumInvoker1 = 0;
    int sumInvoker2 = 0;
    int loop = 10000;
    ShortestResponseLoadBalance lb = new ShortestResponseLoadBalance();
    for (int i = 0; i < loop; i++) {
        Invoker selected = lb.select(weightInvokersSR, null, weightTestInvocation);
        if (selected.getUrl().getProtocol().equals("test1")) {
            sumInvoker1++;
        }
        if (selected.getUrl().getProtocol().equals("test2")) {
            sumInvoker2++;
        }
        // never select invoker5 because it's estimated response time is more than invoker1 and invoker2
        Assertions.assertTrue(!selected.getUrl().getProtocol().equals("test5"), "select is not the shortest one");
    }
    // the sumInvoker1 : sumInvoker2 approximately equal to 1: 9
    System.out.println(sumInvoker1);
    System.out.println(sumInvoker2);
    Assertions.assertEquals(sumInvoker1 + sumInvoker2, loop, "select failed!");
}
Also used : Invoker(org.apache.dubbo.rpc.Invoker) Test(org.junit.jupiter.api.Test)

Example 45 with Invoker

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

the class ConditionRouterTest method testRoute_Placeholder.

@Test
public void testRoute_Placeholder() {
    Router router = new ConditionRouterFactory().getRouter(getRouteUrl("host = " + LOCAL_HOST + " => " + " host = $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)

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