use of com.weibo.api.motan.protocol.example.IWorld in project motan by weibocom.
the class FailoverHaStrategyTest method testCall.
public void testCall() {
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() {
{
// failoverHaStrategy.referersHolder.get());
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(returnValue(response));
}
});
failoverHaStrategy.call(request, loadBalance);
}
use of com.weibo.api.motan.protocol.example.IWorld in project motan by weibocom.
the class FailoverHaStrategyTest method setUp.
@Before
@Override
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
super.setUp();
loadBalance = mockery.mock(LoadBalance.class);
final Referer<IWorld> referer1 = mockery.mock(Referer.class, "ref1");
final Referer<IWorld> referer2 = mockery.mock(Referer.class, "ref2");
referers = new ArrayList<Referer<IWorld>>();
referers.add(referer1);
referers.add(referer2);
failoverHaStrategy = new FailoverHaStrategy<IWorld>() {
@Override
protected List<Referer<IWorld>> selectReferers(Request request, LoadBalance<IWorld> loadBalance) {
return referers;
}
};
URL url = new URL(MotanConstants.PROTOCOL_MOTAN, NetUtils.LOCALHOST, 0, IWorld.class.getName());
url.addParameter(URLParamType.retries.getName(), String.valueOf(retries));
failoverHaStrategy.setUrl(url);
}
use of com.weibo.api.motan.protocol.example.IWorld in project motan by weibocom.
the class FailoverHaStrategyTest method testCallWithFalse.
public void testCallWithFalse() {
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() {
{
one(loadBalance).selectToHolder(request, failoverHaStrategy.referersHolder.get());
for (Referer<IWorld> ref : referers) {
atLeast(0).of(ref).isAvailable();
will(returnValue(true));
atLeast(0).of(ref).getUrl();
will(returnValue(url));
atLeast(0).of(ref).destroy();
}
atLeast(2).of(referers.get(0)).call(request);
will(throwException(new MotanServiceException("mock throw exception when 1th call")));
oneOf(referers.get(1)).call(request);
will(throwException(new MotanServiceException("mock throw exception when 2th call")));
}
});
try {
failoverHaStrategy.call(request, loadBalance);
fail("Should throw exception before!");
// should not run to here
Assert.assertTrue(false);
} catch (Exception e) {
}
}
use of com.weibo.api.motan.protocol.example.IWorld in project motan by weibocom.
the class RefererConfigTest method testException.
@Test
public void testException() {
IWorld ref = null;
// protocol empty
List<ProtocolConfig> protocols = new ArrayList<ProtocolConfig>();
refererConfig.setProtocols(protocols);
try {
ref = refererConfig.getRef();
assertTrue(false);
} catch (Exception e) {
assertTrue(e.getMessage().contains("protocol not set correctly"));
}
// protocol not exists
protocols.add(mockProtocolConfig("notExist"));
try {
ref = refererConfig.getRef();
assertTrue(false);
} catch (Exception e) {
assertTrue(e.getMessage().contains("Protocol is null"));
}
protocols.add(mockProtocolConfig("notExist"));
// method config wrong
MethodConfig mConfig = new MethodConfig();
mConfig.setName("notExist");
refererConfig.setMethods(mConfig);
try {
ref = refererConfig.getRef();
assertTrue(false);
} catch (Exception e) {
assertTrue(e.getMessage().contains("not found method"));
}
}
use of com.weibo.api.motan.protocol.example.IWorld in project motan by weibocom.
the class RefererConfigTest method testMultiProtocol.
@Test
public void testMultiProtocol() {
List<ProtocolConfig> protocols = getMultiProtocols(MotanConstants.PROTOCOL_INJVM, MotanConstants.PROTOCOL_MOTAN);
refererConfig.setProtocols(protocols);
IWorld ref = refererConfig.getRef();
assertNotNull(ref);
assertEquals(protocols.size(), refererConfig.getClusterSupports().size());
}
Aggregations