use of com.alibaba.dubbo.rpc.Invoker in project dubbo by alibaba.
the class MockClusterInvoker method doMockInvoke.
@SuppressWarnings({ "unchecked", "rawtypes" })
private Result doMockInvoke(Invocation invocation, RpcException e) {
Result result = null;
Invoker<T> minvoker;
List<Invoker<T>> mockInvokers = selectMockInvoker(invocation);
if (mockInvokers == null || mockInvokers.isEmpty()) {
minvoker = (Invoker<T>) new MockInvoker(directory.getUrl());
} else {
minvoker = mockInvokers.get(0);
}
try {
result = minvoker.invoke(invocation);
} catch (RpcException me) {
if (me.isBiz()) {
result = new RpcResult(me.getCause());
} else {
throw new RpcException(me.getCode(), getMockExceptionMessage(e, me), me.getCause());
}
} catch (Throwable me) {
throw new RpcException(getMockExceptionMessage(e, me), me.getCause());
}
return result;
}
use of com.alibaba.dubbo.rpc.Invoker in project dubbo by alibaba.
the class LoadBalanceTest method testLeastActiveLoadBalance_select.
@Test
public void testLeastActiveLoadBalance_select() {
int runs = 10000;
Map<Invoker, AtomicLong> counter = getInvokeCounter(runs, LeastActiveLoadBalance.NAME);
for (Invoker minvoker : counter.keySet()) {
Long count = counter.get(minvoker).get();
// System.out.println(count);
Assert.assertTrue("abs diff shoud < avg", Math.abs(count - runs / (0f + invokers.size())) < runs / (0f + invokers.size()));
}
}
use of com.alibaba.dubbo.rpc.Invoker in project dubbo by alibaba.
the class LoadBalanceTest method testRoundRobinLoadBalance_select.
@Test
public void testRoundRobinLoadBalance_select() {
int runs = 10000;
Map<Invoker, AtomicLong> counter = getInvokeCounter(runs, RoundRobinLoadBalance.NAME);
for (Invoker minvoker : counter.keySet()) {
Long count = counter.get(minvoker).get();
Assert.assertTrue("abs diff shoud < 1", Math.abs(count - runs / (0f + invokers.size())) < 1f);
}
}
use of com.alibaba.dubbo.rpc.Invoker in project dubbo by alibaba.
the class LoadBalanceTest method testRandomLoadBalance_select.
@Test
public void testRandomLoadBalance_select() {
int runs = 1000;
Map<Invoker, AtomicLong> counter = getInvokeCounter(runs, RandomLoadBalance.NAME);
for (Invoker minvoker : counter.keySet()) {
Long count = counter.get(minvoker).get();
// System.out.println(count);
Assert.assertTrue("abs diff shoud < avg", Math.abs(count - runs / (0f + invokers.size())) < runs / (0f + invokers.size()));
}
for (int i = 0; i < 5; i++) {
for (int j = 0; j <= i; j++) {
RpcStatus.beginCount(invokers.get(i).getUrl(), invocation.getMethodName());
}
}
counter = getInvokeCounter(runs, LeastActiveLoadBalance.NAME);
for (Invoker minvoker : counter.keySet()) {
Long count = counter.get(minvoker).get();
}
Assert.assertEquals(runs, counter.get(invoker1).intValue());
Assert.assertEquals(0, counter.get(invoker2).intValue());
Assert.assertEquals(0, counter.get(invoker3).intValue());
Assert.assertEquals(0, counter.get(invoker4).intValue());
Assert.assertEquals(0, counter.get(invoker5).intValue());
}
use of com.alibaba.dubbo.rpc.Invoker in project dubbo by alibaba.
the class ConditionRouterTest method testRoute_False_HostFilter.
@Test
public void testRoute_False_HostFilter() {
Router router = new ConditionRouterFactory().getRouter(getRouteUrl("true => " + " host = " + NetUtils.getLocalHost()));
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://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService"));
Invoker<String> invoker3 = new MockInvoker<String>(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService"));
invokers.add(invoker1);
invokers.add(invoker2);
invokers.add(invoker3);
List<Invoker<String>> fileredInvokers = router.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
Assert.assertEquals(2, fileredInvokers.size());
Assert.assertEquals(invoker2, fileredInvokers.get(0));
Assert.assertEquals(invoker3, fileredInvokers.get(1));
}
Aggregations