Update Ratpack latest test
MODIFY
dd-java-agent/instrumentation/ratpack-1.4/src/latestDepTest/groovy/RatpackTest.groovy
dd-java-agent/instrumentation/ratpack-1.4/src/latestDepTest/groovy/RatpackTest.groovy
-import static datadog.trace.agent.test.server.http.TestHttpServer.distributedRequestTrace
-import static datadog.trace.agent.test.server.http.TestHttpServer.httpServer
-import static datadog.trace.agent.test.utils.PortUtils.UNUSABLE_PORT
-
import datadog.trace.agent.test.AgentTestRunner
import datadog.trace.agent.test.utils.OkHttpUtils
import datadog.trace.api.DDSpanTypes
@@ -12,8 +8,6 @@ import io.opentracing.Scope
import io.opentracing.Span
import io.opentracing.tag.Tags
import io.opentracing.util.GlobalTracer
-import java.util.concurrent.CountDownLatch
-import java.util.regex.Pattern
import okhttp3.HttpUrl
import okhttp3.OkHttpClient
import okhttp3.Request
@@ -26,87 +20,55 @@ import ratpack.http.client.HttpClient
import ratpack.path.PathBinding
import ratpack.test.exec.ExecHarness
+import java.util.concurrent.CountDownLatch
+import java.util.regex.Pattern
+
+import static datadog.trace.agent.test.server.http.TestHttpServer.distributedRequestTrace
+import static datadog.trace.agent.test.server.http.TestHttpServer.httpServer
+import static datadog.trace.agent.test.utils.PortUtils.UNUSABLE_PORT
+
class RatpackTest extends AgentTestRunner {
OkHttpClient client = OkHttpUtils.client()
- def "test path call"() {
+ def "test bindings for #path"() {
setup:
def app = GroovyEmbeddedApp.ratpack {
handlers {
- get {
- context.render("success")
+ prefix("a") {
+ all {
+ context.render(context.get(PathBinding).description)
}
}
+ prefix("b/::\\d+") {
+ all {
+ context.render(context.get(PathBinding).description)
}
- def request = new Request.Builder()
- .url(app.address.toURL())
- .get()
- .build()
-
- when:
- def resp = client.newCall(request).execute()
-
- then:
- resp.code() == 200
- resp.body.string() == "success"
-
- assertTraces(1) {
- trace(0, 2) {
- span(0) {
- resourceName "GET /"
- serviceName "unnamed-java-app"
- operationName "netty.request"
- spanType DDSpanTypes.HTTP_SERVER
- parent()
- errored false
- tags {
- "$Tags.COMPONENT.key" "netty"
- "$Tags.SPAN_KIND.key" Tags.SPAN_KIND_SERVER
- "$Tags.HTTP_METHOD.key" "GET"
- "$Tags.HTTP_STATUS.key" 200
- "$Tags.HTTP_URL.key" "$app.address"
- "$Tags.PEER_HOSTNAME.key" "$app.address.host"
- "$Tags.PEER_HOST_IPV4.key" "127.0.0.1"
- "$Tags.PEER_PORT.key" Integer
- defaultTags()
}
+ prefix("c/:val?") {
+ all {
+ context.render(context.get(PathBinding).description)
}
- span(1) {
- resourceName "GET /"
- serviceName "unnamed-java-app"
- operationName "ratpack.handler"
- spanType DDSpanTypes.HTTP_SERVER
- childOf(span(0))
- errored false
- tags {
- "$Tags.COMPONENT.key" "ratpack"
- "$Tags.SPAN_KIND.key" Tags.SPAN_KIND_SERVER
- "$Tags.HTTP_METHOD.key" "GET"
- "$Tags.HTTP_STATUS.key" 200
- "$Tags.HTTP_URL.key" "$app.address"
- "$Tags.PEER_HOSTNAME.key" "$app.address.host"
- "$Tags.PEER_PORT.key" Integer
- defaultTags()
}
+ prefix("d/:val") {
+ all {
+ context.render(context.get(PathBinding).description)
}
}
+ prefix("e/:val?:\\d+") {
+ all {
+ context.render(context.get(PathBinding).description)
}
}
-
- def "test path with bindings call"() {
- setup:
- def app = GroovyEmbeddedApp.ratpack {
- handlers {
- prefix(":foo/:bar?") {
- get("baz") {ctx ->
- context.render(ctx.get(PathBinding).description)
+ prefix("f/:val:\\d+") {
+ all {
+ context.render(context.get(PathBinding).description)
}
}
}
}
def request = new Request.Builder()
- .url(HttpUrl.get(app.address).newBuilder().addPathSegments("a/b/baz").build())
+ .url(HttpUrl.get(app.address).newBuilder().addPathSegments(path).build())
.get()
.build()
@@ -115,12 +77,12 @@ class RatpackTest extends AgentTestRunner {
then:
resp.code() == 200
- resp.body.string() == ":foo/:bar?/baz"
+ resp.body.string() == route
assertTraces(1) {
trace(0, 2) {
span(0) {
- resourceName "GET /:foo/:bar?/baz"
+ resourceName "GET /$route"
serviceName "unnamed-java-app"
operationName "netty.request"
spanType DDSpanTypes.HTTP_SERVER
@@ -131,7 +93,7 @@ class RatpackTest extends AgentTestRunner {
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_SERVER
"$Tags.HTTP_METHOD.key" "GET"
"$Tags.HTTP_STATUS.key" 200
- "$Tags.HTTP_URL.key" "${app.address}a/b/baz"
+ "$Tags.HTTP_URL.key" "${app.address.resolve(path)}"
"$Tags.PEER_HOSTNAME.key" "$app.address.host"
"$Tags.PEER_HOST_IPV4.key" "127.0.0.1"
"$Tags.PEER_PORT.key" Integer
@@ -139,7 +101,7 @@ class RatpackTest extends AgentTestRunner {
}
}
span(1) {
- resourceName "GET /:foo/:bar?/baz"
+ resourceName "GET /$route"
serviceName "unnamed-java-app"
operationName "ratpack.handler"
spanType DDSpanTypes.HTTP_SERVER
@@ -150,7 +112,7 @@ class RatpackTest extends AgentTestRunner {
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_SERVER
"$Tags.HTTP_METHOD.key" "GET"
"$Tags.HTTP_STATUS.key" 200
- "$Tags.HTTP_URL.key" "${app.address}a/b/baz"
+ "$Tags.HTTP_URL.key" "${app.address.resolve(path)}"
"$Tags.PEER_HOSTNAME.key" "$app.address.host"
"$Tags.PEER_PORT.key" Integer
defaultTags()
@@ -158,19 +120,35 @@ class RatpackTest extends AgentTestRunner {
}
}
}
+
+ where:
+ path | route
+ "a" | "a"
+ "b/123" | "b/::\\d+"
+ "c" | "c/:val?"
+ "c/123" | "c/:val?"
+ "c/foo" | "c/:val?"
+ "d/123" | "d/:val"
+ "d/foo" | "d/:val"
+ "e" | "e/:val?:\\d+"
+ "e/123" | "e/:val?:\\d+"
+ "e/foo" | "e/:val?:\\d+"
+ "f/123" | "f/:val:\\d+"
}
def "test handler error response"() {
setup:
def app = GroovyEmbeddedApp.ratpack {
handlers {
- get {
+ prefix("handler-error") {
+ all {
0 / 0
}
}
}
+ }
def request = new Request.Builder()
- .url(app.address.toURL())
+ .url(app.address.resolve("/handler-error?query=param").toURL())
.get()
.build()
when:
@@ -181,7 +159,7 @@ class RatpackTest extends AgentTestRunner {
assertTraces(1) {
trace(0, 2) {
span(0) {
- resourceName "GET /"
+ resourceName "GET /handler-error"
serviceName "unnamed-java-app"
operationName "netty.request"
spanType DDSpanTypes.HTTP_SERVER
@@ -192,7 +170,7 @@ class RatpackTest extends AgentTestRunner {
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_SERVER
"$Tags.HTTP_METHOD.key" "GET"
"$Tags.HTTP_STATUS.key" 500
- "$Tags.HTTP_URL.key" "$app.address"
+ "$Tags.HTTP_URL.key" "${app.address.resolve('handler-error')}"
"$Tags.PEER_HOSTNAME.key" "$app.address.host"
"$Tags.PEER_HOST_IPV4.key" "127.0.0.1"
"$Tags.PEER_PORT.key" Integer
@@ -201,7 +179,7 @@ class RatpackTest extends AgentTestRunner {
}
}
span(1) {
- resourceName "GET /"
+ resourceName "GET /handler-error"
serviceName "unnamed-java-app"
operationName "ratpack.handler"
spanType DDSpanTypes.HTTP_SERVER
@@ -212,7 +190,7 @@ class RatpackTest extends AgentTestRunner {
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_SERVER
"$Tags.HTTP_METHOD.key" "GET"
"$Tags.HTTP_STATUS.key" 500
- "$Tags.HTTP_URL.key" "$app.address"
+ "$Tags.HTTP_URL.key" "${app.address.resolve('handler-error')}"
"$Tags.PEER_HOSTNAME.key" "$app.address.host"
"$Tags.PEER_PORT.key" Integer
errorTags(HandlerException, Pattern.compile("java.lang.ArithmeticException: Division( is)? undefined"))
@@ -227,7 +205,7 @@ class RatpackTest extends AgentTestRunner {
setup:
def app = GroovyEmbeddedApp.ratpack {
handlers {
- get {
+ get("promise-error") {
Promise.async {
0 / 0
}.then {
@@ -237,7 +215,7 @@ class RatpackTest extends AgentTestRunner {
}
}
def request = new Request.Builder()
- .url(app.address.toURL())
+ .url(app.address.resolve("promise-error?query=param").toURL())
.get()
.build()
when:
@@ -248,7 +226,7 @@ class RatpackTest extends AgentTestRunner {
assertTraces(1) {
trace(0, 2) {
span(0) {
- resourceName "GET /"
+ resourceName "GET /promise-error"
serviceName "unnamed-java-app"
operationName "netty.request"
spanType DDSpanTypes.HTTP_SERVER
@@ -259,7 +237,7 @@ class RatpackTest extends AgentTestRunner {
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_SERVER
"$Tags.HTTP_METHOD.key" "GET"
"$Tags.HTTP_STATUS.key" 500
- "$Tags.HTTP_URL.key" "$app.address"
+ "$Tags.HTTP_URL.key" "${app.address.resolve('promise-error')}"
"$Tags.PEER_HOSTNAME.key" "$app.address.host"
"$Tags.PEER_HOST_IPV4.key" "127.0.0.1"
"$Tags.PEER_PORT.key" Integer
@@ -268,7 +246,7 @@ class RatpackTest extends AgentTestRunner {
}
}
span(1) {
- resourceName "GET /"
+ resourceName "GET /promise-error"
serviceName "unnamed-java-app"
operationName "ratpack.handler"
spanType DDSpanTypes.HTTP_SERVER
@@ -279,7 +257,7 @@ class RatpackTest extends AgentTestRunner {
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_SERVER
"$Tags.HTTP_METHOD.key" "GET"
"$Tags.HTTP_STATUS.key" 500
- "$Tags.HTTP_URL.key" "$app.address"
+ "$Tags.HTTP_URL.key" "${app.address.resolve('promise-error')}"
"$Tags.PEER_HOSTNAME.key" "$app.address.host"
"$Tags.PEER_PORT.key" Integer
"$Tags.ERROR.key" true
@@ -294,7 +272,7 @@ class RatpackTest extends AgentTestRunner {
setup:
def app = GroovyEmbeddedApp.ratpack {
handlers {
- get {
+ all {
context.render(Promise.sync {
return "fail " + 0 / 0
})
@@ -302,7 +280,7 @@ class RatpackTest extends AgentTestRunner {
}
}
def request = new Request.Builder()
- .url(app.address.toURL())
+ .url(app.address.resolve("?query=param").toURL())
.get()
.build()
when:
@@ -452,7 +430,7 @@ class RatpackTest extends AgentTestRunner {
serviceName "unnamed-java-app"
operationName "netty.client.request"
spanType DDSpanTypes.HTTP_CLIENT
- childOf(span(3))
+ childOf(span(1))
errored false
tags {
"$Tags.COMPONENT.key" "netty-client"

Update Ratpack latest test