Search in sources :

Example 71 with Invoker

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

the class LeastActiveBalanceTest method testLeastActiveLoadBalance_select.

@Disabled
@Test
public void testLeastActiveLoadBalance_select() {
    int runs = 10000;
    Map<Invoker, AtomicLong> counter = getInvokeCounter(runs, LeastActiveLoadBalance.NAME);
    for (Map.Entry<Invoker, AtomicLong> entry : counter.entrySet()) {
        Long count = entry.getValue().get();
        // System.out.println(count);
        Assertions.assertTrue(Math.abs(count - runs / (0f + invokers.size())) < runs / (0f + invokers.size()), "abs diff should < avg");
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) Invoker(org.apache.dubbo.rpc.Invoker) AtomicLong(java.util.concurrent.atomic.AtomicLong) Map(java.util.Map) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 72 with Invoker

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

the class RandomLoadBalanceTest method testSelectByWeight.

@Test
public void testSelectByWeight() {
    int sumInvoker1 = 0;
    int sumInvoker2 = 0;
    int sumInvoker3 = 0;
    int loop = 10000;
    RandomLoadBalance lb = new RandomLoadBalance();
    for (int i = 0; i < loop; i++) {
        Invoker selected = lb.select(weightInvokers, null, weightTestInvocation);
        if (selected.getUrl().getProtocol().equals("test1")) {
            sumInvoker1++;
        }
        if (selected.getUrl().getProtocol().equals("test2")) {
            sumInvoker2++;
        }
        if (selected.getUrl().getProtocol().equals("test3")) {
            sumInvoker3++;
        }
    }
    // 1 : 9 : 6
    System.out.println(sumInvoker1);
    System.out.println(sumInvoker2);
    System.out.println(sumInvoker3);
    Assertions.assertEquals(sumInvoker1 + sumInvoker2 + sumInvoker3, loop, "select failed!");
}
Also used : Invoker(org.apache.dubbo.rpc.Invoker) Test(org.junit.jupiter.api.Test)

Example 73 with Invoker

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

the class AbstractClusterInvokerTest method testMockedInvokerSelect.

/**
 * Test mock invoker selector works as expected
 */
@Test
public void testMockedInvokerSelect() {
    initlistsize5();
    invokers.add(mockedInvoker1);
    initDic();
    RpcInvocation mockedInvocation = new RpcInvocation();
    mockedInvocation.setMethodName("sayHello");
    mockedInvocation.setAttachment(INVOCATION_NEED_MOCK, "true");
    List<Invoker<IHelloService>> mockedInvokers = dic.list(mockedInvocation);
    Assertions.assertEquals(1, mockedInvokers.size());
    List<Invoker<IHelloService>> invokers = dic.list(invocation);
    Assertions.assertEquals(5, invokers.size());
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) Invoker(org.apache.dubbo.rpc.Invoker) Test(org.junit.jupiter.api.Test)

Example 74 with Invoker

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

the class AbstractClusterInvokerTest method testTimeoutExceptionCode.

@Test()
public void testTimeoutExceptionCode() {
    List<Invoker<DemoService>> invokers = new ArrayList<Invoker<DemoService>>();
    invokers.add(new Invoker<DemoService>() {

        @Override
        public Class<DemoService> getInterface() {
            return DemoService.class;
        }

        public URL getUrl() {
            return URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/" + DemoService.class.getName());
        }

        @Override
        public boolean isAvailable() {
            return false;
        }

        @Override
        public Result invoke(Invocation invocation) throws RpcException {
            throw new RpcException(RpcException.TIMEOUT_EXCEPTION, "test timeout");
        }

        @Override
        public void destroy() {
        }
    });
    Directory<DemoService> directory = new StaticDirectory<DemoService>(invokers);
    FailoverClusterInvoker<DemoService> failoverClusterInvoker = new FailoverClusterInvoker<DemoService>(directory);
    try {
        failoverClusterInvoker.invoke(new RpcInvocation("sayHello", DemoService.class.getName(), "", new Class<?>[0], new Object[0]));
        Assertions.fail();
    } catch (RpcException e) {
        Assertions.assertEquals(RpcException.TIMEOUT_EXCEPTION, e.getCode());
    }
    ForkingClusterInvoker<DemoService> forkingClusterInvoker = new ForkingClusterInvoker<DemoService>(directory);
    try {
        forkingClusterInvoker.invoke(new RpcInvocation("sayHello", DemoService.class.getName(), "", new Class<?>[0], new Object[0]));
        Assertions.fail();
    } catch (RpcException e) {
        Assertions.assertEquals(RpcException.TIMEOUT_EXCEPTION, e.getCode());
    }
    FailfastClusterInvoker<DemoService> failfastClusterInvoker = new FailfastClusterInvoker<DemoService>(directory);
    try {
        failfastClusterInvoker.invoke(new RpcInvocation("sayHello", DemoService.class.getName(), "", new Class<?>[0], new Object[0]));
        Assertions.fail();
    } catch (RpcException e) {
        Assertions.assertEquals(RpcException.TIMEOUT_EXCEPTION, e.getCode());
    }
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) Invocation(org.apache.dubbo.rpc.Invocation) RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) ArrayList(java.util.ArrayList) DemoService(org.apache.dubbo.rpc.cluster.filter.DemoService) URL(org.apache.dubbo.common.URL) Result(org.apache.dubbo.rpc.Result) StaticDirectory(org.apache.dubbo.rpc.cluster.directory.StaticDirectory) Invoker(org.apache.dubbo.rpc.Invoker) RpcException(org.apache.dubbo.rpc.RpcException) Test(org.junit.jupiter.api.Test)

Example 75 with Invoker

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

the class AbstractClusterInvokerTest method testCloseAvailablecheck.

@Test
public void testCloseAvailablecheck() {
    LoadBalance lb = mock(LoadBalance.class);
    given(lb.select(invokers, consumerUrl, invocation)).willReturn(invoker1);
    initlistsize5();
    Invoker sinvoker = cluster_nocheck.select(lb, invocation, invokers, selectedInvokers);
    Assertions.assertFalse(sinvoker.isAvailable());
    Assertions.assertEquals(invoker1, sinvoker);
}
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)

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