Remove opentracing from TestRunner fields to support single test run
This commit is contained in:
parent
0d8df99f80
commit
a004337576
|
|
@ -18,7 +18,7 @@ class JerseyTest extends AgentTestRunner {
|
||||||
def "test resource"() {
|
def "test resource"() {
|
||||||
setup:
|
setup:
|
||||||
// start a trace because the test doesn't go through any servlet or other instrumentation.
|
// start a trace because the test doesn't go through any servlet or other instrumentation.
|
||||||
def scope = TEST_TRACER.buildSpan("test.span").startActive(true)
|
def scope = getTestTracer().buildSpan("test.span").startActive(true)
|
||||||
def response = resources.client().resource("/test/hello/bob").post(String)
|
def response = resources.client().resource("/test/hello/bob").post(String)
|
||||||
scope.close()
|
scope.close()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ class KafkaStreamsTest extends AgentTestRunner {
|
||||||
@Override
|
@Override
|
||||||
void onMessage(ConsumerRecord<String, String> record) {
|
void onMessage(ConsumerRecord<String, String> record) {
|
||||||
WRITER_PHASER.arriveAndAwaitAdvance() // ensure consistent ordering of traces
|
WRITER_PHASER.arriveAndAwaitAdvance() // ensure consistent ordering of traces
|
||||||
TEST_TRACER.activeSpan().setTag("testing", 123)
|
getTestTracer().activeSpan().setTag("testing", 123)
|
||||||
records.add(record)
|
records.add(record)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -81,7 +81,7 @@ class KafkaStreamsTest extends AgentTestRunner {
|
||||||
@Override
|
@Override
|
||||||
String apply(String textLine) {
|
String apply(String textLine) {
|
||||||
WRITER_PHASER.arriveAndAwaitAdvance() // ensure consistent ordering of traces
|
WRITER_PHASER.arriveAndAwaitAdvance() // ensure consistent ordering of traces
|
||||||
TEST_TRACER.activeSpan().setTag("asdf", "testing")
|
getTestTracer().activeSpan().setTag("asdf", "testing")
|
||||||
return textLine.toLowerCase()
|
return textLine.toLowerCase()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import datadog.opentracing.DDTracer;
|
||||||
import datadog.trace.agent.tooling.AgentInstaller;
|
import datadog.trace.agent.tooling.AgentInstaller;
|
||||||
import datadog.trace.agent.tooling.Instrumenter;
|
import datadog.trace.agent.tooling.Instrumenter;
|
||||||
import datadog.trace.common.writer.ListWriter;
|
import datadog.trace.common.writer.ListWriter;
|
||||||
|
import datadog.trace.common.writer.Writer;
|
||||||
import io.opentracing.Tracer;
|
import io.opentracing.Tracer;
|
||||||
import java.lang.instrument.ClassFileTransformer;
|
import java.lang.instrument.ClassFileTransformer;
|
||||||
import java.lang.instrument.Instrumentation;
|
import java.lang.instrument.Instrumentation;
|
||||||
|
|
@ -52,7 +53,10 @@ public abstract class AgentTestRunner extends Specification {
|
||||||
*/
|
*/
|
||||||
public static final ListWriter TEST_WRITER;
|
public static final ListWriter TEST_WRITER;
|
||||||
|
|
||||||
protected static final Tracer TEST_TRACER;
|
// having a reference to io.opentracing.Tracer in test field
|
||||||
|
// loads opentracing before bootstrap classpath is setup
|
||||||
|
// so we declare tracer as an object and cast when needed.
|
||||||
|
private static final Object TEST_TRACER;
|
||||||
private static final AtomicInteger INSTRUMENTATION_ERROR_COUNT = new AtomicInteger();
|
private static final AtomicInteger INSTRUMENTATION_ERROR_COUNT = new AtomicInteger();
|
||||||
|
|
||||||
private static final Instrumentation instrumentation;
|
private static final Instrumentation instrumentation;
|
||||||
|
|
@ -77,7 +81,15 @@ public abstract class AgentTestRunner extends Specification {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
TEST_TRACER = new DDTracer(TEST_WRITER);
|
TEST_TRACER = new DDTracer(TEST_WRITER);
|
||||||
TestUtils.registerOrReplaceGlobalTracer(TEST_TRACER);
|
TestUtils.registerOrReplaceGlobalTracer((Tracer) TEST_TRACER);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static Tracer getTestTracer() {
|
||||||
|
return (Tracer) TEST_TRACER;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static Writer getTestWriter() {
|
||||||
|
return TEST_WRITER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
|
|
@ -100,7 +112,7 @@ public abstract class AgentTestRunner extends Specification {
|
||||||
public void beforeTest() {
|
public void beforeTest() {
|
||||||
TEST_WRITER.start();
|
TEST_WRITER.start();
|
||||||
INSTRUMENTATION_ERROR_COUNT.set(0);
|
INSTRUMENTATION_ERROR_COUNT.set(0);
|
||||||
assert (TEST_TRACER).activeSpan() == null;
|
assert getTestTracer().activeSpan() == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import datadog.trace.agent.test.TestUtils
|
import datadog.trace.agent.test.TestUtils
|
||||||
|
import io.opentracing.Tracer
|
||||||
|
|
||||||
import java.lang.reflect.Field
|
import java.lang.reflect.Field
|
||||||
|
|
||||||
|
|
@ -8,6 +9,8 @@ class AgentTestRunnerTest extends AgentTestRunner {
|
||||||
private static final ClassLoader BOOTSTRAP_CLASSLOADER = null
|
private static final ClassLoader BOOTSTRAP_CLASSLOADER = null
|
||||||
private static final ClassLoader OT_LOADER
|
private static final ClassLoader OT_LOADER
|
||||||
private static final boolean AGENT_INSTALLED_IN_CLINIT
|
private static final boolean AGENT_INSTALLED_IN_CLINIT
|
||||||
|
// having opentracing class in test field should not cause problems
|
||||||
|
private static final Tracer A_TRACER = null
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// when test class initializes, opentracing should be set up, but not the agent.
|
// when test class initializes, opentracing should be set up, but not the agent.
|
||||||
|
|
@ -17,9 +20,10 @@ class AgentTestRunnerTest extends AgentTestRunner {
|
||||||
|
|
||||||
def "classpath setup"() {
|
def "classpath setup"() {
|
||||||
expect:
|
expect:
|
||||||
|
A_TRACER == null
|
||||||
OT_LOADER == BOOTSTRAP_CLASSLOADER
|
OT_LOADER == BOOTSTRAP_CLASSLOADER
|
||||||
!AGENT_INSTALLED_IN_CLINIT
|
!AGENT_INSTALLED_IN_CLINIT
|
||||||
TEST_TRACER == TestUtils.getUnderlyingGlobalTracer()
|
getTestTracer() == TestUtils.getUnderlyingGlobalTracer()
|
||||||
getAgentTransformer() != null
|
getAgentTransformer() != null
|
||||||
datadog.trace.api.Trace.getClassLoader() == BOOTSTRAP_CLASSLOADER
|
datadog.trace.api.Trace.getClassLoader() == BOOTSTRAP_CLASSLOADER
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue