Search in sources :

Example 21 with RpcInvocation

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

the class RpcUtilsTest method testGet_$invoke_Arguments.

@Test
public void testGet_$invoke_Arguments() {
    Object[] args = new Object[] { "hello", "dubbo", 520 };
    Class<?> demoServiceClass = DemoService.class;
    String serviceName = demoServiceClass.getName();
    Invoker invoker = mock(Invoker.class);
    RpcInvocation inv = new RpcInvocation("$invoke", serviceName, "", new Class<?>[] { String.class, String[].class, Object[].class }, new Object[] { "method", new String[] {}, args }, null, invoker, null);
    Object[] arguments = RpcUtils.getArguments(inv);
    for (int i = 0; i < args.length; i++) {
        Assertions.assertNotNull(arguments[i]);
        Assertions.assertEquals(args[i].getClass().getName(), arguments[i].getClass().getName());
        Assertions.assertEquals(args[i], arguments[i]);
    }
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) Invoker(org.apache.dubbo.rpc.Invoker) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 22 with RpcInvocation

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

the class RpcUtilsTest method testAttachInvocationIdIfAsync_sync.

/**
 * scenario: sync invocation, no attachment added by default
 * verify: no id attribute added in attachment
 */
@Test
public void testAttachInvocationIdIfAsync_sync() {
    URL url = URL.valueOf("dubbo://localhost/");
    Invocation inv = new RpcInvocation("test", "DemoService", "", new Class[] {}, new String[] {});
    RpcUtils.attachInvocationIdIfAsync(url, inv);
    assertNull(RpcUtils.getInvocationId(inv));
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) Invocation(org.apache.dubbo.rpc.Invocation) RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 23 with RpcInvocation

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

the class FutureFilterTest method setUp.

@BeforeAll
public static void setUp() {
    invocation = new RpcInvocation();
    invocation.setMethodName("echo");
    invocation.setParameterTypes(new Class<?>[] { Enum.class });
    invocation.setArguments(new Object[] { "hello" });
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 24 with RpcInvocation

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

the class DubboRegistryTest method setUp.

@BeforeEach
public void setUp() {
    registryURL = new URL(REGISTRY_PROTOCOL, NetUtils.getLocalHost(), NetUtils.getAvailablePort()).addParameter(Constants.CHECK_KEY, false).setServiceInterface(RegistryService.class.getName());
    serviceURL = new URL(DubboProtocol.NAME, NetUtils.getLocalHost(), NetUtils.getAvailablePort()).addParameter(Constants.CHECK_KEY, false).setServiceInterface(RegistryService.class.getName());
    registryService = new MockDubboRegistry(registryURL);
    invoker = mock(Invoker.class);
    given(invoker.getUrl()).willReturn(serviceURL);
    given(invoker.getInterface()).willReturn(RegistryService.class);
    given(invoker.invoke(new RpcInvocation())).willReturn(null);
    dubboRegistry = new DubboRegistry(invoker, registryService);
    notifyListener = mock(NotifyListener.class);
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) Invoker(org.apache.dubbo.rpc.Invoker) URL(org.apache.dubbo.common.URL) NotifyListener(org.apache.dubbo.registry.NotifyListener) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 25 with RpcInvocation

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

the class RegistryDirectoryTest method test_Notified3invokers.

// 3 invoker notifications===================================
private void test_Notified3invokers(RegistryDirectory registryDirectory) {
    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);
    Assertions.assertTrue(registryDirectory.isAvailable());
    invocation = new RpcInvocation();
    List invokers = registryDirectory.list(invocation);
    Assertions.assertEquals(3, invokers.size());
    invocation.setMethodName("getXXX");
    invokers = registryDirectory.list(invocation);
    Assertions.assertEquals(3, invokers.size());
    invocation.setMethodName("getXXX1");
    invokers = registryDirectory.list(invocation);
    Assertions.assertEquals(3, invokers.size());
    invocation.setMethodName("getXXX2");
    invokers = registryDirectory.list(invocation);
    Assertions.assertEquals(3, invokers.size());
    invocation.setMethodName("getXXX3");
    invokers = registryDirectory.list(invocation);
    Assertions.assertEquals(3, 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)

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