use of com.weibo.api.motan.rpc.Response in project motan by weibocom.
the class OpenTracingFilter method process.
protected Response process(Caller<?> caller, Request request, Span span) {
Exception ex = null;
boolean exception = true;
try {
Response response = caller.call(request);
if (response.getException() != null) {
ex = response.getException();
} else {
exception = false;
}
return response;
} catch (RuntimeException e) {
ex = e;
throw e;
} finally {
try {
if (exception) {
span.log("request fail." + (ex == null ? "unknown exception" : ex.getMessage()));
} else {
span.log("request success.");
}
span.finish();
} catch (Exception e) {
LoggerUtil.error("opentracing span finish error!", e);
}
}
}
use of com.weibo.api.motan.rpc.Response 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;
}
};
}
use of com.weibo.api.motan.rpc.Response in project motan by weibocom.
the class OpenTracingFilterTest method testException.
@Test
public void testException() {
response.setException(new RuntimeException("in test"));
Response res = OTFilter.filter(refer, request);
assertEquals(response, res);
if (tracer instanceof MockTracer) {
MockSpan span = ((MockTracer) tracer).finishedSpans().get(0);
assertEquals(span.logEntries().size(), 1);
assertTrue("request fail.in test".equals(span.logEntries().get(0).fields().get("event")));
}
}
use of com.weibo.api.motan.rpc.Response in project motan by weibocom.
the class OpenTracingFilterTest method testProviderFilter.
@Test
public void testProviderFilter() {
Response res = OTFilter.filter(provider, request);
assertEquals(response, res);
checkMockTracer();
}
use of com.weibo.api.motan.rpc.Response in project motan by weibocom.
the class FailfastHaStrategyTest method testCall.
@Test
@SuppressWarnings("unchecked")
public void testCall() {
final LoadBalance<IWorld> loadBalance = mockery.mock(LoadBalance.class);
final Referer<IWorld> referer = mockery.mock(Referer.class);
final Request request = mockery.mock(Request.class);
final Response response = mockery.mock(Response.class);
mockery.checking(new Expectations() {
{
one(loadBalance).select(request);
will(returnValue(referer));
one(referer).call(request);
will(returnValue(response));
}
});
assertEquals(response, failfastHaStrategy.call(request, loadBalance));
}
Aggregations