Search in sources :

Example 21 with DefaultRequest

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());
}
Also used : DefaultRequest(com.weibo.api.motan.rpc.DefaultRequest) YarRequest(com.weibo.yar.YarRequest) YarRequest(com.weibo.yar.YarRequest) Request(com.weibo.api.motan.rpc.Request) DefaultRequest(com.weibo.api.motan.rpc.DefaultRequest) Test(org.junit.Test)

Example 22 with DefaultRequest

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;
}
Also used : DefaultRequest(com.weibo.api.motan.rpc.DefaultRequest) IHello(com.weibo.api.motan.protocol.example.IHello)

Example 23 with DefaultRequest

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());
}
Also used : DefaultResponse(com.weibo.api.motan.rpc.DefaultResponse) DefaultRequest(com.weibo.api.motan.rpc.DefaultRequest) Test(org.junit.Test)

Example 24 with DefaultRequest

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());
}
Also used : DefaultRequest(com.weibo.api.motan.rpc.DefaultRequest) Test(org.junit.Test)

Example 25 with DefaultRequest

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());
}
Also used : FutureListener(com.weibo.api.motan.rpc.FutureListener) DefaultResponse(com.weibo.api.motan.rpc.DefaultResponse) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DefaultRequest(com.weibo.api.motan.rpc.DefaultRequest) Future(com.weibo.api.motan.rpc.Future) Test(org.junit.Test)

Aggregations

DefaultRequest (com.weibo.api.motan.rpc.DefaultRequest)45 Test (org.junit.Test)26 DefaultResponse (com.weibo.api.motan.rpc.DefaultResponse)8 Request (com.weibo.api.motan.rpc.Request)7 Model (com.weibo.api.motan.protocol.example.Model)5 Response (com.weibo.api.motan.rpc.Response)5 MotanServiceException (com.weibo.api.motan.exception.MotanServiceException)4 Channel (com.weibo.api.motan.transport.Channel)4 MotanFrameworkException (com.weibo.api.motan.exception.MotanFrameworkException)3 IHello (com.weibo.api.motan.protocol.example.IHello)3 URL (com.weibo.api.motan.rpc.URL)3 MessageHandler (com.weibo.api.motan.transport.MessageHandler)3 HashMap (java.util.HashMap)3 MockChannel (com.weibo.api.motan.mock.MockChannel)2 MockReferer (com.weibo.api.motan.mock.MockReferer)2 Referer (com.weibo.api.motan.rpc.Referer)2 Listener (io.grpc.ServerCall.Listener)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Codec (com.weibo.api.motan.codec.Codec)1 Serialization (com.weibo.api.motan.codec.Serialization)1