Search in sources :

Example 26 with RpcInvocation

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

the class RegistryDirectoryTest method testParametersMerge.

@Test
public void testParametersMerge() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    URL regurl = noMeaningUrl.addParameter("test", "reg").addParameterAndEncoded(REFER_KEY, "key=query&" + LOADBALANCE_KEY + "=" + LeastActiveLoadBalance.NAME);
    RegistryDirectory<RegistryDirectoryTest> registryDirectory2 = new RegistryDirectory(RegistryDirectoryTest.class, regurl);
    registryDirectory2.setProtocol(protocol);
    List<URL> serviceUrls = new ArrayList<URL>();
    // The parameters of the inspection registry need to be cleared
    {
        serviceUrls.clear();
        serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1"));
        registryDirectory.notify(serviceUrls);
        invocation = new RpcInvocation();
        List invokers = registryDirectory.list(invocation);
        Invoker invoker = (Invoker) invokers.get(0);
        URL url = invoker.getUrl();
        Assertions.assertNull(url.getParameter("key"));
    }
    // The parameters of the provider for the inspection service need merge
    {
        serviceUrls.clear();
        serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX2").addParameter("key", "provider"));
        registryDirectory.notify(serviceUrls);
        invocation = new RpcInvocation();
        List invokers = registryDirectory.list(invocation);
        Invoker invoker = (Invoker) invokers.get(0);
        URL url = invoker.getUrl();
        Assertions.assertEquals("provider", url.getParameter("key"));
    }
    // The parameters of the test service query need to be with the providermerge.
    {
        serviceUrls.clear();
        serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX3").addParameter("key", "provider"));
        registryDirectory2.setRegistry(registry);
        registryDirectory2.setRouterChain(RouterChain.buildChain(noMeaningUrl));
        registryDirectory2.subscribe(noMeaningUrl);
        registryDirectory2.notify(serviceUrls);
        invocation = new RpcInvocation();
        List invokers = registryDirectory2.list(invocation);
        Invoker invoker = (Invoker) invokers.get(0);
        URL url = invoker.getUrl();
        Assertions.assertEquals("query", url.getParameter("key"));
    }
    {
        serviceUrls.clear();
        serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1"));
        registryDirectory.notify(serviceUrls);
        invocation = new RpcInvocation();
        List invokers = registryDirectory.list(invocation);
        Invoker invoker = (Invoker) invokers.get(0);
        URL url = invoker.getUrl();
        Assertions.assertFalse(url.getParameter(Constants.CHECK_KEY, false));
    }
    {
        serviceUrls.clear();
        serviceUrls.add(SERVICEURL.addParameter(LOADBALANCE_KEY, RoundRobinLoadBalance.NAME));
        registryDirectory2.notify(serviceUrls);
        invocation = new RpcInvocation();
        invocation.setMethodName("get");
        List invokers = registryDirectory2.list(invocation);
        Invoker invoker = (Invoker) invokers.get(0);
        URL url = invoker.getUrl();
        Assertions.assertEquals(LeastActiveLoadBalance.NAME, url.getMethodParameter("get", LOADBALANCE_KEY));
    }
    // test geturl
    {
        Assertions.assertNull(registryDirectory2.getUrl().getParameter("mock"));
        serviceUrls.clear();
        serviceUrls.add(SERVICEURL.addParameter(MOCK_KEY, "true"));
        registryDirectory2.notify(serviceUrls);
        Assertions.assertEquals("true", ((InvokerWrapper<?>) registryDirectory2.getInvokers().get(0)).getUrl().getParameter("mock"));
    }
}
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) List(java.util.List) ArrayList(java.util.ArrayList) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 27 with RpcInvocation

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

the class RegistryDirectoryTest method testParmeterRoute.

/**
 * When the first arg of a method is String or Enum, Registry server can do parameter-value-based routing.
 */
@Disabled("Parameter routing is not available at present.")
@Test
public void testParmeterRoute() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    List<URL> serviceUrls = new ArrayList<URL>();
    serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1.napoli"));
    serviceUrls.add(SERVICEURL2.addParameter("methods", "getXXX1.MORGAN,getXXX2"));
    serviceUrls.add(SERVICEURL3.addParameter("methods", "getXXX1.morgan,getXXX2,getXXX3"));
    registryDirectory.notify(serviceUrls);
    invocation = new RpcInvocation($INVOKE, GenericService.class.getName(), "", new Class[] { String.class, String[].class, Object[].class }, new Object[] { "getXXX1", new String[] { "Enum" }, new Object[] { Param.MORGAN } });
    List invokers = registryDirectory.list(invocation);
    Assertions.assertEquals(1, invokers.size());
}
Also used : RegistryDirectory(org.apache.dubbo.registry.integration.RegistryDirectory) RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 28 with RpcInvocation

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

the class RegistryDirectoryTest method testNofityOverrideUrls_Provider.

/**
 * Test override rules for a certain provider
 */
@Test
public void testNofityOverrideUrls_Provider() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    invocation = new RpcInvocation();
    List<URL> durls = new ArrayList<URL>();
    // One is the same, one is different
    durls.add(SERVICEURL.setHost("10.20.30.140").addParameter("timeout", "1").addParameter(SIDE_KEY, CONSUMER_SIDE));
    durls.add(SERVICEURL2.setHost("10.20.30.141").addParameter("timeout", "2").addParameter(SIDE_KEY, CONSUMER_SIDE));
    registryDirectory.notify(durls);
    durls = new ArrayList<URL>();
    durls.add(URL.valueOf("override://0.0.0.0?timeout=3"));
    durls.add(URL.valueOf("override://10.20.30.141:9092?timeout=4"));
    registryDirectory.notify(durls);
    List<Invoker<?>> invokers = registryDirectory.list(invocation);
    URL aUrl = invokers.get(0).getUrl();
    URL bUrl = invokers.get(1).getUrl();
    Assertions.assertEquals(aUrl.getHost().equals("10.20.30.140") ? "3" : "4", aUrl.getParameter("timeout"));
    Assertions.assertEquals(bUrl.getHost().equals("10.20.30.141") ? "4" : "3", bUrl.getParameter("timeout"));
}
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 29 with RpcInvocation

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

the class RegistryDirectoryTest method test_Notified2invokers.

// 2 invokers===================================
private void test_Notified2invokers(RegistryDirectory registryDirectory) {
    List<URL> serviceUrls = new ArrayList<URL>();
    serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1"));
    serviceUrls.add(SERVICEURL2.addParameter("methods", "getXXX1,getXXX2"));
    serviceUrls.add(SERVICEURL2.addParameter("methods", "getXXX1,getXXX2"));
    registryDirectory.notify(serviceUrls);
    Assertions.assertTrue(registryDirectory.isAvailable());
    invocation = new RpcInvocation();
    List invokers = registryDirectory.list(invocation);
    Assertions.assertEquals(2, invokers.size());
    invocation.setMethodName("getXXX");
    invokers = registryDirectory.list(invocation);
    Assertions.assertEquals(2, invokers.size());
    invocation.setMethodName("getXXX1");
    invokers = registryDirectory.list(invocation);
    Assertions.assertEquals(2, invokers.size());
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) URL(org.apache.dubbo.common.URL)

Example 30 with RpcInvocation

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

the class RegistryDirectoryTest method test_Notified_acceptProtocol1.

// Test the matching of protocol and select only the matched protocol for refer
@Test
public void test_Notified_acceptProtocol1() {
    URL errorPathUrl = URL.valueOf("notsupport:/xxx");
    errorPathUrl = errorPathUrl.addParameterAndEncoded(REFER_KEY, "interface=" + service + "&protocol=dubbo");
    RegistryDirectory registryDirectory = getRegistryDirectory(errorPathUrl);
    List<URL> serviceUrls = new ArrayList<URL>();
    URL dubbo1URL = URL.valueOf("dubbo://127.0.0.1:9098?lazy=true&methods=getXXX");
    URL dubbo2URL = URL.valueOf("injvm://127.0.0.1:9098?lazy=true&methods=getXXX");
    serviceUrls.add(dubbo1URL);
    serviceUrls.add(dubbo2URL);
    registryDirectory.notify(serviceUrls);
    invocation = new RpcInvocation();
    List<Invoker<DemoService>> invokers = registryDirectory.list(invocation);
    Assertions.assertEquals(1, invokers.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)

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