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