Search in sources :

Example 56 with RpcInvocation

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

the class MockInvokerTest method testInvoke.

@Test
public void testInvoke() {
    URL url = URL.valueOf("remote://1.2.3.4/" + String.class.getName());
    url = url.addParameter(MOCK_KEY, "return ");
    MockInvoker mockInvoker = new MockInvoker(url, String.class);
    RpcInvocation invocation = new RpcInvocation();
    invocation.setMethodName("getSomething");
    Assertions.assertEquals(new HashMap<>(), mockInvoker.invoke(invocation).getObjectAttachments());
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 57 with RpcInvocation

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

the class MockClusterInvokerTest method testMockInvokerFromOverride_Invoke_check_ListString.

@SuppressWarnings("unchecked")
@Test
public void testMockInvokerFromOverride_Invoke_check_ListString() {
    URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()).addParameter("getListString.mock", "force:return [\"hi\",\"hi2\"]").addParameter(REFER_KEY, URL.encode(PATH_KEY + "=" + IHelloService.class.getName())).addParameter("invoke_return_error", "true");
    Invoker<IHelloService> cluster = getClusterInvoker(url);
    // Configured with mock
    RpcInvocation invocation = new RpcInvocation();
    invocation.setMethodName("getListString");
    Result ret = cluster.invoke(invocation);
    List<String> rl = (List<String>) ret.getValue();
    Assertions.assertEquals(2, rl.size());
    Assertions.assertEquals("hi", rl.get(0));
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) ArrayList(java.util.ArrayList) List(java.util.List) URL(org.apache.dubbo.common.URL) Result(org.apache.dubbo.rpc.Result) Test(org.junit.jupiter.api.Test)

Example 58 with RpcInvocation

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

the class MockClusterInvokerTest method testMockInvokerFromOverride_Invoke_force_throw.

@Test
public void testMockInvokerFromOverride_Invoke_force_throw() {
    URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()).addParameter("getBoolean2.mock", "force:throw ").addParameter(REFER_KEY, URL.encode(PATH_KEY + "=" + IHelloService.class.getName())).addParameter("invoke_return_error", "true");
    Invoker<IHelloService> cluster = getClusterInvoker(url);
    // Configured with mock
    RpcInvocation invocation = new RpcInvocation();
    invocation.setMethodName("getBoolean2");
    try {
        cluster.invoke(invocation);
        Assertions.fail();
    } catch (RpcException e) {
        Assertions.assertFalse(e.isBiz(), "not custem exception");
    }
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) RpcException(org.apache.dubbo.rpc.RpcException) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 59 with RpcInvocation

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

the class MockClusterInvokerTest method testMockInvokerFromOverride_Invoke_check_ListPojo_empty.

@SuppressWarnings("unchecked")
@Test
public void testMockInvokerFromOverride_Invoke_check_ListPojo_empty() {
    URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()).addParameter("getUsers.mock", "force:return empty").addParameter(REFER_KEY, URL.encode(PATH_KEY + "=" + IHelloService.class.getName())).addParameter("invoke_return_error", "true");
    Invoker<IHelloService> cluster = getClusterInvoker(url);
    // Configured with mock
    RpcInvocation invocation = new RpcInvocation();
    invocation.setMethodName("getUsers");
    Result ret = cluster.invoke(invocation);
    Assertions.assertEquals(0, ((List<User>) ret.getValue()).size());
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) URL(org.apache.dubbo.common.URL) Result(org.apache.dubbo.rpc.Result) Test(org.junit.jupiter.api.Test)

Example 60 with RpcInvocation

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

the class MockClusterInvokerTest method testMockInvokerFromOverride_Invoke_check_boolean.

@Test
public void testMockInvokerFromOverride_Invoke_check_boolean() {
    URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()).addParameter(REFER_KEY, URL.encode(PATH_KEY + "=" + IHelloService.class.getName())).addParameter("getBoolean1.mock", "force:return true").addParameter("invoke_return_error", "true");
    Invoker<IHelloService> cluster = getClusterInvoker(url);
    // Configured with mock
    RpcInvocation invocation = new RpcInvocation();
    invocation.setMethodName("getBoolean1");
    Result ret = cluster.invoke(invocation);
    Assertions.assertTrue(ret.getValue() instanceof Boolean, "result type must be Boolean but was : " + ret.getValue().getClass());
    Assertions.assertTrue(Boolean.parseBoolean(ret.getValue().toString()));
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) URL(org.apache.dubbo.common.URL) Result(org.apache.dubbo.rpc.Result) 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