Simple test to check loading of bootstrap in a launched vm
ADD
dd-java-agent/src/test/groovy/datadog/trace/agent/AgentLoadedIntoBootstrapTest.groovy
+package datadog.trace.agent
+
+import datadog.trace.agent.test.IntegrationTestUtils
+import jvmbootstraptest.AgentLoadedChecker
+import spock.lang.Shared
+import spock.lang.Specification
+
+import java.lang.management.ManagementFactory
+import java.lang.management.RuntimeMXBean
+
+class AgentLoadedIntoBootstrapTest extends Specification {
+ @Shared
+ private agentArg
+
+ def setupSpec() {
+ final RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean()
+ for (String arg : runtimeMxBean.getInputArguments()) {
+ if (arg.startsWith("-javaagent")) {
+ agentArg = arg
+ break
+ }
+ }
+ assert agentArg != null
+ }
+
+ def "Agent loads in when separate jvm is launched"() {
+ expect:
+ IntegrationTestUtils.runOnSeparateJvm(AgentLoadedChecker.getName()
+ , [agentArg] as String[]
+ , "" as String[]
+ , [:]
+ , true) == 0
+ }
+}

ADD
dd-java-agent/src/test/java/jvmbootstraptest/AgentLoadedChecker.java
+package jvmbootstraptest;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.Arrays;
+
+public class AgentLoadedChecker {
+ public static void main(final String[] args) throws ClassNotFoundException {
+ System.out.println(Arrays.toString(args));
+
+ // Empty classloader that delegates to bootstrap
+ final URLClassLoader emptyClassLoader = new URLClassLoader(new URL[] {}, null);
+ final Class agentClass = emptyClassLoader.loadClass("datadog.trace.agent.TracingAgent");
+
+ if (agentClass.getClassLoader() != null) {
+ throw new RuntimeException(
+ "TracingAgent loaded into classloader other than bootstrap: "
+ + agentClass.getClassLoader());
+ }
+ }
+}

Simple test to check loading of bootstrap in a launched vm