Merge pull request #957 from DataDog/landerson/instrumentation-module-check
Java 9 Modules Smoketest
This commit is contained in:
commit
07b58e1cf4
|
@ -43,7 +43,7 @@ public final class ConnectionInstrumentation extends Instrumenter.Default {
|
|||
nameStartsWith("prepare")
|
||||
.and(takesArgument(0, String.class))
|
||||
// Also include CallableStatement, which is a sub type of PreparedStatement
|
||||
.and(returns(safeHasSuperType(named(PreparedStatement.class.getName())))),
|
||||
.and(returns(safeHasSuperType(named("java.sql.PreparedStatement")))),
|
||||
ConnectionPrepareAdvice.class.getName());
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ public final class DriverInstrumentation extends Instrumenter.Default {
|
|||
nameStartsWith("connect")
|
||||
.and(takesArgument(0, String.class))
|
||||
.and(takesArgument(1, Properties.class))
|
||||
.and(returns(Connection.class)),
|
||||
.and(returns(named("java.sql.Connection"))),
|
||||
DriverAdvice.class.getName());
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
ext {
|
||||
minJavaVersionForTests = JavaVersion.VERSION_1_9
|
||||
}
|
||||
|
||||
apply from: "${rootDir}/gradle/java.gradle"
|
||||
|
||||
jar {
|
||||
manifest {
|
||||
attributes(
|
||||
'Main-Class': 'datadog.smoketest.moduleapp.ModuleApplication'
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// If the current JDK version (the one running gradle) is < 9, we need to find a version >= 9
|
||||
// to compile this project. java.gradle creates a map of java executables
|
||||
// called "javaExecutableVersionCache" pulled from the environment.
|
||||
// This loops over the cache to find a usable jdk.
|
||||
// Since this project is the only one that requires a version above Java 8
|
||||
// it's special cased here instead of putting a generic version matcher in java.gradle
|
||||
if (JavaVersion.VERSION_1_9.compareTo(JavaVersion.current()) > 0) {
|
||||
def targetJavaHome
|
||||
|
||||
// Find a compatible version in the cache
|
||||
ext.javaExecutableVersionCache.find { key, value ->
|
||||
if (JavaVersion.VERSION_1_9.compareTo(value) <= 0) {
|
||||
// JAVA_HOME/bin/java -> JAVA_HOME
|
||||
targetJavaHome = file(key).parentFile.parentFile
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
if (targetJavaHome != null) {
|
||||
// if we found a compatible jdk, compile the src/main/java9 folder with it
|
||||
compileMain_java9Java {
|
||||
options.fork = true
|
||||
options.forkOptions.javaHome = targetJavaHome
|
||||
options.compilerArgs = ['--module-path', classpath.asPath]
|
||||
options.sourcepath = files(sourceSets.main_java9.java.srcDirs)
|
||||
}
|
||||
} else {
|
||||
compileMain_java9Java {
|
||||
enabled = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// java.gradle generates a test task per jdk and assigns the test task its own java executable
|
||||
// For each Test task, this loop creates a jlink image using the test's executable
|
||||
// At the end, we have 1 jlink image per JVM: each one used by a testXXXGenerated task
|
||||
tasks.withType(Test).each {
|
||||
def javaExecutable = it.executable
|
||||
def javaVersion = getJavaExecutableVersion(javaExecutable)
|
||||
|
||||
// Only Java 9 and above have jlink
|
||||
if (JavaVersion.VERSION_1_9.compareTo(javaVersion) > 0) {
|
||||
return
|
||||
}
|
||||
|
||||
// JAVA_HOME/bin/java -> JAVA_HOME
|
||||
def specificJDKHome = file(javaExecutable).parentFile.parent
|
||||
def jlinkExecutable = specificJDKHome + "/bin/jlink"
|
||||
def jdkModulesPath = specificJDKHome + "/jmods"
|
||||
def generatedImageDir = "${buildDir}/${it.name}image"
|
||||
|
||||
it.doFirst {
|
||||
delete generatedImageDir
|
||||
|
||||
// Run the jlink command to create the image
|
||||
exec {
|
||||
commandLine jlinkExecutable, '--no-man-pages', '--no-header-files',
|
||||
'--add-modules', 'java.instrument,datadog.smoketest.moduleapp',
|
||||
"--module-path", "${jdkModulesPath}:" + jar.archiveFile.get().toString(), "--output", generatedImageDir
|
||||
}
|
||||
}
|
||||
|
||||
it.jvmArgs "-Ddatadog.smoketest.module.image=${generatedImageDir}"
|
||||
it.dependsOn jar
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testCompile project(':dd-smoke-tests')
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package datadog.smoketest.moduleapp;
|
||||
|
||||
public class ModuleApplication {
|
||||
public static void main(final String[] args) throws InterruptedException {
|
||||
Thread.sleep(600);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
module datadog.smoketest.moduleapp {
|
||||
exports datadog.smoketest.moduleapp;
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package datadog.smoketest
|
||||
|
||||
import spock.lang.Timeout
|
||||
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class Java9ModulesSmokeTest extends AbstractSmokeTest {
|
||||
// Estimate for the amount of time instrumentation plus some extra
|
||||
private static final int TIMEOUT_SECS = 30
|
||||
|
||||
@Override
|
||||
ProcessBuilder createProcessBuilder() {
|
||||
String imageDir = System.getProperty("datadog.smoketest.module.image")
|
||||
|
||||
assert imageDir != null
|
||||
|
||||
List<String> command = new ArrayList<>()
|
||||
command.add(imageDir + "/bin/java")
|
||||
command.addAll(defaultJavaProperties)
|
||||
command.addAll((String[]) ["-m", "datadog.smoketest.moduleapp/datadog.smoketest.moduleapp.ModuleApplication"])
|
||||
ProcessBuilder processBuilder = new ProcessBuilder(command)
|
||||
processBuilder.directory(new File(buildDirectory))
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
}
|
|
@ -39,6 +39,10 @@ if (project.hasProperty('minJavaVersionForTests') && project.getProperty('minJav
|
|||
"main_${name}CompileOnly" "org.projectlombok:lombok:${project.lombok.version}" transitive false
|
||||
"main_${name}AnnotationProcessor" "org.projectlombok:lombok:${project.lombok.version}" transitive false
|
||||
}
|
||||
|
||||
jar {
|
||||
from sourceSets."main_$name".output
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
if (it.name.toLowerCase().contains("test")) {
|
||||
|
@ -241,6 +245,10 @@ JavaVersion getJavaExecutableVersion(String path) {
|
|||
}
|
||||
}
|
||||
|
||||
ext {
|
||||
getJavaExecutableVersion = this.&getJavaExecutableVersion
|
||||
}
|
||||
|
||||
def isJavaVersionAllowed(JavaVersion version) {
|
||||
if (project.hasProperty('minJavaVersionForTests') && project.getProperty('minJavaVersionForTests').compareTo(version) > 0) {
|
||||
return false
|
||||
|
|
|
@ -19,10 +19,11 @@ include ':dd-java-agent:testing'
|
|||
include ':utils:gc-utils'
|
||||
|
||||
// smoke tests
|
||||
include ':dd-smoke-tests:cli'
|
||||
include ':dd-smoke-tests:java9-modules'
|
||||
include ':dd-smoke-tests:play'
|
||||
include ':dd-smoke-tests:springboot'
|
||||
include ':dd-smoke-tests:wildfly'
|
||||
include ':dd-smoke-tests:cli'
|
||||
|
||||
// instrumentation:
|
||||
include ':dd-java-agent:instrumentation:akka-http-10.0'
|
||||
|
|
Loading…
Reference in New Issue