diff --git a/apm-sniffer/apm-agent-core/pom.xml b/apm-sniffer/apm-agent-core/pom.xml
index 4974ad8d78ca64f1f4eef966592403b5826c019c..f94d04f9668231161327d8b330d01b48de1294cb 100644
--- a/apm-sniffer/apm-agent-core/pom.xml
+++ b/apm-sniffer/apm-agent-core/pom.xml
@@ -77,12 +77,6 @@
${jetty.version}
test
-
- org.skywalking
- apm-test-tools
- ${project.version}
- test
-
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/TraceSegmentRef.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/TraceSegmentRef.java
index fc07d610f51e6c23be8a828c8336e92fa3b4de38..1e2da121733152da9de828743558926a4909e36a 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/TraceSegmentRef.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/TraceSegmentRef.java
@@ -69,7 +69,7 @@ public class TraceSegmentRef {
public TraceSegmentReference transform() {
TraceSegmentReference.Builder refBuilder = TraceSegmentReference.newBuilder();
- if(SegmentRefType.CROSS_PROCESS.equals(type)) {
+ if (SegmentRefType.CROSS_PROCESS.equals(type)) {
refBuilder.setRefType(RefType.CrossProcess);
refBuilder.setParentApplicationInstanceId(applicationInstanceId);
if (peerId == DictionaryUtil.nullValue()) {
@@ -82,7 +82,7 @@ public class TraceSegmentRef {
} else {
refBuilder.setEntryServiceId(operationId);
}
- }else{
+ } else {
refBuilder.setRefType(RefType.CrossThread);
}
refBuilder.setParentTraceSegmentId(traceSegmentId);
diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/ContextManagerTest.java b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/ContextManagerTest.java
index cc1b8bf0a9d84eeaeed1a878bd736263bc561bef..c527656ed3cb358b1707c992dfb94de308b4b4ce 100644
--- a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/ContextManagerTest.java
+++ b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/ContextManagerTest.java
@@ -1,8 +1,6 @@
package org.skywalking.apm.agent.core.context;
-import java.lang.reflect.Field;
import java.util.List;
-import java.util.Map;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -17,14 +15,13 @@ import org.skywalking.apm.agent.core.context.trace.LogDataEntity;
import org.skywalking.apm.agent.core.context.trace.SpanLayer;
import org.skywalking.apm.agent.core.context.trace.TraceSegment;
import org.skywalking.apm.agent.core.context.trace.TraceSegmentRef;
+import org.skywalking.apm.agent.core.context.util.AbstractTracingSpanHelper;
+import org.skywalking.apm.agent.core.context.util.SegmentHelper;
+import org.skywalking.apm.agent.core.context.util.SegmentStorage;
+import org.skywalking.apm.agent.core.context.util.SegmentStoragePoint;
+import org.skywalking.apm.agent.core.context.util.TraceSegmentRefHelper;
+import org.skywalking.apm.agent.core.context.util.TracingSegmentRunner;
import org.skywalking.apm.agent.core.dictionary.DictionaryUtil;
-import org.skywalking.apm.agent.core.dictionary.OperationNameDictionary;
-import org.skywalking.apm.agent.test.helper.AbstractTracingSpanHelper;
-import org.skywalking.apm.agent.test.helper.SegmentHelper;
-import org.skywalking.apm.agent.test.helper.TraceSegmentRefHelper;
-import org.skywalking.apm.agent.test.tools.SegmentStorage;
-import org.skywalking.apm.agent.test.tools.SegmentStoragePoint;
-import org.skywalking.apm.agent.test.tools.TracingSegmentRunner;
import org.skywalking.apm.network.trace.component.ComponentsDefine;
import static org.hamcrest.CoreMatchers.is;
@@ -128,7 +125,6 @@ public class ContextManagerTest {
assertThat(injectContextCarrier.getSpanId(), is(1));
assertThat(injectContextCarrier.getEntryOperationName(), is("#/portal/"));
- assertThat(injectContextCarrier.getApplicationId(), is(1));
assertThat(injectContextCarrier.getPeerHost(), is("#127.0.0.1:12800"));
}
@@ -175,12 +171,10 @@ public class ContextManagerTest {
assertThat(AbstractTracingSpanHelper.getParentSpanId(actualEntrySpan), is(-1));
assertThat(firstExitSpanContextCarrier.getPeerHost(), is("#127.0.0.1:8080"));
- assertThat(firstExitSpanContextCarrier.getApplicationId(), is(1));
assertThat(firstExitSpanContextCarrier.getSpanId(), is(1));
assertThat(firstExitSpanContextCarrier.getEntryOperationName(), is("#/testEntrySpan"));
assertThat(secondExitSpanContextCarrier.getPeerHost(), is("#127.0.0.1:8080"));
- assertThat(secondExitSpanContextCarrier.getApplicationId(), is(1));
assertThat(secondExitSpanContextCarrier.getSpanId(), is(1));
assertThat(secondExitSpanContextCarrier.getEntryOperationName(), is("#/testEntrySpan"));
diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/IgnoredTracerContextTest.java b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/IgnoredTracerContextTest.java
index faffcbf3c31089d22fe62823a2f206296ef84e12..81fc04c375791d536362caf617e81f7186090f02 100644
--- a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/IgnoredTracerContextTest.java
+++ b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/IgnoredTracerContextTest.java
@@ -10,9 +10,9 @@ import org.skywalking.apm.agent.core.conf.Config;
import org.skywalking.apm.agent.core.conf.RemoteDownstreamConfig;
import org.skywalking.apm.agent.core.context.trace.AbstractSpan;
import org.skywalking.apm.agent.core.context.trace.NoopSpan;
-import org.skywalking.apm.agent.test.tools.SegmentStorage;
-import org.skywalking.apm.agent.test.tools.SegmentStoragePoint;
-import org.skywalking.apm.agent.test.tools.TracingSegmentRunner;
+import org.skywalking.apm.agent.core.context.util.SegmentStorage;
+import org.skywalking.apm.agent.core.context.util.SegmentStoragePoint;
+import org.skywalking.apm.agent.core.context.util.TracingSegmentRunner;
import static junit.framework.TestCase.assertNull;
import static org.hamcrest.CoreMatchers.is;
diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/AbstractTracingSpanHelper.java b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/AbstractTracingSpanHelper.java
new file mode 100644
index 0000000000000000000000000000000000000000..c16872e0a3c33c5ca4af9da22e3ca21781280727
--- /dev/null
+++ b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/AbstractTracingSpanHelper.java
@@ -0,0 +1,26 @@
+package org.skywalking.apm.agent.core.context.util;
+
+import java.util.Collections;
+import java.util.List;
+import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
+import org.skywalking.apm.agent.core.context.trace.LogDataEntity;
+
+public class AbstractTracingSpanHelper {
+ public static int getParentSpanId(AbstractTracingSpan tracingSpan) {
+ try {
+ return FieldGetter.getParentFieldValue(tracingSpan, "parentSpanId");
+ } catch (Exception e) {
+ }
+
+ return -9999;
+ }
+
+ public static List getLogs(AbstractTracingSpan tracingSpan) {
+ try {
+ return FieldGetter.getParentFieldValue(tracingSpan, "logs");
+ } catch (Exception e) {
+ }
+
+ return Collections.emptyList();
+ }
+}
diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/FieldGetter.java b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/FieldGetter.java
new file mode 100644
index 0000000000000000000000000000000000000000..0aeaad0b9a265ec3516b0fc8145bcd52e234f28c
--- /dev/null
+++ b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/FieldGetter.java
@@ -0,0 +1,19 @@
+package org.skywalking.apm.agent.core.context.util;
+
+import java.lang.reflect.Field;
+
+public class FieldGetter {
+ public static T getValue(Object instance,
+ String fieldName) throws IllegalAccessException, NoSuchFieldException {
+ Field field = instance.getClass().getDeclaredField(fieldName);
+ field.setAccessible(true);
+ return (T)field.get(instance);
+ }
+
+ public static T getParentFieldValue(Object instance,
+ String fieldName) throws IllegalAccessException, NoSuchFieldException {
+ Field field = instance.getClass().getSuperclass().getDeclaredField(fieldName);
+ field.setAccessible(true);
+ return (T)field.get(instance);
+ }
+}
diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/SegmentHelper.java b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/SegmentHelper.java
new file mode 100644
index 0000000000000000000000000000000000000000..d397c2e95d4e5744cf11fb33686d222c3051abc4
--- /dev/null
+++ b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/SegmentHelper.java
@@ -0,0 +1,17 @@
+package org.skywalking.apm.agent.core.context.util;
+
+import java.util.List;
+import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
+import org.skywalking.apm.agent.core.context.trace.TraceSegment;
+
+public class SegmentHelper {
+
+ public static List getSpan(TraceSegment traceSegment) {
+ try {
+ return FieldGetter.getValue(traceSegment, "spans");
+ } catch (Exception e) {
+ }
+
+ return null;
+ }
+}
diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/SegmentStorage.java b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/SegmentStorage.java
new file mode 100644
index 0000000000000000000000000000000000000000..ea310bba99eac0ebd360825afcde7c909b409dec
--- /dev/null
+++ b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/SegmentStorage.java
@@ -0,0 +1,32 @@
+package org.skywalking.apm.agent.core.context.util;
+
+import java.util.LinkedList;
+import java.util.List;
+import org.skywalking.apm.agent.core.context.IgnoredTracerContext;
+import org.skywalking.apm.agent.core.context.trace.TraceSegment;
+
+public class SegmentStorage {
+ private LinkedList traceSegments;
+ private LinkedList ignoredTracerContexts;
+
+ SegmentStorage() {
+ traceSegments = new LinkedList();
+ ignoredTracerContexts = new LinkedList();
+ }
+
+ void addTraceSegment(TraceSegment segment) {
+ traceSegments.add(segment);
+ }
+
+ public List getTraceSegments() {
+ return traceSegments;
+ }
+
+ void addIgnoreTraceContext(IgnoredTracerContext context) {
+ this.ignoredTracerContexts.add(context);
+ }
+
+ public LinkedList getIgnoredTracerContexts() {
+ return ignoredTracerContexts;
+ }
+}
diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/SegmentStoragePoint.java b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/SegmentStoragePoint.java
new file mode 100644
index 0000000000000000000000000000000000000000..21a450c5c14a2c7d864fed913e38b2c0af7d50ce
--- /dev/null
+++ b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/SegmentStoragePoint.java
@@ -0,0 +1,11 @@
+package org.skywalking.apm.agent.core.context.util;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface SegmentStoragePoint {
+}
diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/TraceSegmentRefHelper.java b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/TraceSegmentRefHelper.java
new file mode 100644
index 0000000000000000000000000000000000000000..26dba94b26624ce4e370fff34f494ed953bf2639
--- /dev/null
+++ b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/TraceSegmentRefHelper.java
@@ -0,0 +1,14 @@
+package org.skywalking.apm.agent.core.context.util;
+
+import org.skywalking.apm.agent.core.context.trace.TraceSegmentRef;
+
+public class TraceSegmentRefHelper {
+ public static String getPeerHost(TraceSegmentRef ref) {
+ try {
+ return FieldGetter.getValue(ref, "peerHost");
+ } catch (Exception e) {
+ }
+
+ return null;
+ }
+}
diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/TracingSegmentRunner.java b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/TracingSegmentRunner.java
new file mode 100644
index 0000000000000000000000000000000000000000..94d4ea639fc5cfff69a0a6350aadf3bc5c0ebad5
--- /dev/null
+++ b/apm-sniffer/apm-agent-core/src/test/java/org/skywalking/apm/agent/core/context/util/TracingSegmentRunner.java
@@ -0,0 +1,86 @@
+package org.skywalking.apm.agent.core.context.util;
+
+import java.lang.reflect.Field;
+import org.junit.runner.Description;
+import org.junit.runner.notification.Failure;
+import org.junit.runner.notification.RunNotifier;
+import org.junit.runners.BlockJUnit4ClassRunner;
+import org.junit.runners.model.InitializationError;
+import org.skywalking.apm.agent.core.context.IgnoreTracerContextListener;
+import org.skywalking.apm.agent.core.context.IgnoredTracerContext;
+import org.skywalking.apm.agent.core.context.TracingContext;
+import org.skywalking.apm.agent.core.context.TracingContextListener;
+import org.skywalking.apm.agent.core.context.trace.TraceSegment;
+
+public class TracingSegmentRunner extends BlockJUnit4ClassRunner {
+ private TracingContextListener tracingContextListener;
+ private IgnoreTracerContextListener ignoreTracerContextListener;
+ private Field field;
+ private Object targetObject;
+ private SegmentStorage tracingData;
+
+ public TracingSegmentRunner(Class> klass) throws InitializationError {
+ super(klass);
+ for (Field field : klass.getDeclaredFields()) {
+ if (field.isAnnotationPresent(SegmentStoragePoint.class) && field.getType().equals(SegmentStorage.class)) {
+ this.field = field;
+ this.field.setAccessible(true);
+ break;
+ }
+ }
+ }
+
+ @Override
+ protected Object createTest() throws Exception {
+ targetObject = super.createTest();
+ return targetObject;
+ }
+
+ @Override
+ public void run(RunNotifier notifier) {
+ notifier.addListener(new RunListener());
+ super.run(notifier);
+ }
+
+ class RunListener extends org.junit.runner.notification.RunListener {
+ @Override
+ public void testStarted(Description description) throws Exception {
+ if (field != null) {
+ try {
+ tracingData = new SegmentStorage();
+ field.set(targetObject, tracingData);
+ } catch (IllegalAccessException e) {
+ }
+ }
+ tracingContextListener = new TracingContextListener() {
+ @Override
+ public void afterFinished(TraceSegment traceSegment) {
+ tracingData.addTraceSegment(traceSegment);
+ }
+ };
+
+ ignoreTracerContextListener = new IgnoreTracerContextListener() {
+ @Override
+ public void afterFinished(IgnoredTracerContext tracerContext) {
+ tracingData.addIgnoreTraceContext(tracerContext);
+ }
+ };
+ TracingContext.ListenerManager.add(tracingContextListener);
+ IgnoredTracerContext.ListenerManager.add(ignoreTracerContextListener);
+ super.testStarted(description);
+ }
+
+ @Override
+ public void testFinished(Description description) throws Exception {
+ super.testFinished(description);
+ TracingContext.ListenerManager.remove(tracingContextListener);
+ IgnoredTracerContext.ListenerManager.remove(ignoreTracerContextListener);
+ }
+
+ @Override
+ public void testFailure(Failure failure) throws Exception {
+ super.testFailure(failure);
+ TracingContext.ListenerManager.remove(tracingContextListener);
+ }
+ }
+}
diff --git a/apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/helper/AbstractTracingSpanHelper.java b/apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/helper/AbstractTracingSpanHelper.java
index de65ba88790caeab5d4acc88b058bb47120fe247..a2624c00eeede3afda5f57b16253311c98fcacb8 100644
--- a/apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/helper/AbstractTracingSpanHelper.java
+++ b/apm-sniffer/apm-test-tools/src/main/java/org/skywalking/apm/agent/test/helper/AbstractTracingSpanHelper.java
@@ -4,7 +4,6 @@ import java.util.Collections;
import java.util.List;
import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.skywalking.apm.agent.core.context.trace.LogDataEntity;
-import org.skywalking.apm.agent.core.context.util.KeyValuePair;
public class AbstractTracingSpanHelper {
public static int getParentSpanId(AbstractTracingSpan tracingSpan) {