Search in sources :

Example 6 with IWorld

use of com.weibo.api.motan.protocol.example.IWorld in project motan by weibocom.

the class MockServiceConfig method mockIWorldServiceConfig.

protected static ServiceConfig<IWorld> mockIWorldServiceConfig() {
    ServiceConfig<IWorld> serviceConfig = new ServiceConfig<IWorld>();
    serviceConfig.setRef(new MockWorld());
    serviceConfig.setApplication(application);
    serviceConfig.setModule(module);
    serviceConfig.setCheck("true");
    serviceConfig.setInterface(IWorld.class);
    serviceConfig.setGroup(group);
    serviceConfig.setShareChannel(true);
    return serviceConfig;
}
Also used : ServiceConfig(com.weibo.api.motan.config.ServiceConfig) IWorld(com.weibo.api.motan.protocol.example.IWorld) MockWorld(com.weibo.api.motan.protocol.example.MockWorld)

Example 7 with IWorld

use of com.weibo.api.motan.protocol.example.IWorld in project motan by weibocom.

the class FailfastHaStrategyTest method testCallError.

@Test(expected = MotanServiceException.class)
@SuppressWarnings("unchecked")
public void testCallError() {
    final LoadBalance<IWorld> loadBalance = mockery.mock(LoadBalance.class);
    final Referer<IWorld> referer = mockery.mock(Referer.class);
    final Request request = mockery.mock(Request.class);
    mockery.checking(new Expectations() {

        {
            one(loadBalance).select(request);
            will(returnValue(referer));
            one(referer).call(request);
            will(returnValue(null));
        }
    });
    assertEquals(null, failfastHaStrategy.call(request, loadBalance));
}
Also used : Expectations(org.jmock.Expectations) IWorld(com.weibo.api.motan.protocol.example.IWorld) Request(com.weibo.api.motan.rpc.Request) Test(org.junit.Test)

Example 8 with IWorld

use of com.weibo.api.motan.protocol.example.IWorld in project motan by weibocom.

the class FailfastHaStrategyTest method testCall.

@Test
@SuppressWarnings("unchecked")
public void testCall() {
    final LoadBalance<IWorld> loadBalance = mockery.mock(LoadBalance.class);
    final Referer<IWorld> referer = mockery.mock(Referer.class);
    final Request request = mockery.mock(Request.class);
    final Response response = mockery.mock(Response.class);
    mockery.checking(new Expectations() {

        {
            one(loadBalance).select(request);
            will(returnValue(referer));
            one(referer).call(request);
            will(returnValue(response));
        }
    });
    assertEquals(response, failfastHaStrategy.call(request, loadBalance));
}
Also used : Response(com.weibo.api.motan.rpc.Response) Expectations(org.jmock.Expectations) IWorld(com.weibo.api.motan.protocol.example.IWorld) Request(com.weibo.api.motan.rpc.Request) Test(org.junit.Test)

Example 9 with IWorld

use of com.weibo.api.motan.protocol.example.IWorld in project motan by weibocom.

the class RefererConfigTest method testGetRef.

@Test
public void testGetRef() {
    MockWorld mWorld = new MockWorld();
    serviceConfig.setRef(mWorld);
    serviceConfig.export();
    IWorld ref = refererConfig.getRef();
    assertNotNull(ref);
    assertEquals(refererConfig.getClusterSupports().size(), 1);
    int times = 3;
    for (int i = 0; i < times; i++) {
        ref.world("test");
    }
    assertEquals(times, mWorld.stringCount.get());
    serviceConfig.unexport();
    // destroy
    refererConfig.destroy();
    assertFalse(refererConfig.getInitialized().get());
}
Also used : IWorld(com.weibo.api.motan.protocol.example.IWorld) MockWorld(com.weibo.api.motan.protocol.example.MockWorld) Test(org.junit.Test)

Example 10 with IWorld

use of com.weibo.api.motan.protocol.example.IWorld in project motan by weibocom.

the class FailoverHaStrategyTest method testCallWithOneError.

public void testCallWithOneError() {
    final DefaultRequest request = new DefaultRequest();
    request.setMethodName(IWorld.class.getMethods()[0].getName());
    request.setArguments(new Object[] {});
    request.setInterfaceName(IHello.class.getSimpleName());
    request.setParamtersDesc("void");
    final Response response = mockery.mock(Response.class);
    final URL url = URL.valueOf("motan%3A%2F%2F10.209.128.244%3A8000%2Fcom.weibo.api.motan.protocol.example.IWorld%3Fprotocol%3Dmotan%26export%3Dmotan%3A8000%26application%3Dapi%26module%3Dtest%26check%3Dtrue%26refreshTimestamp%3D1373275099717%26methodconfig.world%28void%29.retries%3D1%26id%3Dmotan%26methodconfig.world%28java.lang.String%29.retries%3D1%26methodconfig.world%28java.lang.String%2Cboolean%29.retries%3D1%26nodeType%3Dservice%26group%3Dwangzhe-test-yf%26shareChannel%3Dtrue%26&");
    mockery.checking(new Expectations() {

        {
            for (Referer<IWorld> ref : referers) {
                atLeast(0).of(ref).call(request);
                will(returnValue(response));
                atLeast(0).of(ref).isAvailable();
                will(returnValue(true));
                atLeast(0).of(ref).getUrl();
                will(returnValue(url));
                atLeast(1).of(ref).destroy();
            }
            one(referers.get(0)).call(request);
            will(throwException(new MotanServiceException("mock throw exception when call")));
            one(referers.get(1)).call(request);
            will(returnValue(response));
        }
    });
    failoverHaStrategy.call(request, loadBalance);
}
Also used : Response(com.weibo.api.motan.rpc.Response) Expectations(org.jmock.Expectations) DefaultRequest(com.weibo.api.motan.rpc.DefaultRequest) IWorld(com.weibo.api.motan.protocol.example.IWorld) Referer(com.weibo.api.motan.rpc.Referer) MotanServiceException(com.weibo.api.motan.exception.MotanServiceException) IHello(com.weibo.api.motan.protocol.example.IHello) URL(com.weibo.api.motan.rpc.URL)

Aggregations

IWorld (com.weibo.api.motan.protocol.example.IWorld)10 Expectations (org.jmock.Expectations)5 Test (org.junit.Test)5 DefaultRequest (com.weibo.api.motan.rpc.DefaultRequest)4 Referer (com.weibo.api.motan.rpc.Referer)4 Response (com.weibo.api.motan.rpc.Response)4 URL (com.weibo.api.motan.rpc.URL)4 IHello (com.weibo.api.motan.protocol.example.IHello)3 Request (com.weibo.api.motan.rpc.Request)3 MotanServiceException (com.weibo.api.motan.exception.MotanServiceException)2 MockWorld (com.weibo.api.motan.protocol.example.MockWorld)2 ArrayList (java.util.ArrayList)2 LoadBalance (com.weibo.api.motan.cluster.LoadBalance)1 ServiceConfig (com.weibo.api.motan.config.ServiceConfig)1 List (java.util.List)1 Before (org.junit.Before)1