Search in sources :

Example 26 with URL

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

the class AbstractClusterInvokerTest method setUp.

@SuppressWarnings({ "unchecked" })
@Before
public void setUp() throws Exception {
    invocation.setMethodName("sayHello");
    invoker1 = EasyMock.createMock(Invoker.class);
    invoker2 = EasyMock.createMock(Invoker.class);
    invoker3 = EasyMock.createMock(Invoker.class);
    invoker4 = EasyMock.createMock(Invoker.class);
    invoker5 = EasyMock.createMock(Invoker.class);
    mockedInvoker1 = EasyMock.createMock(Invoker.class);
    URL turl = URL.valueOf("test://test:11/test");
    EasyMock.expect(invoker1.isAvailable()).andReturn(false).anyTimes();
    EasyMock.expect(invoker1.getInterface()).andReturn(IHelloService.class).anyTimes();
    EasyMock.expect(invoker1.getUrl()).andReturn(turl.addParameter("name", "invoker1")).anyTimes();
    EasyMock.expect(invoker2.isAvailable()).andReturn(true).anyTimes();
    EasyMock.expect(invoker2.getInterface()).andReturn(IHelloService.class).anyTimes();
    EasyMock.expect(invoker2.getUrl()).andReturn(turl.addParameter("name", "invoker2")).anyTimes();
    EasyMock.expect(invoker3.isAvailable()).andReturn(false).anyTimes();
    EasyMock.expect(invoker3.getInterface()).andReturn(IHelloService.class).anyTimes();
    EasyMock.expect(invoker3.getUrl()).andReturn(turl.addParameter("name", "invoker3")).anyTimes();
    EasyMock.expect(invoker4.isAvailable()).andReturn(true).anyTimes();
    EasyMock.expect(invoker4.getInterface()).andReturn(IHelloService.class).anyTimes();
    EasyMock.expect(invoker4.getUrl()).andReturn(turl.addParameter("name", "invoker4")).anyTimes();
    EasyMock.expect(invoker5.isAvailable()).andReturn(false).anyTimes();
    EasyMock.expect(invoker5.getInterface()).andReturn(IHelloService.class).anyTimes();
    EasyMock.expect(invoker5.getUrl()).andReturn(turl.addParameter("name", "invoker5")).anyTimes();
    EasyMock.expect(mockedInvoker1.isAvailable()).andReturn(false).anyTimes();
    EasyMock.expect(mockedInvoker1.getInterface()).andReturn(IHelloService.class).anyTimes();
    EasyMock.expect(mockedInvoker1.getUrl()).andReturn(turl.setProtocol("mock")).anyTimes();
    EasyMock.replay(invoker1, invoker2, invoker3, invoker4, invoker5, mockedInvoker1);
    invokers.add(invoker1);
    dic = new StaticDirectory<IHelloService>(url, invokers, null);
    cluster = new AbstractClusterInvoker(dic) {

        @Override
        protected Result doInvoke(Invocation invocation, List invokers, LoadBalance loadbalance) throws RpcException {
            return null;
        }
    };
    cluster_nocheck = new AbstractClusterInvoker(dic, url.addParameterIfAbsent(Constants.CLUSTER_AVAILABLE_CHECK_KEY, Boolean.FALSE.toString())) {

        @Override
        protected Result doInvoke(Invocation invocation, List invokers, LoadBalance loadbalance) throws RpcException {
            return null;
        }
    };
}
Also used : Invoker(com.alibaba.dubbo.rpc.Invoker) Invocation(com.alibaba.dubbo.rpc.Invocation) RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) RoundRobinLoadBalance(com.alibaba.dubbo.rpc.cluster.loadbalance.RoundRobinLoadBalance) LeastActiveLoadBalance(com.alibaba.dubbo.rpc.cluster.loadbalance.LeastActiveLoadBalance) RandomLoadBalance(com.alibaba.dubbo.rpc.cluster.loadbalance.RandomLoadBalance) LoadBalance(com.alibaba.dubbo.rpc.cluster.LoadBalance) RpcException(com.alibaba.dubbo.rpc.RpcException) ArrayList(java.util.ArrayList) List(java.util.List) URL(com.alibaba.dubbo.common.URL) Result(com.alibaba.dubbo.rpc.Result) Before(org.junit.Before)

Example 27 with URL

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

the class ClusterUtilsTest method testMergeUrl.

@Test
public void testMergeUrl() throws Exception {
    URL providerURL = URL.valueOf("dubbo://localhost:55555");
    providerURL = providerURL.setPath("path").setUsername("username").setPassword("password");
    providerURL = providerURL.addParameter(Constants.GROUP_KEY, "dubbo").addParameter(Constants.VERSION_KEY, "1.2.3").addParameter(Constants.DUBBO_VERSION_KEY, "2.3.7").addParameter(Constants.THREADPOOL_KEY, "fixed").addParameter(Constants.THREADS_KEY, Integer.MAX_VALUE).addParameter(Constants.THREAD_NAME_KEY, "test").addParameter(Constants.CORE_THREADS_KEY, Integer.MAX_VALUE).addParameter(Constants.QUEUES_KEY, Integer.MAX_VALUE).addParameter(Constants.ALIVE_KEY, Integer.MAX_VALUE).addParameter(Constants.DEFAULT_KEY_PREFIX + Constants.THREADS_KEY, Integer.MAX_VALUE).addParameter(Constants.DEFAULT_KEY_PREFIX + Constants.THREADPOOL_KEY, "fixed").addParameter(Constants.DEFAULT_KEY_PREFIX + Constants.CORE_THREADS_KEY, Integer.MAX_VALUE).addParameter(Constants.DEFAULT_KEY_PREFIX + Constants.QUEUES_KEY, Integer.MAX_VALUE).addParameter(Constants.DEFAULT_KEY_PREFIX + Constants.ALIVE_KEY, Integer.MAX_VALUE).addParameter(Constants.DEFAULT_KEY_PREFIX + Constants.THREAD_NAME_KEY, "test");
    URL consumerURL = URL.valueOf("dubbo://localhost:55555");
    consumerURL = consumerURL.addParameter(Constants.PID_KEY, "1234");
    consumerURL = consumerURL.addParameter(Constants.THREADPOOL_KEY, "foo");
    URL url = ClusterUtils.mergeUrl(providerURL, consumerURL.getParameters());
    Assert.assertFalse(url.hasParameter(Constants.THREADS_KEY));
    Assert.assertFalse(url.hasParameter(Constants.DEFAULT_KEY_PREFIX + Constants.THREADS_KEY));
    Assert.assertFalse(url.hasParameter(Constants.DEFAULT_KEY_PREFIX + Constants.THREADPOOL_KEY));
    Assert.assertFalse(url.hasParameter(Constants.CORE_THREADS_KEY));
    Assert.assertFalse(url.hasParameter(Constants.DEFAULT_KEY_PREFIX + Constants.CORE_THREADS_KEY));
    Assert.assertFalse(url.hasParameter(Constants.QUEUES_KEY));
    Assert.assertFalse(url.hasParameter(Constants.DEFAULT_KEY_PREFIX + Constants.QUEUES_KEY));
    Assert.assertFalse(url.hasParameter(Constants.ALIVE_KEY));
    Assert.assertFalse(url.hasParameter(Constants.DEFAULT_KEY_PREFIX + Constants.ALIVE_KEY));
    Assert.assertFalse(url.hasParameter(Constants.THREAD_NAME_KEY));
    Assert.assertFalse(url.hasParameter(Constants.DEFAULT_KEY_PREFIX + Constants.THREAD_NAME_KEY));
    Assert.assertEquals(url.getPath(), "path");
    Assert.assertEquals(url.getUsername(), "username");
    Assert.assertEquals(url.getPassword(), "password");
    Assert.assertEquals(url.getParameter(Constants.PID_KEY), "1234");
    Assert.assertEquals(url.getParameter(Constants.THREADPOOL_KEY), "foo");
}
Also used : URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 28 with URL

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

the class MockClusterInvokerTest method testMockInvokerFromOverride_Invoke_mock_false.

@Test
public void testMockInvokerFromOverride_Invoke_mock_false() {
    URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()).addParameter("mock", "false").addParameter("invoke_return_error", "true");
    Invoker<IHelloService> cluster = getClusterInvoker(url);
    //方法配置了mock
    RpcInvocation invocation = new RpcInvocation();
    invocation.setMethodName("getBoolean2");
    try {
        cluster.invoke(invocation);
        Assert.fail();
    } catch (RpcException e) {
        Assert.assertTrue(e.isTimeout());
    }
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) RpcException(com.alibaba.dubbo.rpc.RpcException) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 29 with URL

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

the class MockClusterInvokerTest method testMockInvokerFromOverride_Invoke_Fock_WithOutDefault.

/**
	 * 测试mock策略是否正常-fail-mock
	 */
@Test
public void testMockInvokerFromOverride_Invoke_Fock_WithOutDefault() {
    URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()).addParameter("getSomething.mock", "fail:return x").addParameter("getSomething2.mock", "force:return y").addParameter("invoke_return_error", "true");
    Invoker<IHelloService> cluster = getClusterInvoker(url);
    //方法配置了mock
    RpcInvocation invocation = new RpcInvocation();
    invocation.setMethodName("getSomething");
    Result ret = cluster.invoke(invocation);
    Assert.assertEquals("x", ret.getValue());
    //如果没有配置mock,则直接返回null
    invocation = new RpcInvocation();
    invocation.setMethodName("getSomething2");
    ret = cluster.invoke(invocation);
    Assert.assertEquals("y", ret.getValue());
    //如果没有配置mock,则直接返回null
    invocation = new RpcInvocation();
    invocation.setMethodName("getSomething3");
    try {
        ret = cluster.invoke(invocation);
        Assert.fail();
    } catch (RpcException e) {
    }
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) RpcException(com.alibaba.dubbo.rpc.RpcException) URL(com.alibaba.dubbo.common.URL) Result(com.alibaba.dubbo.rpc.Result) Test(org.junit.Test)

Example 30 with URL

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

the class MockClusterInvokerTest method testMockInvokerFromOverride_Invoke_force_throwCustemException.

@Test
public void testMockInvokerFromOverride_Invoke_force_throwCustemException() throws Throwable {
    URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()).addParameter("getBoolean2.mock", "force:throw com.alibaba.dubbo.rpc.cluster.support.wrapper.MyMockException").addParameter("invoke_return_error", "true");
    Invoker<IHelloService> cluster = getClusterInvoker(url);
    //方法配置了mock
    RpcInvocation invocation = new RpcInvocation();
    invocation.setMethodName("getBoolean2");
    try {
        cluster.invoke(invocation).recreate();
        Assert.fail();
    } catch (MyMockException e) {
    }
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) URL(com.alibaba.dubbo.common.URL) 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