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));
}
}
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);
}
}
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);
}
}
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;
}
};
}
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);
}
Aggregations