Module smoke test framework
ADD
dd-smoke-tests/java9-modules/instrumentable-module-app/instrumentable-module-app.gradle
+ext {
+ minJavaVersionForTests = JavaVersion.VERSION_1_9
+}
+
+apply from: "${rootDir}/gradle/java.gradle"
+
+jar {
+ manifest {
+ attributes(
+ 'Main-Class': 'datadog.smoketest.moduleapp.instrumentable.ModuleApplication'
+ )
+ }
+}
+
+jlink {
+ moduleName = 'datadog.smoketest.moduleapp.instrumentable'
+ options = ['--no-man-pages', '--no-header-files']
+}
+
+sourceCompatibility = "1.9"
+targetCompatibility = "1.9"
\ No newline at end of file

ADD
dd-smoke-tests/java9-modules/instrumentable-module-app/src/main/java/datadog/smoketest/moduleapp/instrumentable/ModuleApplication.java
+package datadog.smoketest.moduleapp.instrumentable;
+
+public class ModuleApplication {
+ public static void main(final String[] args) {
+ final String agentStatus = System.getProperty("dd.agent.status");
+
+ if (!"INSTALLED".equals(agentStatus)) {
+ throw new RuntimeException("Incorrect agent status: " + agentStatus);
+ }
+ }
+}

ADD
dd-smoke-tests/java9-modules/instrumentable-module-app/src/main/java/module-info.java
+module datadog.smoketest.moduleapp.instrumentable {
+ exports datadog.smoketest.moduleapp.instrumentable;
+}

ADD
dd-smoke-tests/java9-modules/java9-modules.gradle
+plugins {
+ id 'org.beryx.jlink' version '2.1.1' // latest version that doesn't have a Java 11+ warning
+}
+
+apply from: "${rootDir}/gradle/java.gradle"
+
+sourceCompatibility = "1.9"
+targetCompatibility = "1.9"
+
+dependencies {
+ testCompile project(':dd-smoke-tests')
+}
+
+Project main_project = project
+subprojects { subProject ->
+ apply plugin: "org.beryx.jlink"
+
+ main_project.tasks.test.dependsOn subProject.tasks.jlink
+
+ main_project.tasks.test.jvmArgs "-Ddatadog.smoketest.${subProject.tasks.jlink.moduleName.get()}.image=${subProject.tasks.jlink.imageDir.get()}"
+}
+

ADD
dd-smoke-tests/java9-modules/src/test/groovy/datadog/smoketest/Java9ModulesSmokeTest.groovy
+package datadog.smoketest
+
+import spock.lang.Timeout
+
+import java.util.concurrent.TimeUnit
+
+abstract class Java9ModulesSmokeTest extends AbstractSmokeTest {
+ // Estimate for the amount of time instrumentation plus some extra
+ private static final int TIMEOUT_SECS = 30
+
+ @Override
+ ProcessBuilder createProcessBuilder() {
+ println System.getProperties()
+ String imageDir = System.getProperty("datadog.smoketest.${moduleName}.image")
+
+ assert imageDir != null
+
+ List<String> command = new ArrayList<>()
+ command.add(imageDir + "/bin/java")
+ command.addAll(defaultJavaProperties)
+ command.addAll((String[]) ["-m", "${moduleName}/${moduleName}.ModuleApplication"])
+ ProcessBuilder processBuilder = new ProcessBuilder(command)
+ processBuilder.directory(new File(buildDirectory))
+ }
+
+ abstract getModuleName()
+
+ // TODO: once java7 support is dropped use waitFor() with timeout call added in java8
+ // instead of timeout on test
+ @Timeout(value = TIMEOUT_SECS, unit = TimeUnit.SECONDS)
+ def "Module application runs correctly"() {
+ expect:
+ assert serverProcess.waitFor() == 0
+ }
+}
+
+class InstrumentableModuleTest extends Java9ModulesSmokeTest {
+
+ @Override
+ def getModuleName() {
+ return "datadog.smoketest.moduleapp.instrumentable"
+ }
+}
+
+class UninstrumentableModuleTest extends Java9ModulesSmokeTest {
+
+ @Override
+ def getModuleName() {
+ return "datadog.smoketest.moduleapp.uninstrumentable"
+ }
+}

ADD
dd-smoke-tests/java9-modules/uninstrumentable-module-app/src/main/java/datadog/smoketest/moduleapp/uninstrumentable/ModuleApplication.java
+package datadog.smoketest.moduleapp.uninstrumentable;
+
+public class ModuleApplication {
+ public static void main(final String[] args) {
+ final String agentStatus = System.getProperty("dd.agent.status");
+
+ if (!"NOT_INSTALLED".equals(agentStatus)) {
+ throw new RuntimeException("Incorrect agent status: " + agentStatus);
+ }
+ }
+}

ADD
dd-smoke-tests/java9-modules/uninstrumentable-module-app/src/main/java/module-info.java
+module datadog.smoketest.moduleapp.uninstrumentable {
+ exports datadog.smoketest.moduleapp.uninstrumentable;
+}

ADD
dd-smoke-tests/java9-modules/uninstrumentable-module-app/uninstrumentable-module-app.gradle
+ext {
+ minJavaVersionForTests = JavaVersion.VERSION_1_9
+}
+
+apply from: "${rootDir}/gradle/java.gradle"
+
+jar {
+ manifest {
+ attributes(
+ 'Main-Class': 'datadog.smoketest.moduleapp.uninstrumentable.ModuleApplication'
+ )
+ }
+}
+
+jlink {
+ moduleName = 'datadog.smoketest.moduleapp.uninstrumentable'
+ options = ['--no-man-pages', '--no-header-files']
+}
+
+sourceCompatibility = "1.9"
+targetCompatibility = "1.9"

MODIFY
settings.gradle
settings.gradle
@@ -23,6 +23,9 @@ include ':dd-smoke-tests:play'
include ':dd-smoke-tests:springboot'
include ':dd-smoke-tests:wildfly'
include ':dd-smoke-tests:cli'
+include ':dd-smoke-tests:java9-modules'
+include ':dd-smoke-tests:java9-modules:instrumentable-module-app'
+include ':dd-smoke-tests:java9-modules:uninstrumentable-module-app'
// instrumentation:
include ':dd-java-agent:instrumentation:akka-http-10.0'

Module smoke test framework