From 264ac9f819c4c54fa1d0820d754095fea469ab5a Mon Sep 17 00:00:00 2001 From: Ian Luo Date: Fri, 22 Mar 2019 10:57:07 +0800 Subject: [PATCH] fix issue #3713: org.apache.dubbo.rpc.support.MockInvoker#getInterface should not return null --- .../rpc/cluster/support/wrapper/MockClusterInvoker.java | 4 ++-- .../java/org/apache/dubbo/rpc/support/MockInvoker.java | 7 ++++--- .../java/org/apache/dubbo/rpc/support/MockProtocol.java | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvoker.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvoker.java index 009f4df4428..59303142d85 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvoker.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvoker.java @@ -88,7 +88,7 @@ public Result invoke(Invocation invocation) throws RpcException { if (e.isBiz()) { throw e; } - + if (logger.isWarnEnabled()) { logger.warn("fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } @@ -105,7 +105,7 @@ private Result doMockInvoke(Invocation invocation, RpcException e) { List> mockInvokers = selectMockInvoker(invocation); if (CollectionUtils.isEmpty(mockInvokers)) { - minvoker = (Invoker) new MockInvoker(directory.getUrl()); + minvoker = (Invoker) new MockInvoker(directory.getUrl(), directory.getInterface()); } else { minvoker = mockInvokers.get(0); } diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/MockInvoker.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/MockInvoker.java index 436fb4799b5..923c7cb0fd1 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/MockInvoker.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/MockInvoker.java @@ -46,9 +46,11 @@ final public class MockInvoker implements Invoker { private final static Map throwables = new ConcurrentHashMap(); private final URL url; + private final Class type; - public MockInvoker(URL url) { + public MockInvoker(URL url, Class type) { this.url = url; + this.type = type; } public static Object parseMockValue(String mock) throws Exception { @@ -251,7 +253,6 @@ public void destroy() { @Override public Class getInterface() { - //FIXME - return null; + return type; } } diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/MockProtocol.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/MockProtocol.java index 0b6f4d145fc..9237ab955c0 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/MockProtocol.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/MockProtocol.java @@ -39,6 +39,6 @@ public Exporter export(Invoker invoker) throws RpcException { @Override public Invoker refer(Class type, URL url) throws RpcException { - return new MockInvoker(url); + return new MockInvoker<>(url, type); } }