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);
}
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);
}
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()));
}
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());
}
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;
}
Aggregations