Skip to content

Commit

Permalink
Fix function test using other server stub
Browse files Browse the repository at this point in the history
  • Loading branch information
jsalinaspolo committed Jan 11, 2022
1 parent 47edf76 commit c559781
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,23 @@ package io.opentelemetry.instrumentation.ratpack

import io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter
import io.opentelemetry.sdk.trace.export.SpanExporter
import ratpack.guice.BindingsImposition
import ratpack.impose.ForceDevelopmentImposition
import ratpack.impose.ImpositionsSpec
import ratpack.impose.UserRegistryImposition
import ratpack.registry.Registry
import ratpack.test.MainClassApplicationUnderTest
import ratpack.test.embed.EmbeddedApp

class RatpackFunctionalTest extends MainClassApplicationUnderTest {

Registry registry
@Lazy InMemorySpanExporter spanExporter = registry.get(SpanExporter) as InMemorySpanExporter
@Lazy EmbeddedApp app = EmbeddedApp.of { server ->
server.handlers { chain ->
chain.get("other") { ctx -> ctx.render("hi-other") }
}
}

RatpackFunctionalTest(Class<?> mainClass) {
super(mainClass)
Expand All @@ -31,5 +38,8 @@ class RatpackFunctionalTest extends MainClassApplicationUnderTest {
registry = r
registry
})
impositions.add(BindingsImposition.of {
it.bindInstance(URI, app.address.resolve("other"))
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,15 @@ class OpenTelemetryModule extends AbstractModule {

@Singleton
@Provides
ExecInitializer ratpackExecInitializer(RatpackHttpTracing ratpackTracing) {
return ratpackTracing.getOpenTelemetryExecInitializer()
ExecInitializer ratpackExecInitializer(RatpackHttpTracing ratpackHttpTracing) {
return ratpackHttpTracing.getOpenTelemetryExecInitializer()
}

}

@CompileStatic
class RatpackApp {

static void main(String... args) {
def other = RatpackServer.start { server ->
server.handlers { chain ->
chain.get("other") { ctx -> ctx.render("hi-other") }
}
}

RatpackServer.start { server ->
server
.registry(Guice.registry { b -> b.module(OpenTelemetryModule) })
Expand All @@ -162,8 +156,7 @@ class RatpackApp {
.all(OpenTelemetryServerHandler)
.get("foo") { ctx -> ctx.render("hi-foo") }
.get("bar") { ctx ->
def instrumentedHttpClient = ctx.get(HttpClient)
instrumentedHttpClient.get(new URI("http://${other.bindHost}:${other.bindPort}/other"))
ctx.get(HttpClient).get(ctx.get(URI))
.then { ctx.render("hi-bar") }
}
}
Expand Down

0 comments on commit c559781

Please sign in to comment.