Search in sources :

Example 6 with DefaultRequest

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

the class RefererInvocationHandler method invoke.

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    if (isLocalMethod(method)) {
        if ("toString".equals(method.getName())) {
            return clustersToString();
        }
        if ("equals".equals(method.getName())) {
            return proxyEquals(args[0]);
        }
        if ("hashCode".equals(method.getName())) {
            return this.clusters == null ? 0 : this.clusters.hashCode();
        }
        throw new MotanServiceException("can not invoke local method:" + method.getName());
    }
    DefaultRequest request = new DefaultRequest();
    request.setRequestId(RequestIdGenerator.getRequestId());
    request.setArguments(args);
    String methodName = method.getName();
    boolean async = false;
    if (methodName.endsWith(MotanConstants.ASYNC_SUFFIX) && method.getReturnType().equals(ResponseFuture.class)) {
        methodName = MotanFrameworkUtil.removeAsyncSuffix(methodName);
        async = true;
    }
    request.setMethodName(methodName);
    request.setParamtersDesc(ReflectUtil.getMethodParamDesc(method));
    request.setInterfaceName(interfaceName);
    return invokeRequest(request, getRealReturnType(async, this.clz, method, methodName), async);
}
Also used : DefaultRequest(com.weibo.api.motan.rpc.DefaultRequest) ResponseFuture(com.weibo.api.motan.rpc.ResponseFuture) MotanServiceException(com.weibo.api.motan.exception.MotanServiceException)

Example 7 with DefaultRequest

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

the class ConfigurableWeightLoadBalanceTest method testDoSelectToHolder.

@Test
public void testDoSelectToHolder() {
    generate(3, new int[] { 2, 3, 5 }, new int[] { 3, 4, 5 });
    List<Referer<IHello>> list = new ArrayList<Referer<IHello>>();
    balance.doSelectToHolder(new DefaultRequest(), list);
    assertTrue(list.size() > 0 && list.size() <= ConfigurableWeightLoadBalance.MAX_REFERER_COUNT);
}
Also used : DefaultRequest(com.weibo.api.motan.rpc.DefaultRequest) Referer(com.weibo.api.motan.rpc.Referer) MockReferer(com.weibo.api.motan.mock.MockReferer) ArrayList(java.util.ArrayList) IHello(com.weibo.api.motan.protocol.example.IHello) Test(org.junit.Test)

Example 8 with DefaultRequest

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

the class DefaultRpcCodecTest method testStringArrayRequest.

@Test
public void testStringArrayRequest() throws Exception {
    DefaultRequest request = getRequest("java.lang.String[]", new Object[] { new String[] { "hello", "world" } });
    testCodecRequest(request);
}
Also used : DefaultRequest(com.weibo.api.motan.rpc.DefaultRequest) Test(org.junit.Test)

Example 9 with DefaultRequest

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

the class DefaultRpcCodecTest method testObjectTypeRequest.

@Test
public void testObjectTypeRequest() throws Exception {
    DefaultRequest request = getRequest("com.weibo.api.motan.protocol.example.Model", new Object[] { new Model("world", 12, Model.class) });
    testCodecRequest(request);
}
Also used : DefaultRequest(com.weibo.api.motan.rpc.DefaultRequest) Model(com.weibo.api.motan.protocol.example.Model) Test(org.junit.Test)

Example 10 with DefaultRequest

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

the class DefaultRpcCodecTest method testOriginalTypeRequest.

@Test
public void testOriginalTypeRequest() throws Exception {
    DefaultRequest request = getRequest("java.lang.Integer", new Object[] { 1 });
    testCodecRequest(request);
}
Also used : DefaultRequest(com.weibo.api.motan.rpc.DefaultRequest) 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