Search in sources :

Example 51 with Invoker

use of com.alibaba.dubbo.rpc.Invoker in project dubbo by alibaba.

the class CompatibleFilterFilterTest method testInvokerJsonPojoSerialization.

@Test
public void testInvokerJsonPojoSerialization() {
    invocation = EasyMock.createMock(Invocation.class);
    EasyMock.expect(invocation.getMethodName()).andReturn("enumlength").anyTimes();
    EasyMock.expect(invocation.getParameterTypes()).andReturn(new Class<?>[] { Type[].class }).anyTimes();
    EasyMock.expect(invocation.getArguments()).andReturn(new Object[] { "hello" }).anyTimes();
    EasyMock.replay(invocation);
    invoker = EasyMock.createMock(Invoker.class);
    EasyMock.expect(invoker.isAvailable()).andReturn(true).anyTimes();
    EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class).anyTimes();
    RpcResult result = new RpcResult();
    result.setValue("High");
    EasyMock.expect(invoker.invoke(invocation)).andReturn(result).anyTimes();
    URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1&serialization=json");
    EasyMock.expect(invoker.getUrl()).andReturn(url).anyTimes();
    EasyMock.replay(invoker);
    Result filterResult = compatibleFilter.invoke(invoker, invocation);
    assertEquals(Type.High, filterResult.getValue());
}
Also used : Invocation(com.alibaba.dubbo.rpc.Invocation) Invoker(com.alibaba.dubbo.rpc.Invoker) RpcResult(com.alibaba.dubbo.rpc.RpcResult) DemoService(com.alibaba.dubbo.rpc.support.DemoService) URL(com.alibaba.dubbo.common.URL) Result(com.alibaba.dubbo.rpc.Result) RpcResult(com.alibaba.dubbo.rpc.RpcResult) Test(org.junit.Test)

Example 52 with Invoker

use of com.alibaba.dubbo.rpc.Invoker in project dubbo by alibaba.

the class RegistryDirectoryTest method testDestroy.

/**
 * When destroying, RegistryDirectory should: 1. be disconnected from Registry 2. destroy all invokers
 */
@Test
public void testDestroy() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    List<URL> serviceUrls = new ArrayList<URL>();
    serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1"));
    serviceUrls.add(SERVICEURL2.addParameter("methods", "getXXX1,getXXX2"));
    serviceUrls.add(SERVICEURL3.addParameter("methods", "getXXX1,getXXX2,getXXX3"));
    registryDirectory.notify(serviceUrls);
    List<Invoker> invokers = registryDirectory.list(invocation);
    Assert.assertEquals(true, registryDirectory.isAvailable());
    Assert.assertEquals(true, invokers.get(0).isAvailable());
    registryDirectory.destroy();
    Assert.assertEquals(false, registryDirectory.isAvailable());
    Assert.assertEquals(false, invokers.get(0).isAvailable());
    registryDirectory.destroy();
    Map<String, List<Invoker<RegistryDirectoryTest>>> methodInvokerMap = registryDirectory.getMethodInvokerMap();
    Map<String, Invoker<RegistryDirectoryTest>> urlInvokerMap = registryDirectory.getUrlInvokerMap();
    Assert.assertTrue(methodInvokerMap == null);
    Assert.assertEquals(0, urlInvokerMap.size());
    // List<U> urls = mockRegistry.getSubscribedUrls();
    RpcInvocation inv = new RpcInvocation();
    try {
        registryDirectory.list(inv);
        fail();
    } catch (RpcException e) {
        Assert.assertTrue(e.getMessage().contains("already destroyed"));
    }
}
Also used : RegistryDirectory(com.alibaba.dubbo.registry.integration.RegistryDirectory) RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) ArrayList(java.util.ArrayList) URL(com.alibaba.dubbo.common.URL) Invoker(com.alibaba.dubbo.rpc.Invoker) RpcException(com.alibaba.dubbo.rpc.RpcException) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 53 with Invoker

use of com.alibaba.dubbo.rpc.Invoker in project dubbo by alibaba.

the class RegistryDirectoryTest method testNotifyoverrideUrls_afterInvoker.

/**
 * Test whether the override rule have a high priority
 * Scene: first push override , then push invoker
 */
@Test
public void testNotifyoverrideUrls_afterInvoker() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    // After pushing two provider, the directory state is restored to true
    List<URL> serviceUrls = new ArrayList<URL>();
    serviceUrls.add(SERVICEURL.addParameter("timeout", "1000"));
    serviceUrls.add(SERVICEURL2.addParameter("timeout", "1000").addParameter("connections", "10"));
    registryDirectory.notify(serviceUrls);
    Assert.assertEquals(true, registryDirectory.isAvailable());
    List<URL> overrideUrls = new ArrayList<URL>();
    overrideUrls.add(URL.valueOf("override://0.0.0.0?timeout=1&connections=5"));
    registryDirectory.notify(overrideUrls);
    // Start validation of parameter values
    invocation = new RpcInvocation();
    List<Invoker<?>> invokers = registryDirectory.list(invocation);
    Assert.assertEquals(2, invokers.size());
    Assert.assertEquals("override rute must be first priority", "1", invokers.get(0).getUrl().getParameter("timeout"));
    Assert.assertEquals("override rute must be first priority", "5", invokers.get(0).getUrl().getParameter("connections"));
}
Also used : RegistryDirectory(com.alibaba.dubbo.registry.integration.RegistryDirectory) RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) Invoker(com.alibaba.dubbo.rpc.Invoker) ArrayList(java.util.ArrayList) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 54 with Invoker

use of com.alibaba.dubbo.rpc.Invoker in project dubbo by alibaba.

the class RegistryDirectoryTest method testNofity_disabled_specifiedProvider.

/**
 * Test override disables a specified service provider through enable=false
 * It is expected that a specified service provider can be disable.
 */
@Test
public void testNofity_disabled_specifiedProvider() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    invocation = new RpcInvocation();
    // Initially disable
    List<URL> durls = new ArrayList<URL>();
    durls.add(SERVICEURL.setHost("10.20.30.140").addParameter(Constants.ENABLED_KEY, "false"));
    durls.add(SERVICEURL.setHost("10.20.30.141"));
    registryDirectory.notify(durls);
    List<Invoker<?>> invokers = registryDirectory.list(invocation);
    Assert.assertEquals(1, invokers.size());
    Assert.assertEquals("10.20.30.141", invokers.get(0).getUrl().getHost());
    // Enabled by override rule
    durls = new ArrayList<URL>();
    durls.add(URL.valueOf("override://10.20.30.140:9091?" + Constants.DISABLED_KEY + "=false"));
    registryDirectory.notify(durls);
    List<Invoker<?>> invokers2 = registryDirectory.list(invocation);
    Assert.assertEquals(2, invokers2.size());
}
Also used : RegistryDirectory(com.alibaba.dubbo.registry.integration.RegistryDirectory) RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) Invoker(com.alibaba.dubbo.rpc.Invoker) ArrayList(java.util.ArrayList) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 55 with Invoker

use of com.alibaba.dubbo.rpc.Invoker in project dubbo by alibaba.

the class RegistryDirectoryTest method testNofityOverrideUrls_disabled_allProvider.

/**
 * Test override disables all service providers through enable=false
 * Expectation: all service providers can not be disabled through override.
 */
@Test
public void testNofityOverrideUrls_disabled_allProvider() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    invocation = new RpcInvocation();
    List<URL> durls = new ArrayList<URL>();
    durls.add(SERVICEURL.setHost("10.20.30.140"));
    durls.add(SERVICEURL.setHost("10.20.30.141"));
    registryDirectory.notify(durls);
    durls = new ArrayList<URL>();
    durls.add(URL.valueOf("override://0.0.0.0?" + Constants.ENABLED_KEY + "=false"));
    registryDirectory.notify(durls);
    List<Invoker<?>> invokers = registryDirectory.list(invocation);
    // All service providers can not be disabled through override.
    Assert.assertEquals(2, invokers.size());
}
Also used : RegistryDirectory(com.alibaba.dubbo.registry.integration.RegistryDirectory) RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) Invoker(com.alibaba.dubbo.rpc.Invoker) ArrayList(java.util.ArrayList) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Aggregations

Invoker (com.alibaba.dubbo.rpc.Invoker)67 Test (org.junit.Test)50 ArrayList (java.util.ArrayList)39 RpcInvocation (com.alibaba.dubbo.rpc.RpcInvocation)38 URL (com.alibaba.dubbo.common.URL)34 RegistryDirectory (com.alibaba.dubbo.registry.integration.RegistryDirectory)19 Router (com.alibaba.dubbo.rpc.cluster.Router)14 MockInvoker (com.alibaba.dubbo.rpc.cluster.router.MockInvoker)13 Result (com.alibaba.dubbo.rpc.Result)11 Invocation (com.alibaba.dubbo.rpc.Invocation)10 RpcException (com.alibaba.dubbo.rpc.RpcException)9 RpcResult (com.alibaba.dubbo.rpc.RpcResult)9 LoadBalance (com.alibaba.dubbo.rpc.cluster.LoadBalance)8 DemoService (com.alibaba.dubbo.rpc.support.DemoService)7 LeastActiveLoadBalance (com.alibaba.dubbo.rpc.cluster.loadbalance.LeastActiveLoadBalance)5 RandomLoadBalance (com.alibaba.dubbo.rpc.cluster.loadbalance.RandomLoadBalance)5 RoundRobinLoadBalance (com.alibaba.dubbo.rpc.cluster.loadbalance.RoundRobinLoadBalance)5 AtomicLong (java.util.concurrent.atomic.AtomicLong)5 List (java.util.List)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4