Additional test for shared field
MODIFY
dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/Utils.java
dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/Utils.java
@@ -6,7 +6,11 @@ import java.lang.reflect.Method;
import java.net.URL;
public class Utils {
- /* packages which will be loaded on the bootstrap classloader*/
+ /**
+ * packages which will be loaded on the bootstrap classloader
+ *
+ * <p>Updates should be mirrored in TestUtils#BOOTSTRAP_PACKAGE_PREFIXES_COPY
+ */
public static final String[] BOOTSTRAP_PACKAGE_PREFIXES = {
"io.opentracing",
"datadog.slf4j",
@@ -14,6 +18,7 @@ public class Utils {
"datadog.trace.api",
"datadog.trace.context"
};
+
public static final String[] AGENT_PACKAGE_PREFIXES = {
"datadog.trace.common",
"datadog.trace.agent",

MODIFY
dd-java-agent/testing/src/main/java/datadog/trace/agent/test/TestUtils.java
dd-java-agent/testing/src/main/java/datadog/trace/agent/test/TestUtils.java
@@ -252,9 +252,6 @@ public class TestUtils {
/**
* Parse JVM classpath and return ClassLoader containing all classpath entries. Inspired by Guava.
- *
- * <p>TODO: use we cannot use Guava version when we can update Guava to version that has this
- * logic, i.e. when we drop Java7 support.
*/
private static ClassLoader buildJavaClassPathClassLoader() {
ImmutableList.Builder<URL> urls = ImmutableList.builder();

MODIFY
dd-java-agent/testing/src/test/groovy/AgentTestRunnerTest.groovy
dd-java-agent/testing/src/test/groovy/AgentTestRunnerTest.groovy
@@ -3,7 +3,9 @@ import datadog.trace.agent.test.AgentTestRunner
import datadog.trace.agent.test.SpockRunner
import datadog.trace.agent.test.TestUtils
import datadog.trace.agent.tooling.Utils
+import io.opentracing.Span
import io.opentracing.Tracer
+import spock.lang.Shared
import java.lang.reflect.Field
@@ -16,12 +18,19 @@ class AgentTestRunnerTest extends AgentTestRunner {
// having dd tracer api class in test field should not cause problems
private static final datadog.trace.api.Tracer DD_API_TRACER = null
+ @Shared
+ private Class sharedSpanClass
+
static {
// when test class initializes, opentracing should be set up, but not the agent.
OT_LOADER = io.opentracing.Tracer.getClassLoader()
AGENT_INSTALLED_IN_CLINIT = getAgentTransformer() != null
}
+ def setupSpec() {
+ sharedSpanClass = Span
+ }
+
def "spock runner bootstrap prefixes correct for test setup"() {
expect:
SpockRunner.BOOTSTRAP_PACKAGE_PREFIXES_COPY == Utils.BOOTSTRAP_PACKAGE_PREFIXES
@@ -43,6 +52,8 @@ class AgentTestRunnerTest extends AgentTestRunner {
}
expect:
+ // a shared OT class should cause no trouble
+ sharedSpanClass.getClassLoader() == BOOTSTRAP_CLASSLOADER
A_TRACER == null
DD_API_TRACER == null
!AGENT_INSTALLED_IN_CLINIT

Additional test for shared field