SpringBoot smoke test
ADD
dd-smoke-tests/springboot/springboot.gradle
+plugins {
+ id "com.github.johnrengelman.shadow" version "4.0.1"
+ id 'com.github.psxpaul.execfork' version '0.1.8'
+}
+apply from: "${rootDir}/gradle/java.gradle"
+description = 'SpringBoot Smoke Tests.'
+
+
+ext {
+ springbootHttpPort = 8080
+}
+
+// The standard spring-boot plugin doesn't play nice with our project
+// so we'll build a fat jar instead
+jar {
+ manifest {
+ attributes(
+ 'Main-Class': 'datadog.smoketest.springboot.SpringbootApplication'
+ )
+ }
+}
+
+
+// TODO: move to common util
+/** Open up a random, reusable port. */
+def randomOpenPort() {
+ final ServerSocket socket
+ try {
+ socket = new ServerSocket(0)
+ socket.setReuseAddress(true)
+ socket.close()
+ return socket.getLocalPort()
+ } catch (final IOException ioe) {
+ ioe.printStackTrace()
+ return -1
+ }
+}
+
+dependencies {
+ compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '1.5.18.RELEASE'
+
+ testCompile project(':dd-trace-api')
+ testCompile project(':dd-trace-ot')
+ testCompile project(':dd-java-agent:testing')
+ testCompile group: 'com.squareup.okhttp3', name: 'okhttp', version: '3.6.0'
+}
+
+task startServer(type: com.github.psxpaul.task.ExecFork) {
+ springbootHttpPort = randomOpenPort()
+ dependsOn project(':dd-java-agent').shadowJar, shadowJar
+
+ if (springbootHttpPort == -1) {
+ throw new GradleException("Failed to get random port to start springboot")
+ }
+ workingDir = "${buildDir}"
+ commandLine = "java"
+ args = ["-javaagent:${project(':dd-java-agent').tasks.shadowJar.archivePath}",
+ "-Ddd.writer.type=LoggingWriter",
+ "-Ddd.service.name=java-app",
+ "-Ddatadog.slf4j.simpleLogger.defaultLogLevel=debug",
+ "-jar",
+ "${tasks.shadowJar.archivePath}",
+ "--server.port=$springbootHttpPort"]
+ standardOutput "${buildDir}/reports/server.log"
+ waitForPort = springbootHttpPort
+ waitForOutput = "datadog.smoketest.springboot.SpringbootApplication - Started SpringbootApplication"
+ stopAfter = test
+}
+
+tasks.withType(Test) {
+ jvmArgs "-Ddatadog.smoketest.server.port=${springbootHttpPort}"
+
+ dependsOn startServer
+}

ADD
dd-smoke-tests/springboot/src/main/java/datadog/smoketest/springboot/SpringbootApplication.java
+package datadog.smoketest.springboot;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class SpringbootApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(SpringbootApplication.class, args);
+ }
+}

ADD
dd-smoke-tests/springboot/src/main/java/datadog/smoketest/springboot/controller/WebController.java
+package datadog.smoketest.springboot.controller;
+
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+public class WebController {
+ @RequestMapping("/greeting")
+ public String greeting() {
+ return "Sup Dawg";
+ }
+}

ADD
dd-smoke-tests/springboot/src/main/resources/application.properties
+logging.level.root=WARN
\ No newline at end of file

ADD
dd-smoke-tests/springboot/src/test/groovy/datadog/trace/agent/SpringBootSmokeTest.groovy
+package datadog.trace.agent
+
+import datadog.trace.agent.test.utils.OkHttpUtils
+import okhttp3.OkHttpClient
+import okhttp3.Request
+import spock.lang.Specification
+
+class SpringBootSmokeTest extends Specification {
+
+ private OkHttpClient client = OkHttpUtils.client()
+ private int port = Integer.parseInt(System.getProperty("datadog.smoketest.server.port", "8080"))
+
+ def "default home page #n th time"() {
+ setup:
+ String url = "http://localhost:$port/greeting"
+ def request = new Request.Builder().url(url).get().build()
+
+ when:
+ def response = client.newCall(request).execute()
+
+ then:
+ def responseBodyStr = response.body().string()
+ responseBodyStr != null
+ responseBodyStr.contains("Sup Dawg")
+ response.body().contentType().toString().contains("text/plain")
+ response.code() == 200
+
+ where:
+ n << (1..200)
+ }
+}

MODIFY
settings.gradle
settings.gradle
@@ -18,8 +18,9 @@ include ':dd-java-agent:agent-jmxfetch'
include ':dd-java-agent:testing'
// smoke tests
-include ':dd-smoke-tests:wildfly'
include ':dd-smoke-tests:play'
+include ':dd-smoke-tests:springboot'
+include ':dd-smoke-tests:wildfly'
// instrumentation:
include ':dd-java-agent:instrumentation:akka-http-10.0'

SpringBoot smoke test