Search in sources :

Example 36 with RpcInvocation

use of org.apache.dubbo.rpc.RpcInvocation in project dubbo by alibaba.

the class RegistryDirectoryTest method testNofityOverrideUrls_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 testNofityOverrideUrls_disabled_specifiedProvider() {
    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://10.20.30.140:9091?" + DISABLED_KEY + "=true"));
    registryDirectory.notify(durls);
    List<Invoker<?>> invokers = registryDirectory.list(invocation);
    Assertions.assertEquals(1, invokers.size());
    Assertions.assertEquals("10.20.30.141", invokers.get(0).getUrl().getHost());
    durls = new ArrayList<URL>();
    durls.add(URL.valueOf("empty://0.0.0.0?" + DISABLED_KEY + "=true&" + CATEGORY_KEY + "=" + CONFIGURATORS_CATEGORY));
    registryDirectory.notify(durls);
    List<Invoker<?>> invokers2 = registryDirectory.list(invocation);
    Assertions.assertEquals(2, invokers2.size());
}
Also used : RegistryDirectory(org.apache.dubbo.registry.integration.RegistryDirectory) RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) MockClusterInvoker(org.apache.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker) Invoker(org.apache.dubbo.rpc.Invoker) ArrayList(java.util.ArrayList) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 37 with RpcInvocation

use of org.apache.dubbo.rpc.RpcInvocation in project dubbo by alibaba.

the class RegistryDirectoryTest method test_Notified_withGroupFilter.

@Test
public void test_Notified_withGroupFilter() {
    URL directoryUrl = noMeaningUrl.addParameterAndEncoded(REFER_KEY, "interface" + service + "&group=group1,group2");
    RegistryDirectory directory = this.getRegistryDirectory(directoryUrl);
    URL provider1 = URL.valueOf("dubbo://10.134.108.1:20880/" + service + "?methods=getXXX&group=group1&mock=false&application=mockApplication");
    URL provider2 = URL.valueOf("dubbo://10.134.108.1:20880/" + service + "?methods=getXXX&group=group2&mock=false&application=mockApplication");
    List<URL> providers = new ArrayList<>();
    providers.add(provider1);
    providers.add(provider2);
    directory.notify(providers);
    invocation = new RpcInvocation();
    invocation.setMethodName("getXXX");
    List<Invoker<DemoService>> invokers = directory.list(invocation);
    Assertions.assertEquals(2, invokers.size());
    Assertions.assertTrue(invokers.get(0) instanceof MockClusterInvoker);
    Assertions.assertTrue(invokers.get(1) instanceof MockClusterInvoker);
    directoryUrl = noMeaningUrl.addParameterAndEncoded(REFER_KEY, "interface" + service + "&group=group1");
    directory = this.getRegistryDirectory(directoryUrl);
    directory.notify(providers);
    invokers = directory.list(invocation);
    Assertions.assertEquals(2, invokers.size());
    Assertions.assertFalse(invokers.get(0) instanceof MockClusterInvoker);
    Assertions.assertFalse(invokers.get(1) instanceof MockClusterInvoker);
}
Also used : RegistryDirectory(org.apache.dubbo.registry.integration.RegistryDirectory) RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) MockClusterInvoker(org.apache.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker) Invoker(org.apache.dubbo.rpc.Invoker) ArrayList(java.util.ArrayList) MockClusterInvoker(org.apache.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 38 with RpcInvocation

use of org.apache.dubbo.rpc.RpcInvocation in project dubbo by alibaba.

the class RegistryDirectoryTest method testNotifyoverrideUrls_Nouse.

/**
 * Test whether the override rule have a high priority
 * Scene: the rules of the push are the same as the parameters of the provider
 * Expectation: no need to be re-referenced
 */
@Test
public void testNotifyoverrideUrls_Nouse() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    invocation = new RpcInvocation();
    List<URL> durls = new ArrayList<URL>();
    // One is the same, one is different
    durls.add(SERVICEURL.addParameter("timeout", "1"));
    durls.add(SERVICEURL2.addParameter("timeout", "1").addParameter("connections", "5"));
    registryDirectory.notify(durls);
    List<Invoker<?>> invokers = registryDirectory.list(invocation);
    Assertions.assertEquals(2, invokers.size());
    Map<String, Invoker<?>> map = new HashMap<>();
    map.put(invokers.get(0).getUrl().getAddress(), invokers.get(0));
    map.put(invokers.get(1).getUrl().getAddress(), invokers.get(1));
    durls = new ArrayList<URL>();
    durls.add(URL.valueOf("override://0.0.0.0?timeout=1&connections=5"));
    registryDirectory.notify(durls);
    Assertions.assertTrue(registryDirectory.isAvailable());
    invokers = registryDirectory.list(invocation);
    Assertions.assertEquals(2, invokers.size());
    Map<String, Invoker<?>> map2 = new HashMap<>();
    map2.put(invokers.get(0).getUrl().getAddress(), invokers.get(0));
    map2.put(invokers.get(1).getUrl().getAddress(), invokers.get(1));
    // The parameters are different and must be rereferenced.
    Assertions.assertNotSame(map.get(SERVICEURL.getAddress()), map2.get(SERVICEURL.getAddress()), "object should not same");
    // The parameters can not be rereferenced
    Assertions.assertSame(map.get(SERVICEURL2.getAddress()), map2.get(SERVICEURL2.getAddress()), "object should not same");
}
Also used : RegistryDirectory(org.apache.dubbo.registry.integration.RegistryDirectory) RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) MockClusterInvoker(org.apache.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker) Invoker(org.apache.dubbo.rpc.Invoker) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 39 with RpcInvocation

use of org.apache.dubbo.rpc.RpcInvocation in project dubbo by alibaba.

the class RegistryDirectoryTest method testforbid.

// forbid
private void testforbid(RegistryDirectory registryDirectory) {
    invocation = new RpcInvocation();
    List<URL> serviceUrls = new ArrayList<URL>();
    serviceUrls.add(new URL(EMPTY_PROTOCOL, ANYHOST_VALUE, 0, service, CATEGORY_KEY, PROVIDERS_CATEGORY));
    registryDirectory.notify(serviceUrls);
    Assertions.assertFalse(registryDirectory.isAvailable(), "invokers size=0 ,then the registry directory is not available");
    try {
        registryDirectory.list(invocation);
        fail("forbid must throw RpcException");
    } catch (RpcException e) {
        Assertions.assertEquals(RpcException.FORBIDDEN_EXCEPTION, e.getCode());
    }
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) RpcException(org.apache.dubbo.rpc.RpcException) ArrayList(java.util.ArrayList) URL(org.apache.dubbo.common.URL)

Example 40 with RpcInvocation

use of org.apache.dubbo.rpc.RpcInvocation in project dubbo by alibaba.

the class StaticDirectoryTest method testStaticDirectory.

@Test
public void testStaticDirectory() {
    Router router = new ConditionRouterFactory().getRouter(getRouteUrl(" => " + " host = " + NetUtils.getLocalHost()));
    List<Router> routers = new ArrayList<Router>();
    routers.add(router);
    List<Invoker<String>> invokers = new ArrayList<Invoker<String>>();
    Invoker<String> invoker1 = new MockInvoker<String>(URL.valueOf("dubbo://10.20.3.3:20880/com.foo.BarService"));
    Invoker<String> invoker2 = new MockInvoker<String>(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService"));
    Invoker<String> invoker3 = new MockInvoker<String>(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService"));
    invokers.add(invoker1);
    invokers.add(invoker2);
    invokers.add(invoker3);
    List<Invoker<String>> filteredInvokers = router.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
    StaticDirectory<String> staticDirectory = new StaticDirectory<>(filteredInvokers);
    boolean isAvailable = staticDirectory.isAvailable();
    Assertions.assertTrue(!isAvailable);
    List<Invoker<String>> newInvokers = staticDirectory.list(new MockDirInvocation());
    Assertions.assertTrue(newInvokers.size() > 0);
    staticDirectory.destroy();
    Assertions.assertEquals(0, newInvokers.size());
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) ArrayList(java.util.ArrayList) Router(org.apache.dubbo.rpc.cluster.Router) Invoker(org.apache.dubbo.rpc.Invoker) MockInvoker(org.apache.dubbo.rpc.cluster.router.MockInvoker) MockInvoker(org.apache.dubbo.rpc.cluster.router.MockInvoker) ConditionRouterFactory(org.apache.dubbo.rpc.cluster.router.condition.ConditionRouterFactory) Test(org.junit.jupiter.api.Test)

Aggregations

RpcInvocation (org.apache.dubbo.rpc.RpcInvocation)172 Test (org.junit.jupiter.api.Test)122 URL (org.apache.dubbo.common.URL)101 Invoker (org.apache.dubbo.rpc.Invoker)65 ArrayList (java.util.ArrayList)51 Result (org.apache.dubbo.rpc.Result)38 Invocation (org.apache.dubbo.rpc.Invocation)36 RpcException (org.apache.dubbo.rpc.RpcException)26 RegistryDirectory (org.apache.dubbo.registry.integration.RegistryDirectory)23 AppResponse (org.apache.dubbo.rpc.AppResponse)20 MockClusterInvoker (org.apache.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker)20 Router (org.apache.dubbo.rpc.cluster.Router)19 MockInvoker (org.apache.dubbo.rpc.cluster.router.MockInvoker)18 HashMap (java.util.HashMap)16 AsyncRpcResult (org.apache.dubbo.rpc.AsyncRpcResult)16 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)14 Method (java.lang.reflect.Method)9 List (java.util.List)8 Person (org.apache.dubbo.rpc.support.Person)7 Protocol (org.apache.dubbo.rpc.Protocol)6