meterMap = FieldGetter.getValue(service, "meterMap");
Assert.assertEquals(1, meterMap.size());
final Object field = meterMap.values().iterator().next();
diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/span/ConstructorWithSpanBuilderInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/span/ConstructorWithSpanBuilderInterceptor.java
index abc5d0415..ac5ea87db 100644
--- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/span/ConstructorWithSpanBuilderInterceptor.java
+++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/opentracing/span/ConstructorWithSpanBuilderInterceptor.java
@@ -36,7 +36,7 @@ public class ConstructorWithSpanBuilderInterceptor implements InstanceConstructo
AbstractSpan span;
if (spanBuilder.isEntry()) {
span = ContextManager.createEntrySpan(spanBuilder.getOperationName(), null);
- } else if (spanBuilder.isExit() && (!StringUtil.isEmpty(spanBuilder.getPeer()))) {
+ } else if (spanBuilder.isExit() && !StringUtil.isEmpty(spanBuilder.getPeer())) {
span = ContextManager.createExitSpan(spanBuilder.getOperationName(), buildRemotePeer(spanBuilder));
} else {
span = ContextManager.createLocalSpan(spanBuilder.getOperationName());
diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/opentracing/SkywalkingSpanActivationTest.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/opentracing/SkywalkingSpanActivationTest.java
index 6c6e6deed..9c88aa8b6 100644
--- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/opentracing/SkywalkingSpanActivationTest.java
+++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-opentracing-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/opentracing/SkywalkingSpanActivationTest.java
@@ -18,10 +18,11 @@
package org.apache.skywalking.apm.toolkit.activation.opentracing;
-import io.opentracing.Tracer;
-import io.opentracing.propagation.Format;
-import io.opentracing.propagation.TextMap;
-import io.opentracing.tag.Tags;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -61,17 +62,12 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.modules.junit4.PowerMockRunnerDelegate;
+import io.opentracing.Tracer;
+import io.opentracing.propagation.Format;
+import io.opentracing.propagation.TextMap;
+import io.opentracing.tag.Tags;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-@RunWith(PowerMockRunner.class)
-@PowerMockRunnerDelegate(TracingSegmentRunner.class)
+@RunWith(TracingSegmentRunner.class)
public class SkywalkingSpanActivationTest {
@SegmentStoragePoint
diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TracerCreateLocalSpanInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TracerCreateLocalSpanInterceptor.java
index 592c956c6..2c856eb6f 100644
--- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TracerCreateLocalSpanInterceptor.java
+++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TracerCreateLocalSpanInterceptor.java
@@ -23,11 +23,9 @@ import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.StaticMethodsAroundInterceptor;
-// import org.apache.skywalking.apm.toolkit.trace.SpanRef;
import java.lang.reflect.Method;
-
// Some problems about EnhancedInstance
public class TracerCreateLocalSpanInterceptor implements StaticMethodsAroundInterceptor {
diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/trace/ActiveSpanTest.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/trace/ActiveSpanTest.java
index dc80a4c59..42e7c97b8 100644
--- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/trace/ActiveSpanTest.java
+++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/trace/ActiveSpanTest.java
@@ -17,6 +17,9 @@
package org.apache.skywalking.apm.toolkit.activation.trace;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.List;
@@ -36,15 +39,10 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.modules.junit4.PowerMockRunnerDelegate;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-@RunWith(PowerMockRunner.class)
-@PowerMockRunnerDelegate(TracingSegmentRunner.class)
+@RunWith(TracingSegmentRunner.class)
public class ActiveSpanTest {
private TraceAnnotationMethodInterceptor methodInterceptor;
@@ -57,6 +55,9 @@ public class ActiveSpanTest {
private EnhancedInstance enhancedInstance;
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
+ @Rule
+ public MockitoRule rule = MockitoJUnit.rule();
+
@SegmentStoragePoint
private SegmentStorage storage;
diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/trace/CallableOrRunnableInterceptorTest.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/trace/CallableOrRunnableInterceptorTest.java
index ce3f59de9..45e00baa7 100644
--- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/trace/CallableOrRunnableInterceptorTest.java
+++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/trace/CallableOrRunnableInterceptorTest.java
@@ -17,6 +17,11 @@
package org.apache.skywalking.apm.toolkit.activation.trace;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.concurrent.Callable;
import org.apache.skywalking.apm.agent.core.context.ContextSnapshot;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
@@ -32,18 +37,10 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.modules.junit4.PowerMockRunnerDelegate;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
-import java.lang.reflect.Method;
-import java.util.List;
-import java.util.concurrent.Callable;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-@RunWith(PowerMockRunner.class)
-@PowerMockRunnerDelegate(TracingSegmentRunner.class)
+@RunWith(TracingSegmentRunner.class)
public class CallableOrRunnableInterceptorTest {
private CallableOrRunnableConstructInterceptor constructorInterceptor;
@@ -51,6 +48,9 @@ public class CallableOrRunnableInterceptorTest {
private CallableOrRunnableInvokeInterceptor callableCallInterceptor;
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
+ @Rule
+ public MockitoRule rule = MockitoJUnit.rule();
+
@SegmentStoragePoint
private SegmentStorage segmentStorage;
diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/trace/ContextCarrierRefTest.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/trace/ContextCarrierRefTest.java
index bc52f56ec..fea16c8f6 100644
--- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/trace/ContextCarrierRefTest.java
+++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/trace/ContextCarrierRefTest.java
@@ -18,6 +18,10 @@
package org.apache.skywalking.apm.toolkit.activation.trace;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import java.lang.reflect.Method;
+import java.util.List;
import org.apache.skywalking.apm.agent.core.context.CarrierItem;
import org.apache.skywalking.apm.agent.core.context.ContextCarrier;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
@@ -37,23 +41,18 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.modules.junit4.PowerMockRunnerDelegate;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
-import java.lang.reflect.Method;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-@RunWith(PowerMockRunner.class)
-@PowerMockRunnerDelegate(TracingSegmentRunner.class)
+@RunWith(TracingSegmentRunner.class)
public class ContextCarrierRefTest {
@SegmentStoragePoint
private SegmentStorage storage;
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
+ @Rule
+ public MockitoRule rule = MockitoJUnit.rule();
@Mock
private EnhancedInstance enhancedContextCarrierRef;
diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/trace/SpanRefTest.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/trace/SpanRefTest.java
index 26cc060c1..20990111f 100644
--- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/trace/SpanRefTest.java
+++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/trace/SpanRefTest.java
@@ -18,6 +18,13 @@
package org.apache.skywalking.apm.toolkit.activation.trace;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
/*
* build an EnhancedInstance to store the created span
* and then use this span to do
@@ -45,25 +52,18 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.modules.junit4.PowerMockRunnerDelegate;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
-import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-@RunWith(PowerMockRunner.class)
-@PowerMockRunnerDelegate(TracingSegmentRunner.class)
+@RunWith(TracingSegmentRunner.class)
public class SpanRefTest {
@SegmentStoragePoint
private SegmentStorage storage;
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
+ @Rule
+ public MockitoRule rule = MockitoJUnit.rule();
@Mock
private EnhancedInstance enhancedSpanRef;
diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/trace/TagAnnotationTest.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/trace/TagAnnotationTest.java
index 5aa53061a..67f93e329 100644
--- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/trace/TagAnnotationTest.java
+++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/trace/TagAnnotationTest.java
@@ -18,12 +18,14 @@
package org.apache.skywalking.apm.toolkit.activation.trace;
+import static org.hamcrest.CoreMatchers.anything;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-
import org.apache.skywalking.apm.agent.core.context.ContextManager;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
@@ -43,15 +45,10 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.modules.junit4.PowerMockRunnerDelegate;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
-import static org.hamcrest.CoreMatchers.anything;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-@RunWith(PowerMockRunner.class)
-@PowerMockRunnerDelegate(TracingSegmentRunner.class)
+@RunWith(TracingSegmentRunner.class)
public class TagAnnotationTest {
@SegmentStoragePoint
@@ -59,6 +56,8 @@ public class TagAnnotationTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
+ @Rule
+ public MockitoRule rule = MockitoJUnit.rule();
@Mock
private EnhancedInstance enhancedInstance;
diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationTest.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationTest.java
index 9c09881eb..591d56b14 100644
--- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationTest.java
+++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationTest.java
@@ -18,9 +18,10 @@
package org.apache.skywalking.apm.toolkit.activation.trace;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
import java.lang.reflect.Method;
import java.util.List;
-import lombok.AllArgsConstructor;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
import org.apache.skywalking.apm.agent.core.context.util.TagValuePair;
@@ -39,14 +40,11 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.modules.junit4.PowerMockRunnerDelegate;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
+import lombok.AllArgsConstructor;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-@RunWith(PowerMockRunner.class)
-@PowerMockRunnerDelegate(TracingSegmentRunner.class)
+@RunWith(TracingSegmentRunner.class)
public class TraceAnnotationTest {
@SegmentStoragePoint
@@ -54,6 +52,8 @@ public class TraceAnnotationTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
+ @Rule
+ public MockitoRule rule = MockitoJUnit.rule();
@Mock
private EnhancedInstance enhancedInstance;
diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/trace/TracerTest.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/trace/TracerTest.java
index f4d02396f..309e0fb20 100644
--- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/trace/TracerTest.java
+++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/trace/TracerTest.java
@@ -18,10 +18,13 @@
package org.apache.skywalking.apm.toolkit.activation.trace;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import java.lang.reflect.Method;
+import java.util.List;
import org.apache.skywalking.apm.agent.core.conf.Config;
import org.apache.skywalking.apm.agent.core.context.ContextCarrier;
import org.apache.skywalking.apm.agent.core.context.ContextSnapshot;
-
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.EntrySpan;
import org.apache.skywalking.apm.agent.core.context.trace.ExitSpan;
@@ -43,23 +46,18 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.modules.junit4.PowerMockRunnerDelegate;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
-import java.lang.reflect.Method;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-@RunWith(PowerMockRunner.class)
-@PowerMockRunnerDelegate(TracingSegmentRunner.class)
+@RunWith(TracingSegmentRunner.class)
public class TracerTest {
@SegmentStoragePoint
private SegmentStorage storage;
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
+ @Rule
+ public MockitoRule rule = MockitoJUnit.rule();
@Mock
private EnhancedInstance enhancedSpanRef;
diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
new file mode 100644
index 000000000..1f0955d45
--- /dev/null
+++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
@@ -0,0 +1 @@
+mock-maker-inline
diff --git a/apm-sniffer/optional-plugins/ehcache-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/ehcache/v2/EhcacheInterceptorTest.java b/apm-sniffer/optional-plugins/ehcache-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/ehcache/v2/EhcacheInterceptorTest.java
index a612b9c3e..b3e10e556 100644
--- a/apm-sniffer/optional-plugins/ehcache-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/ehcache/v2/EhcacheInterceptorTest.java
+++ b/apm-sniffer/optional-plugins/ehcache-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/ehcache/v2/EhcacheInterceptorTest.java
@@ -18,11 +18,20 @@
package org.apache.skywalking.apm.plugin.ehcache.v2;
+import static org.apache.skywalking.apm.plugin.ehcache.v2.define.EhcachePluginInstrumentation.CACHE_NAME_ENHANCE_METHOD;
+import static org.apache.skywalking.apm.plugin.ehcache.v2.define.EhcachePluginInstrumentation.GET_ALL_CACHE_ENHANCE_METHOD;
+import static org.apache.skywalking.apm.plugin.ehcache.v2.define.EhcachePluginInstrumentation.GET_CACHE_ENHANCE_METHOD;
+import static org.apache.skywalking.apm.plugin.ehcache.v2.define.EhcachePluginInstrumentation.PUT_CACHE_ENHANCE_METHOD;
+import static org.apache.skywalking.apm.plugin.ehcache.v2.define.EhcachePluginInstrumentation.READ_LOCK_RELEASE_ENHANCE_METHOD;
+import static org.apache.skywalking.apm.plugin.ehcache.v2.define.EhcachePluginInstrumentation.READ_LOCK_TRY_ENHANCE_METHOD;
+import static org.apache.skywalking.apm.plugin.ehcache.v2.define.EhcachePluginInstrumentation.WRITE_LOCK_RELEASE_ENHANCE_METHOD;
+import static org.apache.skywalking.apm.plugin.ehcache.v2.define.EhcachePluginInstrumentation.WRITE_LOCK_TRY_ENHANCE_METHOD;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import java.io.Serializable;
import java.lang.reflect.Method;
+import java.util.Collection;
import java.util.List;
-import net.sf.ehcache.Cache;
-import net.sf.ehcache.Element;
-import net.sf.ehcache.config.CacheConfiguration;
import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule;
@@ -34,23 +43,13 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.modules.junit4.PowerMockRunnerDelegate;
-import org.powermock.reflect.Whitebox;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
+import net.sf.ehcache.Cache;
+import net.sf.ehcache.Element;
+import net.sf.ehcache.config.CacheConfiguration;
-import static org.apache.skywalking.apm.plugin.ehcache.v2.define.EhcachePluginInstrumentation.GET_ALL_CACHE_ENHANCE_METHOD;
-import static org.apache.skywalking.apm.plugin.ehcache.v2.define.EhcachePluginInstrumentation.GET_CACHE_ENHANCE_METHOD;
-import static org.apache.skywalking.apm.plugin.ehcache.v2.define.EhcachePluginInstrumentation.PUT_CACHE_ENHANCE_METHOD;
-import static org.apache.skywalking.apm.plugin.ehcache.v2.define.EhcachePluginInstrumentation.READ_LOCK_RELEASE_ENHANCE_METHOD;
-import static org.apache.skywalking.apm.plugin.ehcache.v2.define.EhcachePluginInstrumentation.READ_LOCK_TRY_ENHANCE_METHOD;
-import static org.apache.skywalking.apm.plugin.ehcache.v2.define.EhcachePluginInstrumentation.WRITE_LOCK_RELEASE_ENHANCE_METHOD;
-import static org.apache.skywalking.apm.plugin.ehcache.v2.define.EhcachePluginInstrumentation.WRITE_LOCK_TRY_ENHANCE_METHOD;
-import static org.apache.skywalking.apm.plugin.ehcache.v2.define.EhcachePluginInstrumentation.CACHE_NAME_ENHANCE_METHOD;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-
-@RunWith(PowerMockRunner.class)
-@PowerMockRunnerDelegate(TracingSegmentRunner.class)
+@RunWith(TracingSegmentRunner.class)
public class EhcacheInterceptorTest {
private static final String CACHE_NAME = "test";
@@ -60,6 +59,8 @@ public class EhcacheInterceptorTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
+ @Rule
+ public MockitoRule rule = MockitoJUnit.rule();
private EhcacheOperateObjectInterceptor operateObjectInterceptor;
private EhcacheOperateElementInterceptor operateElementInterceptor;
@@ -122,16 +123,16 @@ public class EhcacheInterceptorTest {
releaseLockArguments = new Object[] {"dataKey"};
cacheNameArguments = new Object[] {"cacheName"};
- putCacheMethod = Whitebox.getMethods(Cache.class, PUT_CACHE_ENHANCE_METHOD)[0];
- getCacheMethod = Whitebox.getMethods(Cache.class, GET_CACHE_ENHANCE_METHOD)[0];
- getAllMethod = Whitebox.getMethods(Cache.class, GET_ALL_CACHE_ENHANCE_METHOD)[0];
+ putCacheMethod = Cache.class.getDeclaredMethod(PUT_CACHE_ENHANCE_METHOD, Element.class);
+ getCacheMethod = Cache.class.getDeclaredMethod(GET_CACHE_ENHANCE_METHOD, Serializable.class);
+ getAllMethod = Cache.class.getDeclaredMethod(GET_ALL_CACHE_ENHANCE_METHOD, Collection.class);
- tryReadLockMethod = Whitebox.getMethods(Cache.class, READ_LOCK_TRY_ENHANCE_METHOD)[0];
- tryWriteLockMethod = Whitebox.getMethods(Cache.class, WRITE_LOCK_TRY_ENHANCE_METHOD)[0];
- releaseReadLockMethod = Whitebox.getMethods(Cache.class, READ_LOCK_RELEASE_ENHANCE_METHOD)[0];
- releaseWriteLockMethod = Whitebox.getMethods(Cache.class, WRITE_LOCK_RELEASE_ENHANCE_METHOD)[0];
+ tryReadLockMethod = Cache.class.getDeclaredMethod(READ_LOCK_TRY_ENHANCE_METHOD, Object.class, long.class);
+ tryWriteLockMethod = Cache.class.getDeclaredMethod(WRITE_LOCK_TRY_ENHANCE_METHOD, Object.class, long.class);
+ releaseReadLockMethod = Cache.class.getDeclaredMethod(READ_LOCK_RELEASE_ENHANCE_METHOD, Object.class);
+ releaseWriteLockMethod = Cache.class.getDeclaredMethod(WRITE_LOCK_RELEASE_ENHANCE_METHOD, Object.class);
- setNameMethod = Whitebox.getMethods(Cache.class, CACHE_NAME_ENHANCE_METHOD)[0];
+ setNameMethod = Cache.class.getDeclaredMethod(CACHE_NAME_ENHANCE_METHOD, String.class);
enhancedInstance.setSkyWalkingDynamicField(new EhcacheEnhanceInfo(CACHE_NAME));
}
diff --git a/apm-sniffer/optional-plugins/ehcache-2.x-plugin/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/apm-sniffer/optional-plugins/ehcache-2.x-plugin/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
new file mode 100644
index 000000000..1f0955d45
--- /dev/null
+++ b/apm-sniffer/optional-plugins/ehcache-2.x-plugin/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
@@ -0,0 +1 @@
+mock-maker-inline
diff --git a/apm-sniffer/optional-plugins/fastjson-1.2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/fastjson/ParseArrayInterceptorTest.java b/apm-sniffer/optional-plugins/fastjson-1.2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/fastjson/ParseArrayInterceptorTest.java
index 783822a6a..803088ade 100644
--- a/apm-sniffer/optional-plugins/fastjson-1.2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/fastjson/ParseArrayInterceptorTest.java
+++ b/apm-sniffer/optional-plugins/fastjson-1.2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/fastjson/ParseArrayInterceptorTest.java
@@ -18,7 +18,10 @@
package org.apache.skywalking.apm.plugin.fastjson;
-import com.alibaba.fastjson.JSON;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import java.lang.reflect.Method;
+import java.util.List;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
import org.apache.skywalking.apm.agent.test.helper.SegmentHelper;
@@ -30,17 +33,11 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.modules.junit4.PowerMockRunnerDelegate;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
+import com.alibaba.fastjson.JSON;
-import java.lang.reflect.Method;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-@RunWith(PowerMockRunner.class)
-@PowerMockRunnerDelegate(TracingSegmentRunner.class)
+@RunWith(TracingSegmentRunner.class)
public class ParseArrayInterceptorTest {
private ParseArrayInterceptor parseArrayInterceptor;
@@ -50,6 +47,8 @@ public class ParseArrayInterceptorTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
+ @Rule
+ public MockitoRule rule = MockitoJUnit.rule();
private Object[] arguments;
@@ -76,4 +75,4 @@ public class ParseArrayInterceptorTest {
assertThat(spans.size(), is(1));
}
-}
\ No newline at end of file
+}
diff --git a/apm-sniffer/optional-plugins/fastjson-1.2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/fastjson/ParseInterceptorTest.java b/apm-sniffer/optional-plugins/fastjson-1.2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/fastjson/ParseInterceptorTest.java
index dc924bbaf..4680e2311 100644
--- a/apm-sniffer/optional-plugins/fastjson-1.2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/fastjson/ParseInterceptorTest.java
+++ b/apm-sniffer/optional-plugins/fastjson-1.2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/fastjson/ParseInterceptorTest.java
@@ -18,7 +18,10 @@
package org.apache.skywalking.apm.plugin.fastjson;
-import com.alibaba.fastjson.JSON;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import java.lang.reflect.Method;
+import java.util.List;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
import org.apache.skywalking.apm.agent.test.helper.SegmentHelper;
@@ -30,17 +33,11 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.modules.junit4.PowerMockRunnerDelegate;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
+import com.alibaba.fastjson.JSON;
-import java.lang.reflect.Method;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-@RunWith(PowerMockRunner.class)
-@PowerMockRunnerDelegate(TracingSegmentRunner.class)
+@RunWith(TracingSegmentRunner.class)
public class ParseInterceptorTest {
private ParseInterceptor parseInterceptor;
@@ -50,6 +47,8 @@ public class ParseInterceptorTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
+ @Rule
+ public MockitoRule rule = MockitoJUnit.rule();
private Object[] arguments;
@@ -76,4 +75,4 @@ public class ParseInterceptorTest {
assertThat(spans.size(), is(1));
}
-}
\ No newline at end of file
+}
diff --git a/apm-sniffer/optional-plugins/fastjson-1.2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/fastjson/ParseObjectInterceptorTest.java b/apm-sniffer/optional-plugins/fastjson-1.2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/fastjson/ParseObjectInterceptorTest.java
index a5ab570e0..1f595a20a 100644
--- a/apm-sniffer/optional-plugins/fastjson-1.2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/fastjson/ParseObjectInterceptorTest.java
+++ b/apm-sniffer/optional-plugins/fastjson-1.2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/fastjson/ParseObjectInterceptorTest.java
@@ -18,7 +18,10 @@
package org.apache.skywalking.apm.plugin.fastjson;
-import com.alibaba.fastjson.JSON;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import java.lang.reflect.Method;
+import java.util.List;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
import org.apache.skywalking.apm.agent.test.helper.SegmentHelper;
@@ -30,17 +33,11 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.modules.junit4.PowerMockRunnerDelegate;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
+import com.alibaba.fastjson.JSON;
-import java.lang.reflect.Method;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-@RunWith(PowerMockRunner.class)
-@PowerMockRunnerDelegate(TracingSegmentRunner.class)
+@RunWith(TracingSegmentRunner.class)
public class ParseObjectInterceptorTest {
private ParseObjectInterceptor parseObjectInterceptor;
@@ -50,6 +47,8 @@ public class ParseObjectInterceptorTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
+ @Rule
+ public MockitoRule rule = MockitoJUnit.rule();
private Object[] arguments;
@@ -76,4 +75,4 @@ public class ParseObjectInterceptorTest {
assertThat(spans.size(), is(1));
}
-}
\ No newline at end of file
+}
diff --git a/apm-sniffer/optional-plugins/fastjson-1.2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/fastjson/ToJavaObjectInterceptorTest.java b/apm-sniffer/optional-plugins/fastjson-1.2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/fastjson/ToJavaObjectInterceptorTest.java
index 16b547ce9..f8fab1a36 100644
--- a/apm-sniffer/optional-plugins/fastjson-1.2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/fastjson/ToJavaObjectInterceptorTest.java
+++ b/apm-sniffer/optional-plugins/fastjson-1.2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/fastjson/ToJavaObjectInterceptorTest.java
@@ -18,8 +18,10 @@
package org.apache.skywalking.apm.plugin.fastjson;
-import com.alibaba.fastjson.JSON;
-import lombok.Data;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import java.lang.reflect.Method;
+import java.util.List;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
import org.apache.skywalking.apm.agent.test.helper.SegmentHelper;
@@ -31,17 +33,12 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.modules.junit4.PowerMockRunnerDelegate;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
+import com.alibaba.fastjson.JSON;
+import lombok.Data;
-import java.lang.reflect.Method;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-@RunWith(PowerMockRunner.class)
-@PowerMockRunnerDelegate(TracingSegmentRunner.class)
+@RunWith(TracingSegmentRunner.class)
public class ToJavaObjectInterceptorTest {
private ToJavaObjectInterceptor toJavaObjectInterceptor;
@@ -51,6 +48,8 @@ public class ToJavaObjectInterceptorTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
+ @Rule
+ public MockitoRule rule = MockitoJUnit.rule();
private Object[] arguments;
@@ -82,4 +81,4 @@ public class ToJavaObjectInterceptorTest {
assertThat(spans.size(), is(1));
}
-}
\ No newline at end of file
+}
diff --git a/apm-sniffer/optional-plugins/fastjson-1.2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/fastjson/ToJsonBytesInterceptorTest.java b/apm-sniffer/optional-plugins/fastjson-1.2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/fastjson/ToJsonBytesInterceptorTest.java
index 375b2fb0d..144e65a81 100644
--- a/apm-sniffer/optional-plugins/fastjson-1.2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/fastjson/ToJsonBytesInterceptorTest.java
+++ b/apm-sniffer/optional-plugins/fastjson-1.2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/fastjson/ToJsonBytesInterceptorTest.java
@@ -18,9 +18,10 @@
package org.apache.skywalking.apm.plugin.fastjson;
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.serializer.SerializerFeature;
-import lombok.Data;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import java.lang.reflect.Method;
+import java.util.List;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
import org.apache.skywalking.apm.agent.test.helper.SegmentHelper;
@@ -32,17 +33,13 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.modules.junit4.PowerMockRunnerDelegate;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.serializer.SerializerFeature;
+import lombok.Data;
-import java.lang.reflect.Method;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-@RunWith(PowerMockRunner.class)
-@PowerMockRunnerDelegate(TracingSegmentRunner.class)
+@RunWith(TracingSegmentRunner.class)
public class ToJsonBytesInterceptorTest {
private ToJsonBytesInterceptor toJsonBytesInterceptor;
@@ -52,6 +49,8 @@ public class ToJsonBytesInterceptorTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
+ @Rule
+ public MockitoRule rule = MockitoJUnit.rule();
private Object[] arguments;
@@ -86,4 +85,4 @@ public class ToJsonBytesInterceptorTest {
assertThat(spans.size(), is(1));
}
-}
\ No newline at end of file
+}
diff --git a/apm-sniffer/optional-plugins/fastjson-1.2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/fastjson/ToJsonInterceptorTest.java b/apm-sniffer/optional-plugins/fastjson-1.2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/fastjson/ToJsonInterceptorTest.java
index bab818138..de4211674 100644
--- a/apm-sniffer/optional-plugins/fastjson-1.2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/fastjson/ToJsonInterceptorTest.java
+++ b/apm-sniffer/optional-plugins/fastjson-1.2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/fastjson/ToJsonInterceptorTest.java
@@ -18,9 +18,10 @@
package org.apache.skywalking.apm.plugin.fastjson;
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
-import lombok.Data;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import java.lang.reflect.Method;
+import java.util.List;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
import org.apache.skywalking.apm.agent.test.helper.SegmentHelper;
@@ -32,17 +33,13 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.modules.junit4.PowerMockRunnerDelegate;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import lombok.Data;
-import java.lang.reflect.Method;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-@RunWith(PowerMockRunner.class)
-@PowerMockRunnerDelegate(TracingSegmentRunner.class)
+@RunWith(TracingSegmentRunner.class)
public class ToJsonInterceptorTest {
private ToJsonInterceptor toJsonInterceptor;
@@ -52,6 +49,8 @@ public class ToJsonInterceptorTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
+ @Rule
+ public MockitoRule rule = MockitoJUnit.rule();
private Object[] arguments;
@@ -86,4 +85,4 @@ public class ToJsonInterceptorTest {
assertThat(spans.size(), is(1));
}
-}
\ No newline at end of file
+}
diff --git a/apm-sniffer/optional-plugins/fastjson-1.2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/fastjson/ToJsonStringInterceptorTest.java b/apm-sniffer/optional-plugins/fastjson-1.2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/fastjson/ToJsonStringInterceptorTest.java
index 3c10a50f9..9dcf27b64 100644
--- a/apm-sniffer/optional-plugins/fastjson-1.2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/fastjson/ToJsonStringInterceptorTest.java
+++ b/apm-sniffer/optional-plugins/fastjson-1.2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/fastjson/ToJsonStringInterceptorTest.java
@@ -18,9 +18,10 @@
package org.apache.skywalking.apm.plugin.fastjson;
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
-import lombok.Data;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import java.lang.reflect.Method;
+import java.util.List;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
import org.apache.skywalking.apm.agent.test.helper.SegmentHelper;
@@ -32,17 +33,13 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.modules.junit4.PowerMockRunnerDelegate;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import lombok.Data;
-import java.lang.reflect.Method;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-@RunWith(PowerMockRunner.class)
-@PowerMockRunnerDelegate(TracingSegmentRunner.class)
+@RunWith(TracingSegmentRunner.class)
public class ToJsonStringInterceptorTest {
private ToJsonStringInterceptor toJsonStringInterceptor;
@@ -52,6 +49,8 @@ public class ToJsonStringInterceptorTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
+ @Rule
+ public MockitoRule rule = MockitoJUnit.rule();
private Object[] arguments;
@@ -86,4 +85,4 @@ public class ToJsonStringInterceptorTest {
assertThat(spans.size(), is(1));
}
-}
\ No newline at end of file
+}
diff --git a/apm-sniffer/optional-plugins/fastjson-1.2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/fastjson/WriteJsonStringInterceptorTest.java b/apm-sniffer/optional-plugins/fastjson-1.2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/fastjson/WriteJsonStringInterceptorTest.java
index 5ebf84228..3d35beffa 100644
--- a/apm-sniffer/optional-plugins/fastjson-1.2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/fastjson/WriteJsonStringInterceptorTest.java
+++ b/apm-sniffer/optional-plugins/fastjson-1.2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/fastjson/WriteJsonStringInterceptorTest.java
@@ -18,9 +18,11 @@
package org.apache.skywalking.apm.plugin.fastjson;
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.serializer.SerializerFeature;
-import lombok.Data;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import java.io.OutputStream;
+import java.lang.reflect.Method;
+import java.util.List;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
import org.apache.skywalking.apm.agent.test.helper.SegmentHelper;
@@ -32,18 +34,13 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.modules.junit4.PowerMockRunnerDelegate;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.serializer.SerializerFeature;
+import lombok.Data;
-import java.io.OutputStream;
-import java.lang.reflect.Method;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-@RunWith(PowerMockRunner.class)
-@PowerMockRunnerDelegate(TracingSegmentRunner.class)
+@RunWith(TracingSegmentRunner.class)
public class WriteJsonStringInterceptorTest {
private WriteJsonStringInterceptor writeJsonStringInterceptor;
@@ -53,6 +50,8 @@ public class WriteJsonStringInterceptorTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
+ @Rule
+ public MockitoRule rule = MockitoJUnit.rule();
private Object[] arguments;
@@ -87,4 +86,4 @@ public class WriteJsonStringInterceptorTest {
assertThat(spans.size(), is(1));
}
-}
\ No newline at end of file
+}
diff --git a/apm-sniffer/optional-plugins/fastjson-1.2.x-plugin/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/apm-sniffer/optional-plugins/fastjson-1.2.x-plugin/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
new file mode 100644
index 000000000..1f0955d45
--- /dev/null
+++ b/apm-sniffer/optional-plugins/fastjson-1.2.x-plugin/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
@@ -0,0 +1 @@
+mock-maker-inline
diff --git a/apm-sniffer/optional-plugins/gson-2.8.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/gson/GsonFromJsonInterceptorTest.java b/apm-sniffer/optional-plugins/gson-2.8.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/gson/GsonFromJsonInterceptorTest.java
index a6baaaa1f..f78a3b91b 100644
--- a/apm-sniffer/optional-plugins/gson-2.8.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/gson/GsonFromJsonInterceptorTest.java
+++ b/apm-sniffer/optional-plugins/gson-2.8.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/gson/GsonFromJsonInterceptorTest.java
@@ -18,6 +18,9 @@
package org.apache.skywalking.apm.plugin.gson;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import java.util.List;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
import org.apache.skywalking.apm.agent.test.helper.SegmentHelper;
@@ -29,16 +32,10 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.modules.junit4.PowerMockRunnerDelegate;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-@RunWith(PowerMockRunner.class)
-@PowerMockRunnerDelegate(TracingSegmentRunner.class)
+@RunWith(TracingSegmentRunner.class)
public class GsonFromJsonInterceptorTest {
private GsonFromJsonInterceptor gsonFromJsonInterceptor;
@@ -48,11 +45,11 @@ public class GsonFromJsonInterceptorTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
+ @Rule
+ public MockitoRule rule = MockitoJUnit.rule();
private Object[] arguments;
- private Class[] argumentType;
-
@Before
public void setUp() {
gsonFromJsonInterceptor = new GsonFromJsonInterceptor();
@@ -72,4 +69,4 @@ public class GsonFromJsonInterceptorTest {
assertThat(spans.size(), is(1));
}
-}
\ No newline at end of file
+}
diff --git a/apm-sniffer/optional-plugins/gson-2.8.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/gson/GsonToJsonInterceptorTest.java b/apm-sniffer/optional-plugins/gson-2.8.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/gson/GsonToJsonInterceptorTest.java
index b76bfa005..4091ae93c 100644
--- a/apm-sniffer/optional-plugins/gson-2.8.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/gson/GsonToJsonInterceptorTest.java
+++ b/apm-sniffer/optional-plugins/gson-2.8.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/gson/GsonToJsonInterceptorTest.java
@@ -18,6 +18,9 @@
package org.apache.skywalking.apm.plugin.gson;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import java.util.List;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
import org.apache.skywalking.apm.agent.test.helper.SegmentHelper;
@@ -29,16 +32,10 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.modules.junit4.PowerMockRunnerDelegate;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-@RunWith(PowerMockRunner.class)
-@PowerMockRunnerDelegate(TracingSegmentRunner.class)
+@RunWith(TracingSegmentRunner.class)
public class GsonToJsonInterceptorTest {
private GsonToJsonInterceptor gsonToJsonInterceptor;
@@ -48,6 +45,8 @@ public class GsonToJsonInterceptorTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
+ @Rule
+ public MockitoRule rule = MockitoJUnit.rule();
private Object[] arguments;
diff --git a/apm-sniffer/optional-plugins/gson-2.8.x-plugin/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/apm-sniffer/optional-plugins/gson-2.8.x-plugin/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
new file mode 100644
index 000000000..1f0955d45
--- /dev/null
+++ b/apm-sniffer/optional-plugins/gson-2.8.x-plugin/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
@@ -0,0 +1 @@
+mock-maker-inline
diff --git a/apm-sniffer/optional-plugins/guava-cache-plugin/src/test/java/org/apache/skywalking/apm/plugin/guava/cache/GuavaCacheInterceptorTest.java b/apm-sniffer/optional-plugins/guava-cache-plugin/src/test/java/org/apache/skywalking/apm/plugin/guava/cache/GuavaCacheInterceptorTest.java
index 2930ef7b1..40ca8648c 100644
--- a/apm-sniffer/optional-plugins/guava-cache-plugin/src/test/java/org/apache/skywalking/apm/plugin/guava/cache/GuavaCacheInterceptorTest.java
+++ b/apm-sniffer/optional-plugins/guava-cache-plugin/src/test/java/org/apache/skywalking/apm/plugin/guava/cache/GuavaCacheInterceptorTest.java
@@ -18,6 +18,11 @@
package org.apache.skywalking.apm.plugin.guava.cache;
+import static org.hamcrest.CoreMatchers.is;
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Callable;
import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule;
import org.apache.skywalking.apm.agent.test.tools.SegmentStorage;
@@ -28,17 +33,10 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.modules.junit4.PowerMockRunnerDelegate;
-import org.powermock.reflect.Whitebox;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
-import java.lang.reflect.Method;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.is;
-
-@RunWith(PowerMockRunner.class)
-@PowerMockRunnerDelegate(TracingSegmentRunner.class)
+@RunWith(TracingSegmentRunner.class)
public class GuavaCacheInterceptorTest {
@SegmentStoragePoint
@@ -63,6 +61,8 @@ public class GuavaCacheInterceptorTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
+ @Rule
+ public MockitoRule rule = MockitoJUnit.rule();
@Before
public void setUp() throws Exception {
@@ -71,13 +71,13 @@ public class GuavaCacheInterceptorTest {
exception = new Exception();
operateObjectArguments = new Object[]{"dataKey"};
Class> cache = Class.forName("com.google.common.cache.LocalCache$LocalManualCache");
- getAllPresentMethod = Whitebox.getMethods(cache, "getAllPresent")[0];
- invalidateAllMethod = Whitebox.getMethods(cache, "invalidateAll")[0];
- getMethod = Whitebox.getMethods(cache, "get")[0];
- invalidateMethod = Whitebox.getMethods(cache, "invalidate")[0];
- putAllMethod = Whitebox.getMethods(cache, "putAll")[0];
- putMethod = Whitebox.getMethods(cache, "put")[0];
- getIfPresentMethod = Whitebox.getMethods(cache, "getIfPresent")[0];
+ getAllPresentMethod = cache.getDeclaredMethod("getAllPresent", Iterable.class);
+ invalidateAllMethod = cache.getDeclaredMethod("invalidateAll", Iterable.class);
+ getMethod = cache.getDeclaredMethod("get", Object.class, Callable.class);
+ invalidateMethod = cache.getDeclaredMethod("invalidate", Object.class);
+ putAllMethod = cache.getDeclaredMethod("putAll", Map.class);
+ putMethod = cache.getDeclaredMethod("put", Object.class, Object.class);
+ getIfPresentMethod = cache.getDeclaredMethod("getIfPresent", Object.class);
}
diff --git a/apm-sniffer/optional-plugins/guava-cache-plugin/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/apm-sniffer/optional-plugins/guava-cache-plugin/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
new file mode 100644
index 000000000..1f0955d45
--- /dev/null
+++ b/apm-sniffer/optional-plugins/guava-cache-plugin/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
@@ -0,0 +1 @@
+mock-maker-inline
diff --git a/apm-sniffer/optional-plugins/jackson-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jackson/BasicMethodsInterceptorTest.java b/apm-sniffer/optional-plugins/jackson-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jackson/BasicMethodsInterceptorTest.java
index 03285ef68..da01f6ea8 100644
--- a/apm-sniffer/optional-plugins/jackson-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jackson/BasicMethodsInterceptorTest.java
+++ b/apm-sniffer/optional-plugins/jackson-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jackson/BasicMethodsInterceptorTest.java
@@ -18,7 +18,11 @@
package org.apache.skywalking.apm.plugin.jackson;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import java.io.File;
+import java.lang.reflect.Method;
+import java.util.List;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
import org.apache.skywalking.apm.agent.test.helper.SegmentHelper;
@@ -30,18 +34,11 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.modules.junit4.PowerMockRunnerDelegate;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
+import com.fasterxml.jackson.databind.ObjectMapper;
-import java.io.File;
-import java.lang.reflect.Method;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-@RunWith(PowerMockRunner.class)
-@PowerMockRunnerDelegate(TracingSegmentRunner.class)
+@RunWith(TracingSegmentRunner.class)
public class BasicMethodsInterceptorTest {
private BasicMethodsInterceptor basicMethodsInterceptor;
@@ -51,6 +48,8 @@ public class BasicMethodsInterceptorTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
+ @Rule
+ public MockitoRule rule = MockitoJUnit.rule();
private Object[] arguments;
@@ -77,4 +76,4 @@ public class BasicMethodsInterceptorTest {
assertThat(spans.size(), is(1));
}
-}
\ No newline at end of file
+}
diff --git a/apm-sniffer/optional-plugins/jackson-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jackson/ReadValueInterceptorTest.java b/apm-sniffer/optional-plugins/jackson-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jackson/ReadValueInterceptorTest.java
index 786ee613a..61ae24777 100644
--- a/apm-sniffer/optional-plugins/jackson-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jackson/ReadValueInterceptorTest.java
+++ b/apm-sniffer/optional-plugins/jackson-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jackson/ReadValueInterceptorTest.java
@@ -18,7 +18,10 @@
package org.apache.skywalking.apm.plugin.jackson;
-import com.fasterxml.jackson.databind.ObjectReader;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import java.lang.reflect.Method;
+import java.util.List;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
import org.apache.skywalking.apm.agent.test.helper.SegmentHelper;
@@ -30,17 +33,11 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.modules.junit4.PowerMockRunnerDelegate;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
+import com.fasterxml.jackson.databind.ObjectReader;
-import java.lang.reflect.Method;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-@RunWith(PowerMockRunner.class)
-@PowerMockRunnerDelegate(TracingSegmentRunner.class)
+@RunWith(TracingSegmentRunner.class)
public class ReadValueInterceptorTest {
private ReadValueInterceptor readValueInterceptor;
@@ -50,6 +47,8 @@ public class ReadValueInterceptorTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
+ @Rule
+ public MockitoRule rule = MockitoJUnit.rule();
private Object[] arguments;
@@ -76,4 +75,4 @@ public class ReadValueInterceptorTest {
assertThat(spans.size(), is(1));
}
-}
\ No newline at end of file
+}
diff --git a/apm-sniffer/optional-plugins/jackson-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jackson/WriteValueAsBytesInterceptorTest.java b/apm-sniffer/optional-plugins/jackson-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jackson/WriteValueAsBytesInterceptorTest.java
index e3d8c1fb8..0a4caa8f6 100644
--- a/apm-sniffer/optional-plugins/jackson-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jackson/WriteValueAsBytesInterceptorTest.java
+++ b/apm-sniffer/optional-plugins/jackson-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jackson/WriteValueAsBytesInterceptorTest.java
@@ -18,8 +18,10 @@
package org.apache.skywalking.apm.plugin.jackson;
-import com.fasterxml.jackson.databind.ObjectWriter;
-import lombok.Data;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import java.lang.reflect.Method;
+import java.util.List;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
import org.apache.skywalking.apm.agent.test.helper.SegmentHelper;
@@ -31,17 +33,12 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.modules.junit4.PowerMockRunnerDelegate;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
+import com.fasterxml.jackson.databind.ObjectWriter;
+import lombok.Data;
-import java.lang.reflect.Method;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-@RunWith(PowerMockRunner.class)
-@PowerMockRunnerDelegate(TracingSegmentRunner.class)
+@RunWith(TracingSegmentRunner.class)
public class WriteValueAsBytesInterceptorTest {
private WriteValueAsBytesInterceptor writeValueAsBytesInterceptor;
@@ -51,6 +48,8 @@ public class WriteValueAsBytesInterceptorTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
+ @Rule
+ public MockitoRule rule = MockitoJUnit.rule();
private Object[] arguments;
@@ -86,4 +85,4 @@ public class WriteValueAsBytesInterceptorTest {
assertThat(spans.size(), is(1));
}
-}
\ No newline at end of file
+}
diff --git a/apm-sniffer/optional-plugins/jackson-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jackson/WriteValueAsStringInterceptorTest.java b/apm-sniffer/optional-plugins/jackson-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jackson/WriteValueAsStringInterceptorTest.java
index 3464f2e6b..fc5af0fd5 100644
--- a/apm-sniffer/optional-plugins/jackson-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jackson/WriteValueAsStringInterceptorTest.java
+++ b/apm-sniffer/optional-plugins/jackson-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jackson/WriteValueAsStringInterceptorTest.java
@@ -18,8 +18,10 @@
package org.apache.skywalking.apm.plugin.jackson;
-import com.fasterxml.jackson.databind.ObjectWriter;
-import lombok.Data;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import java.lang.reflect.Method;
+import java.util.List;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
import org.apache.skywalking.apm.agent.test.helper.SegmentHelper;
@@ -31,17 +33,12 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.modules.junit4.PowerMockRunnerDelegate;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
+import com.fasterxml.jackson.databind.ObjectWriter;
+import lombok.Data;
-import java.lang.reflect.Method;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-@RunWith(PowerMockRunner.class)
-@PowerMockRunnerDelegate(TracingSegmentRunner.class)
+@RunWith(TracingSegmentRunner.class)
public class WriteValueAsStringInterceptorTest {
private WriteValueAsStringInterceptor writeValueAsStringInterceptor;
@@ -51,6 +48,8 @@ public class WriteValueAsStringInterceptorTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
+ @Rule
+ public MockitoRule rule = MockitoJUnit.rule();
private Object[] arguments;
@@ -85,4 +84,4 @@ public class WriteValueAsStringInterceptorTest {
assertThat(spans.size(), is(1));
}
-}
\ No newline at end of file
+}
diff --git a/apm-sniffer/optional-plugins/jackson-2.x-plugin/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/apm-sniffer/optional-plugins/jackson-2.x-plugin/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
new file mode 100644
index 000000000..1f0955d45
--- /dev/null
+++ b/apm-sniffer/optional-plugins/jackson-2.x-plugin/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
@@ -0,0 +1 @@
+mock-maker-inline
diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/pom.xml b/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/pom.xml
new file mode 100644
index 000000000..3a42943cb
--- /dev/null
+++ b/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/pom.xml
@@ -0,0 +1,71 @@
+
+
+
+
+ optional-spring-plugins
+ org.apache.skywalking
+ 8.15.0-SNAPSHOT
+
+ 4.0.0
+
+ apm-springmvc-annotation-6.x-plugin
+ jar
+
+ mvc-annotation-6.x-plugin
+ http://maven.apache.org
+
+
+ 6.0.0
+ 6.0.0
+ 6.0.0
+ 6.0.0
+
+
+
+
+ org.springframework
+ spring-core
+ ${spring-core.version}
+ provided
+
+
+ org.springframework
+ spring-webmvc
+ ${spring-webmvc.version}
+ provided
+
+
+ org.apache.skywalking
+ apm-springmvc-annotation-commons
+ ${project.version}
+ provided
+
+
+ org.springframework
+ spring-webflux
+ ${spring-webflux.version}
+ provided
+
+
+ jakarta.servlet
+ jakarta.servlet-api
+ ${jakarta-servlet-api.version}
+ provided
+
+
+
diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/ControllerConstructorInterceptor.java b/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/ControllerConstructorInterceptor.java
new file mode 100644
index 000000000..6157e9fdb
--- /dev/null
+++ b/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/ControllerConstructorInterceptor.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.apm.plugin.spring.mvc.v6;
+
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
+import org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache;
+import org.apache.skywalking.apm.plugin.spring.mvc.commons.PathMappingCache;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor;
+import org.springframework.core.annotation.AnnotationUtils;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+/**
+ * The ControllerConstructorInterceptor intercepts the Controller's constructor, in order to acquire the
+ * mapping annotation, if exist.
+ *
+ * But, you can see we only use the first mapping value, Why?
+ *
+ * Right now, we intercept the controller by annotation as you known, so we CAN'T know which uri patten is actually
+ * matched. Even we know, that costs a lot.
+ *
+ * If we want to resolve that, we must intercept the Spring MVC core codes, that is not a good choice for now.
+ *
+ * Comment by @wu-sheng
+ */
+public class ControllerConstructorInterceptor implements InstanceConstructorInterceptor {
+
+ @Override
+ public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
+ String basePath = "";
+ RequestMapping basePathRequestMapping = AnnotationUtils.findAnnotation(objInst.getClass(), RequestMapping.class);
+ if (basePathRequestMapping != null) {
+ if (basePathRequestMapping.value().length > 0) {
+ basePath = basePathRequestMapping.value()[0];
+ } else if (basePathRequestMapping.path().length > 0) {
+ basePath = basePathRequestMapping.path()[0];
+ }
+ }
+ EnhanceRequireObjectCache enhanceRequireObjectCache = new EnhanceRequireObjectCache();
+ enhanceRequireObjectCache.setPathMappingCache(new PathMappingCache(basePath));
+ objInst.setSkyWalkingDynamicField(enhanceRequireObjectCache);
+ }
+}
diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/GetBeanInterceptor.java b/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/GetBeanInterceptor.java
new file mode 100644
index 000000000..33a588c68
--- /dev/null
+++ b/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/GetBeanInterceptor.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.skywalking.apm.plugin.spring.mvc.v6;
+
+import java.lang.reflect.Method;
+import org.apache.skywalking.apm.agent.core.context.ContextManager;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
+import org.springframework.web.context.request.NativeWebRequest;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+
+import static org.apache.skywalking.apm.plugin.spring.mvc.commons.Constants.REQUEST_KEY_IN_RUNTIME_CONTEXT;
+import static org.apache.skywalking.apm.plugin.spring.mvc.commons.Constants.RESPONSE_KEY_IN_RUNTIME_CONTEXT;
+
+/**
+ * {@link GetBeanInterceptor} pass the {@link NativeWebRequest} object into the {@link
+ * org.springframework.stereotype.Controller} object.
+ */
+public class GetBeanInterceptor implements InstanceMethodsAroundInterceptor {
+ @Override
+ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class>[] argumentsTypes,
+ MethodInterceptResult result) throws Throwable {
+ }
+
+ @Override
+ public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class>[] argumentsTypes,
+ Object ret) throws Throwable {
+ if (ret instanceof EnhancedInstance) {
+ ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
+ if (requestAttributes != null) {
+ ContextManager.getRuntimeContext()
+ .put(
+ REQUEST_KEY_IN_RUNTIME_CONTEXT,
+ requestAttributes.getRequest()
+ );
+ ContextManager.getRuntimeContext()
+ .put(
+ RESPONSE_KEY_IN_RUNTIME_CONTEXT,
+ requestAttributes.getResponse()
+ );
+ }
+ }
+ return ret;
+ }
+
+ @Override
+ public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
+ Class>[] argumentsTypes, Throwable t) {
+
+ }
+}
diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/InvokeInterceptor.java b/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/InvokeInterceptor.java
new file mode 100644
index 000000000..da9a33d93
--- /dev/null
+++ b/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/InvokeInterceptor.java
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.skywalking.apm.plugin.spring.mvc.v6;
+
+import org.apache.skywalking.apm.agent.core.context.ContextManager;
+import org.apache.skywalking.apm.agent.core.context.RuntimeContext;
+import org.apache.skywalking.apm.agent.core.context.tag.Tags;
+import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.v2.InstanceMethodsAroundInterceptorV2;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.v2.MethodInvocationContext;
+import org.springframework.http.HttpStatusCode;
+import org.springframework.http.server.reactive.ServerHttpResponse;
+import org.springframework.web.server.ServerWebExchange;
+import reactor.core.publisher.Mono;
+
+import java.lang.reflect.Method;
+
+import static org.apache.skywalking.apm.plugin.spring.mvc.commons.Constants.REACTIVE_ASYNC_SPAN_IN_RUNTIME_CONTEXT;
+import static org.apache.skywalking.apm.plugin.spring.mvc.commons.Constants.REQUEST_KEY_IN_RUNTIME_CONTEXT;
+import static org.apache.skywalking.apm.plugin.spring.mvc.commons.Constants.RESPONSE_KEY_IN_RUNTIME_CONTEXT;
+
+public class InvokeInterceptor implements InstanceMethodsAroundInterceptorV2 {
+ @Override
+ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class>[] argumentsTypes, MethodInvocationContext context) throws Throwable {
+ ServerWebExchange exchange = (ServerWebExchange) allArguments[0];
+ final ServerHttpResponse response = exchange.getResponse();
+ /**
+ * First, we put the slot in the RuntimeContext,
+ * as well as the MethodInvocationContext (MIC),
+ * so that we can access it in the {@link org.apache.skywalking.apm.plugin.spring.mvc.v6.InvokeInterceptor#afterMethod}
+ * Then we fetch the slot from {@link org.apache.skywalking.apm.plugin.spring.mvc.commons.interceptor.AbstractMethodInterceptor#afterMethod}
+ * and fulfill the slot with the real AbstractSpan.
+ * Afterwards, we can safely remove the RuntimeContext.
+ * Finally, when the lambda executes in the {@link reactor.core.publisher.Mono#doFinally},
+ * ref of span could be acquired from MIC.
+ */
+ AbstractSpan[] ref = new AbstractSpan[1];
+ RuntimeContext runtimeContext = ContextManager.getRuntimeContext();
+ runtimeContext.put(REACTIVE_ASYNC_SPAN_IN_RUNTIME_CONTEXT, ref);
+ runtimeContext.put(RESPONSE_KEY_IN_RUNTIME_CONTEXT, response);
+ runtimeContext.put(REQUEST_KEY_IN_RUNTIME_CONTEXT, exchange.getRequest());
+ context.setContext(ref);
+ }
+
+ @Override
+ public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class>[] argumentsTypes, Object ret, MethodInvocationContext context) throws Throwable {
+ ServerWebExchange exchange = (ServerWebExchange) allArguments[0];
+ return ((Mono) ret).doFinally(s -> {
+ Object ctx = context.getContext();
+ if (ctx == null) {
+ return;
+ }
+ AbstractSpan span = ((AbstractSpan[]) ctx)[0];
+ if (span == null) {
+ return;
+ }
+ HttpStatusCode httpStatus = exchange.getResponse().getStatusCode();
+ if (httpStatus != null) {
+ Tags.HTTP_RESPONSE_STATUS_CODE.set(span, httpStatus.value());
+ if (httpStatus.isError()) {
+ span.errorOccurred();
+ }
+ }
+ span.asyncFinish();
+ });
+ }
+
+ @Override
+ public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class>[] argumentsTypes, Throwable t, MethodInvocationContext context) {
+
+ }
+}
diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/define/AbstractControllerInstrumentation.java b/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/define/AbstractControllerInstrumentation.java
new file mode 100644
index 000000000..ad1ffdbdc
--- /dev/null
+++ b/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/define/AbstractControllerInstrumentation.java
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.skywalking.apm.plugin.spring.mvc.v6.define;
+
+import net.bytebuddy.description.method.MethodDescription;
+import net.bytebuddy.matcher.ElementMatcher;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.DeclaredInstanceMethodsInterceptPoint;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
+import org.apache.skywalking.apm.agent.core.plugin.match.ClassAnnotationMatch;
+import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
+import org.apache.skywalking.apm.plugin.spring.mvc.commons.Constants;
+
+import static net.bytebuddy.matcher.ElementMatchers.any;
+import static net.bytebuddy.matcher.ElementMatchers.named;
+import static org.apache.skywalking.apm.agent.core.plugin.match.MethodInheritanceAnnotationMatcher.byMethodInheritanceAnnotationMatcher;
+
+/**
+ * {@link ControllerInstrumentation} enhance all constructor and method annotated with
+ * org.springframework.web.bind.annotation.RequestMapping that class has
+ * org.springframework.stereotype.Controller annotation.
+ *
+ * ControllerConstructorInterceptor set the controller base path to
+ * dynamic field before execute constructor.
+ *
+ * org.apache.skywalking.apm.plugin.spring.mvc.commons.interceptor.RequestMappingMethodInterceptor get the request path
+ * from dynamic field first, if not found, RequestMappingMethodInterceptor generate request path that
+ * combine the path value of current annotation on current method and the base path and set the new path to the dynamic
+ * filed
+ */
+public abstract class AbstractControllerInstrumentation extends AbstractSpring6Instrumentation {
+ @Override
+ public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
+ return new ConstructorInterceptPoint[] {
+ new ConstructorInterceptPoint() {
+ @Override
+ public ElementMatcher getConstructorMatcher() {
+ return any();
+ }
+
+ @Override
+ public String getConstructorInterceptor() {
+ return "org.apache.skywalking.apm.plugin.spring.mvc.v6.ControllerConstructorInterceptor";
+ }
+ }
+ };
+ }
+
+ @Override
+ public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
+ return new InstanceMethodsInterceptPoint[] {
+ new DeclaredInstanceMethodsInterceptPoint() {
+ @Override
+ public ElementMatcher getMethodsMatcher() {
+ return byMethodInheritanceAnnotationMatcher(named("org.springframework.web.bind.annotation.RequestMapping"));
+ }
+
+ @Override
+ public String getMethodsInterceptor() {
+ return Constants.REQUEST_MAPPING_METHOD_INTERCEPTOR;
+ }
+
+ @Override
+ public boolean isOverrideArgs() {
+ return false;
+ }
+ },
+ new DeclaredInstanceMethodsInterceptPoint() {
+ @Override
+ public ElementMatcher getMethodsMatcher() {
+ return byMethodInheritanceAnnotationMatcher(named("org.springframework.web.bind.annotation.GetMapping"))
+ .or(byMethodInheritanceAnnotationMatcher(named("org.springframework.web.bind.annotation.PostMapping")))
+ .or(byMethodInheritanceAnnotationMatcher(named("org.springframework.web.bind.annotation.PutMapping")))
+ .or(byMethodInheritanceAnnotationMatcher(named("org.springframework.web.bind.annotation.DeleteMapping")))
+ .or(byMethodInheritanceAnnotationMatcher(named("org.springframework.web.bind.annotation.PatchMapping")));
+ }
+
+ @Override
+ public String getMethodsInterceptor() {
+ return Constants.REST_MAPPING_METHOD_INTERCEPTOR;
+ }
+
+ @Override
+ public boolean isOverrideArgs() {
+ return false;
+ }
+ }
+ };
+ }
+
+ @Override
+ protected ClassMatch enhanceClass() {
+ return ClassAnnotationMatch.byClassAnnotationMatch(getEnhanceAnnotations());
+ }
+
+ protected abstract String[] getEnhanceAnnotations();
+
+}
diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/define/AbstractSpring6Instrumentation.java b/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/define/AbstractSpring6Instrumentation.java
new file mode 100644
index 000000000..56de6c276
--- /dev/null
+++ b/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/define/AbstractSpring6Instrumentation.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.skywalking.apm.plugin.spring.mvc.v6.define;
+
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
+
+public abstract class AbstractSpring6Instrumentation extends ClassInstanceMethodsEnhancePluginDefine {
+ public static final String WITNESS_CLASSES = "org.springframework.web.servlet.resource.HttpResource";
+
+ @Override
+ protected final String[] witnessClasses() {
+ return new String[] {WITNESS_CLASSES};
+ }
+}
diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/define/ControllerInstrumentation.java b/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/define/ControllerInstrumentation.java
new file mode 100644
index 000000000..04c5d963b
--- /dev/null
+++ b/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/define/ControllerInstrumentation.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.skywalking.apm.plugin.spring.mvc.v6.define;
+
+public class ControllerInstrumentation extends AbstractControllerInstrumentation {
+
+ public static final String ENHANCE_ANNOTATION = "org.springframework.stereotype.Controller";
+
+ @Override
+ protected String[] getEnhanceAnnotations() {
+ return new String[] {ENHANCE_ANNOTATION};
+ }
+}
diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/define/HandlerMethodInstrumentation.java b/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/define/HandlerMethodInstrumentation.java
new file mode 100644
index 000000000..b09f49158
--- /dev/null
+++ b/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/define/HandlerMethodInstrumentation.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.skywalking.apm.plugin.spring.mvc.v6.define;
+
+import net.bytebuddy.description.method.MethodDescription;
+import net.bytebuddy.matcher.ElementMatcher;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
+import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
+import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch;
+
+import static net.bytebuddy.matcher.ElementMatchers.named;
+
+/**
+ * {@link HandlerMethodInstrumentation} intercept the getBean method in the
+ * org.springframework.web.method.HandlerMethod class.
+ */
+public class HandlerMethodInstrumentation extends AbstractSpring6Instrumentation {
+
+ public static final String ENHANCE_METHOD = "getBean";
+ public static final String ENHANCE_CLASS = "org.springframework.web.method.HandlerMethod";
+
+ @Override
+ public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
+ return new ConstructorInterceptPoint[0];
+ }
+
+ @Override
+ public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
+ return new InstanceMethodsInterceptPoint[] {
+ new InstanceMethodsInterceptPoint() {
+ @Override
+ public ElementMatcher getMethodsMatcher() {
+ return named(ENHANCE_METHOD);
+ }
+
+ @Override
+ public String getMethodsInterceptor() {
+ return "org.apache.skywalking.apm.plugin.spring.mvc.v6.GetBeanInterceptor";
+ }
+
+ @Override
+ public boolean isOverrideArgs() {
+ return false;
+ }
+ }
+ };
+ }
+
+ @Override
+ protected ClassMatch enhanceClass() {
+ return NameMatch.byName(ENHANCE_CLASS);
+ }
+}
diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/define/RestControllerInstrumentation.java b/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/define/RestControllerInstrumentation.java
new file mode 100644
index 000000000..27a416de0
--- /dev/null
+++ b/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/define/RestControllerInstrumentation.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.apm.plugin.spring.mvc.v6.define;
+
+public class RestControllerInstrumentation extends AbstractControllerInstrumentation {
+
+ public static final String ENHANCE_ANNOTATION = "org.springframework.web.bind.annotation.RestController";
+
+ @Override
+ protected String[] getEnhanceAnnotations() {
+ return new String[] {ENHANCE_ANNOTATION};
+ }
+}
diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/define/reactive/AbstractReactiveControllerInstrumentation.java b/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/define/reactive/AbstractReactiveControllerInstrumentation.java
new file mode 100644
index 000000000..f5189735d
--- /dev/null
+++ b/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/define/reactive/AbstractReactiveControllerInstrumentation.java
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.skywalking.apm.plugin.spring.mvc.v6.define.reactive;
+
+import net.bytebuddy.description.method.MethodDescription;
+import net.bytebuddy.matcher.ElementMatcher;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.DeclaredInstanceMethodsInterceptPoint;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
+import org.apache.skywalking.apm.agent.core.plugin.match.ClassAnnotationMatch;
+import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
+import org.apache.skywalking.apm.plugin.spring.mvc.commons.Constants;
+import org.apache.skywalking.apm.plugin.spring.mvc.v6.define.ControllerInstrumentation;
+
+import static net.bytebuddy.matcher.ElementMatchers.any;
+import static net.bytebuddy.matcher.ElementMatchers.named;
+import static org.apache.skywalking.apm.agent.core.plugin.match.MethodInheritanceAnnotationMatcher.byMethodInheritanceAnnotationMatcher;
+
+/**
+ * {@link ControllerInstrumentation} enhance all constructor and method annotated with
+ * org.springframework.web.bind.annotation.RequestMapping that class has
+ * org.springframework.stereotype.Controller annotation.
+ *
+ * ControllerConstructorInterceptor set the controller base path to
+ * dynamic field before execute constructor.
+ *
+ * org.apache.skywalking.apm.plugin.spring.mvc.v4.RequestMappingMethodInterceptor get the request path
+ * from dynamic field first, if not found, RequestMappingMethodInterceptor generate request path that
+ * combine the path value of current annotation on current method and the base path and set the new path to the dynamic
+ * filed
+ */
+public abstract class AbstractReactiveControllerInstrumentation extends AbstractSpring6ReactiveInstrumentation {
+ @Override
+ public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
+ return new ConstructorInterceptPoint[] {
+ new ConstructorInterceptPoint() {
+ @Override
+ public ElementMatcher getConstructorMatcher() {
+ return any();
+ }
+
+ @Override
+ public String getConstructorInterceptor() {
+ return "org.apache.skywalking.apm.plugin.spring.mvc.v6.ControllerConstructorInterceptor";
+ }
+ }
+ };
+ }
+
+ @Override
+ public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
+ return new InstanceMethodsInterceptPoint[] {
+ new DeclaredInstanceMethodsInterceptPoint() {
+ @Override
+ public ElementMatcher getMethodsMatcher() {
+ return byMethodInheritanceAnnotationMatcher(
+ named("org.springframework.web.bind.annotation.RequestMapping"));
+ }
+
+ @Override
+ public String getMethodsInterceptor() {
+ return Constants.REQUEST_MAPPING_METHOD_INTERCEPTOR;
+ }
+
+ @Override
+ public boolean isOverrideArgs() {
+ return false;
+ }
+ },
+ new DeclaredInstanceMethodsInterceptPoint() {
+ @Override
+ public ElementMatcher getMethodsMatcher() {
+ return byMethodInheritanceAnnotationMatcher(
+ named("org.springframework.web.bind.annotation.GetMapping"))
+ .or(byMethodInheritanceAnnotationMatcher(
+ named("org.springframework.web.bind.annotation.PostMapping")))
+ .or(byMethodInheritanceAnnotationMatcher(
+ named("org.springframework.web.bind.annotation.PutMapping")))
+ .or(byMethodInheritanceAnnotationMatcher(
+ named("org.springframework.web.bind.annotation.DeleteMapping")))
+ .or(byMethodInheritanceAnnotationMatcher(
+ named("org.springframework.web.bind.annotation.PatchMapping")));
+ }
+
+ @Override
+ public String getMethodsInterceptor() {
+ return Constants.REST_MAPPING_METHOD_INTERCEPTOR;
+ }
+
+ @Override
+ public boolean isOverrideArgs() {
+ return false;
+ }
+ }
+ };
+ }
+
+ @Override
+ protected ClassMatch enhanceClass() {
+ return ClassAnnotationMatch.byClassAnnotationMatch(getEnhanceAnnotations());
+ }
+
+ protected abstract String[] getEnhanceAnnotations();
+
+}
diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/define/reactive/AbstractSpring6ReactiveInstrumentation.java b/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/define/reactive/AbstractSpring6ReactiveInstrumentation.java
new file mode 100644
index 000000000..703e2d472
--- /dev/null
+++ b/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/define/reactive/AbstractSpring6ReactiveInstrumentation.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.skywalking.apm.plugin.spring.mvc.v6.define.reactive;
+
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
+
+public abstract class AbstractSpring6ReactiveInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
+ public static final String WITNESS_CLASSES = "org.springframework.web.method.support.InvocableHandlerMethod";
+
+ @Override
+ protected final String[] witnessClasses() {
+ return new String[] {WITNESS_CLASSES};
+ }
+}
diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/define/reactive/AbstractSpring6ReactiveInstrumentationV2.java b/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/define/reactive/AbstractSpring6ReactiveInstrumentationV2.java
new file mode 100644
index 000000000..55c9a4f8e
--- /dev/null
+++ b/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/define/reactive/AbstractSpring6ReactiveInstrumentationV2.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.skywalking.apm.plugin.spring.mvc.v6.define.reactive;
+
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.v2.ClassInstanceMethodsEnhancePluginDefineV2;
+
+public abstract class AbstractSpring6ReactiveInstrumentationV2 extends ClassInstanceMethodsEnhancePluginDefineV2 {
+ public static final String WITNESS_CLASSES = "org.springframework.web.method.support.InvocableHandlerMethod";
+
+ @Override
+ protected final String[] witnessClasses() {
+ return new String[] {WITNESS_CLASSES};
+ }
+}
diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/define/reactive/InvocableHandlerMethodInstrumentation.java b/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/define/reactive/InvocableHandlerMethodInstrumentation.java
new file mode 100644
index 000000000..9137cf78e
--- /dev/null
+++ b/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/define/reactive/InvocableHandlerMethodInstrumentation.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.skywalking.apm.plugin.spring.mvc.v6.define.reactive;
+
+import net.bytebuddy.description.method.MethodDescription;
+import net.bytebuddy.matcher.ElementMatcher;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.v2.InstanceMethodsInterceptV2Point;
+import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
+
+import static net.bytebuddy.matcher.ElementMatchers.named;
+import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType;
+import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
+
+public class InvocableHandlerMethodInstrumentation extends AbstractSpring6ReactiveInstrumentationV2 {
+ @Override
+ protected ClassMatch enhanceClass() {
+ return byName("org.springframework.web.reactive.result.method.InvocableHandlerMethod");
+ }
+
+ @Override
+ public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
+ return new ConstructorInterceptPoint[0];
+ }
+
+ @Override
+ public InstanceMethodsInterceptV2Point[] getInstanceMethodsInterceptV2Points() {
+ return new InstanceMethodsInterceptV2Point[] {
+ new InstanceMethodsInterceptV2Point() {
+ @Override
+ public ElementMatcher getMethodsMatcher() {
+ return named("invoke").and(
+ takesArgumentWithType(0, "org.springframework.web.server.ServerWebExchange"));
+ }
+
+ @Override
+ public String getMethodsInterceptorV2() {
+ return "org.apache.skywalking.apm.plugin.spring.mvc.v6.InvokeInterceptor";
+ }
+
+ @Override
+ public boolean isOverrideArgs() {
+ return false;
+ }
+ }
+ };
+ }
+}
diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/define/reactive/ReactiveControllerInstrumentation.java b/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/define/reactive/ReactiveControllerInstrumentation.java
new file mode 100644
index 000000000..8e68eb1ee
--- /dev/null
+++ b/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/define/reactive/ReactiveControllerInstrumentation.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.skywalking.apm.plugin.spring.mvc.v6.define.reactive;
+
+public class ReactiveControllerInstrumentation extends AbstractReactiveControllerInstrumentation {
+
+ public static final String ENHANCE_ANNOTATION = "org.springframework.stereotype.Controller";
+
+ @Override
+ protected String[] getEnhanceAnnotations() {
+ return new String[] {ENHANCE_ANNOTATION};
+ }
+}
diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/define/reactive/ReactiveRestControllerInstrumentation.java b/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/define/reactive/ReactiveRestControllerInstrumentation.java
new file mode 100644
index 000000000..0e50c2da9
--- /dev/null
+++ b/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/v6/define/reactive/ReactiveRestControllerInstrumentation.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.apm.plugin.spring.mvc.v6.define.reactive;
+
+public class ReactiveRestControllerInstrumentation extends AbstractReactiveControllerInstrumentation {
+
+ public static final String ENHANCE_ANNOTATION = "org.springframework.web.bind.annotation.RestController";
+
+ @Override
+ protected String[] getEnhanceAnnotations() {
+ return new String[] {ENHANCE_ANNOTATION};
+ }
+}
diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/resources/skywalking-plugin.def
new file mode 100644
index 000000000..b81ab9422
--- /dev/null
+++ b/apm-sniffer/optional-plugins/optional-spring-plugins/mvc-annotation-6.x-plugin/src/main/resources/skywalking-plugin.def
@@ -0,0 +1,22 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+spring-mvc-annotation-6.x=org.apache.skywalking.apm.plugin.spring.mvc.v6.define.ControllerInstrumentation
+spring-mvc-annotation-6.x=org.apache.skywalking.apm.plugin.spring.mvc.v6.define.RestControllerInstrumentation
+spring-mvc-annotation-6.x=org.apache.skywalking.apm.plugin.spring.mvc.v6.define.HandlerMethodInstrumentation
+spring-mvc-annotation-6.x=org.apache.skywalking.apm.plugin.spring.mvc.v6.define.reactive.InvocableHandlerMethodInstrumentation
+spring-mvc-annotation-6.x=org.apache.skywalking.apm.plugin.spring.mvc.v6.define.reactive.ReactiveControllerInstrumentation
+spring-mvc-annotation-6.x=org.apache.skywalking.apm.plugin.spring.mvc.v6.define.reactive.ReactiveRestControllerInstrumentation
diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-2.1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/cloud/gateway/v21x/NettyRoutingFilterInterceptorTest.java b/apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-2.1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/cloud/gateway/v21x/NettyRoutingFilterInterceptorTest.java
index 94e608155..43d75b0ce 100644
--- a/apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-2.1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/cloud/gateway/v21x/NettyRoutingFilterInterceptorTest.java
+++ b/apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-2.1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/cloud/gateway/v21x/NettyRoutingFilterInterceptorTest.java
@@ -33,8 +33,8 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.modules.junit4.PowerMockRunnerDelegate;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import org.springframework.context.ApplicationContext;
import org.springframework.context.i18n.LocaleContext;
import org.springframework.http.codec.multipart.Part;
@@ -45,12 +45,14 @@ import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebSession;
import reactor.core.publisher.Mono;
-@RunWith(PowerMockRunner.class)
-@PowerMockRunnerDelegate(TracingSegmentRunner.class)
+@RunWith(TracingSegmentRunner.class)
public class NettyRoutingFilterInterceptorTest {
private final NettyRoutingFilterInterceptor interceptor = new NettyRoutingFilterInterceptor();
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
+ @Rule
+ public MockitoRule rule = MockitoJUnit.rule();
+
@SegmentStoragePoint
private SegmentStorage segmentStorage;
diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-2.1.x-plugin/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-2.1.x-plugin/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
new file mode 100644
index 000000000..1f0955d45
--- /dev/null
+++ b/apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-2.1.x-plugin/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
@@ -0,0 +1 @@
+mock-maker-inline
diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/cloud/gateway/v3x/HttpClientFinalizerConstructorInterceptorTest.java b/apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/cloud/gateway/v3x/HttpClientFinalizerConstructorInterceptorTest.java
index f91d5b385..eac588955 100644
--- a/apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/cloud/gateway/v3x/HttpClientFinalizerConstructorInterceptorTest.java
+++ b/apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/cloud/gateway/v3x/HttpClientFinalizerConstructorInterceptorTest.java
@@ -18,22 +18,19 @@
package org.apache.skywalking.apm.plugin.spring.cloud.gateway.v3x;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.plugin.spring.cloud.gateway.v3x.define.EnhanceObjectCache;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
+import org.mockito.junit.MockitoJUnitRunner;
import reactor.netty.http.client.HttpClientConfig;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.powermock.api.mockito.PowerMockito.mock;
-import static org.powermock.api.mockito.PowerMockito.when;
-
-@RunWith(PowerMockRunner.class)
-@PrepareForTest(HttpClientConfig.class)
+@RunWith(MockitoJUnitRunner.class)
public class HttpClientFinalizerConstructorInterceptorTest {
private static final String URI = "http://localhost:8080/get";
@@ -67,4 +64,4 @@ public class HttpClientFinalizerConstructorInterceptorTest {
assertNotNull(enhanceCache);
assertEquals(enhanceCache.getUrl(), URI);
}
-}
\ No newline at end of file
+}
diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/cloud/gateway/v3x/HttpClientFinalizerInterceptorTest.java b/apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/cloud/gateway/v3x/HttpClientFinalizerInterceptorTest.java
index b3bfbde11..a9e4575da 100644
--- a/apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/cloud/gateway/v3x/HttpClientFinalizerInterceptorTest.java
+++ b/apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/cloud/gateway/v3x/HttpClientFinalizerInterceptorTest.java
@@ -18,7 +18,11 @@
package org.apache.skywalking.apm.plugin.spring.cloud.gateway.v3x;
-import io.netty.handler.codec.http.HttpResponseStatus;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import java.util.List;
+import java.util.function.BiFunction;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
@@ -37,24 +41,17 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.modules.junit4.PowerMockRunnerDelegate;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import org.reactivestreams.Publisher;
+import io.netty.handler.codec.http.HttpResponseStatus;
import reactor.core.publisher.Flux;
import reactor.netty.Connection;
import reactor.netty.NettyOutbound;
import reactor.netty.http.client.HttpClientRequest;
import reactor.netty.http.client.HttpClientResponse;
-import java.util.List;
-import java.util.function.BiFunction;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-@RunWith(PowerMockRunner.class)
-@PowerMockRunnerDelegate(TracingSegmentRunner.class)
+@RunWith(TracingSegmentRunner.class)
public class HttpClientFinalizerInterceptorTest {
private final static String URI = "http://localhost:8080/get";
@@ -80,6 +77,9 @@ public class HttpClientFinalizerInterceptorTest {
};
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
+ @Rule
+ public MockitoRule rule = MockitoJUnit.rule();
+
private HttpClientResponse mockResponse;
private HttpClientRequest mockRequest;
@SegmentStoragePoint
@@ -155,7 +155,7 @@ public class HttpClientFinalizerInterceptorTest {
Flux flux = Flux.just(0);
flux = (Flux) responseConnectionInterceptor.afterMethod(enhancedInstance, null, new Object[0], null, flux);
-
+
((BiFunction super HttpClientResponse, ? super Connection, ? extends Publisher>) responseConnectionArguments[0])
.apply(mockResponse, null);
flux.blockFirst();
@@ -173,4 +173,4 @@ public class HttpClientFinalizerInterceptorTest {
SpanAssert.assertTag(span, 0, URI);
SpanAssert.assertTag(span, 1, String.valueOf(HttpResponseStatus.OK.code()));
}
-}
\ No newline at end of file
+}
diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/cloud/gateway/v3x/NettyRoutingFilterInterceptorTest.java b/apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/cloud/gateway/v3x/NettyRoutingFilterInterceptorTest.java
index 47b76c427..36a262ab3 100644
--- a/apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/cloud/gateway/v3x/NettyRoutingFilterInterceptorTest.java
+++ b/apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/cloud/gateway/v3x/NettyRoutingFilterInterceptorTest.java
@@ -21,6 +21,7 @@ package org.apache.skywalking.apm.plugin.spring.cloud.gateway.v3x;
import java.security.Principal;
import java.time.Instant;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.function.Function;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
@@ -42,10 +43,8 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.modules.junit4.PowerMockRunnerDelegate;
-
-import java.util.List;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import org.springframework.context.ApplicationContext;
import org.springframework.context.i18n.LocaleContext;
import org.springframework.http.codec.multipart.Part;
@@ -56,8 +55,7 @@ import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebSession;
import reactor.core.publisher.Mono;
-@RunWith(PowerMockRunner.class)
-@PowerMockRunnerDelegate(TracingSegmentRunner.class)
+@RunWith(TracingSegmentRunner.class)
public class NettyRoutingFilterInterceptorTest {
private static class ServerWebExchangeEnhancedInstance implements ServerWebExchange, EnhancedInstance {
private ContextSnapshot snapshot;
@@ -158,6 +156,9 @@ public class NettyRoutingFilterInterceptorTest {
private final NettyRoutingFilterInterceptor interceptor = new NettyRoutingFilterInterceptor();
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
+ @Rule
+ public MockitoRule rule = MockitoJUnit.rule();
+
@SegmentStoragePoint
private SegmentStorage segmentStorage;
@@ -214,4 +215,4 @@ public class NettyRoutingFilterInterceptorTest {
interceptor.afterMethod(null, null, null, null, null);
Assert.assertEquals(enhancedInstance.getAttributes().get(NETTY_ROUTING_FILTER_TRACED_ATTR), true);
}
-}
\ No newline at end of file
+}
diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-3.x-plugin/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-3.x-plugin/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
new file mode 100644
index 000000000..1f0955d45
--- /dev/null
+++ b/apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-3.x-plugin/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
@@ -0,0 +1 @@
+mock-maker-inline
diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/pom.xml b/apm-sniffer/optional-plugins/optional-spring-plugins/pom.xml
index 4b1730ceb..353709238 100644
--- a/apm-sniffer/optional-plugins/optional-spring-plugins/pom.xml
+++ b/apm-sniffer/optional-plugins/optional-spring-plugins/pom.xml
@@ -33,6 +33,8 @@
spring-tx-plugin
optional-spring-cloud
spring-webflux-5.x-plugin
+ resttemplate-6.x-plugin
+ mvc-annotation-6.x-plugin
diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/resttemplate-6.x-plugin/pom.xml b/apm-sniffer/optional-plugins/optional-spring-plugins/resttemplate-6.x-plugin/pom.xml
new file mode 100644
index 000000000..ecad2c024
--- /dev/null
+++ b/apm-sniffer/optional-plugins/optional-spring-plugins/resttemplate-6.x-plugin/pom.xml
@@ -0,0 +1,51 @@
+
+
+
+
+ optional-spring-plugins
+ org.apache.skywalking
+ 8.15.0-SNAPSHOT
+
+
+ 4.0.0
+
+ apm-resttemplate-6.x-plugin
+ jar
+
+ resttemplate-6.x-plugin
+
+
+ 6.0.0
+
+
+
+
+ org.springframework
+ spring-web
+ ${spring-web.version}
+ provided
+
+
+
+ org.apache.skywalking
+ spring-commons
+ ${project.version}
+
+
+
diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/resttemplate-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/v6x/helper/RestTemplateRuntimeContextHelper.java b/apm-sniffer/optional-plugins/optional-spring-plugins/resttemplate-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/v6x/helper/RestTemplateRuntimeContextHelper.java
new file mode 100644
index 000000000..bed866a0b
--- /dev/null
+++ b/apm-sniffer/optional-plugins/optional-spring-plugins/resttemplate-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/v6x/helper/RestTemplateRuntimeContextHelper.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.apm.plugin.spring.resttemplate.v6x.helper;
+
+import org.apache.skywalking.apm.agent.core.context.ContextCarrier;
+import org.apache.skywalking.apm.agent.core.context.ContextManager;
+
+public class RestTemplateRuntimeContextHelper {
+
+ private static final String REST_TEMPLATE_CONTEXT_CARRIER_KEY_IN_RUNTIME_CONTEXT = "REST_TEMPLATE_CONTEXT_CARRIER";
+
+ private static final String REST_TEMPLATE_URI_KEY_IN_RUNTIME_CONTEXT = "REST_TEMPLATE_URI";
+
+ public static void cleanUri() {
+ ContextManager.getRuntimeContext().remove(REST_TEMPLATE_URI_KEY_IN_RUNTIME_CONTEXT);
+ }
+
+ public static void cleanContextCarrier() {
+ ContextManager.getRuntimeContext().remove(REST_TEMPLATE_CONTEXT_CARRIER_KEY_IN_RUNTIME_CONTEXT);
+ }
+
+ public static void addUri(String uri) {
+ ContextManager.getRuntimeContext().put(REST_TEMPLATE_URI_KEY_IN_RUNTIME_CONTEXT, uri);
+ }
+
+ public static void addContextCarrier(ContextCarrier contextCarrier) {
+ ContextManager.getRuntimeContext().put(REST_TEMPLATE_CONTEXT_CARRIER_KEY_IN_RUNTIME_CONTEXT, contextCarrier);
+ }
+
+ public static String getUri() {
+ return (String) ContextManager.getRuntimeContext().get(REST_TEMPLATE_URI_KEY_IN_RUNTIME_CONTEXT);
+ }
+
+ public static ContextCarrier getContextCarrier() {
+ return (ContextCarrier) ContextManager.getRuntimeContext().get(REST_TEMPLATE_CONTEXT_CARRIER_KEY_IN_RUNTIME_CONTEXT);
+ }
+}
diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/resttemplate-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/v6x/sync/RestExecuteInterceptor.java b/apm-sniffer/optional-plugins/optional-spring-plugins/resttemplate-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/v6x/sync/RestExecuteInterceptor.java
new file mode 100644
index 000000000..7b9e7398e
--- /dev/null
+++ b/apm-sniffer/optional-plugins/optional-spring-plugins/resttemplate-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/v6x/sync/RestExecuteInterceptor.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.apm.plugin.spring.resttemplate.v6x.sync;
+
+import java.lang.reflect.Method;
+import java.net.URI;
+import org.apache.skywalking.apm.agent.core.context.ContextCarrier;
+import org.apache.skywalking.apm.agent.core.context.ContextManager;
+import org.apache.skywalking.apm.agent.core.context.tag.Tags;
+import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
+import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
+import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
+import org.apache.skywalking.apm.plugin.spring.resttemplate.v6x.helper.RestTemplateRuntimeContextHelper;
+import org.springframework.http.HttpMethod;
+
+public class RestExecuteInterceptor implements InstanceMethodsAroundInterceptor {
+ @Override
+ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class>[] argumentsTypes,
+ MethodInterceptResult result) throws Throwable {
+ final URI requestURL = (URI) allArguments[0];
+ final HttpMethod httpMethod = (HttpMethod) allArguments[2];
+ final ContextCarrier contextCarrier = new ContextCarrier();
+
+ String remotePeer = requestURL.getHost() + ":" + (requestURL.getPort() > 0 ? requestURL.getPort() : "https".equalsIgnoreCase(requestURL
+ .getScheme()) ? 443 : 80);
+ String formatURIPath = requestURL.getPath();
+ AbstractSpan span = ContextManager.createExitSpan(formatURIPath, contextCarrier, remotePeer);
+
+ span.setComponent(ComponentsDefine.SPRING_REST_TEMPLATE);
+ Tags.URL.set(span, requestURL.getScheme() + "://" + requestURL.getHost() +
+ (requestURL.getPort() > 0 ? ":" + requestURL.getPort() : "") + requestURL.getPath());
+ Tags.HTTP.METHOD.set(span, httpMethod.toString());
+ SpanLayer.asHttp(span);
+
+ RestTemplateRuntimeContextHelper.addContextCarrier(contextCarrier);
+ }
+
+ @Override
+ public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class>[] argumentsTypes,
+ Object ret) throws Throwable {
+ RestTemplateRuntimeContextHelper.cleanContextCarrier();
+ ContextManager.stopSpan();
+ return ret;
+ }
+
+ @Override
+ public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
+ Class>[] argumentsTypes, Throwable t) {
+ ContextManager.activeSpan().log(t);
+ }
+}
diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/resttemplate-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/v6x/sync/RestRequestInterceptor.java b/apm-sniffer/optional-plugins/optional-spring-plugins/resttemplate-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/v6x/sync/RestRequestInterceptor.java
new file mode 100644
index 000000000..455b897c5
--- /dev/null
+++ b/apm-sniffer/optional-plugins/optional-spring-plugins/resttemplate-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/v6x/sync/RestRequestInterceptor.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.apm.plugin.spring.resttemplate.v6x.sync;
+
+import java.lang.reflect.Method;
+import org.apache.skywalking.apm.agent.core.context.CarrierItem;
+import org.apache.skywalking.apm.agent.core.context.ContextCarrier;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
+import org.apache.skywalking.apm.plugin.spring.resttemplate.v6x.helper.RestTemplateRuntimeContextHelper;
+import org.springframework.http.client.AbstractClientHttpRequest;
+import org.springframework.http.client.ClientHttpRequest;
+
+public class RestRequestInterceptor implements InstanceMethodsAroundInterceptor {
+
+ @Override
+ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class>[] argumentsTypes,
+ MethodInterceptResult result) throws Throwable {
+
+ }
+
+ @Override
+ public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class>[] argumentsTypes,
+ Object ret) throws Throwable {
+ ClientHttpRequest clientHttpRequest = (ClientHttpRequest) ret;
+ if (clientHttpRequest instanceof AbstractClientHttpRequest) {
+ AbstractClientHttpRequest httpRequest = (AbstractClientHttpRequest) clientHttpRequest;
+ ContextCarrier contextCarrier = RestTemplateRuntimeContextHelper.getContextCarrier();
+ CarrierItem next = contextCarrier.items();
+ while (next.hasNext()) {
+ next = next.next();
+ httpRequest.getHeaders().set(next.getHeadKey(), next.getHeadValue());
+ }
+ }
+ return ret;
+ }
+
+ @Override
+ public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
+ Class>[] argumentsTypes, Throwable t) {
+
+ }
+}
diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/resttemplate-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/v6x/sync/RestResponseInterceptor.java b/apm-sniffer/optional-plugins/optional-spring-plugins/resttemplate-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/v6x/sync/RestResponseInterceptor.java
new file mode 100644
index 000000000..3975562df
--- /dev/null
+++ b/apm-sniffer/optional-plugins/optional-spring-plugins/resttemplate-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/v6x/sync/RestResponseInterceptor.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.apm.plugin.spring.resttemplate.v6x.sync;
+
+import java.lang.reflect.Method;
+import org.apache.skywalking.apm.agent.core.context.tag.Tags;
+import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
+import org.apache.skywalking.apm.agent.core.context.ContextManager;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
+import org.springframework.http.client.ClientHttpResponse;
+
+public class RestResponseInterceptor implements InstanceMethodsAroundInterceptor {
+
+ @Override
+ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class>[] argumentsTypes,
+ MethodInterceptResult result) throws Throwable {
+
+ }
+
+ @Override
+ public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class>[] argumentsTypes,
+ Object ret) throws Throwable {
+
+ ClientHttpResponse response = (ClientHttpResponse) allArguments[2];
+ int statusCode = response.getStatusCode().value();
+ AbstractSpan span = ContextManager.activeSpan();
+ Tags.HTTP_RESPONSE_STATUS_CODE.set(span, statusCode);
+ if (statusCode >= 400) {
+ span.errorOccurred();
+ }
+ return ret;
+ }
+
+ @Override
+ public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
+ Class>[] argumentsTypes, Throwable t) {
+ ContextManager.activeSpan().log(t);
+ }
+}
diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/resttemplate-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/v6x/sync/define/RestTemplateInstrumentation.java b/apm-sniffer/optional-plugins/optional-spring-plugins/resttemplate-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/v6x/sync/define/RestTemplateInstrumentation.java
new file mode 100644
index 000000000..c9fdb3823
--- /dev/null
+++ b/apm-sniffer/optional-plugins/optional-spring-plugins/resttemplate-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/v6x/sync/define/RestTemplateInstrumentation.java
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.apm.plugin.spring.resttemplate.v6x.sync.define;
+
+import net.bytebuddy.description.method.MethodDescription;
+import net.bytebuddy.matcher.ElementMatcher;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
+import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
+
+import static net.bytebuddy.matcher.ElementMatchers.named;
+import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
+
+/**
+ * {@link RestTemplateInstrumentation} enhance the doExecute method,handleResponse method and
+ * handleResponse method of org.springframework.web.client.RestTemplate by
+ * RestExecuteInterceptor,
+ * RestResponseInterceptor and
+ * RestRequestInterceptor.
+ *
+ * RestResponseInterceptor set context to header for
+ * propagate trace context after execute createRequest.
+ */
+public class RestTemplateInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
+
+ private static final String ENHANCE_CLASS = "org.springframework.web.client.RestTemplate";
+ private static final String DO_EXECUTE_METHOD_NAME = "doExecute";
+ private static final String DO_EXECUTE_INTERCEPTOR = "org.apache.skywalking.apm.plugin.spring.resttemplate.v6x.sync.RestExecuteInterceptor";
+ private static final String HANDLE_REQUEST_METHOD_NAME = "handleResponse";
+ private static final String HAND_REQUEST_INTERCEPTOR = "org.apache.skywalking.apm.plugin.spring.resttemplate.v6x.sync.RestResponseInterceptor";
+ private static final String CREATE_REQUEST_METHOD_NAME = "createRequest";
+ private static final String CREATE_REQUEST_INTERCEPTOR = "org.apache.skywalking.apm.plugin.spring.resttemplate.v6x.sync.RestRequestInterceptor";
+
+ @Override
+ public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
+ return new ConstructorInterceptPoint[0];
+ }
+
+ @Override
+ public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
+ return new InstanceMethodsInterceptPoint[] {
+ new InstanceMethodsInterceptPoint() {
+ @Override
+ public ElementMatcher getMethodsMatcher() {
+ return named(DO_EXECUTE_METHOD_NAME);
+ }
+
+ @Override
+ public String getMethodsInterceptor() {
+ return DO_EXECUTE_INTERCEPTOR;
+ }
+
+ @Override
+ public boolean isOverrideArgs() {
+ return false;
+ }
+ },
+ new InstanceMethodsInterceptPoint() {
+ @Override
+ public ElementMatcher getMethodsMatcher() {
+ return named(HANDLE_REQUEST_METHOD_NAME);
+ }
+
+ @Override
+ public String getMethodsInterceptor() {
+ return HAND_REQUEST_INTERCEPTOR;
+ }
+
+ @Override
+ public boolean isOverrideArgs() {
+ return false;
+ }
+ },
+ new InstanceMethodsInterceptPoint() {
+ @Override
+ public ElementMatcher getMethodsMatcher() {
+ return named(CREATE_REQUEST_METHOD_NAME);
+ }
+
+ @Override
+ public String getMethodsInterceptor() {
+ return CREATE_REQUEST_INTERCEPTOR;
+ }
+
+ @Override
+ public boolean isOverrideArgs() {
+ return false;
+ }
+ }
+ };
+ }
+
+ @Override
+ protected ClassMatch enhanceClass() {
+ return byName(ENHANCE_CLASS);
+ }
+
+ @Override
+ protected String[] witnessClasses() {
+ return new String[] {
+ "org.springframework.web.client.ClientHttpResponseDecorator"
+ };
+ }
+}
diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/resttemplate-6.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/optional-plugins/optional-spring-plugins/resttemplate-6.x-plugin/src/main/resources/skywalking-plugin.def
new file mode 100644
index 000000000..2499f4bb2
--- /dev/null
+++ b/apm-sniffer/optional-plugins/optional-spring-plugins/resttemplate-6.x-plugin/src/main/resources/skywalking-plugin.def
@@ -0,0 +1,17 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+spring-resttemplate-6.x=org.apache.skywalking.apm.plugin.spring.resttemplate.v6x.sync.define.RestTemplateInstrumentation
diff --git a/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/define/ServerWebExchangeInstrumentation.java b/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/define/ServerWebExchangeInstrumentation.java
index d04e69f5e..7660abf1b 100644
--- a/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/define/ServerWebExchangeInstrumentation.java
+++ b/apm-sniffer/optional-plugins/shenyu-2.4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shenyu/v24x/define/ServerWebExchangeInstrumentation.java
@@ -18,7 +18,6 @@
package org.apache.skywalking.apm.plugin.shenyu.v24x.define;
-
/**
* Since all plugins have access to the ServerWebExchange and the plugins are processed in asynchronous threads,
* we can put the snapshot into the enhanced ServerWebExchange object.
diff --git a/apm-sniffer/optional-plugins/trace-ignore-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/ignore/matcher/FastPathMatcher.java b/apm-sniffer/optional-plugins/trace-ignore-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/ignore/matcher/FastPathMatcher.java
index eb79e5dd0..d89a56bf8 100644
--- a/apm-sniffer/optional-plugins/trace-ignore-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/ignore/matcher/FastPathMatcher.java
+++ b/apm-sniffer/optional-plugins/trace-ignore-plugin/src/main/java/org/apache/skywalking/apm/plugin/trace/ignore/matcher/FastPathMatcher.java
@@ -64,7 +64,7 @@ public class FastPathMatcher implements TracePathMatcher {
// pattern: a/?/c a/b/c a/b
// ↓ ↓ ↓
// string: a/b/c a/b/d a/d
- if ((pc == '?' && sc != 0 && sc != '/') || pc == sc) {
+ if (pc == '?' && sc != 0 && sc != '/' || pc == sc) {
s++;
p++;
continue;
diff --git a/apm-sniffer/optional-plugins/trace-ignore-plugin/src/test/java/org/apache/skywalking/apm/plugin/trace/ignore/TraceIgnorePatternWatcherTest.java b/apm-sniffer/optional-plugins/trace-ignore-plugin/src/test/java/org/apache/skywalking/apm/plugin/trace/ignore/TraceIgnorePatternWatcherTest.java
index ef97e510e..d8c2ff96b 100644
--- a/apm-sniffer/optional-plugins/trace-ignore-plugin/src/test/java/org/apache/skywalking/apm/plugin/trace/ignore/TraceIgnorePatternWatcherTest.java
+++ b/apm-sniffer/optional-plugins/trace-ignore-plugin/src/test/java/org/apache/skywalking/apm/plugin/trace/ignore/TraceIgnorePatternWatcherTest.java
@@ -21,12 +21,12 @@ package org.apache.skywalking.apm.plugin.trace.ignore;
import org.apache.skywalking.apm.agent.core.boot.ServiceManager;
import org.apache.skywalking.apm.agent.core.conf.dynamic.AgentConfigChangeWatcher;
import org.apache.skywalking.apm.agent.core.sampling.SamplingService;
+import org.apache.skywalking.apm.agent.test.helper.FieldGetter;
import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
-import org.powermock.reflect.Whitebox;
public class TraceIgnorePatternWatcherTest {
@@ -42,9 +42,9 @@ public class TraceIgnorePatternWatcherTest {
}
@Test
- public void testConfigModifyEvent() {
- TraceIgnorePatternWatcher traceIgnorePatternWatcher = Whitebox.getInternalState(traceIgnoreExtendService
- , "traceIgnorePatternWatcher");
+ public void testConfigModifyEvent() throws IllegalAccessException, NoSuchFieldException {
+ TraceIgnorePatternWatcher traceIgnorePatternWatcher =
+ FieldGetter.getValue(traceIgnoreExtendService, "traceIgnorePatternWatcher");
traceIgnorePatternWatcher.notify(new AgentConfigChangeWatcher.ConfigChangeEvent(
"/eureka/apps/**",
AgentConfigChangeWatcher.EventType.MODIFY
@@ -54,9 +54,9 @@ public class TraceIgnorePatternWatcherTest {
}
@Test
- public void testConfigDeleteEvent() {
- TraceIgnorePatternWatcher traceIgnorePatternWatcher = Whitebox.getInternalState(traceIgnoreExtendService
- , "traceIgnorePatternWatcher");
+ public void testConfigDeleteEvent() throws IllegalAccessException, NoSuchFieldException {
+ TraceIgnorePatternWatcher traceIgnorePatternWatcher =
+ FieldGetter.getValue(traceIgnoreExtendService, "traceIgnorePatternWatcher");
traceIgnorePatternWatcher.notify(new AgentConfigChangeWatcher.ConfigChangeEvent(
null,
AgentConfigChangeWatcher.EventType.DELETE
diff --git a/apm-sniffer/optional-plugins/trace-ignore-plugin/src/test/java/org/apache/skywalking/apm/plugin/trace/ignore/TraceIgnoreTest.java b/apm-sniffer/optional-plugins/trace-ignore-plugin/src/test/java/org/apache/skywalking/apm/plugin/trace/ignore/TraceIgnoreTest.java
index 78d2b01df..417b98958 100644
--- a/apm-sniffer/optional-plugins/trace-ignore-plugin/src/test/java/org/apache/skywalking/apm/plugin/trace/ignore/TraceIgnoreTest.java
+++ b/apm-sniffer/optional-plugins/trace-ignore-plugin/src/test/java/org/apache/skywalking/apm/plugin/trace/ignore/TraceIgnoreTest.java
@@ -18,6 +18,9 @@
package org.apache.skywalking.apm.plugin.trace.ignore;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import java.lang.reflect.Field;
import java.util.Properties;
import org.apache.skywalking.apm.agent.core.boot.ServiceManager;
import org.apache.skywalking.apm.agent.core.sampling.SamplingService;
@@ -29,10 +32,6 @@ import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.EnvironmentVariables;
-import org.powermock.reflect.Whitebox;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
public class TraceIgnoreTest {
@@ -50,10 +49,12 @@ public class TraceIgnoreTest {
}
@Test
- public void testTraceIgnore() {
+ public void testTraceIgnore() throws Exception {
SamplingService service = ServiceManager.INSTANCE.findService(SamplingService.class);
- Whitebox.setInternalState(
- service, "patterns",
+ Field patterns = TraceIgnoreExtendService.class.getDeclaredField("patterns");
+ patterns.setAccessible(true);
+ patterns.set(
+ service,
new String[] {"/eureka/**"}
);
diff --git a/apm-sniffer/optional-plugins/zookeeper-3.4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/zookeeper/ClientCnxnInterceptorTest.java b/apm-sniffer/optional-plugins/zookeeper-3.4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/zookeeper/ClientCnxnInterceptorTest.java
index 6aa4c4c2e..37229ef2f 100644
--- a/apm-sniffer/optional-plugins/zookeeper-3.4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/zookeeper/ClientCnxnInterceptorTest.java
+++ b/apm-sniffer/optional-plugins/zookeeper-3.4.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/zookeeper/ClientCnxnInterceptorTest.java
@@ -18,6 +18,11 @@
package org.apache.skywalking.apm.plugin.zookeeper;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.List;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
@@ -40,18 +45,10 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.modules.junit4.PowerMockRunnerDelegate;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
-import java.net.InetSocketAddress;
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-@RunWith(PowerMockRunner.class)
-@PowerMockRunnerDelegate(TracingSegmentRunner.class)
+@RunWith(TracingSegmentRunner.class)
public class ClientCnxnInterceptorTest {
@SegmentStoragePoint
@@ -59,6 +56,8 @@ public class ClientCnxnInterceptorTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
+ @Rule
+ public MockitoRule rule = MockitoJUnit.rule();
@Mock
private MockInstance instance;
diff --git a/apm-sniffer/optional-plugins/zookeeper-3.4.x-plugin/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/apm-sniffer/optional-plugins/zookeeper-3.4.x-plugin/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
new file mode 100644
index 000000000..1f0955d45
--- /dev/null
+++ b/apm-sniffer/optional-plugins/zookeeper-3.4.x-plugin/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
@@ -0,0 +1 @@
+mock-maker-inline
diff --git a/apm-sniffer/optional-reporter-plugins/kafka-reporter-plugin/src/test/java/org/apache/skywalking/apm/agent/core/kafka/KafkaProducerManagerTest.java b/apm-sniffer/optional-reporter-plugins/kafka-reporter-plugin/src/test/java/org/apache/skywalking/apm/agent/core/kafka/KafkaProducerManagerTest.java
index 00031a505..20dc5935d 100644
--- a/apm-sniffer/optional-reporter-plugins/kafka-reporter-plugin/src/test/java/org/apache/skywalking/apm/agent/core/kafka/KafkaProducerManagerTest.java
+++ b/apm-sniffer/optional-reporter-plugins/kafka-reporter-plugin/src/test/java/org/apache/skywalking/apm/agent/core/kafka/KafkaProducerManagerTest.java
@@ -18,12 +18,10 @@
package org.apache.skywalking.apm.agent.core.kafka;
-import org.junit.Test;
-import org.powermock.reflect.Whitebox;
-
-import java.util.concurrent.atomic.AtomicInteger;
-
import static org.junit.Assert.assertEquals;
+import java.lang.reflect.Method;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.junit.Test;
public class KafkaProducerManagerTest {
@Test
@@ -34,7 +32,11 @@ public class KafkaProducerManagerTest {
for (int i = 0; i < times; i++) {
kafkaProducerManager.addListener(new MockListener(counter));
}
- Whitebox.invokeMethod(kafkaProducerManager, "notifyListeners", KafkaConnectionStatus.CONNECTED);
+ Method notifyListeners = kafkaProducerManager
+ .getClass()
+ .getDeclaredMethod("notifyListeners", KafkaConnectionStatus.class);
+ notifyListeners.setAccessible(true);
+ notifyListeners.invoke(kafkaProducerManager, KafkaConnectionStatus.CONNECTED);
assertEquals(counter.get(), times);
}
diff --git a/docs/en/setup/service-agent/java-agent/Optional-plugins.md b/docs/en/setup/service-agent/java-agent/Optional-plugins.md
index ffc684900..7272790a7 100644
--- a/docs/en/setup/service-agent/java-agent/Optional-plugins.md
+++ b/docs/en/setup/service-agent/java-agent/Optional-plugins.md
@@ -9,7 +9,7 @@ Now, we have the following known optional plugins.
* Plugin of Gson serialization lib in optional plugin folder.
* Plugin of Zookeeper 3.4.x in optional plugin folder. The reason of being optional plugin is, many business irrelevant traces are generated, which cause extra payload to agents and backends. At the same time, those traces may be just heartbeat(s).
* [Customize enhance](Customize-enhance-trace.md) Trace methods based on description files, rather than write plugin or change source codes.
-* Plugin of Spring Cloud Gateway 2.x and 3.x in optional plugin folder. Please only activate this plugin when you install agent in Spring Gateway.
+* Plugin of Spring Cloud Gateway 2.x and 3.x in optional plugin folder. Please only activate this plugin when you install agent in Spring Gateway.
* Plugin of Spring Transaction in optional plugin folder. The reason of being optional plugin is, many local span are generated, which also spend more CPU, memory and network.
* [Plugin of Kotlin coroutine](agent-optional-plugins/Kotlin-Coroutine-plugin.md) provides the tracing across coroutines automatically. As it will add local spans to all across routines scenarios, Please assess the performance impact.
* Plugin of quartz-scheduler-2.x in the optional plugin folder. The reason for being an optional plugin is, many task scheduling systems are based on quartz-scheduler, this will cause duplicate tracing and link different sub-tasks as they share the same quartz level trigger, such as ElasticJob.
@@ -22,3 +22,4 @@ Now, we have the following known optional plugins.
* Plugin of jackson serialization lib in optional plugin folder.
* Plugin of Apache ShenYu(incubating) Gateway 2.4.x in optional plugin folder. Please only activate this plugin when you install agent in Apache ShenYu Gateway.
* Plugin of trace sampler CPU policy in the optional plugin folder. Please only activate this plugin when you need to disable trace collecting when the agent process CPU usage is too high(over threshold).
+* Plugin for Spring 6.x and RestTemplate 6.x are in the optional plugin folder. Spring 6 requires Java 17 but SkyWalking is still compatible with Java 8. So, we put it in the optional plugin folder.
diff --git a/docs/en/setup/service-agent/java-agent/Plugin-list.md b/docs/en/setup/service-agent/java-agent/Plugin-list.md
index d3c83a07f..651b15f2f 100644
--- a/docs/en/setup/service-agent/java-agent/Plugin-list.md
+++ b/docs/en/setup/service-agent/java-agent/Plugin-list.md
@@ -104,7 +104,9 @@
- spring-mvc-annotation-3.x
- spring-mvc-annotation-4.x
- spring-mvc-annotation-5.x
+- spring-mvc-annotation-6.x
- spring-resttemplate-4.x
+- spring-resttemplate-6.x
- spring-scheduled-annotation
- spring-tx
- spring-webflux-5.x
diff --git a/docs/en/setup/service-agent/java-agent/Supported-list.md b/docs/en/setup/service-agent/java-agent/Supported-list.md
index 979654460..4b8973828 100644
--- a/docs/en/setup/service-agent/java-agent/Supported-list.md
+++ b/docs/en/setup/service-agent/java-agent/Supported-list.md
@@ -1,5 +1,5 @@
# Tracing and Tracing based Metrics Analyze Plugins
-The following plugins provide the distributed tracing capability, and the OAP backend would analyze the topology and
+The following plugins provide the distributed tracing capability, and the OAP backend would analyze the topology and
metrics based on the tracing data.
* HTTP Server
@@ -9,6 +9,7 @@ metrics based on the tracing data.
* [Tomcat](https://github.com/apache/tomcat) 10
* [Spring Boot](https://github.com/spring-projects/spring-boot) Web 4.x
* Spring MVC 3.x, 4.x 5.x with servlet 3.x
+ * Spring MVC 6.x (Optional²)
* [Nutz Web Framework](https://github.com/nutzam/nutz) 1.x
* [Struts2 MVC](http://struts.apache.org/) 2.3.x -> 2.5.x
* [Resin](https://www.caucho.com/resin-4.0/) 3 (Optional¹)
@@ -27,6 +28,7 @@ metrics based on the tracing data.
* [Okhttp](https://github.com/square/okhttp) 2.x -> 3.x -> 4.x
* [Apache httpcomponent HttpClient](http://hc.apache.org/) 2.0 -> 3.1, 4.2, 4.3, 5.0, 5.1
* [Spring RestTemplate](https://github.com/spring-projects/spring-framework) 4.x
+ * [Spring RestTemplate](https://github.com/spring-projects/spring-framework) 6.x (Optional²)
* [Jetty Client](http://www.eclipse.org/jetty/) 9
* [Apache httpcomponent AsyncClient](https://hc.apache.org/httpcomponents-asyncclient-4.1.x/) 4.x
* [AsyncHttpClient](https://github.com/AsyncHttpClient/async-http-client) 2.1+
@@ -138,7 +140,7 @@ metrics based on the tracing data.
* [HikariCP](https://github.com/brettwooldridge/HikariCP) 3.x -> 4.x
* Logging Framework
* [log4j](https://github.com/apache/log4j) 2.x
- * [log4j2](https://github.com/apache/logging-log4j2) 1.2.x
+ * [log4j2](https://github.com/apache/logging-log4j2) 1.2.x
* [logback](https://github.com/qos-ch/logback) 1.2.x
* ORM
* [MyBatis](https://github.com/mybatis/mybatis-3) 3.4.x -> 3.5.x
@@ -153,7 +155,7 @@ The meter plugin provides the advanced metrics collections, which are not a part
* [Tomcat](https://github.com/apache/tomcat) 7.0.x -> 10.0.x
* [Dubbo](https://github.com/apache/dubbo) 2.5.x -> 2.7.x
___
-¹Due to license incompatibilities/restrictions these plugins are hosted and released in 3rd part repository,
+¹Due to license incompatibilities/restrictions these plugins are hosted and released in 3rd part repository,
go to [SkyAPM java plugin extension repository](https://github.com/SkyAPM/java-plugin-extensions) to get these.
²These plugins affect the performance or must be used under some conditions, from experiences. So only released in `/optional-plugins` or `/bootstrap-plugins`, copy to `/plugins` in order to make them work.
diff --git a/pom.xml b/pom.xml
index 510c4b083..1a1276501 100755
--- a/pom.xml
+++ b/pom.xml
@@ -78,11 +78,11 @@
UTF-8
- 1.8
- 2.0.7
+ 8
6.18
4.12
- 3.5.13
+ 5.0.0
+ 2.0.2
1.18.20
@@ -113,12 +113,12 @@
3.1.0
3.1.1
3.0.0-M2
- 3.8.0
+ 3.10.1
3.1.0
3.0.1
2.5
4.3.0
- 3.1.0
+ 3.2.1
1.33
1.5
true
@@ -168,16 +168,6 @@
junit
test
-
- org.powermock
- powermock-module-junit4
- test
-
-
- org.powermock
- powermock-api-mockito2
- test
-
net.bytebuddy
byte-buddy-agent
@@ -208,6 +198,17 @@
${javax.annotation-api.version}
provided
+
+
+ org.mockito
+ mockito-core
+ test
+
+
+ org.mockito
+ mockito-inline
+ test
+
@@ -225,17 +226,18 @@
test
- org.powermock
- powermock-module-junit4
- ${powermock.version}
+ org.mockito
+ mockito-inline
+ ${mockito-core.version}
test
- org.powermock
- powermock-api-mockito2
- ${powermock.version}
+ uk.org.webcompere
+ system-stubs-junit4
+ ${system-stubs-junit4.version}
test
+
net.bytebuddy
byte-buddy-agent
@@ -433,6 +435,24 @@
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 3.0.0-M8
+
+ 1
+ false
+
+ --add-opens java.base/java.lang=ALL-UNNAMED
+ --add-opens java.base/java.lang.reflect=ALL-UNNAMED
+ --add-opens java.base/java.io=ALL-UNNAMED
+ --add-opens java.base/java.util=ALL-UNNAMED
+ --add-opens java.base/java.nio.charset=ALL-UNNAMED
+ --add-opens java.base/sun.security.action=ALL-UNNAMED
+
+
+