Search in sources :

Example 11 with Response

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

the class ClusterTest method testCall.

@Test
public void testCall() {
    final Request request = mockery.mock(Request.class);
    final Response rs = mockery.mock(Response.class);
    mockery.checking(new Expectations() {

        {
            allowing(any(Referer.class)).method("getUrl").withNoArguments();
            will(returnValue(new URL(MotanConstants.PROTOCOL_MOTAN, NetUtils.getLocalAddress().getHostAddress(), 18080, Object.class.getName())));
            allowing(any(Referer.class)).method("isAvailable").withNoArguments();
            will(returnValue(true));
            allowing(any(Referer.class)).method("call").with(same(request));
            will(returnValue(rs));
            atLeast(0).of(request).setRetries(0);
            will(returnValue(null));
            atLeast(0).of(request).getRetries();
            will(returnValue(0));
            atLeast(0).of(request).getMethodName();
            will(returnValue("get"));
            atLeast(0).of(request).getParamtersDesc();
            will(returnValue("void"));
        }
    });
    Response callRs = cluster.call(request);
    Assert.assertEquals(rs, callRs);
}
Also used : Response(com.weibo.api.motan.rpc.Response) Expectations(org.jmock.Expectations) Request(com.weibo.api.motan.rpc.Request) URL(com.weibo.api.motan.rpc.URL) Test(org.junit.Test)

Example 12 with Response

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

the class AccessLogFilterTest method testCall.

@SuppressWarnings("unchecked")
public void testCall() {
    final Request request = mockery.mock(Request.class);
    final Response response = mockery.mock(Response.class);
    final URL url = new URL(MotanConstants.PROTOCOL_MOTAN, NetUtils.getLocalAddress().getHostAddress(), 0, RegistryService.class.getName());
    url.addParameter(URLParamType.accessLog.getName(), String.valueOf(true));
    final Caller<IHello> caller = mockery.mock(Caller.class);
    final Map<String, String> attachments = new HashMap<String, String>();
    attachments.put(URLParamType.host.getName(), URLParamType.host.getValue());
    attachments.put(URLParamType.application.getName(), URLParamType.application.getValue());
    attachments.put(URLParamType.module.getName(), URLParamType.module.getValue());
    mockery.checking(new Expectations() {

        {
            atLeast(1).of(caller).getUrl();
            will(returnValue(url));
            exactly(1).of(caller).call(request);
            will(returnValue(response));
            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"));
            exactly(1).of(request).getRequestId();
            will(returnValue(100L));
            atLeast(1).of(request).getAttachments();
            will(returnValue(attachments));
        }
    });
    accessLogFilter.filter(caller, request);
}
Also used : Response(com.weibo.api.motan.rpc.Response) Expectations(org.jmock.Expectations) HashMap(java.util.HashMap) Request(com.weibo.api.motan.rpc.Request) RegistryService(com.weibo.api.motan.registry.RegistryService) URL(com.weibo.api.motan.rpc.URL) IHello(com.weibo.api.motan.protocol.example.IHello)

Example 13 with Response

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

the class C method testCall.

@Test
public void testCall() {
    ProviderMessageRouter providerMessageRouter = new ProviderMessageRouter();
    Provider<ProviderA> providerA = new DefaultProvider<ProviderA>(new A(), new URL("injvm", "localhost", 0, ProviderA.class.getName()), ProviderA.class);
    Provider<ProviderB> providerB = new DefaultProvider<ProviderB>(new B(), new URL("injvm", "localhost", 0, ProviderB.class.getName()), ProviderB.class);
    providerMessageRouter.addProvider(providerA);
    providerMessageRouter.addProvider(providerB);
    Assert.assertEquals(providerMessageRouter.getPublicMethodCount(), PUBLIC_METHOD_COUNT_ALL);
    DefaultRequest requestA = new DefaultRequest();
    requestA.setInterfaceName(com.weibo.api.motan.transport.ProviderA.class.getName());
    requestA.setMethodName("providerA");
    requestA.setParamtersDesc(ReflectUtil.EMPTY_PARAM);
    Response response = (Response) providerMessageRouter.handle(new MockChannel(TestConstants.EMPTY_URL), requestA);
    Assert.assertEquals("A", response.getValue());
    DefaultRequest requestB = new DefaultRequest();
    requestB.setInterfaceName(com.weibo.api.motan.transport.ProviderB.class.getName());
    requestB.setMethodName("providerB");
    requestB.setParamtersDesc(ReflectUtil.EMPTY_PARAM);
    response = (Response) providerMessageRouter.handle(new MockChannel(TestConstants.EMPTY_URL), requestB);
    Assert.assertEquals("B", response.getValue());
    providerMessageRouter.removeProvider(providerA);
    Assert.assertEquals(providerMessageRouter.getPublicMethodCount(), PUBLIC_METHOD_COUNT_B);
    try {
        Response result = (Response) providerMessageRouter.handle(new MockChannel(TestConstants.EMPTY_URL), requestA);
        result.getValue();
        Assert.assertTrue(false);
    } catch (Exception e) {
        Assert.assertTrue(true);
    }
}
Also used : MockChannel(com.weibo.api.motan.mock.MockChannel) DefaultRequest(com.weibo.api.motan.rpc.DefaultRequest) URL(com.weibo.api.motan.rpc.URL) Response(com.weibo.api.motan.rpc.Response) DefaultProvider(com.weibo.api.motan.rpc.DefaultProvider) Test(org.junit.Test)

Example 14 with Response

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

the class OpenTracingFilterTest method testRefererFilter.

@Test
public void testRefererFilter() {
    Response res = OTFilter.filter(refer, request);
    assertEquals(response, res);
    checkMockTracer();
// brave test must run with jdk1.8 
//        tracer = new BraveTracer();// use bravetracer
//        res = OTFilter.filter(refer, request);
//        assertEquals(response, res);
//        checkBraveTrace();
}
Also used : DefaultResponse(com.weibo.api.motan.rpc.DefaultResponse) Response(com.weibo.api.motan.rpc.Response) Test(org.junit.Test)

Example 15 with Response

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

the class YarMessageRouter method handle.

@Override
public Object handle(Channel channel, Object message) {
    YarRequest yarRequest = (YarRequest) message;
    String packagerName = yarRequest.getPackagerName();
    Provider<?> provider = providerMap.get(yarRequest.getRequestPath());
    if (provider == null) {
        throw new MotanServiceException("can not find service provider. request path:" + yarRequest.getRequestPath());
    }
    Class<?> clazz = provider.getInterface();
    Request request = YarProtocolUtil.convert(yarRequest, clazz);
    Response response = call(request, provider);
    YarResponse yarResponse = YarProtocolUtil.convert(response, packagerName);
    return yarResponse;
}
Also used : Response(com.weibo.api.motan.rpc.Response) YarResponse(com.weibo.yar.YarResponse) YarRequest(com.weibo.yar.YarRequest) YarRequest(com.weibo.yar.YarRequest) Request(com.weibo.api.motan.rpc.Request) YarResponse(com.weibo.yar.YarResponse) MotanServiceException(com.weibo.api.motan.exception.MotanServiceException)

Aggregations

Response (com.weibo.api.motan.rpc.Response)31 URL (com.weibo.api.motan.rpc.URL)13 MotanServiceException (com.weibo.api.motan.exception.MotanServiceException)11 DefaultResponse (com.weibo.api.motan.rpc.DefaultResponse)11 Request (com.weibo.api.motan.rpc.Request)11 Expectations (org.jmock.Expectations)10 Test (org.junit.Test)9 DefaultRequest (com.weibo.api.motan.rpc.DefaultRequest)7 IHello (com.weibo.api.motan.protocol.example.IHello)6 MotanFrameworkException (com.weibo.api.motan.exception.MotanFrameworkException)4 IWorld (com.weibo.api.motan.protocol.example.IWorld)4 Referer (com.weibo.api.motan.rpc.Referer)4 RegistryService (com.weibo.api.motan.registry.RegistryService)3 HashMap (java.util.HashMap)3 MotanBizException (com.weibo.api.motan.exception.MotanBizException)2 AccessLogFilter (com.weibo.api.motan.filter.AccessLogFilter)2 Filter (com.weibo.api.motan.filter.Filter)2 Channel (com.weibo.api.motan.transport.Channel)2 YarResponse (com.weibo.yar.YarResponse)2 MockTracer (io.opentracing.mock.MockTracer)2