Search in sources :

Example 1 with DemoService

use of com.alibaba.dubbo.rpc.cluster.filter.DemoService in project dubbo by alibaba.

the class AbstractClusterInvokerTest method testTimeoutExceptionCode.

@Test()
public void testTimeoutExceptionCode() {
    List<Invoker<DemoService>> invokers = new ArrayList<Invoker<DemoService>>();
    invokers.add(new Invoker<DemoService>() {

        public Class<DemoService> getInterface() {
            return DemoService.class;
        }

        public URL getUrl() {
            return URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/" + DemoService.class.getName());
        }

        public boolean isAvailable() {
            return false;
        }

        public Result invoke(Invocation invocation) throws RpcException {
            throw new RpcException(RpcException.TIMEOUT_EXCEPTION, "test timeout");
        }

        public void destroy() {
        }
    });
    Directory<DemoService> directory = new StaticDirectory<DemoService>(invokers);
    FailoverClusterInvoker<DemoService> failoverClusterInvoker = new FailoverClusterInvoker<DemoService>(directory);
    try {
        failoverClusterInvoker.invoke(new RpcInvocation("sayHello", new Class<?>[0], new Object[0]));
        Assert.fail();
    } catch (RpcException e) {
        Assert.assertEquals(RpcException.TIMEOUT_EXCEPTION, e.getCode());
    }
    ForkingClusterInvoker<DemoService> forkingClusterInvoker = new ForkingClusterInvoker<DemoService>(directory);
    try {
        forkingClusterInvoker.invoke(new RpcInvocation("sayHello", new Class<?>[0], new Object[0]));
        Assert.fail();
    } catch (RpcException e) {
        Assert.assertEquals(RpcException.TIMEOUT_EXCEPTION, e.getCode());
    }
    FailfastClusterInvoker<DemoService> failfastClusterInvoker = new FailfastClusterInvoker<DemoService>(directory);
    try {
        failfastClusterInvoker.invoke(new RpcInvocation("sayHello", new Class<?>[0], new Object[0]));
        Assert.fail();
    } catch (RpcException e) {
        Assert.assertEquals(RpcException.TIMEOUT_EXCEPTION, e.getCode());
    }
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) Invocation(com.alibaba.dubbo.rpc.Invocation) RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) ArrayList(java.util.ArrayList) DemoService(com.alibaba.dubbo.rpc.cluster.filter.DemoService) URL(com.alibaba.dubbo.common.URL) Result(com.alibaba.dubbo.rpc.Result) StaticDirectory(com.alibaba.dubbo.rpc.cluster.directory.StaticDirectory) Invoker(com.alibaba.dubbo.rpc.Invoker) RpcException(com.alibaba.dubbo.rpc.RpcException) BeforeClass(org.junit.BeforeClass) Test(org.junit.Test)

Example 2 with DemoService

use of com.alibaba.dubbo.rpc.cluster.filter.DemoService in project dubbo by alibaba.

the class FailSafeClusterInvokerTest method testInvokeNoExceptoin.

@Test()
public void testInvokeNoExceptoin() {
    resetInvokerToNoException();
    FailsafeClusterInvoker<DemoService> invoker = new FailsafeClusterInvoker<DemoService>(dic);
    Result ret = invoker.invoke(invocation);
    Assert.assertSame(result, ret);
}
Also used : DemoService(com.alibaba.dubbo.rpc.cluster.filter.DemoService) Result(com.alibaba.dubbo.rpc.Result) RpcResult(com.alibaba.dubbo.rpc.RpcResult) Test(org.junit.Test)

Aggregations

Result (com.alibaba.dubbo.rpc.Result)2 DemoService (com.alibaba.dubbo.rpc.cluster.filter.DemoService)2 Test (org.junit.Test)2 URL (com.alibaba.dubbo.common.URL)1 Invocation (com.alibaba.dubbo.rpc.Invocation)1 Invoker (com.alibaba.dubbo.rpc.Invoker)1 RpcException (com.alibaba.dubbo.rpc.RpcException)1 RpcInvocation (com.alibaba.dubbo.rpc.RpcInvocation)1 RpcResult (com.alibaba.dubbo.rpc.RpcResult)1 StaticDirectory (com.alibaba.dubbo.rpc.cluster.directory.StaticDirectory)1 ArrayList (java.util.ArrayList)1 BeforeClass (org.junit.BeforeClass)1