Use Ratpack core API for test server. (#3215)
* Use Ratpack core API for test server. * Fix async path param test * Spotless
This commit is contained in:
parent
1b63e3265f
commit
d94a92c4ab
|
@ -13,7 +13,7 @@ dependencies {
|
|||
|
||||
implementation project(':instrumentation:netty:netty-4.1:javaagent')
|
||||
|
||||
testLibrary "io.ratpack:ratpack-groovy-test:1.4.0"
|
||||
testLibrary "io.ratpack:ratpack-test:1.4.0"
|
||||
|
||||
if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_11)) {
|
||||
testImplementation "com.sun.activation:jakarta.activation:1.2.2"
|
||||
|
|
|
@ -12,8 +12,8 @@ import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
|
|||
import okhttp3.HttpUrl
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import ratpack.groovy.test.embed.GroovyEmbeddedApp
|
||||
import ratpack.path.PathBinding
|
||||
import ratpack.server.RatpackServer
|
||||
|
||||
class RatpackOtherTest extends AgentInstrumentationSpecification {
|
||||
|
||||
|
@ -21,42 +21,43 @@ class RatpackOtherTest extends AgentInstrumentationSpecification {
|
|||
|
||||
def "test bindings for #path"() {
|
||||
setup:
|
||||
def app = GroovyEmbeddedApp.ratpack {
|
||||
handlers {
|
||||
prefix("a") {
|
||||
all {
|
||||
def app = RatpackServer.start {
|
||||
it.handlers {
|
||||
it.prefix("a") {
|
||||
it.all {context ->
|
||||
context.render(context.get(PathBinding).description)
|
||||
}
|
||||
}
|
||||
prefix("b/::\\d+") {
|
||||
all {
|
||||
it.prefix("b/::\\d+") {
|
||||
it.all {context ->
|
||||
context.render(context.get(PathBinding).description)
|
||||
}
|
||||
}
|
||||
prefix("c/:val?") {
|
||||
all {
|
||||
it.prefix("c/:val?") {
|
||||
it.all {context ->
|
||||
context.render(context.get(PathBinding).description)
|
||||
}
|
||||
}
|
||||
prefix("d/:val") {
|
||||
all {
|
||||
it.prefix("d/:val") {
|
||||
it.all {context ->
|
||||
context.render(context.get(PathBinding).description)
|
||||
}
|
||||
}
|
||||
prefix("e/:val?:\\d+") {
|
||||
all {
|
||||
it.prefix("e/:val?:\\d+") {
|
||||
it.all {context ->
|
||||
context.render(context.get(PathBinding).description)
|
||||
}
|
||||
}
|
||||
prefix("f/:val:\\d+") {
|
||||
all {
|
||||
it.prefix("f/:val:\\d+") {
|
||||
it.all {context ->
|
||||
context.render(context.get(PathBinding).description)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
def address = "${app.scheme}://${app.bindHost}:${app.bindPort}"
|
||||
def request = new Request.Builder()
|
||||
.url(HttpUrl.get(app.address).newBuilder().addPathSegments(path).build())
|
||||
.url(HttpUrl.get(address).newBuilder().addPathSegments(path).build())
|
||||
.get()
|
||||
.build()
|
||||
|
||||
|
@ -76,7 +77,7 @@ class RatpackOtherTest extends AgentInstrumentationSpecification {
|
|||
attributes {
|
||||
"${SemanticAttributes.NET_PEER_IP.key}" "127.0.0.1"
|
||||
"${SemanticAttributes.NET_PEER_PORT.key}" Long
|
||||
"${SemanticAttributes.HTTP_URL.key}" "${app.address.resolve(path)}"
|
||||
"${SemanticAttributes.HTTP_URL.key}" "${address}/${path}"
|
||||
"${SemanticAttributes.HTTP_METHOD.key}" "GET"
|
||||
"${SemanticAttributes.HTTP_STATUS_CODE.key}" 200
|
||||
"${SemanticAttributes.HTTP_FLAVOR.key}" "1.1"
|
||||
|
@ -94,6 +95,9 @@ class RatpackOtherTest extends AgentInstrumentationSpecification {
|
|||
}
|
||||
}
|
||||
|
||||
cleanup:
|
||||
app.stop()
|
||||
|
||||
where:
|
||||
path | route
|
||||
"a" | "a"
|
||||
|
|
|
@ -13,25 +13,25 @@ import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEn
|
|||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
|
||||
import ratpack.error.ServerErrorHandler
|
||||
import ratpack.exec.Promise
|
||||
import ratpack.groovy.test.embed.GroovyEmbeddedApp
|
||||
import ratpack.test.embed.EmbeddedApp
|
||||
import ratpack.server.RatpackServer
|
||||
|
||||
class RatpackAsyncHttpServerTest extends RatpackHttpServerTest {
|
||||
|
||||
@Override
|
||||
EmbeddedApp startServer(int bindPort) {
|
||||
def ratpack = GroovyEmbeddedApp.ratpack {
|
||||
serverConfig {
|
||||
port bindPort
|
||||
address InetAddress.getByName('localhost')
|
||||
RatpackServer startServer(int bindPort) {
|
||||
def ratpack = RatpackServer.start {
|
||||
it.serverConfig {
|
||||
it.port(bindPort)
|
||||
it.address(InetAddress.getByName("localhost"))
|
||||
}
|
||||
bindings {
|
||||
bind TestErrorHandler
|
||||
}
|
||||
handlers {
|
||||
prefix(SUCCESS.rawPath()) {
|
||||
all {
|
||||
it.handlers {
|
||||
it.register {
|
||||
it.add(ServerErrorHandler, new TestErrorHandler())
|
||||
}
|
||||
it.prefix(SUCCESS.rawPath()) {
|
||||
it.all {context ->
|
||||
Promise.sync {
|
||||
SUCCESS
|
||||
} then { endpoint ->
|
||||
|
@ -41,31 +41,31 @@ class RatpackAsyncHttpServerTest extends RatpackHttpServerTest {
|
|||
}
|
||||
}
|
||||
}
|
||||
prefix(INDEXED_CHILD.rawPath()) {
|
||||
all {
|
||||
it.prefix(INDEXED_CHILD.rawPath()) {
|
||||
it.all {context ->
|
||||
Promise.sync {
|
||||
INDEXED_CHILD
|
||||
} then {
|
||||
controller(INDEXED_CHILD) {
|
||||
INDEXED_CHILD.collectSpanAttributes { request.queryParams.get(it) }
|
||||
INDEXED_CHILD.collectSpanAttributes { context.request.queryParams.get(it) }
|
||||
context.response.status(INDEXED_CHILD.status).send()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
prefix(QUERY_PARAM.rawPath()) {
|
||||
all {
|
||||
it.prefix(QUERY_PARAM.rawPath()) {
|
||||
it.all { context ->
|
||||
Promise.sync {
|
||||
QUERY_PARAM
|
||||
} then { endpoint ->
|
||||
controller(endpoint) {
|
||||
context.response.status(endpoint.status).send(request.query)
|
||||
context.response.status(endpoint.status).send(context.request.query)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
prefix(REDIRECT.rawPath()) {
|
||||
all {
|
||||
it.prefix(REDIRECT.rawPath()) {
|
||||
it.all {context ->
|
||||
Promise.sync {
|
||||
REDIRECT
|
||||
} then { endpoint ->
|
||||
|
@ -75,8 +75,8 @@ class RatpackAsyncHttpServerTest extends RatpackHttpServerTest {
|
|||
}
|
||||
}
|
||||
}
|
||||
prefix(ERROR.rawPath()) {
|
||||
all {
|
||||
it.prefix(ERROR.rawPath()) {
|
||||
it.all {context ->
|
||||
Promise.sync {
|
||||
ERROR
|
||||
} then { endpoint ->
|
||||
|
@ -86,8 +86,8 @@ class RatpackAsyncHttpServerTest extends RatpackHttpServerTest {
|
|||
}
|
||||
}
|
||||
}
|
||||
prefix(EXCEPTION.rawPath()) {
|
||||
all {
|
||||
it.prefix(EXCEPTION.rawPath()) {
|
||||
it.all {
|
||||
Promise.sync {
|
||||
EXCEPTION
|
||||
} then { endpoint ->
|
||||
|
@ -97,23 +97,22 @@ class RatpackAsyncHttpServerTest extends RatpackHttpServerTest {
|
|||
}
|
||||
}
|
||||
}
|
||||
prefix("path/:id/param") {
|
||||
all {
|
||||
it.prefix("path/:id/param") {
|
||||
it.all {context ->
|
||||
Promise.sync {
|
||||
PATH_PARAM
|
||||
}.fork().then { endpoint ->
|
||||
} then { endpoint ->
|
||||
controller(endpoint) {
|
||||
context.response.status(endpoint.status).send(pathTokens.id)
|
||||
context.response.status(endpoint.status).send(context.pathTokens.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ratpack.server.start()
|
||||
|
||||
assert ratpack.address.port == bindPort
|
||||
assert ratpack.server.bindHost == 'localhost'
|
||||
assert ratpack.bindPort == bindPort
|
||||
assert ratpack.bindHost == 'localhost'
|
||||
return ratpack
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,25 +13,26 @@ import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEn
|
|||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
|
||||
import ratpack.error.ServerErrorHandler
|
||||
import ratpack.exec.Promise
|
||||
import ratpack.groovy.test.embed.GroovyEmbeddedApp
|
||||
import ratpack.test.embed.EmbeddedApp
|
||||
import ratpack.server.RatpackServer
|
||||
|
||||
class RatpackForkedHttpServerTest extends RatpackHttpServerTest {
|
||||
|
||||
@Override
|
||||
EmbeddedApp startServer(int bindPort) {
|
||||
def ratpack = GroovyEmbeddedApp.ratpack {
|
||||
serverConfig {
|
||||
port bindPort
|
||||
address InetAddress.getByName('localhost')
|
||||
RatpackServer startServer(int bindPort) {
|
||||
|
||||
def ratpack = RatpackServer.start {
|
||||
it.serverConfig {
|
||||
it.port(bindPort)
|
||||
it.address(InetAddress.getByName("localhost"))
|
||||
}
|
||||
bindings {
|
||||
bind TestErrorHandler
|
||||
}
|
||||
handlers {
|
||||
prefix(SUCCESS.rawPath()) {
|
||||
all {
|
||||
it.handlers {
|
||||
it.register {
|
||||
it.add(ServerErrorHandler, new TestErrorHandler())
|
||||
}
|
||||
it.prefix(SUCCESS.rawPath()) {
|
||||
it.all {context ->
|
||||
Promise.sync {
|
||||
SUCCESS
|
||||
}.fork().then { endpoint ->
|
||||
|
@ -41,31 +42,31 @@ class RatpackForkedHttpServerTest extends RatpackHttpServerTest {
|
|||
}
|
||||
}
|
||||
}
|
||||
prefix(INDEXED_CHILD.rawPath()) {
|
||||
all {
|
||||
it.prefix(INDEXED_CHILD.rawPath()) {
|
||||
it.all {context ->
|
||||
Promise.sync {
|
||||
INDEXED_CHILD
|
||||
}.fork().then {
|
||||
controller(INDEXED_CHILD) {
|
||||
INDEXED_CHILD.collectSpanAttributes { request.queryParams.get(it) }
|
||||
INDEXED_CHILD.collectSpanAttributes { context.request.queryParams.get(it) }
|
||||
context.response.status(INDEXED_CHILD.status).send()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
prefix(QUERY_PARAM.rawPath()) {
|
||||
all {
|
||||
it.prefix(QUERY_PARAM.rawPath()) {
|
||||
it.all { context ->
|
||||
Promise.sync {
|
||||
QUERY_PARAM
|
||||
}.fork().then { endpoint ->
|
||||
controller(endpoint) {
|
||||
context.response.status(endpoint.status).send(request.query)
|
||||
context.response.status(endpoint.status).send(context.request.query)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
prefix(REDIRECT.rawPath()) {
|
||||
all {
|
||||
it.prefix(REDIRECT.rawPath()) {
|
||||
it.all {context ->
|
||||
Promise.sync {
|
||||
REDIRECT
|
||||
}.fork().then { endpoint ->
|
||||
|
@ -75,8 +76,8 @@ class RatpackForkedHttpServerTest extends RatpackHttpServerTest {
|
|||
}
|
||||
}
|
||||
}
|
||||
prefix(ERROR.rawPath()) {
|
||||
all {
|
||||
it.prefix(ERROR.rawPath()) {
|
||||
it.all {context ->
|
||||
Promise.sync {
|
||||
ERROR
|
||||
}.fork().then { endpoint ->
|
||||
|
@ -86,8 +87,8 @@ class RatpackForkedHttpServerTest extends RatpackHttpServerTest {
|
|||
}
|
||||
}
|
||||
}
|
||||
prefix(EXCEPTION.rawPath()) {
|
||||
all {
|
||||
it.prefix(EXCEPTION.rawPath()) {
|
||||
it.all {
|
||||
Promise.sync {
|
||||
EXCEPTION
|
||||
}.fork().then { endpoint ->
|
||||
|
@ -97,22 +98,22 @@ class RatpackForkedHttpServerTest extends RatpackHttpServerTest {
|
|||
}
|
||||
}
|
||||
}
|
||||
prefix("path/:id/param") {
|
||||
all {
|
||||
it.prefix("path/:id/param") {
|
||||
it.all {context ->
|
||||
Promise.sync {
|
||||
PATH_PARAM
|
||||
}.fork().then { endpoint ->
|
||||
controller(endpoint) {
|
||||
context.response.status(endpoint.status).send(pathTokens.id)
|
||||
context.response.status(endpoint.status).send(context.pathTokens.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ratpack.server.start()
|
||||
|
||||
assert ratpack.address.port == bindPort
|
||||
assert ratpack.bindPort == bindPort
|
||||
assert ratpack.bindHost == 'localhost'
|
||||
return ratpack
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,78 +20,76 @@ import io.opentelemetry.instrumentation.test.asserts.TraceAssert
|
|||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.sdk.trace.data.SpanData
|
||||
import ratpack.error.ServerErrorHandler
|
||||
import ratpack.groovy.test.embed.GroovyEmbeddedApp
|
||||
import ratpack.handling.Context
|
||||
import ratpack.test.embed.EmbeddedApp
|
||||
import ratpack.server.RatpackServer
|
||||
|
||||
class RatpackHttpServerTest extends HttpServerTest<EmbeddedApp> implements AgentTestTrait {
|
||||
class RatpackHttpServerTest extends HttpServerTest<RatpackServer> implements AgentTestTrait {
|
||||
|
||||
@Override
|
||||
EmbeddedApp startServer(int bindPort) {
|
||||
def ratpack = GroovyEmbeddedApp.ratpack {
|
||||
serverConfig {
|
||||
port bindPort
|
||||
address InetAddress.getByName('localhost')
|
||||
RatpackServer startServer(int bindPort) {
|
||||
def ratpack = RatpackServer.start {
|
||||
it.serverConfig {
|
||||
it.port(bindPort)
|
||||
it.address(InetAddress.getByName("localhost"))
|
||||
}
|
||||
bindings {
|
||||
bind TestErrorHandler
|
||||
}
|
||||
handlers {
|
||||
prefix(SUCCESS.rawPath()) {
|
||||
all {
|
||||
it.handlers {
|
||||
it.register {
|
||||
it.add(ServerErrorHandler, new TestErrorHandler())
|
||||
}
|
||||
it.prefix(SUCCESS.rawPath()) {
|
||||
it.all {context ->
|
||||
controller(SUCCESS) {
|
||||
context.response.status(SUCCESS.status).send(SUCCESS.body)
|
||||
}
|
||||
}
|
||||
}
|
||||
prefix(INDEXED_CHILD.rawPath()) {
|
||||
all {
|
||||
it.prefix(INDEXED_CHILD.rawPath()) {
|
||||
it.all {context ->
|
||||
controller(INDEXED_CHILD) {
|
||||
INDEXED_CHILD.collectSpanAttributes { request.queryParams.get(it) }
|
||||
INDEXED_CHILD.collectSpanAttributes { context.request.queryParams.get(it) }
|
||||
context.response.status(INDEXED_CHILD.status).send()
|
||||
}
|
||||
}
|
||||
}
|
||||
prefix(QUERY_PARAM.rawPath()) {
|
||||
all {
|
||||
it.prefix(QUERY_PARAM.rawPath()) {
|
||||
it.all { context ->
|
||||
controller(QUERY_PARAM) {
|
||||
context.response.status(QUERY_PARAM.status).send(request.query)
|
||||
context.response.status(QUERY_PARAM.status).send(context.request.query)
|
||||
}
|
||||
}
|
||||
}
|
||||
prefix(REDIRECT.rawPath()) {
|
||||
all {
|
||||
it.prefix(REDIRECT.rawPath()) {
|
||||
it.all {context ->
|
||||
controller(REDIRECT) {
|
||||
context.redirect(REDIRECT.body)
|
||||
}
|
||||
}
|
||||
}
|
||||
prefix(ERROR.rawPath()) {
|
||||
all {
|
||||
it.prefix(ERROR.rawPath()) {
|
||||
it.all {context ->
|
||||
controller(ERROR) {
|
||||
context.response.status(ERROR.status).send(ERROR.body)
|
||||
}
|
||||
}
|
||||
}
|
||||
prefix(EXCEPTION.rawPath()) {
|
||||
all {
|
||||
it.prefix(EXCEPTION.rawPath()) {
|
||||
it.all {
|
||||
controller(EXCEPTION) {
|
||||
throw new Exception(EXCEPTION.body)
|
||||
}
|
||||
}
|
||||
}
|
||||
prefix("path/:id/param") {
|
||||
all {
|
||||
it.prefix("path/:id/param") {
|
||||
it.all {context ->
|
||||
controller(PATH_PARAM) {
|
||||
context.response.status(PATH_PARAM.status).send(pathTokens.id)
|
||||
context.response.status(PATH_PARAM.status).send(context.pathTokens.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ratpack.server.start()
|
||||
|
||||
assert ratpack.address.port == bindPort
|
||||
assert ratpack.bindPort == bindPort
|
||||
return ratpack
|
||||
}
|
||||
|
||||
|
@ -103,8 +101,8 @@ class RatpackHttpServerTest extends HttpServerTest<EmbeddedApp> implements Agent
|
|||
}
|
||||
|
||||
@Override
|
||||
void stopServer(EmbeddedApp server) {
|
||||
server.close()
|
||||
void stopServer(RatpackServer server) {
|
||||
server.stop()
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue