From 2bdeccf72317148dbcc552a3e7a9888fbacfa8b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8E=E7=8E=89=E6=A1=94?= Date: Fri, 21 Feb 2020 23:47:15 +0800 Subject: [PATCH] Fix Dubbo 2.7.5 compatibility problem of sentinel-apache-dubbo-adapter (#1296) --- .../sentinel-apache-dubbo-adapter/pom.xml | 2 +- .../adapter/dubbo/BaseSentinelDubboFilter.java | 16 ++++++++++------ .../adapter/dubbo/DubboAppContextFilterTest.java | 2 +- .../dubbo/SentinelDubboConsumerFilterTest.java | 4 ++-- .../dubbo/SentinelDubboProviderFilterTest.java | 2 +- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/sentinel-adapter/sentinel-apache-dubbo-adapter/pom.xml b/sentinel-adapter/sentinel-apache-dubbo-adapter/pom.xml index 5ccf1846..44f799db 100644 --- a/sentinel-adapter/sentinel-apache-dubbo-adapter/pom.xml +++ b/sentinel-adapter/sentinel-apache-dubbo-adapter/pom.xml @@ -15,7 +15,7 @@ 1.8 1.8 - 2.7.3 + 2.7.5 diff --git a/sentinel-adapter/sentinel-apache-dubbo-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/dubbo/BaseSentinelDubboFilter.java b/sentinel-adapter/sentinel-apache-dubbo-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/dubbo/BaseSentinelDubboFilter.java index 9ea01e59..bc2101ff 100644 --- a/sentinel-adapter/sentinel-apache-dubbo-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/dubbo/BaseSentinelDubboFilter.java +++ b/sentinel-adapter/sentinel-apache-dubbo-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/dubbo/BaseSentinelDubboFilter.java @@ -22,11 +22,7 @@ import com.alibaba.csp.sentinel.adapter.dubbo.config.DubboConfig; import com.alibaba.csp.sentinel.context.ContextUtil; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.constants.CommonConstants; -import org.apache.dubbo.rpc.Invocation; -import org.apache.dubbo.rpc.Invoker; -import org.apache.dubbo.rpc.ListenableFilter; -import org.apache.dubbo.rpc.Result; -import org.apache.dubbo.rpc.RpcContext; +import org.apache.dubbo.rpc.*; /** * Base Class of the {@link SentinelDubboProviderFilter} and {@link SentinelDubboConsumerFilter}. @@ -41,8 +37,16 @@ public abstract class BaseSentinelDubboFilter extends ListenableFilter { static class SentinelDubboListener implements Listener { - @Override public void onResponse(Result appResponse, Invoker invoker, Invocation invocation) { + onSuccess(appResponse, invoker); + } + + //for compatible dubbo 2.7.5 rename onResponse to onMessage + public void onMessage(Result appResponse, Invoker invoker, Invocation invocation) { + onSuccess(appResponse, invoker); + } + + private void onSuccess(Result appResponse, Invoker invoker) { if (DubboConfig.getDubboBizExceptionTraceEnabled()) { traceAndExit(appResponse.getException(), invoker.getUrl()); } else { diff --git a/sentinel-adapter/sentinel-apache-dubbo-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/dubbo/DubboAppContextFilterTest.java b/sentinel-adapter/sentinel-apache-dubbo-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/dubbo/DubboAppContextFilterTest.java index 8c8721e1..60a7de22 100644 --- a/sentinel-adapter/sentinel-apache-dubbo-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/dubbo/DubboAppContextFilterTest.java +++ b/sentinel-adapter/sentinel-apache-dubbo-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/dubbo/DubboAppContextFilterTest.java @@ -70,6 +70,6 @@ public class DubboAppContextFilterTest extends BaseTest { verify(invoker).invoke(invocation); String application = RpcContext.getContext().getAttachment(DubboUtils.SENTINEL_DUBBO_APPLICATION_KEY); - assertNull(application); + assertEquals(application, ""); } } diff --git a/sentinel-adapter/sentinel-apache-dubbo-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboConsumerFilterTest.java b/sentinel-adapter/sentinel-apache-dubbo-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboConsumerFilterTest.java index f949231b..ea69ab8b 100644 --- a/sentinel-adapter/sentinel-apache-dubbo-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboConsumerFilterTest.java +++ b/sentinel-adapter/sentinel-apache-dubbo-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboConsumerFilterTest.java @@ -227,7 +227,7 @@ public class SentinelDubboConsumerFilterTest extends BaseTest { } public Result responseBack(Result result) { - filter.listener().onResponse(result, invoker, invocation); + filter.listener().onMessage(result, invoker, invocation); return result; } @@ -265,7 +265,7 @@ public class SentinelDubboConsumerFilterTest extends BaseTest { filter.invoke(invoker, invocation); verify(invoker).invoke(invocation); - filter.listener().onResponse(result, invoker, invocation); + filter.listener().onMessage(result, invoker, invocation); Context context = ContextUtil.getContext(); assertNull(context); } diff --git a/sentinel-adapter/sentinel-apache-dubbo-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboProviderFilterTest.java b/sentinel-adapter/sentinel-apache-dubbo-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboProviderFilterTest.java index 1a7000f1..ed97800a 100644 --- a/sentinel-adapter/sentinel-apache-dubbo-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboProviderFilterTest.java +++ b/sentinel-adapter/sentinel-apache-dubbo-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboProviderFilterTest.java @@ -89,7 +89,7 @@ public class SentinelDubboProviderFilterTest extends BaseTest { filter.invoke(invoker, invocation); verify(invoker).invoke(invocation); - filter.listener().onResponse(result, invoker, invocation); + filter.listener().onMessage(result, invoker, invocation); Context context = ContextUtil.getContext(); assertNull(context); }