Search in sources :

Example 11 with DefaultResponse

use of com.weibo.api.motan.rpc.DefaultResponse in project motan by weibocom.

the class DefaultRpcCodecTest method exceptionResponseSize.

/**
     * 不带参数的Request大小
     */
private static byte[] exceptionResponseSize(DefaultRpcCodec codec, Channel channel) throws Exception {
    DefaultResponse response = new DefaultResponse();
    response.setRequestId(System.currentTimeMillis());
    response.setProcessTime(System.currentTimeMillis());
    response.setException(new MotanBizException(new RuntimeException("hi, boy, i am biz exception.")));
    byte[] bytes = codec.encode(channel, response);
    return bytes;
}
Also used : DefaultResponse(com.weibo.api.motan.rpc.DefaultResponse) MotanBizException(com.weibo.api.motan.exception.MotanBizException)

Example 12 with DefaultResponse

use of com.weibo.api.motan.rpc.DefaultResponse in project motan by weibocom.

the class YarProtocolUtil method convert.

public static Response convert(YarResponse yarResponse) {
    DefaultResponse response = new DefaultResponse();
    response.setRequestId(yarResponse.getId());
    response.setValue(yarResponse.getRet());
    if (StringUtils.isNotBlank(yarResponse.getError())) {
        response.setException(new MotanBizException(yarResponse.getError()));
    }
    return response;
}
Also used : DefaultResponse(com.weibo.api.motan.rpc.DefaultResponse) MotanBizException(com.weibo.api.motan.exception.MotanBizException)

Example 13 with DefaultResponse

use of com.weibo.api.motan.rpc.DefaultResponse in project motan by weibocom.

the class YarMessageRouterTest method testHandle.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testHandle() {
    response = new DefaultResponse();
    response.setValue("test");
    response.setProcessTime(1);
    Provider provider = new DefaultProvider(null, null, AnnoService.class);
    router.addProvider(provider);
    YarRequest yarRequest = new YarRequest(1, "JSON", "hello", new Object[] { "params" });
    yarRequest.setRequestPath(requestPath);
    YarResponse yarResponse = (YarResponse) router.handle(null, yarRequest);
    assertEquals(YarProtocolUtil.convert(response, "JSON"), yarResponse);
}
Also used : DefaultResponse(com.weibo.api.motan.rpc.DefaultResponse) YarRequest(com.weibo.yar.YarRequest) YarResponse(com.weibo.yar.YarResponse) DefaultProvider(com.weibo.api.motan.rpc.DefaultProvider) DefaultProvider(com.weibo.api.motan.rpc.DefaultProvider) Provider(com.weibo.api.motan.rpc.Provider) Test(org.junit.Test)

Example 14 with DefaultResponse

use of com.weibo.api.motan.rpc.DefaultResponse in project motan by weibocom.

the class DefaultRpcCodecTest method testOriginalTypeResponse.

@Test
public void testOriginalTypeResponse() throws Exception {
    DefaultResponse response = new DefaultResponse();
    response.setValue(1);
    testCodecResponse(response);
}
Also used : DefaultResponse(com.weibo.api.motan.rpc.DefaultResponse) Test(org.junit.Test)

Example 15 with DefaultResponse

use of com.weibo.api.motan.rpc.DefaultResponse 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)

Aggregations

DefaultResponse (com.weibo.api.motan.rpc.DefaultResponse)28 Test (org.junit.Test)12 DefaultRequest (com.weibo.api.motan.rpc.DefaultRequest)7 Request (com.weibo.api.motan.rpc.Request)7 MotanServiceException (com.weibo.api.motan.exception.MotanServiceException)5 MotanFrameworkException (com.weibo.api.motan.exception.MotanFrameworkException)4 Response (com.weibo.api.motan.rpc.Response)4 Channel (com.weibo.api.motan.transport.Channel)4 MessageHandler (com.weibo.api.motan.transport.MessageHandler)4 MotanBizException (com.weibo.api.motan.exception.MotanBizException)3 URL (com.weibo.api.motan.rpc.URL)2 YarResponse (com.weibo.yar.YarResponse)2 ObjectInput (java.io.ObjectInput)2 Model (com.weibo.api.motan.protocol.example.Model)1 DefaultProvider (com.weibo.api.motan.rpc.DefaultProvider)1 Future (com.weibo.api.motan.rpc.Future)1 FutureListener (com.weibo.api.motan.rpc.FutureListener)1 Provider (com.weibo.api.motan.rpc.Provider)1 YarRequest (com.weibo.yar.YarRequest)1 Tracer (io.opentracing.Tracer)1