Search in sources :

Example 36 with RpcInvocation

use of com.alibaba.dubbo.rpc.RpcInvocation in project dubbo by alibaba.

the class MockClusterInvokerTest method testMockInvokerFromOverride_Invoke_check_int.

@Test
public void testMockInvokerFromOverride_Invoke_check_int() {
    URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()).addParameter("getInt1.mock", "force:return 1688").addParameter("invoke_return_error", "true");
    Invoker<IHelloService> cluster = getClusterInvoker(url);
    // Configured with mock
    RpcInvocation invocation = new RpcInvocation();
    invocation.setMethodName("getInt1");
    Result ret = cluster.invoke(invocation);
    Assert.assertTrue("result type must be integer but was : " + ret.getValue().getClass(), ret.getValue() instanceof Integer);
    Assert.assertEquals(new Integer(1688), (Integer) ret.getValue());
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) URL(com.alibaba.dubbo.common.URL) Result(com.alibaba.dubbo.rpc.Result) Test(org.junit.Test)

Example 37 with RpcInvocation

use of com.alibaba.dubbo.rpc.RpcInvocation in project dubbo by alibaba.

the class MockClusterInvokerTest method testMockInvokerFromOverride_Invoke_check_ListPojo_error.

@Test
public void testMockInvokerFromOverride_Invoke_check_ListPojo_error() {
    URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()).addParameter("getUsers.mock", "force:return [{id:x, name:\"hi1\"}]").addParameter("invoke_return_error", "true");
    Invoker<IHelloService> cluster = getClusterInvoker(url);
    // Configured with mock
    RpcInvocation invocation = new RpcInvocation();
    invocation.setMethodName("getUsers");
    try {
        cluster.invoke(invocation);
    } catch (RpcException e) {
    }
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) RpcException(com.alibaba.dubbo.rpc.RpcException) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 38 with RpcInvocation

use of com.alibaba.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("invoke_return_error", "true");
    Invoker<IHelloService> cluster = getClusterInvoker(url);
    // Configured with mock
    RpcInvocation invocation = new RpcInvocation();
    invocation.setMethodName("getBoolean2");
    try {
        cluster.invoke(invocation);
        Assert.fail();
    } catch (RpcException e) {
        Assert.assertFalse("not custem exception", e.isBiz());
    }
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) RpcException(com.alibaba.dubbo.rpc.RpcException) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 39 with RpcInvocation

use of com.alibaba.dubbo.rpc.RpcInvocation in project dubbo by alibaba.

the class MockClusterInvokerTest method testMockInvokerFromOverride_Invoke_mock_false.

@Test
public void testMockInvokerFromOverride_Invoke_mock_false() {
    URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()).addParameter("mock", "false").addParameter("invoke_return_error", "true");
    Invoker<IHelloService> cluster = getClusterInvoker(url);
    // Configured with mock
    RpcInvocation invocation = new RpcInvocation();
    invocation.setMethodName("getBoolean2");
    try {
        cluster.invoke(invocation);
        Assert.fail();
    } catch (RpcException e) {
        Assert.assertTrue(e.isTimeout());
    }
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) RpcException(com.alibaba.dubbo.rpc.RpcException) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 40 with RpcInvocation

use of com.alibaba.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("invoke_return_error", "true");
    Invoker<IHelloService> cluster = getClusterInvoker(url);
    // Configured with mock
    RpcInvocation invocation = new RpcInvocation();
    invocation.setMethodName("getUsers");
    Result ret = cluster.invoke(invocation);
    Assert.assertEquals(0, ((List<User>) ret.getValue()).size());
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) URL(com.alibaba.dubbo.common.URL) Result(com.alibaba.dubbo.rpc.Result) Test(org.junit.Test)

Aggregations

RpcInvocation (com.alibaba.dubbo.rpc.RpcInvocation)104 Test (org.junit.Test)77 URL (com.alibaba.dubbo.common.URL)62 ArrayList (java.util.ArrayList)45 Invoker (com.alibaba.dubbo.rpc.Invoker)37 Result (com.alibaba.dubbo.rpc.Result)29 RegistryDirectory (com.alibaba.dubbo.registry.integration.RegistryDirectory)22 RpcException (com.alibaba.dubbo.rpc.RpcException)22 Router (com.alibaba.dubbo.rpc.cluster.Router)15 MockInvoker (com.alibaba.dubbo.rpc.cluster.router.MockInvoker)13 Invocation (com.alibaba.dubbo.rpc.Invocation)12 List (java.util.List)10 RpcResult (com.alibaba.dubbo.rpc.RpcResult)9 Method (java.lang.reflect.Method)6 Protocol (com.alibaba.dubbo.rpc.Protocol)4 MockProtocol (com.alibaba.dubbo.rpc.support.MockProtocol)4 RemotingException (com.alibaba.dubbo.remoting.RemotingException)3 TimeoutException (com.alibaba.dubbo.remoting.TimeoutException)3 Request (com.alibaba.dubbo.remoting.exchange.Request)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3