Search in sources :

Example 6 with LoadBalance

use of org.apache.dubbo.rpc.cluster.LoadBalance in project dubbo by alibaba.

the class AbstractClusterInvokerTest method testDonotSelectAgainAndNoCheckAvailable.

@Test
public void testDonotSelectAgainAndNoCheckAvailable() {
    LoadBalance lb = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(RoundRobinLoadBalance.NAME);
    initlistsize5();
    {
        // Boundary condition test .
        selectedInvokers.clear();
        selectedInvokers.add(invoker2);
        selectedInvokers.add(invoker3);
        selectedInvokers.add(invoker4);
        selectedInvokers.add(invoker5);
        Invoker sinvoker = cluster_nocheck.select(lb, invocation, invokers, selectedInvokers);
        Assertions.assertSame(invoker1, sinvoker);
    }
    {
        // Boundary condition test .
        selectedInvokers.clear();
        selectedInvokers.add(invoker1);
        selectedInvokers.add(invoker3);
        selectedInvokers.add(invoker4);
        selectedInvokers.add(invoker5);
        Invoker sinvoker = cluster_nocheck.select(lb, invocation, invokers, selectedInvokers);
        Assertions.assertSame(invoker2, sinvoker);
    }
    {
        // Boundary condition test .
        selectedInvokers.clear();
        selectedInvokers.add(invoker1);
        selectedInvokers.add(invoker2);
        selectedInvokers.add(invoker4);
        selectedInvokers.add(invoker5);
        Invoker sinvoker = cluster_nocheck.select(lb, invocation, invokers, selectedInvokers);
        Assertions.assertSame(invoker3, sinvoker);
    }
    {
        // Boundary condition test .
        selectedInvokers.clear();
        selectedInvokers.add(invoker1);
        selectedInvokers.add(invoker2);
        selectedInvokers.add(invoker3);
        selectedInvokers.add(invoker4);
        Invoker sinvoker = cluster_nocheck.select(lb, invocation, invokers, selectedInvokers);
        Assertions.assertSame(invoker5, sinvoker);
    }
    {
        // Boundary condition test .
        selectedInvokers.clear();
        selectedInvokers.add(invoker1);
        selectedInvokers.add(invoker2);
        selectedInvokers.add(invoker3);
        selectedInvokers.add(invoker4);
        selectedInvokers.add(invoker5);
        Invoker sinvoker = cluster_nocheck.select(lb, invocation, invokers, selectedInvokers);
        Assertions.assertTrue(invokers.contains(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)

Example 7 with LoadBalance

use of org.apache.dubbo.rpc.cluster.LoadBalance in project dubbo by alibaba.

the class AbstractClusterInvokerTest method testSelect_Invokersize2AndselectNotNull.

@Test
public void testSelect_Invokersize2AndselectNotNull() throws Exception {
    invokers.clear();
    invokers.add(invoker2);
    invokers.add(invoker4);
    LoadBalance l = cluster.initLoadBalance(invokers, invocation);
    Assertions.assertNotNull(l, "cluster.initLoadBalance returns null!");
    {
        selectedInvokers.clear();
        selectedInvokers.add(invoker4);
        Invoker invoker = cluster.select(l, invocation, invokers, selectedInvokers);
        Assertions.assertEquals(invoker2, invoker);
    }
    {
        selectedInvokers.clear();
        selectedInvokers.add(invoker2);
        Invoker invoker = cluster.select(l, invocation, invokers, selectedInvokers);
        Assertions.assertEquals(invoker4, 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 8 with LoadBalance

use of org.apache.dubbo.rpc.cluster.LoadBalance in project dubbo by alibaba.

the class AbstractClusterInvokerTest method testSelect_Invokersize0.

@Test
public void testSelect_Invokersize0() throws Exception {
    LoadBalance l = cluster.initLoadBalance(invokers, invocation);
    Assertions.assertNotNull(l, "cluster.initLoadBalance returns null!");
    {
        Invoker invoker = cluster.select(l, null, null, null);
        Assertions.assertNull(invoker);
    }
    {
        invokers.clear();
        selectedInvokers.clear();
        Invoker invoker = cluster.select(l, null, invokers, null);
        Assertions.assertNull(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 9 with LoadBalance

use of org.apache.dubbo.rpc.cluster.LoadBalance in project dubbo by alibaba.

the class AbstractClusterInvokerTest method setUp.

@SuppressWarnings({ "unchecked" })
@BeforeEach
public void setUp() throws Exception {
    invocation.setMethodName("sayHello");
    invoker1 = mock(Invoker.class);
    invoker2 = mock(Invoker.class);
    invoker3 = mock(Invoker.class);
    invoker4 = mock(Invoker.class);
    invoker5 = mock(Invoker.class);
    mockedInvoker1 = mock(Invoker.class);
    URL turl = URL.valueOf("test://test:11/test");
    given(invoker1.isAvailable()).willReturn(false);
    given(invoker1.getInterface()).willReturn(IHelloService.class);
    given(invoker1.getUrl()).willReturn(turl.setPort(1).addParameter("name", "invoker1"));
    given(invoker2.isAvailable()).willReturn(true);
    given(invoker2.getInterface()).willReturn(IHelloService.class);
    given(invoker2.getUrl()).willReturn(turl.setPort(2).addParameter("name", "invoker2"));
    given(invoker3.isAvailable()).willReturn(false);
    given(invoker3.getInterface()).willReturn(IHelloService.class);
    given(invoker3.getUrl()).willReturn(turl.setPort(3).addParameter("name", "invoker3"));
    given(invoker4.isAvailable()).willReturn(true);
    given(invoker4.getInterface()).willReturn(IHelloService.class);
    given(invoker4.getUrl()).willReturn(turl.setPort(4).addParameter("name", "invoker4"));
    given(invoker5.isAvailable()).willReturn(false);
    given(invoker5.getInterface()).willReturn(IHelloService.class);
    given(invoker5.getUrl()).willReturn(turl.setPort(5).addParameter("name", "invoker5"));
    given(mockedInvoker1.isAvailable()).willReturn(false);
    given(mockedInvoker1.getInterface()).willReturn(IHelloService.class);
    given(mockedInvoker1.getUrl()).willReturn(turl.setPort(999).setProtocol("mock"));
    invokers.add(invoker1);
    dic = new StaticDirectory<>(url, invokers, null);
    dic.setConsumerUrl(consumerUrl);
    cluster = new AbstractClusterInvoker(dic) {

        @Override
        protected Result doInvoke(Invocation invocation, List invokers, LoadBalance loadbalance) throws RpcException {
            return null;
        }
    };
    cluster_nocheck = new AbstractClusterInvoker(dic, url.addParameterIfAbsent(CLUSTER_AVAILABLE_CHECK_KEY, Boolean.FALSE.toString())) {

        @Override
        protected Result doInvoke(Invocation invocation, List invokers, LoadBalance loadbalance) throws RpcException {
            return null;
        }
    };
}
Also used : Invoker(org.apache.dubbo.rpc.Invoker) Invocation(org.apache.dubbo.rpc.Invocation) RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) 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) RpcException(org.apache.dubbo.rpc.RpcException) ArrayList(java.util.ArrayList) List(java.util.List) URL(org.apache.dubbo.common.URL) Result(org.apache.dubbo.rpc.Result) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 10 with LoadBalance

use of org.apache.dubbo.rpc.cluster.LoadBalance 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)13 LoadBalance (org.apache.dubbo.rpc.cluster.LoadBalance)13 LeastActiveLoadBalance (org.apache.dubbo.rpc.cluster.loadbalance.LeastActiveLoadBalance)9 RandomLoadBalance (org.apache.dubbo.rpc.cluster.loadbalance.RandomLoadBalance)9 RoundRobinLoadBalance (org.apache.dubbo.rpc.cluster.loadbalance.RoundRobinLoadBalance)9 Test (org.junit.jupiter.api.Test)7 URL (org.apache.dubbo.common.URL)4 RpcInvocation (org.apache.dubbo.rpc.RpcInvocation)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Invocation (org.apache.dubbo.rpc.Invocation)3 RpcException (org.apache.dubbo.rpc.RpcException)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 ProxyFactory (org.apache.dubbo.rpc.ProxyFactory)2 StaticDirectory (org.apache.dubbo.rpc.cluster.directory.StaticDirectory)2 AbstractClusterInvoker (org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker)2 Map (java.util.Map)1 Result (org.apache.dubbo.rpc.Result)1 ClusterInvoker (org.apache.dubbo.rpc.cluster.ClusterInvoker)1