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);
}
}
use of com.weibo.api.motan.rpc.Response in project motan by weibocom.
the class OpenTracingFilterTest method testRefererFilter.
@Test
public void testRefererFilter() {
Response res = OTFilter.filter(refer, request);
assertEquals(response, res);
checkMockTracer();
// brave test must run with jdk1.8
// tracer = new BraveTracer();// use bravetracer
// res = OTFilter.filter(refer, request);
// assertEquals(response, res);
// checkBraveTrace();
}
use of com.weibo.api.motan.rpc.Response in project motan by weibocom.
the class YarMessageRouter method handle.
@Override
public Object handle(Channel channel, Object message) {
YarRequest yarRequest = (YarRequest) message;
String packagerName = yarRequest.getPackagerName();
Provider<?> provider = providerMap.get(yarRequest.getRequestPath());
if (provider == null) {
throw new MotanServiceException("can not find service provider. request path:" + yarRequest.getRequestPath());
}
Class<?> clazz = provider.getInterface();
Request request = YarProtocolUtil.convert(yarRequest, clazz);
Response response = call(request, provider);
YarResponse yarResponse = YarProtocolUtil.convert(response, packagerName);
return yarResponse;
}
Aggregations