Search in sources :

Example 6 with RpcInvocation

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

the class MockClusterInvokerTest method testMockInvokerFromOverride_Invoke_force_throwCustemException.

@Test
public void testMockInvokerFromOverride_Invoke_force_throwCustemException() throws Throwable {
    URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()).addParameter("getBoolean2.mock", "force:throw com.alibaba.dubbo.rpc.cluster.support.wrapper.MyMockException").addParameter("invoke_return_error", "true");
    Invoker<IHelloService> cluster = getClusterInvoker(url);
    //方法配置了mock
    RpcInvocation invocation = new RpcInvocation();
    invocation.setMethodName("getBoolean2");
    try {
        cluster.invoke(invocation).recreate();
        Assert.fail();
    } catch (MyMockException e) {
    }
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 7 with RpcInvocation

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

the class MockClusterInvokerTest method testMockInvokerFromOverride_Invoke_checkCompatible_ImplMock.

/**
	 * 测试mock策略是否正常-fail-mock
	 */
@Test
public void testMockInvokerFromOverride_Invoke_checkCompatible_ImplMock() {
    URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()).addParameter("mock", "true").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("somethingmock", 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 8 with RpcInvocation

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

the class MockClusterInvokerTest method testMockInvokerFromOverride_Invoke_check_ListPojo.

@SuppressWarnings("unchecked")
@Test
public void testMockInvokerFromOverride_Invoke_check_ListPojo() {
    URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()).addParameter("getUsers.mock", "force:return [{id:1, name:\"hi1\"}, {id:2, name:\"hi2\"}]").addParameter("invoke_return_error", "true");
    Invoker<IHelloService> cluster = getClusterInvoker(url);
    //方法配置了mock
    RpcInvocation invocation = new RpcInvocation();
    invocation.setMethodName("getUsers");
    Result ret = cluster.invoke(invocation);
    List<User> rl = (List<User>) ret.getValue();
    System.out.println(rl);
    Assert.assertEquals(2, rl.size());
    Assert.assertEquals("hi1", ((User) rl.get(0)).getName());
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) ArrayList(java.util.ArrayList) List(java.util.List) URL(com.alibaba.dubbo.common.URL) Result(com.alibaba.dubbo.rpc.Result) Test(org.junit.Test)

Example 9 with RpcInvocation

use of com.alibaba.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("invoke_return_error", "true");
    Invoker<IHelloService> cluster = getClusterInvoker(url);
    //方法配置了mock
    RpcInvocation invocation = new RpcInvocation();
    invocation.setMethodName("getListString");
    Result ret = cluster.invoke(invocation);
    List<String> rl = (List<String>) ret.getValue();
    Assert.assertEquals(2, rl.size());
    Assert.assertEquals("hi", rl.get(0));
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) ArrayList(java.util.ArrayList) List(java.util.List) URL(com.alibaba.dubbo.common.URL) Result(com.alibaba.dubbo.rpc.Result) Test(org.junit.Test)

Example 10 with RpcInvocation

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

the class MockClusterInvokerTest method testMockInvokerFromOverride_Invoke_checkCompatible_ImplMock3.

/**
	 * 测试mock策略是否正常-fail-mock
	 */
@Test
public void testMockInvokerFromOverride_Invoke_checkCompatible_ImplMock3() {
    URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()).addParameter("mock", "force");
    Invoker<IHelloService> cluster = getClusterInvoker(url);
    //方法配置了mock
    RpcInvocation invocation = new RpcInvocation();
    invocation.setMethodName("getSomething");
    Result ret = cluster.invoke(invocation);
    Assert.assertEquals("somethingmock", 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