use of com.weibo.api.motan.rpc.DefaultRequest in project motan by weibocom.
the class YarProtocolUtilTest method testConvertYarRequest.
@Test
public void testConvertYarRequest() throws NoSuchMethodException, SecurityException {
DefaultRequest request = new DefaultRequest();
request.setRequestId(123);
request.setMethodName("hello");
request.setArguments(new Object[] { "param1" });
request.setInterfaceName(YarMessageRouterTest.AnnoService.class.getName());
request.setParamtersDesc(ReflectUtil.getMethodParamDesc(YarMessageRouterTest.AnnoService.class.getMethod("hello", String.class)));
YarRequest yarRequest = YarProtocolUtil.convert(request, "JSON");
assertNotNull(yarRequest);
Request newRequest = YarProtocolUtil.convert(yarRequest, YarMessageRouterTest.AnnoService.class);
assertNotNull(newRequest);
assertEquals(request.toString(), newRequest.toString());
}
use of com.weibo.api.motan.rpc.DefaultRequest in project motan by weibocom.
the class ClusterSpiTest method mockRequest.
private Request mockRequest() {
final DefaultRequest request = new DefaultRequest();
request.setMethodName(IHello.class.getMethods()[0].getName());
request.setArguments(new Object[] {});
request.setInterfaceName(IHello.class.getSimpleName());
request.setParamtersDesc("void");
return request;
}
use of com.weibo.api.motan.rpc.DefaultRequest in project motan by weibocom.
the class NettyResponseFutureTest method testNormal.
@Test
public void testNormal() {
DefaultRequest request = new DefaultRequest();
DefaultResponse defaultResponse = new DefaultResponse();
defaultResponse.setValue("success");
NettyResponseFuture response = new NettyResponseFuture(request, 100, client);
response.onSuccess(defaultResponse);
Object result = response.getValue();
Assert.assertEquals(result, defaultResponse.getValue());
Assert.assertTrue(response.isDone());
}
use of com.weibo.api.motan.rpc.DefaultRequest in project motan by weibocom.
the class NettyResponseFutureTest method testTimeout.
@Test
public void testTimeout() {
DefaultRequest request = new DefaultRequest();
NettyResponseFuture response = new NettyResponseFuture(request, 10, client);
try {
response.getValue();
Assert.assertTrue(false);
} catch (Exception e) {
Assert.assertTrue(true);
}
Assert.assertTrue(response.isCancelled());
}
use of com.weibo.api.motan.rpc.DefaultRequest in project motan by weibocom.
the class NettyResponseFutureTest method testListener.
@Test
public void testListener() {
DefaultRequest request = new DefaultRequest();
NettyResponseFuture response = new NettyResponseFuture(request, 100, client);
final AtomicBoolean result = new AtomicBoolean(false);
response.addListener(new FutureListener() {
@Override
public void operationComplete(Future future) throws Exception {
if (future.isSuccess()) {
result.set(true);
} else {
result.set(false);
}
}
});
DefaultResponse defaultResponse = new DefaultResponse();
defaultResponse.setValue(new Object());
response.onSuccess(defaultResponse);
Assert.assertTrue(result.get());
response = new NettyResponseFuture(request, 100, client);
response.addListener(new FutureListener() {
@Override
public void operationComplete(Future future) throws Exception {
if (future.isSuccess()) {
result.set(true);
} else {
result.set(false);
}
}
});
response.cancel();
result.set(true);
response.addListener(new FutureListener() {
@Override
public void operationComplete(Future future) throws Exception {
if (future.isSuccess()) {
result.set(true);
} else {
result.set(false);
}
}
});
Assert.assertFalse(result.get());
}
Aggregations