diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvokerTest.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvokerTest.java index 1c63de651e39..e7e2ff77663d 100644 --- a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvokerTest.java +++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvokerTest.java @@ -226,36 +226,41 @@ void testMockInvokerFromOverride_Invoke_Fock_someMethods() { * Test if mock policy works fine: fail-mock */ @Test - void testMockInvokerFromOverride_Invoke_Fock_WithOutDefault() { - URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()) - .addParameter( - REFER_KEY, - URL.encode(PATH_KEY + "=" + IHelloService.class.getName() - + "&" + "getSomething.mock=fail:return x" - + "&" + "getSomething2.mock=fail:return y")) - .addParameter("invoke_return_error", "true"); - Invoker cluster = getClusterInvoker(url); - // Configured with mock + void testMockInvokerFromOverride_Invoke_Fock_WithOutDefault_getSomething() { + Invoker cluster = getFailMockClusterInvokerWithoutDefault(); + 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(); + /** + * Test if mock policy works fine: fail-mock + */ + @Test + void testMockInvokerFromOverride_Invoke_Fock_WithOutDefault_notConfigure() { + Invoker cluster = getFailMockClusterInvokerWithoutDefault(); + + RpcInvocation invocation = new RpcInvocation(); invocation.setMethodName("getSomething3"); - try { - ret = cluster.invoke(invocation); - Assertions.fail(); - } catch (RpcException e) { + Assertions.assertThrows(RpcException.class, () -> cluster.invoke(invocation)); + } - } + private Invoker getFailMockClusterInvokerWithoutDefault() { + URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()) + .addParameter( + REFER_KEY, + URL.encode(PATH_KEY + "=" + IHelloService.class.getName() + + "&" + "getSomething.mock=fail:return x" + + "&" + "getSomething2.mock=fail:return y")) + .addParameter("invoke_return_error", "true"); + return getClusterInvoker(url); } /**