Search in sources :

Example 16 with DefaultResponse

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

the class DefaultRpcCodecTest method testObjectResponse.

@Test
public void testObjectResponse() throws Exception {
    DefaultResponse response = new DefaultResponse();
    response.setValue(new Model("world", 12, Model.class));
    testCodecResponse(response);
}
Also used : DefaultResponse(com.weibo.api.motan.rpc.DefaultResponse) Model(com.weibo.api.motan.protocol.example.Model) Test(org.junit.Test)

Example 17 with DefaultResponse

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

the class DefaultRpcCodecTest method testStringResponse.

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

Example 18 with DefaultResponse

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

the class DefaultRpcCodecTest method testException.

@Test
public void testException() throws Exception {
    DefaultResponse response = new DefaultResponse();
    response.setException(new MotanServiceException("process thread pool is full, reject", MotanErrorMsgConstant.SERVICE_REJECT));
    byte[] bytes = rpcCodec.encode(channel, response);
    Response result = (Response) rpcCodec.decode(channel, "", bytes);
    Assert.assertTrue(result.getException().getMessage().equals(response.getException().getMessage()));
    Assert.assertTrue(result.getException().getClass().equals(response.getException().getClass()));
}
Also used : DefaultResponse(com.weibo.api.motan.rpc.DefaultResponse) DefaultResponse(com.weibo.api.motan.rpc.DefaultResponse) Response(com.weibo.api.motan.rpc.Response) MotanServiceException(com.weibo.api.motan.exception.MotanServiceException) Test(org.junit.Test)

Example 19 with DefaultResponse

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

the class YarProtocolUtilTest method testConvertYarResponse.

@Test
public void testConvertYarResponse() {
    DefaultResponse response = new DefaultResponse();
    response.setRequestId(456);
    response.setValue("stringValue");
    YarResponse yarResponse = YarProtocolUtil.convert(response, "JSON");
    assertNotNull(yarResponse);
    Response newResponse = YarProtocolUtil.convert(yarResponse);
    assertEquals(response.getRequestId(), newResponse.getRequestId());
    assertEquals(response.getValue(), newResponse.getValue());
    response.setException(new RuntimeException("test exception"));
    yarResponse = YarProtocolUtil.convert(response, "JSON");
    assertNotNull(yarResponse);
    newResponse = YarProtocolUtil.convert(yarResponse);
    assertEquals(response.getRequestId(), newResponse.getRequestId());
    // yarresponse的异常会转为motan业务异常
    assertEquals(new MotanBizException(response.getException().getMessage()).getMessage(), newResponse.getException().getMessage());
}
Also used : DefaultResponse(com.weibo.api.motan.rpc.DefaultResponse) YarResponse(com.weibo.yar.YarResponse) DefaultResponse(com.weibo.api.motan.rpc.DefaultResponse) Response(com.weibo.api.motan.rpc.Response) YarResponse(com.weibo.yar.YarResponse) MotanBizException(com.weibo.api.motan.exception.MotanBizException) Test(org.junit.Test)

Example 20 with DefaultResponse

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

the class NettyEncoder method buildExceptionResponse.

private Response buildExceptionResponse(long requestId, Exception e) {
    DefaultResponse response = new DefaultResponse();
    response.setRequestId(requestId);
    response.setException(e);
    return response;
}
Also used : DefaultResponse(com.weibo.api.motan.rpc.DefaultResponse)

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