use of com.weibo.api.motan.rpc.Referer in project motan by weibocom.
the class ConfigurableWeightLoadBalanceTest method testDoSelectToHolder.
@Test
public void testDoSelectToHolder() {
generate(3, new int[] { 2, 3, 5 }, new int[] { 3, 4, 5 });
List<Referer<IHello>> list = new ArrayList<Referer<IHello>>();
balance.doSelectToHolder(new DefaultRequest(), list);
assertTrue(list.size() > 0 && list.size() <= ConfigurableWeightLoadBalance.MAX_REFERER_COUNT);
}
use of com.weibo.api.motan.rpc.Referer in project motan by weibocom.
the class ConsistentHashLoadBalanceTest method testSelect.
public void testSelect() {
final Request request = mockery.mock(Request.class);
mockery.checking(new Expectations() {
{
for (Referer<IHello> ref : referers) {
atLeast(0).of(ref).isAvailable();
will(returnValue(true));
}
atLeast(1).of(request).getArguments();
will(returnValue(new Object[] { 1, 2, 3 }));
atLeast(0).of(request).getParamtersDesc();
will(returnValue("void_"));
}
});
Referer<IHello> ref1 = consistentHashLoadBalance.select(request);
for (int i = 0; i < 100; i++) {
Referer<IHello> ref2 = consistentHashLoadBalance.select(request);
assertEquals(ref1, ref2);
}
}
use of com.weibo.api.motan.rpc.Referer in project motan by weibocom.
the class ConsistentHashLoadBalanceTest method testSelect2.
public void testSelect2() {
final Request request = mockery.mock(Request.class);
mockery.checking(new Expectations() {
{
int i = 0;
for (Referer<IHello> ref : referers) {
boolean rs = i++ % 2 == 1;
atLeast(0).of(ref).isAvailable();
will(returnValue(rs));
}
atLeast(1).of(request).getArguments();
will(returnValue(new Object[] { 1, 2, 3 }));
atLeast(0).of(request).getParamtersDesc();
will(returnValue("void_"));
}
});
Referer<IHello> ref1 = consistentHashLoadBalance.select(request);
for (int i = 0; i < 100; i++) {
Referer<IHello> ref2 = consistentHashLoadBalance.select(request);
assertEquals(ref1, ref2);
}
}
use of com.weibo.api.motan.rpc.Referer in project motan by weibocom.
the class ClusterSpiTest method initCluster.
@SuppressWarnings("unchecked")
private void initCluster(boolean throwException) {
referers = new ArrayList<Referer<IHello>>();
for (int i = 0; i < 10; i++) {
referers.add(mockery.mock(Referer.class, "ref_" + i));
}
clusterSpi.setHaStrategy(new FailoverHaStrategy<IHello>());
clusterSpi.setLoadBalance(new RandomLoadBalance<IHello>());
URL url = new URL(MotanConstants.PROTOCOL_MOTAN, NetUtils.getLocalAddress().getHostAddress(), 0, RegistryService.class.getName());
url.addParameter(URLParamType.throwException.getName(), String.valueOf(throwException));
url.addParameter(URLParamType.retries.getName(), "2");
clusterSpi.setUrl(url);
clusterSpi.onRefresh(referers);
clusterSpi.init();
}
use of com.weibo.api.motan.rpc.Referer in project motan by weibocom.
the class ClusterSpiTest method testSilentCall.
public void testSilentCall() {
initCluster(false);
final Request request = mockRequest();
final URL url = mockURL();
mockery.checking(new Expectations() {
{
for (Referer<IHello> ref : referers) {
atLeast(0).of(ref).call(request);
will(throwException(new IllegalStateException("Throw exception for test")));
atLeast(0).of(ref).isAvailable();
will(returnValue(true));
atLeast(0).of(ref).getUrl();
will(returnValue(url));
atLeast(1).of(ref).destroy();
}
}
});
clusterSpi.call(request);
clusterSpi.destroy();
}
Aggregations