Search in sources :

Example 61 with RpcInvocation

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

the class MockClusterInvokerTest method testMockInvokerFromOverride_Invoke_Fock_WithFailDefault.

/**
 * Test if mock policy works fine: fail-mock
 */
@Test
public void testMockInvokerFromOverride_Invoke_Fock_WithFailDefault() {
    URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()).addParameter("mock", "fail:return z").addParameter("getSomething.mock", "fail:return x").addParameter("getSomething2.mock", "force:return y").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("getSomething");
    Result ret = cluster.invoke(invocation);
    Assertions.assertEquals("x", ret.getValue());
    // If no mock was configured, return null directly
    invocation = new RpcInvocation();
    invocation.setMethodName("getSomething2");
    ret = cluster.invoke(invocation);
    Assertions.assertEquals("y", ret.getValue());
    // If no mock was configured, return null directly
    invocation = new RpcInvocation();
    invocation.setMethodName("getSomething3");
    ret = cluster.invoke(invocation);
    Assertions.assertEquals("z", ret.getValue());
    // If no mock was configured, return null directly
    invocation = new RpcInvocation();
    invocation.setMethodName("sayHello");
    ret = cluster.invoke(invocation);
    Assertions.assertEquals("z", ret.getValue());
}
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 62 with RpcInvocation

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

the class MockClusterInvokerTest method testMockInvokerFromOverride_Invoke_checkCompatible_ImplMock3.

/**
 * Test if mock policy works fine: fail-mock
 */
@Test
public void testMockInvokerFromOverride_Invoke_checkCompatible_ImplMock3() {
    URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()).addParameter(REFER_KEY, URL.encode(PATH_KEY + "=" + IHelloService.class.getName())).addParameter("mock", "force");
    Invoker<IHelloService> cluster = getClusterInvoker(url);
    // Configured with mock
    RpcInvocation invocation = new RpcInvocation();
    invocation.setMethodName("getSomething");
    Result ret = cluster.invoke(invocation);
    Assertions.assertEquals("somethingmock", ret.getValue());
}
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 63 with RpcInvocation

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

the class MockClusterInvokerTest method testMockInvokerFromOverride_Invoke_Fock_WithDefault.

/**
 * Test if mock policy works fine: 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(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("getSomething");
    Result ret = cluster.invoke(invocation);
    Assertions.assertEquals("x", ret.getValue());
    // If no mock was configured, return null directly
    invocation = new RpcInvocation();
    invocation.setMethodName("getSomething2");
    ret = cluster.invoke(invocation);
    Assertions.assertEquals("y", ret.getValue());
    // If no mock was configured, return null directly
    invocation = new RpcInvocation();
    invocation.setMethodName("getSomething3");
    ret = cluster.invoke(invocation);
    Assertions.assertNull(ret.getValue());
    // If no mock was configured, return null directly
    invocation = new RpcInvocation();
    invocation.setMethodName("sayHello");
    ret = cluster.invoke(invocation);
    Assertions.assertNull(ret.getValue());
}
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 64 with RpcInvocation

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

the class MockClusterInvokerTest method testMockInvokerFromOverride_Invoke_checkCompatible_return.

/**
 * Test if mock policy works fine: fail-mock
 */
@Test
public void testMockInvokerFromOverride_Invoke_checkCompatible_return() {
    URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()).addParameter("getSomething.mock", "return x").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("getSomething");
    Result ret = cluster.invoke(invocation);
    Assertions.assertEquals("x", ret.getValue());
    // If no mock was configured, return null directly
    invocation = new RpcInvocation();
    invocation.setMethodName("getSomething3");
    try {
        ret = cluster.invoke(invocation);
        Assertions.fail("fail invoke");
    } catch (RpcException e) {
    }
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) RpcException(org.apache.dubbo.rpc.RpcException) URL(org.apache.dubbo.common.URL) Result(org.apache.dubbo.rpc.Result) Test(org.junit.jupiter.api.Test)

Example 65 with RpcInvocation

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

the class MockClusterInvokerTest method testMockInvokerFromOverride_Invoke_Fock_someMethods.

/**
 * Test if mock policy works fine: fail-mock
 */
@Test
public void testMockInvokerFromOverride_Invoke_Fock_someMethods() {
    URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()).addParameter("getSomething.mock", "fail:return x").addParameter("getSomething2.mock", "force:return y").addParameter(REFER_KEY, URL.encode(PATH_KEY + "=" + IHelloService.class.getName()));
    Invoker<IHelloService> cluster = getClusterInvoker(url);
    // Configured with mock
    RpcInvocation invocation = new RpcInvocation();
    invocation.setMethodName("getSomething");
    Result ret = cluster.invoke(invocation);
    Assertions.assertEquals("something", ret.getValue());
    // If no mock was configured, return null directly
    invocation = new RpcInvocation();
    invocation.setMethodName("getSomething2");
    ret = cluster.invoke(invocation);
    Assertions.assertEquals("y", ret.getValue());
    // If no mock was configured, return null directly
    invocation = new RpcInvocation();
    invocation.setMethodName("getSomething3");
    ret = cluster.invoke(invocation);
    Assertions.assertEquals("something3", ret.getValue());
    // If no mock was configured, return null directly
    invocation = new RpcInvocation();
    invocation.setMethodName("sayHello");
    ret = cluster.invoke(invocation);
    Assertions.assertNull(ret.getValue());
}
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