fix: create a test to verify that spark is indeed responding
This commit is contained in:
parent
ede4620b52
commit
bb5c413be1
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,5 +15,4 @@ public class TestSparkJavaApplication {
|
|||
});
|
||||
Spark.awaitInitialization();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue