use of com.weibo.api.motan.rpc.Request 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.rpc.Request in project motan by weibocom.
the class ActiveLimitFilterTest method testFilter.
@SuppressWarnings("unchecked")
public void testFilter() {
final Request request = mockery.mock(Request.class);
final Response response = mockery.mock(Response.class);
final Caller<IHello> caller = mockery.mock(Caller.class);
Map<String, String> parameters = new HashMap<String, String>();
parameters.put(URLParamType.actives.getName(), "" + 3);
final URL url = new URL(MotanConstants.PROTOCOL_MOTAN, NetUtils.getLocalAddress().getHostAddress(), 0, RegistryService.class.getName(), parameters);
mockery.checking(new Expectations() {
{
oneOf(caller).call(request);
will(returnValue(response));
atLeast(1).of(caller).getUrl();
will(returnValue(url));
atLeast(1).of(request).getMethodName();
will(returnValue("mock_mothod_name"));
atLeast(1).of(request).getParamtersDesc();
will(returnValue("mock_param_desc"));
}
});
activeLimitFilter.filter(caller, request);
for (int i = 0; i < 4; i++) {
RpcStats.beforeCall(url, request);
}
try {
activeLimitFilter.filter(caller, request);
assertFalse(true);
} catch (MotanServiceException e) {
assertEquals(MotanErrorMsgConstant.SERVICE_REJECT, e.getMotanErrorMsg());
} catch (Exception e) {
assertFalse(true);
}
}
use of com.weibo.api.motan.rpc.Request in project motan by weibocom.
the class RandomLoadBalanceTest method testSelect.
public void testSelect() {
final Request request = mockery.mock(Request.class);
mockery.checking(new Expectations() {
{
atLeast(1).of(request).getArguments();
will(returnValue(new Object[] { 1, 2, 3 }));
atLeast(0).of(request).getParamtersDesc();
will(returnValue("void_"));
}
});
for (int i = 0; i < 10; i++) {
Referer<IHello> ref = randomLoadBalance.select(request);
for (int j = 0; j < falseCount; j++) {
assertNotSame(ref, referers.get(j));
}
}
}
use of com.weibo.api.motan.rpc.Request in project motan by weibocom.
the class AccessStatisticFilterTest method testFilter.
@SuppressWarnings("unchecked")
public void testFilter() {
final Request request = mockery.mock(Request.class);
final Response response = mockery.mock(Response.class);
final Caller<IHello> caller = mockery.mock(Caller.class);
final URL url = new URL(MotanConstants.PROTOCOL_MOTAN, NetUtils.getLocalAddress().getHostAddress(), 0, RegistryService.class.getName());
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());
// TODO 优化重复代码
mockery.checking(new Expectations() {
{
oneOf(caller).call(request);
will(returnValue(response));
atLeast(2).of(caller).getUrl();
will(returnValue(url));
oneOf(response).getException();
will(returnValue(null));
oneOf(response).getProcessTime();
will(returnValue(1000L));
allowing(request).getInterfaceName();
will(returnValue(IHello.class.getName()));
allowing(request).getParamtersDesc();
will(returnValue("mock_param_desc"));
allowing(request).getMethodName();
will(returnValue("mock_method_name"));
atLeast(1).of(request).getAttachments();
will(returnValue(attachments));
}
});
assertEquals(response, accessStatisticFilter.filter(caller, request));
mockery.checking(new Expectations() {
{
oneOf(caller).call(request);
will(returnValue(null));
oneOf(caller).getUrl();
will(returnValue(url));
allowing(request).getInterfaceName();
will(returnValue(IHello.class.getName()));
allowing(request).getParamtersDesc();
will(returnValue("mock_param_desc"));
allowing(request).getMethodName();
will(returnValue("mock_method_name"));
}
});
assertNull(accessStatisticFilter.filter(caller, request));
mockery.checking(new Expectations() {
{
oneOf(caller).call(request);
will(returnValue(response));
oneOf(caller).getUrl();
will(returnValue(url));
atMost(2).of(response).getException();
will(returnValue(new MotanBizException()));
oneOf(response).getProcessTime();
will(returnValue(1000L));
allowing(request).getInterfaceName();
will(returnValue(IHello.class.getName()));
allowing(request).getParamtersDesc();
will(returnValue("mock_param_desc"));
allowing(request).getMethodName();
will(returnValue("mock_method_name"));
}
});
assertEquals(response, accessStatisticFilter.filter(caller, request));
mockery.checking(new Expectations() {
{
oneOf(caller).call(request);
will(returnValue(response));
oneOf(caller).getUrl();
will(returnValue(url));
atMost(2).of(response).getException();
will(returnValue(new MotanServiceException()));
oneOf(response).getProcessTime();
will(returnValue(1000L));
allowing(request).getInterfaceName();
will(returnValue(IHello.class.getName()));
allowing(request).getParamtersDesc();
will(returnValue("mock_param_desc"));
allowing(request).getMethodName();
will(returnValue("mock_method_name"));
}
});
assertEquals(response, accessStatisticFilter.filter(caller, request));
}
use of com.weibo.api.motan.rpc.Request in project motan by weibocom.
the class OpenTracingFilterTest method setUp.
@Before
public void setUp() throws Exception {
OTFilter = new OpenTracingFilter();
tracer = new MockTracer();
OpenTracingContext.tracerFactory = new TracerFactory() {
@Override
public Tracer getTracer() {
return tracer;
}
};
URL url = new URL("motan", "localhost", 8002, "HelloService");
request = new DefaultRequest();
request.setInterfaceName("HelloService");
request.setAttachment(URLParamType.group.name(), "test");
request.setMethodName("sayHello");
request.setParamtersDesc("java.lang.String");
response = new DefaultResponse();
refer = new AbstractReferer<HelloService>(HelloService.class, url) {
@Override
public void destroy() {
}
@Override
public boolean isAvailable() {
return true;
}
@Override
protected Response doCall(Request request) {
return response;
}
@Override
protected boolean doInit() {
return true;
}
};
provider = new DefaultProvider<HelloService>(new HelloServiceImpl(), url, HelloService.class) {
@Override
public Response call(Request request) {
return response;
}
};
}
Aggregations