Search in sources :

Example 21 with URL

use of com.alibaba.dubbo.common.URL in project dubbo by alibaba.

the class MockClusterInvokerTest method testMockInvokerInvoke_forcemock.

/**
	 * 测试mock策略是否正常-force-mork
	 */
@Test
public void testMockInvokerInvoke_forcemock() {
    URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName());
    url = url.addParameter(Constants.MOCK_KEY, "force:return null");
    Invoker<IHelloService> cluster = getClusterInvoker(url);
    URL mockUrl = URL.valueOf("mock://localhost/" + IHelloService.class.getName() + "?getSomething.mock=return aa&getSomething3xx.mock=return xx").addParameters(url.getParameters());
    Protocol protocol = new MockProtocol();
    Invoker<IHelloService> mInvoker1 = protocol.refer(IHelloService.class, mockUrl);
    invokers.add(mInvoker1);
    //方法配置了mock
    RpcInvocation invocation = new RpcInvocation();
    invocation.setMethodName("getSomething");
    Result ret = cluster.invoke(invocation);
    Assert.assertEquals("aa", ret.getValue());
    //如果没有配置mock,则直接返回null
    invocation = new RpcInvocation();
    invocation.setMethodName("getSomething2");
    ret = cluster.invoke(invocation);
    Assert.assertEquals(null, ret.getValue());
    //如果没有配置mock,则直接返回null
    invocation = new RpcInvocation();
    invocation.setMethodName("sayHello");
    ret = cluster.invoke(invocation);
    Assert.assertEquals(null, ret.getValue());
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) MockProtocol(com.alibaba.dubbo.rpc.support.MockProtocol) Protocol(com.alibaba.dubbo.rpc.Protocol) MockProtocol(com.alibaba.dubbo.rpc.support.MockProtocol) URL(com.alibaba.dubbo.common.URL) Result(com.alibaba.dubbo.rpc.Result) Test(org.junit.Test)

Example 22 with URL

use of com.alibaba.dubbo.common.URL in project dubbo by alibaba.

the class AbsentConfiguratorTest method testOverride_Host.

@Test
public void testOverride_Host() {
    AbsentConfigurator configurator = new AbsentConfigurator(URL.valueOf("override://10.20.153.10/com.foo.BarService?timeout=200"));
    URL url = configurator.configure(URL.valueOf("dubbo://10.20.153.10:20880/com.foo.BarService?application=foo"));
    Assert.assertEquals("200", url.getParameter("timeout"));
    url = configurator.configure(URL.valueOf("dubbo://10.20.153.10:20880/com.foo.BarService?application=foo&timeout=1000"));
    Assert.assertEquals("1000", url.getParameter("timeout"));
    url = configurator.configure(URL.valueOf("dubbo://10.20.153.11:20880/com.foo.BarService?application=bar"));
    Assert.assertNull(url.getParameter("timeout"));
    url = configurator.configure(URL.valueOf("dubbo://10.20.153.11:20880/com.foo.BarService?application=bar&timeout=1000"));
    Assert.assertEquals("1000", url.getParameter("timeout"));
}
Also used : URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 23 with URL

use of com.alibaba.dubbo.common.URL in project dubbo by alibaba.

the class OverrideConfiguratorTest method testOverride_Host.

@Test
public void testOverride_Host() {
    OverrideConfigurator configurator = new OverrideConfigurator(URL.valueOf("override://10.20.153.10/com.foo.BarService?timeout=200"));
    URL url = configurator.configure(URL.valueOf("dubbo://10.20.153.10:20880/com.foo.BarService?application=foo"));
    Assert.assertEquals("200", url.getParameter("timeout"));
    url = configurator.configure(URL.valueOf("dubbo://10.20.153.10:20880/com.foo.BarService?application=foo&timeout=1000"));
    Assert.assertEquals("200", url.getParameter("timeout"));
    url = configurator.configure(URL.valueOf("dubbo://10.20.153.11:20880/com.foo.BarService?application=bar"));
    Assert.assertNull(url.getParameter("timeout"));
    url = configurator.configure(URL.valueOf("dubbo://10.20.153.11:20880/com.foo.BarService?application=bar&timeout=1000"));
    Assert.assertEquals("1000", url.getParameter("timeout"));
}
Also used : URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 24 with URL

use of com.alibaba.dubbo.common.URL in project dubbo by alibaba.

the class FileRouterEngineTest method testRouteAvailable.

@Test
public void testRouteAvailable() {
    if (isScriptUnsupported)
        return;
    URL url = initUrl("availablerule.javascript");
    initInvocation("method1");
    initDic(url);
    initInvokers(url);
    MockClusterInvoker<FileRouterEngineTest> sinvoker = new MockClusterInvoker<FileRouterEngineTest>(dic, url);
    for (int i = 0; i < 100; i++) {
        sinvoker.invoke(invocation);
        Invoker<FileRouterEngineTest> invoker = sinvoker.getSelectedInvoker();
        Assert.assertEquals(invoker1, invoker);
    }
}
Also used : URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 25 with URL

use of com.alibaba.dubbo.common.URL 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)

Aggregations

URL (com.alibaba.dubbo.common.URL)283 Test (org.junit.Test)157 ArrayList (java.util.ArrayList)73 RpcInvocation (com.alibaba.dubbo.rpc.RpcInvocation)62 HashMap (java.util.HashMap)39 Result (com.alibaba.dubbo.rpc.Result)37 Map (java.util.Map)36 Invoker (com.alibaba.dubbo.rpc.Invoker)34 List (java.util.List)30 ConcurrentMap (java.util.concurrent.ConcurrentMap)29 RegistryDirectory (com.alibaba.dubbo.registry.integration.RegistryDirectory)28 Invocation (com.alibaba.dubbo.rpc.Invocation)28 RpcException (com.alibaba.dubbo.rpc.RpcException)22 NotifyListener (com.alibaba.dubbo.registry.NotifyListener)20 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)17 RpcResult (com.alibaba.dubbo.rpc.RpcResult)16 DemoService (com.alibaba.dubbo.rpc.support.DemoService)12 Set (java.util.Set)12 ConcurrentHashSet (com.alibaba.dubbo.common.utils.ConcurrentHashSet)11 Protocol (com.alibaba.dubbo.rpc.Protocol)10