fix: create a test to verify that spark is indeed responding

This commit is contained in:
Jørgen Grøndal 2018-03-09 12:48:42 +01:00 committed by Tyler Benson
parent ede4620b52
commit bb5c413be1
3 changed files with 39 additions and 18 deletions

View File

@ -89,7 +89,7 @@ public final class HandlerInstrumentation extends Instrumenter.Configurable {
.asChildOf(extractedContext)
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER)
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.WEB_SERVLET)
// .withTag("span.origin.type", statement.getClass().getName())
.withTag("span.origin.type", HandlerInstrumentationAdvice.class.getName())
.withTag(DDTags.RESOURCE_NAME, resourceName)
.startActive(false);

View File

@ -2,16 +2,25 @@ import datadog.trace.agent.test.AgentTestRunner
import datadog.trace.api.DDSpanTypes
import okhttp3.OkHttpClient
import okhttp3.Request
import spark.Spark
import spock.lang.Timeout
@Timeout(20)
class SparkJavaBasedTest extends AgentTestRunner {
static {
def setupSpec() {
TestSparkJavaApplication.initSpark()
}
def cleanupSpec() {
Spark.stop()
}
def setup() {
TEST_WRITER.start()
}
private int port = 4567
OkHttpClient client = new OkHttpClient.Builder().build()
@ -26,6 +35,19 @@ class SparkJavaBasedTest extends AgentTestRunner {
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)
@ -48,22 +70,22 @@ class SparkJavaBasedTest extends AgentTestRunner {
def trace = TEST_WRITER.firstTrace()
trace.size() == 1
def span = trace[0]
def spanContext = trace[0].context()
span.context().operationName == "jetty.request"
span.context().resourceName == "GET /param/:param/"
span.context().spanType == DDSpanTypes.WEB_SERVLET
!span.context().getErrorFlag()
span.context().parentId == 0
span.context().tags["http.url"] == "http://localhost:$port/param/asdf1234/"
span.context().tags["http.method"] == "GET"
span.context().tags["span.kind"] == "server"
span.context().tags["span.type"] == "web"
span.context().tags["component"] == "java-web-servlet"
span.context().tags["http.status_code"] == 200
span.context().tags["thread.name"] != null
span.context().tags["thread.id"] != null
span.context().tags.size() == 8
spanContext.operationName == "jetty.request"
spanContext.resourceName == "GET /param/:param/"
spanContext.spanType == DDSpanTypes.WEB_SERVLET
!spanContext.getErrorFlag()
spanContext.parentId == 0
spanContext.tags["http.url"] == "http://localhost:$port/param/asdf1234/"
spanContext.tags["http.method"] == "GET"
spanContext.tags["span.kind"] == "server"
spanContext.tags["span.type"] == "web"
spanContext.tags["component"] == "java-web-servlet"
spanContext.tags["http.status_code"] == 200
spanContext.tags["thread.name"] != null
spanContext.tags["thread.id"] != null
spanContext.tags.size() == 8
}
}

View File

@ -15,5 +15,4 @@ public class TestSparkJavaApplication {
});
Spark.awaitInitialization();
}
}