use of com.weibo.api.motan.protocol.example.IWorld in project motan by weibocom.
the class MockServiceConfig method mockIWorldServiceConfig.
protected static ServiceConfig<IWorld> mockIWorldServiceConfig() {
ServiceConfig<IWorld> serviceConfig = new ServiceConfig<IWorld>();
serviceConfig.setRef(new MockWorld());
serviceConfig.setApplication(application);
serviceConfig.setModule(module);
serviceConfig.setCheck("true");
serviceConfig.setInterface(IWorld.class);
serviceConfig.setGroup(group);
serviceConfig.setShareChannel(true);
return serviceConfig;
}
use of com.weibo.api.motan.protocol.example.IWorld in project motan by weibocom.
the class FailfastHaStrategyTest method testCallError.
@Test(expected = MotanServiceException.class)
@SuppressWarnings("unchecked")
public void testCallError() {
final LoadBalance<IWorld> loadBalance = mockery.mock(LoadBalance.class);
final Referer<IWorld> referer = mockery.mock(Referer.class);
final Request request = mockery.mock(Request.class);
mockery.checking(new Expectations() {
{
one(loadBalance).select(request);
will(returnValue(referer));
one(referer).call(request);
will(returnValue(null));
}
});
assertEquals(null, failfastHaStrategy.call(request, loadBalance));
}
use of com.weibo.api.motan.protocol.example.IWorld in project motan by weibocom.
the class FailfastHaStrategyTest method testCall.
@Test
@SuppressWarnings("unchecked")
public void testCall() {
final LoadBalance<IWorld> loadBalance = mockery.mock(LoadBalance.class);
final Referer<IWorld> referer = mockery.mock(Referer.class);
final Request request = mockery.mock(Request.class);
final Response response = mockery.mock(Response.class);
mockery.checking(new Expectations() {
{
one(loadBalance).select(request);
will(returnValue(referer));
one(referer).call(request);
will(returnValue(response));
}
});
assertEquals(response, failfastHaStrategy.call(request, loadBalance));
}
use of com.weibo.api.motan.protocol.example.IWorld in project motan by weibocom.
the class RefererConfigTest method testGetRef.
@Test
public void testGetRef() {
MockWorld mWorld = new MockWorld();
serviceConfig.setRef(mWorld);
serviceConfig.export();
IWorld ref = refererConfig.getRef();
assertNotNull(ref);
assertEquals(refererConfig.getClusterSupports().size(), 1);
int times = 3;
for (int i = 0; i < times; i++) {
ref.world("test");
}
assertEquals(times, mWorld.stringCount.get());
serviceConfig.unexport();
// destroy
refererConfig.destroy();
assertFalse(refererConfig.getInitialized().get());
}
use of com.weibo.api.motan.protocol.example.IWorld in project motan by weibocom.
the class FailoverHaStrategyTest method testCallWithOneError.
public void testCallWithOneError() {
final DefaultRequest request = new DefaultRequest();
request.setMethodName(IWorld.class.getMethods()[0].getName());
request.setArguments(new Object[] {});
request.setInterfaceName(IHello.class.getSimpleName());
request.setParamtersDesc("void");
final Response response = mockery.mock(Response.class);
final URL url = URL.valueOf("motan%3A%2F%2F10.209.128.244%3A8000%2Fcom.weibo.api.motan.protocol.example.IWorld%3Fprotocol%3Dmotan%26export%3Dmotan%3A8000%26application%3Dapi%26module%3Dtest%26check%3Dtrue%26refreshTimestamp%3D1373275099717%26methodconfig.world%28void%29.retries%3D1%26id%3Dmotan%26methodconfig.world%28java.lang.String%29.retries%3D1%26methodconfig.world%28java.lang.String%2Cboolean%29.retries%3D1%26nodeType%3Dservice%26group%3Dwangzhe-test-yf%26shareChannel%3Dtrue%26&");
mockery.checking(new Expectations() {
{
for (Referer<IWorld> ref : referers) {
atLeast(0).of(ref).call(request);
will(returnValue(response));
atLeast(0).of(ref).isAvailable();
will(returnValue(true));
atLeast(0).of(ref).getUrl();
will(returnValue(url));
atLeast(1).of(ref).destroy();
}
one(referers.get(0)).call(request);
will(throwException(new MotanServiceException("mock throw exception when call")));
one(referers.get(1)).call(request);
will(returnValue(response));
}
});
failoverHaStrategy.call(request, loadBalance);
}
Aggregations