Search in sources :

Example 16 with Response

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);
        }
    }
}
Also used : Response(com.weibo.api.motan.rpc.Response)

Example 17 with Response

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;
        }
    };
}
Also used : DefaultResponse(com.weibo.api.motan.rpc.DefaultResponse) DefaultRequest(com.weibo.api.motan.rpc.DefaultRequest) Tracer(io.opentracing.Tracer) MockTracer(io.opentracing.mock.MockTracer) Request(com.weibo.api.motan.rpc.Request) DefaultRequest(com.weibo.api.motan.rpc.DefaultRequest) MockTracer(io.opentracing.mock.MockTracer) URL(com.weibo.api.motan.rpc.URL) DefaultResponse(com.weibo.api.motan.rpc.DefaultResponse) Response(com.weibo.api.motan.rpc.Response) Before(org.junit.Before)

Example 18 with 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")));
    }
}
Also used : DefaultResponse(com.weibo.api.motan.rpc.DefaultResponse) Response(com.weibo.api.motan.rpc.Response) MockTracer(io.opentracing.mock.MockTracer) MockSpan(io.opentracing.mock.MockSpan) Test(org.junit.Test)

Example 19 with Response

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();
}
Also used : DefaultResponse(com.weibo.api.motan.rpc.DefaultResponse) Response(com.weibo.api.motan.rpc.Response) Test(org.junit.Test)

Example 20 with Response

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));
}
Also used : Response(com.weibo.api.motan.rpc.Response) Expectations(org.jmock.Expectations) IWorld(com.weibo.api.motan.protocol.example.IWorld) Request(com.weibo.api.motan.rpc.Request) Test(org.junit.Test)

Aggregations

Response (com.weibo.api.motan.rpc.Response)31 URL (com.weibo.api.motan.rpc.URL)13 MotanServiceException (com.weibo.api.motan.exception.MotanServiceException)11 DefaultResponse (com.weibo.api.motan.rpc.DefaultResponse)11 Request (com.weibo.api.motan.rpc.Request)11 Expectations (org.jmock.Expectations)10 Test (org.junit.Test)9 DefaultRequest (com.weibo.api.motan.rpc.DefaultRequest)7 IHello (com.weibo.api.motan.protocol.example.IHello)6 MotanFrameworkException (com.weibo.api.motan.exception.MotanFrameworkException)4 IWorld (com.weibo.api.motan.protocol.example.IWorld)4 Referer (com.weibo.api.motan.rpc.Referer)4 RegistryService (com.weibo.api.motan.registry.RegistryService)3 HashMap (java.util.HashMap)3 MotanBizException (com.weibo.api.motan.exception.MotanBizException)2 AccessLogFilter (com.weibo.api.motan.filter.AccessLogFilter)2 Filter (com.weibo.api.motan.filter.Filter)2 Channel (com.weibo.api.motan.transport.Channel)2 YarResponse (com.weibo.yar.YarResponse)2 MockTracer (io.opentracing.mock.MockTracer)2