Search in sources :

Example 11 with Request

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

the class ConsistentHashLoadBalanceTest method testSelect2.

public void testSelect2() {
    final Request request = mockery.mock(Request.class);
    mockery.checking(new Expectations() {

        {
            int i = 0;
            for (Referer<IHello> ref : referers) {
                boolean rs = i++ % 2 == 1;
                atLeast(0).of(ref).isAvailable();
                will(returnValue(rs));
            }
            atLeast(1).of(request).getArguments();
            will(returnValue(new Object[] { 1, 2, 3 }));
            atLeast(0).of(request).getParamtersDesc();
            will(returnValue("void_"));
        }
    });
    Referer<IHello> ref1 = consistentHashLoadBalance.select(request);
    for (int i = 0; i < 100; i++) {
        Referer<IHello> ref2 = consistentHashLoadBalance.select(request);
        assertEquals(ref1, ref2);
    }
}
Also used : Expectations(org.jmock.Expectations) Request(com.weibo.api.motan.rpc.Request) Referer(com.weibo.api.motan.rpc.Referer) IHello(com.weibo.api.motan.protocol.example.IHello)

Example 12 with Request

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

the class ConsistentHashLoadBalanceTest method testSelect.

public void testSelect() {
    final Request request = mockery.mock(Request.class);
    mockery.checking(new Expectations() {

        {
            for (Referer<IHello> ref : referers) {
                atLeast(0).of(ref).isAvailable();
                will(returnValue(true));
            }
            atLeast(1).of(request).getArguments();
            will(returnValue(new Object[] { 1, 2, 3 }));
            atLeast(0).of(request).getParamtersDesc();
            will(returnValue("void_"));
        }
    });
    Referer<IHello> ref1 = consistentHashLoadBalance.select(request);
    for (int i = 0; i < 100; i++) {
        Referer<IHello> ref2 = consistentHashLoadBalance.select(request);
        assertEquals(ref1, ref2);
    }
}
Also used : Expectations(org.jmock.Expectations) Request(com.weibo.api.motan.rpc.Request) Referer(com.weibo.api.motan.rpc.Referer) IHello(com.weibo.api.motan.protocol.example.IHello)

Example 13 with Request

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

the class AccessLogFilterTest method testSwitcher.

public void testSwitcher() {
    final Request request = mockery.mock(Request.class);
    final Caller<IHello> caller = mockery.mock(Caller.class);
    URL url = new URL(MotanConstants.PROTOCOL_MOTAN, NetUtils.getLocalAddress().getHostAddress(), 0, RegistryService.class.getName());
    url.addParameter(URLParamType.accessLog.getName(), String.valueOf(false));
    final Map<String, String> attachments = new HashMap<>();
    attachments.put(URLParamType.host.getName(), URLParamType.host.getValue());
    attachments.put(URLParamType.application.getName(), URLParamType.application.getValue());
    attachments.put(URLParamType.module.getName(), URLParamType.module.getValue());
    final LogService logService = mockery.mock(LogService.class);
    LoggerUtil.setLogService(logService);
    mockery.checking(new Expectations() {

        {
            atLeast(1).of(caller).getUrl();
            will(returnValue(url));
            atLeast(1).of(caller).call(request);
        }
    });
    accessLogFilter.filter(caller, request);
    mockery.assertIsSatisfied();
    MotanSwitcherUtil.setSwitcherValue(AccessLogFilter.ACCESS_LOG_SWITCHER_NAME, true);
    mockery.checking(new Expectations() {

        {
            exactly(1).of(request).getInterfaceName();
            will(returnValue(IHello.class.getName()));
            exactly(1).of(request).getMethodName();
            will(returnValue("get"));
            exactly(1).of(request).getParamtersDesc();
            will(returnValue("param_desc"));
            atLeast(1).of(request).getAttachments();
            will(returnValue(attachments));
            exactly(1).of(logService).accessLog(with(any(String.class)));
            allowing(request).getRequestId();
        }
    });
    accessLogFilter.filter(caller, request);
    mockery.assertIsSatisfied();
    MotanSwitcherUtil.setSwitcherValue(AccessLogFilter.ACCESS_LOG_SWITCHER_NAME, false);
    accessLogFilter.filter(caller, request);
    mockery.assertIsSatisfied();
    LoggerUtil.setLogService(new DefaultLogService());
}
Also used : Expectations(org.jmock.Expectations) HashMap(java.util.HashMap) DefaultLogService(com.weibo.api.motan.log.DefaultLogService) Request(com.weibo.api.motan.rpc.Request) RegistryService(com.weibo.api.motan.registry.RegistryService) IHello(com.weibo.api.motan.protocol.example.IHello) URL(com.weibo.api.motan.rpc.URL) DefaultLogService(com.weibo.api.motan.log.DefaultLogService) LogService(com.weibo.api.motan.log.LogService)

Example 14 with Request

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

the class DefaultRpcCodecTest method testCodecRequest.

@Test
public void testCodecRequest(Request request) throws Exception {
    byte[] bytes = rpcCodec.encode(channel, request);
    Request result = (Request) rpcCodec.decode(channel, "", bytes);
    Assert.assertTrue(equals(request, result));
}
Also used : Request(com.weibo.api.motan.rpc.Request) DefaultRequest(com.weibo.api.motan.rpc.DefaultRequest) Test(org.junit.Test)

Example 15 with Request

use of com.weibo.api.motan.rpc.Request 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)

Aggregations

Request (com.weibo.api.motan.rpc.Request)31 DefaultRequest (com.weibo.api.motan.rpc.DefaultRequest)12 Expectations (org.jmock.Expectations)12 Response (com.weibo.api.motan.rpc.Response)10 IHello (com.weibo.api.motan.protocol.example.IHello)9 URL (com.weibo.api.motan.rpc.URL)9 Test (org.junit.Test)9 DefaultResponse (com.weibo.api.motan.rpc.DefaultResponse)7 MotanServiceException (com.weibo.api.motan.exception.MotanServiceException)6 Referer (com.weibo.api.motan.rpc.Referer)5 HashMap (java.util.HashMap)5 RegistryService (com.weibo.api.motan.registry.RegistryService)4 MotanFrameworkException (com.weibo.api.motan.exception.MotanFrameworkException)3 IWorld (com.weibo.api.motan.protocol.example.IWorld)3 Channel (com.weibo.api.motan.transport.Channel)3 MessageHandler (com.weibo.api.motan.transport.MessageHandler)3 YarRequest (com.weibo.yar.YarRequest)3 ArrayList (java.util.ArrayList)3 Serialization (com.weibo.api.motan.codec.Serialization)2 IOException (java.io.IOException)2