use of com.alipay.sofa.rpc.codec.msgpack.model.DemoRequest in project sofa-rpc by sofastack.
the class MsgPackSerializerTest method encodeAndDecode.
@Test
public void encodeAndDecode() {
boolean error = false;
try {
serializer.encode(null, null);
} catch (Exception e) {
error = true;
}
Assert.assertTrue(error);
DemoRequest demoRequest = new DemoRequest();
demoRequest.setName("a");
AbstractByteBuf byteBuf = serializer.encode(demoRequest, null);
DemoRequest req2 = (DemoRequest) serializer.decode(byteBuf, DemoRequest.class, null);
Assert.assertEquals(demoRequest.getName(), req2.getName());
AbstractByteBuf data = serializer.encode("xxx", null);
String dst = (String) serializer.decode(data, String.class, null);
Assert.assertEquals("xxx", dst);
error = false;
Date object = new Date();
try {
AbstractByteBuf encode = serializer.encode(object, null);
Assert.assertEquals(object, serializer.decode(encode, Date.class, null));
} catch (Exception e) {
error = true;
}
Assert.assertTrue(!error);
error = false;
try {
serializer.encode(1, null);
} catch (Exception e) {
error = true;
}
Assert.assertTrue(!error);
error = false;
try {
serializer.decode(data, null, null);
} catch (Exception e) {
error = true;
}
Assert.assertTrue(error);
error = false;
try {
serializer.decode(data, "", null);
} catch (Exception e) {
error = true;
}
Assert.assertTrue(error);
}
use of com.alipay.sofa.rpc.codec.msgpack.model.DemoRequest in project sofa-rpc by sofastack.
the class MsgPackSerializerTest method buildRequest.
private SofaRequest buildRequest() throws NoSuchMethodException {
SofaRequest request = new SofaRequest();
request.setInterfaceName(DemoService.class.getName());
request.setMethodName("say");
request.setMethod(DemoService.class.getMethod("say", DemoRequest.class));
final DemoRequest demoRequest = new DemoRequest();
demoRequest.setName("name");
request.setMethodArgs(new Object[] { demoRequest });
request.setMethodArgSigs(new String[] { DemoRequest.class.getCanonicalName() });
request.setTargetServiceUniqueName(DemoService.class.getName() + ":1.0");
request.setTargetAppName("targetApp");
request.setSerializeType((byte) 11);
request.setTimeout(1024);
request.setInvokeType(RpcConstants.INVOKER_TYPE_SYNC);
Map<String, String> map = new HashMap<String, String>();
map.put("a", "xxx");
map.put("b", "yyy");
request.addRequestProp(RemotingConstants.RPC_TRACE_NAME, map);
request.setSofaResponseCallback(new SofaResponseCallback() {
@Override
public void onAppResponse(Object appResponse, String methodName, RequestBase request) {
}
@Override
public void onAppException(Throwable throwable, String methodName, RequestBase request) {
}
@Override
public void onSofaException(SofaRpcException sofaException, String methodName, RequestBase request) {
}
});
return request;
}
Aggregations