Search in sources :

Example 31 with RpcInvocation

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

the class RegistryDirectoryTest method testEmptyNotifyCauseForbidden.

/**
 * Empty notify cause forbidden, non-empty notify cancels forbidden state
 */
@Test
public void testEmptyNotifyCauseForbidden() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    List invokers = null;
    List<URL> serviceUrls = new ArrayList<URL>();
    registryDirectory.notify(serviceUrls);
    RpcInvocation inv = new RpcInvocation();
    try {
        invokers = registryDirectory.list(inv);
    } catch (RpcException e) {
        Assertions.assertEquals(RpcException.FORBIDDEN_EXCEPTION, e.getCode());
        Assertions.assertFalse(registryDirectory.isAvailable());
    }
    serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1"));
    serviceUrls.add(SERVICEURL2.addParameter("methods", "getXXX1,getXXX2"));
    serviceUrls.add(SERVICEURL3.addParameter("methods", "getXXX1,getXXX2,getXXX3"));
    registryDirectory.notify(serviceUrls);
    inv.setMethodName("getXXX2");
    invokers = registryDirectory.list(inv);
    Assertions.assertTrue(registryDirectory.isAvailable());
    Assertions.assertEquals(3, invokers.size());
}
Also used : RegistryDirectory(org.apache.dubbo.registry.integration.RegistryDirectory) RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) RpcException(org.apache.dubbo.rpc.RpcException) 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 32 with RpcInvocation

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

the class RegistryDirectoryTest method testDubbo1UrlWithGenericInvocation.

@Test
public void testDubbo1UrlWithGenericInvocation() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    List<URL> serviceUrls = new ArrayList<URL>();
    URL serviceURL = SERVICEURL_DUBBO_NOPATH.addParameter("methods", "getXXX1,getXXX2,getXXX3");
    serviceUrls.add(serviceURL);
    registryDirectory.notify(serviceUrls);
    // Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException;
    invocation = new RpcInvocation($INVOKE, GenericService.class.getName(), "", new Class[] { String.class, String[].class, Object[].class }, new Object[] { "getXXX1", "", new Object[] {} });
    List<Invoker> invokers = registryDirectory.list(invocation);
    Assertions.assertEquals(1, invokers.size());
// Assertions.assertEquals(
// serviceURL.setPath(service).addParameters("check", "false", "interface", DemoService.class.getName(), REMOTE_APPLICATION_KEY, serviceURL.getParameter(APPLICATION_KEY))
// , invokers.get(0).getUrl()
// );
}
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 33 with RpcInvocation

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

the class RegistryDirectoryTest method testNotifyoverrideUrls_withInvoker.

/**
 * Test whether the override rule have a high priority
 * Scene: push override rules with invoker
 */
@Test
public void testNotifyoverrideUrls_withInvoker() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    List<URL> durls = new ArrayList<URL>();
    durls.add(SERVICEURL.addParameter("timeout", "1000"));
    durls.add(SERVICEURL2.addParameter("timeout", "1000").addParameter("connections", "10"));
    durls.add(URL.valueOf("override://0.0.0.0?timeout=1&connections=5"));
    registryDirectory.notify(durls);
    Assertions.assertTrue(registryDirectory.isAvailable());
    // Start validation of parameter values
    invocation = new RpcInvocation();
    List<Invoker<?>> invokers = registryDirectory.list(invocation);
    Assertions.assertEquals(2, invokers.size());
    Assertions.assertEquals("1", invokers.get(0).getUrl().getParameter("timeout"), "override rute must be first priority");
    Assertions.assertEquals("5", invokers.get(0).getUrl().getParameter("connections"), "override rute must be first priority");
}
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 34 with RpcInvocation

use of org.apache.dubbo.rpc.RpcInvocation 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(ENABLED_KEY, "false"));
    durls.add(SERVICEURL.setHost("10.20.30.141"));
    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());
    // Enabled by override rule
    durls = new ArrayList<URL>();
    durls.add(URL.valueOf("override://10.20.30.140:9091?" + DISABLED_KEY + "=false"));
    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 35 with RpcInvocation

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

the class RegistryDirectoryTest method testNotify_MockProviderOnly.

/**
 * Test mock provider distribution
 */
@Test
public void testNotify_MockProviderOnly() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    List<URL> serviceUrls = new ArrayList<URL>();
    serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1"));
    serviceUrls.add(SERVICEURL2.addParameter("methods", "getXXX1,getXXX2"));
    serviceUrls.add(SERVICEURL.setProtocol(MOCK_PROTOCOL));
    registryDirectory.notify(serviceUrls);
    Assertions.assertTrue(registryDirectory.isAvailable());
    invocation = new RpcInvocation();
    List invokers = registryDirectory.list(invocation);
    Assertions.assertEquals(2, invokers.size());
    RpcInvocation mockinvocation = new RpcInvocation();
    mockinvocation.setAttachment(INVOCATION_NEED_MOCK, "true");
    invokers = registryDirectory.list(mockinvocation);
    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)

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