Browse Source

Fix Dubbo 2.7.5 compatibility problem of sentinel-apache-dubbo-adapter (#1296)

master
于玉桔 GitHub 5 years ago
parent
commit
2bdeccf723
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 11 deletions
  1. +1
    -1
      sentinel-adapter/sentinel-apache-dubbo-adapter/pom.xml
  2. +10
    -6
      sentinel-adapter/sentinel-apache-dubbo-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/dubbo/BaseSentinelDubboFilter.java
  3. +1
    -1
      sentinel-adapter/sentinel-apache-dubbo-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/dubbo/DubboAppContextFilterTest.java
  4. +2
    -2
      sentinel-adapter/sentinel-apache-dubbo-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboConsumerFilterTest.java
  5. +1
    -1
      sentinel-adapter/sentinel-apache-dubbo-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboProviderFilterTest.java

+ 1
- 1
sentinel-adapter/sentinel-apache-dubbo-adapter/pom.xml View File

@@ -15,7 +15,7 @@
<properties>
<java.source.version>1.8</java.source.version>
<java.target.version>1.8</java.target.version>
<apache.dubbo.version>2.7.3</apache.dubbo.version>
<apache.dubbo.version>2.7.5</apache.dubbo.version>
</properties>

<dependencies>


+ 10
- 6
sentinel-adapter/sentinel-apache-dubbo-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/dubbo/BaseSentinelDubboFilter.java View File

@@ -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 {


+ 1
- 1
sentinel-adapter/sentinel-apache-dubbo-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/dubbo/DubboAppContextFilterTest.java View File

@@ -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, "");
}
}

+ 2
- 2
sentinel-adapter/sentinel-apache-dubbo-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboConsumerFilterTest.java View File

@@ -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);
}


+ 1
- 1
sentinel-adapter/sentinel-apache-dubbo-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboProviderFilterTest.java View File

@@ -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);
}


Loading…
Cancel
Save