Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<IHelloService> cluster = getClusterInvoker(url);
// Configured with mock
void testMockInvokerFromOverride_Invoke_Fock_WithOutDefault_getSomething() {
Invoker<IHelloService> 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<IHelloService> 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<IHelloService> 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);
}

/**
Expand Down
Loading