Remove redundant tests from SparkJava
Tests that create traces and do not assert on them may leave traces
behind for the next test causing errors.
MODIFY
dd-java-agent/instrumentation/jetty-8/src/test/groovy/JettyHandlerTest.groovy
dd-java-agent/instrumentation/jetty-8/src/test/groovy/JettyHandlerTest.groovy
@@ -2,6 +2,7 @@ import datadog.trace.agent.test.AgentTestRunner
import datadog.trace.agent.test.TestUtils
import datadog.trace.agent.test.utils.OkHttpUtils
import datadog.trace.api.DDSpanTypes
+import datadog.trace.api.DDTags
import okhttp3.OkHttpClient
import org.eclipse.jetty.continuation.Continuation
import org.eclipse.jetty.continuation.ContinuationSupport
@@ -72,7 +73,7 @@ class JettyHandlerTest extends AgentTestRunner {
"span.kind" "server"
"component" "jetty-handler"
"span.origin.type" handler.class.name
- "span.type" DDSpanTypes.HTTP_SERVER
+ "$DDTags.SPAN_TYPE" DDSpanTypes.HTTP_SERVER
"http.status_code" 200
defaultTags()
}

MODIFY
dd-java-agent/instrumentation/sparkjava-2.3/src/test/groovy/SparkJavaBasedTest.groovy
dd-java-agent/instrumentation/sparkjava-2.3/src/test/groovy/SparkJavaBasedTest.groovy
import datadog.trace.agent.test.AgentTestRunner
import datadog.trace.agent.test.TestUtils
import datadog.trace.agent.test.utils.OkHttpUtils
-import datadog.trace.api.Config
import datadog.trace.api.DDSpanTypes
+import datadog.trace.api.DDTags
import okhttp3.OkHttpClient
import okhttp3.Request
import spark.Spark
-import spark.embeddedserver.jetty.JettyHandler
import spock.lang.Shared
class SparkJavaBasedTest extends AgentTestRunner {
@@ -30,37 +29,6 @@ class SparkJavaBasedTest extends AgentTestRunner {
Spark.stop()
}
- def "valid response"() {
- setup:
- def request = new Request.Builder()
- .url("http://localhost:$port/")
- .get()
- .build()
- def response = client.newCall(request).execute()
-
- expect:
- port != 0
- response.body().string() == "Hello World"
- }
-
- def "valid response with registered trace"() {
- setup:
- def request = new Request.Builder()
- .url("http://localhost:$port/")
- .get()
- .build()
- def response = client.newCall(request).execute()
-
- expect:
- port != 0
- response.body().string() == "Hello World"
-
- and:
- TEST_WRITER.waitForTraces(1)
- TEST_WRITER.size() == 1
- }
-
-
def "generates spans"() {
setup:
def request = new Request.Builder()
@@ -70,31 +38,31 @@ class SparkJavaBasedTest extends AgentTestRunner {
def response = client.newCall(request).execute()
expect:
+ port != 0
response.body().string() == "Hello asdf1234"
- TEST_WRITER.waitForTraces(1)
- TEST_WRITER.size() == 1
- def trace = TEST_WRITER.firstTrace()
- trace.size() == 1
- def context = trace[0].context()
- context.serviceName == "unnamed-java-app"
- context.operationName == "jetty.request"
- context.resourceName == "GET /param/:param"
- context.spanType == DDSpanTypes.HTTP_SERVER
- !context.getErrorFlag()
- context.parentId == "0"
- def tags = context.tags
- tags["http.url"] == "http://localhost:$port/param/asdf1234"
- tags["http.method"] == "GET"
- tags["span.kind"] == "server"
- tags["span.type"] == DDSpanTypes.HTTP_SERVER
- tags["component"] == "jetty-handler"
- tags["http.status_code"] == 200
- tags["thread.name"] != null
- tags["thread.id"] != null
- tags[Config.RUNTIME_ID_TAG] == Config.get().runtimeId
- tags["span.origin.type"] == JettyHandler.name
- tags.size() == 10
+ assertTraces(1) {
+ trace(0, 1) {
+ span(0) {
+ serviceName "unnamed-java-app"
+ operationName "jetty.request"
+ resourceName "GET /param/:param"
+ spanType DDSpanTypes.HTTP_SERVER
+ errored false
+ parent()
+ tags {
+ "http.url" "http://localhost:$port/param/asdf1234"
+ "http.method" "GET"
+ "span.kind" "server"
+ "component" "jetty-handler"
+ "span.origin.type" spark.embeddedserver.jetty.JettyHandler.name
+ "$DDTags.SPAN_TYPE" DDSpanTypes.HTTP_SERVER
+ "http.status_code" 200
+ defaultTags()
+ }
+ }
+ }
+ }
}
}

Remove redundant tests from SparkJava

Tests that create traces and do not assert on them may leave traces
behind for the next test causing errors.