Search in sources :

Example 11 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);
    //方法配置了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 12 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);
    //方法配置了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)

Example 13 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);
    //方法配置了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 14 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);
    //方法配置了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 15 with RpcInvocation

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

the class MockClusterInvokerTest method testMockInvokerFromOverride_Invoke_Fock_WithDefault.

/**
	 * 测试mock策略是否正常-fail-mock
	 */
@Test
public void testMockInvokerFromOverride_Invoke_Fock_WithDefault() {
    URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()).addParameter("mock", "fail:return null").addParameter("getSomething.mock", "fail:return x").addParameter("getSomething2.mock", "force:return y").addParameter("invoke_return_error", "true");
    Invoker<IHelloService> cluster = getClusterInvoker(url);
    //方法配置了mock
    RpcInvocation invocation = new RpcInvocation();
    invocation.setMethodName("getSomething");
    Result ret = cluster.invoke(invocation);
    Assert.assertEquals("x", ret.getValue());
    //如果没有配置mock,则直接返回null
    invocation = new RpcInvocation();
    invocation.setMethodName("getSomething2");
    ret = cluster.invoke(invocation);
    Assert.assertEquals("y", ret.getValue());
    //如果没有配置mock,则直接返回null
    invocation = new RpcInvocation();
    invocation.setMethodName("getSomething3");
    ret = cluster.invoke(invocation);
    Assert.assertEquals(null, ret.getValue());
    //如果没有配置mock,则直接返回null
    invocation = new RpcInvocation();
    invocation.setMethodName("sayHello");
    ret = cluster.invoke(invocation);
    Assert.assertEquals(null, 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)

Aggregations

RpcInvocation (com.alibaba.dubbo.rpc.RpcInvocation)99 Test (org.junit.Test)73 URL (com.alibaba.dubbo.common.URL)60 ArrayList (java.util.ArrayList)43 Invoker (com.alibaba.dubbo.rpc.Invoker)35 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)12 MockInvoker (com.alibaba.dubbo.rpc.cluster.router.MockInvoker)11 List (java.util.List)10 Invocation (com.alibaba.dubbo.rpc.Invocation)9 RpcResult (com.alibaba.dubbo.rpc.RpcResult)8 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 ExchangeClient (com.alibaba.dubbo.remoting.exchange.ExchangeClient)3 Request (com.alibaba.dubbo.remoting.exchange.Request)3