use of com.weibo.api.motan.rpc.Response 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.rpc.Response in project motan by weibocom.
the class ClusterSpiTest method testCall.
public void testCall() {
initCluster(true);
final Request request = mockRequest();
final Response response = mockery.mock(Response.class);
final URL url = mockURL();
mockery.checking(new Expectations() {
{
for (Referer<IHello> 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();
}
}
});
clusterSpi.call(request);
clusterSpi.destroy();
try {
clusterSpi.call(request);
fail("Should not run to here!");
} catch (Exception e) {
assertTrue(e instanceof MotanServiceException);
}
}
use of com.weibo.api.motan.rpc.Response in project motan by weibocom.
the class ClusterTest method testCall.
@Test
public void testCall() {
final Request request = mockery.mock(Request.class);
final Response rs = mockery.mock(Response.class);
mockery.checking(new Expectations() {
{
allowing(any(Referer.class)).method("getUrl").withNoArguments();
will(returnValue(new URL(MotanConstants.PROTOCOL_MOTAN, NetUtils.getLocalAddress().getHostAddress(), 18080, Object.class.getName())));
allowing(any(Referer.class)).method("isAvailable").withNoArguments();
will(returnValue(true));
allowing(any(Referer.class)).method("call").with(same(request));
will(returnValue(rs));
atLeast(0).of(request).setRetries(0);
will(returnValue(null));
atLeast(0).of(request).getRetries();
will(returnValue(0));
atLeast(0).of(request).getMethodName();
will(returnValue("get"));
atLeast(0).of(request).getParamtersDesc();
will(returnValue("void"));
}
});
Response callRs = cluster.call(request);
Assert.assertEquals(rs, callRs);
}
use of com.weibo.api.motan.rpc.Response in project motan by weibocom.
the class AccessLogFilterTest method testCall.
@SuppressWarnings("unchecked")
public void testCall() {
final Request request = mockery.mock(Request.class);
final Response response = mockery.mock(Response.class);
final URL url = new URL(MotanConstants.PROTOCOL_MOTAN, NetUtils.getLocalAddress().getHostAddress(), 0, RegistryService.class.getName());
url.addParameter(URLParamType.accessLog.getName(), String.valueOf(true));
final Caller<IHello> caller = mockery.mock(Caller.class);
final Map<String, String> attachments = new HashMap<String, String>();
attachments.put(URLParamType.host.getName(), URLParamType.host.getValue());
attachments.put(URLParamType.application.getName(), URLParamType.application.getValue());
attachments.put(URLParamType.module.getName(), URLParamType.module.getValue());
mockery.checking(new Expectations() {
{
atLeast(1).of(caller).getUrl();
will(returnValue(url));
exactly(1).of(caller).call(request);
will(returnValue(response));
exactly(1).of(request).getInterfaceName();
will(returnValue(IHello.class.getName()));
exactly(1).of(request).getMethodName();
will(returnValue("get"));
exactly(1).of(request).getParamtersDesc();
will(returnValue("param_desc"));
exactly(1).of(request).getRequestId();
will(returnValue(100L));
atLeast(1).of(request).getAttachments();
will(returnValue(attachments));
}
});
accessLogFilter.filter(caller, request);
}
use of com.weibo.api.motan.rpc.Response in project motan by weibocom.
the class C method testCall.
@Test
public void testCall() {
ProviderMessageRouter providerMessageRouter = new ProviderMessageRouter();
Provider<ProviderA> providerA = new DefaultProvider<ProviderA>(new A(), new URL("injvm", "localhost", 0, ProviderA.class.getName()), ProviderA.class);
Provider<ProviderB> providerB = new DefaultProvider<ProviderB>(new B(), new URL("injvm", "localhost", 0, ProviderB.class.getName()), ProviderB.class);
providerMessageRouter.addProvider(providerA);
providerMessageRouter.addProvider(providerB);
Assert.assertEquals(providerMessageRouter.getPublicMethodCount(), PUBLIC_METHOD_COUNT_ALL);
DefaultRequest requestA = new DefaultRequest();
requestA.setInterfaceName(com.weibo.api.motan.transport.ProviderA.class.getName());
requestA.setMethodName("providerA");
requestA.setParamtersDesc(ReflectUtil.EMPTY_PARAM);
Response response = (Response) providerMessageRouter.handle(new MockChannel(TestConstants.EMPTY_URL), requestA);
Assert.assertEquals("A", response.getValue());
DefaultRequest requestB = new DefaultRequest();
requestB.setInterfaceName(com.weibo.api.motan.transport.ProviderB.class.getName());
requestB.setMethodName("providerB");
requestB.setParamtersDesc(ReflectUtil.EMPTY_PARAM);
response = (Response) providerMessageRouter.handle(new MockChannel(TestConstants.EMPTY_URL), requestB);
Assert.assertEquals("B", response.getValue());
providerMessageRouter.removeProvider(providerA);
Assert.assertEquals(providerMessageRouter.getPublicMethodCount(), PUBLIC_METHOD_COUNT_B);
try {
Response result = (Response) providerMessageRouter.handle(new MockChannel(TestConstants.EMPTY_URL), requestA);
result.getValue();
Assert.assertTrue(false);
} catch (Exception e) {
Assert.assertTrue(true);
}
}
Aggregations