use of com.weibo.api.motan.rpc.Request 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.Request 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.Request in project motan by weibocom.
the class AccessLogFilterTest method testSwitcher.
public void testSwitcher() {
final Request request = mockery.mock(Request.class);
final Caller<IHello> caller = mockery.mock(Caller.class);
URL url = new URL(MotanConstants.PROTOCOL_MOTAN, NetUtils.getLocalAddress().getHostAddress(), 0, RegistryService.class.getName());
url.addParameter(URLParamType.accessLog.getName(), String.valueOf(false));
final Map<String, String> attachments = new HashMap<>();
attachments.put(URLParamType.host.getName(), URLParamType.host.getValue());
attachments.put(URLParamType.application.getName(), URLParamType.application.getValue());
attachments.put(URLParamType.module.getName(), URLParamType.module.getValue());
final LogService logService = mockery.mock(LogService.class);
LoggerUtil.setLogService(logService);
mockery.checking(new Expectations() {
{
atLeast(1).of(caller).getUrl();
will(returnValue(url));
atLeast(1).of(caller).call(request);
}
});
accessLogFilter.filter(caller, request);
mockery.assertIsSatisfied();
MotanSwitcherUtil.setSwitcherValue(AccessLogFilter.ACCESS_LOG_SWITCHER_NAME, true);
mockery.checking(new Expectations() {
{
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"));
atLeast(1).of(request).getAttachments();
will(returnValue(attachments));
exactly(1).of(logService).accessLog(with(any(String.class)));
allowing(request).getRequestId();
}
});
accessLogFilter.filter(caller, request);
mockery.assertIsSatisfied();
MotanSwitcherUtil.setSwitcherValue(AccessLogFilter.ACCESS_LOG_SWITCHER_NAME, false);
accessLogFilter.filter(caller, request);
mockery.assertIsSatisfied();
LoggerUtil.setLogService(new DefaultLogService());
}
use of com.weibo.api.motan.rpc.Request in project motan by weibocom.
the class DefaultRpcCodecTest method testCodecRequest.
@Test
public void testCodecRequest(Request request) throws Exception {
byte[] bytes = rpcCodec.encode(channel, request);
Request result = (Request) rpcCodec.decode(channel, "", bytes);
Assert.assertTrue(equals(request, result));
}
use of com.weibo.api.motan.rpc.Request in project motan by weibocom.
the class YarProtocolUtilTest method testConvertYarRequest.
@Test
public void testConvertYarRequest() throws NoSuchMethodException, SecurityException {
DefaultRequest request = new DefaultRequest();
request.setRequestId(123);
request.setMethodName("hello");
request.setArguments(new Object[] { "param1" });
request.setInterfaceName(YarMessageRouterTest.AnnoService.class.getName());
request.setParamtersDesc(ReflectUtil.getMethodParamDesc(YarMessageRouterTest.AnnoService.class.getMethod("hello", String.class)));
YarRequest yarRequest = YarProtocolUtil.convert(request, "JSON");
assertNotNull(yarRequest);
Request newRequest = YarProtocolUtil.convert(yarRequest, YarMessageRouterTest.AnnoService.class);
assertNotNull(newRequest);
assertEquals(request.toString(), newRequest.toString());
}
Aggregations