Skip to content

Commit 8eac124

Browse files
committed
Add tapir routes test to verify fix
Prior to adding the on exit finalization logic to the Future, this test failed because of an NPE thrown because PekkoRouteHolder.restore was called in the wrong order.
1 parent 5c6730a commit 8eac124

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

instrumentation/pekko/pekko-http-1.0/javaagent/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ dependencies {
3131
library("org.apache.pekko:pekko-http_2.12:1.0.0")
3232
library("org.apache.pekko:pekko-stream_2.12:1.0.1")
3333

34+
testImplementation("com.softwaremill.sttp.tapir:tapir-pekko-http-server_2.12:1.7.0")
35+
3436
testInstrumentation(project(":instrumentation:pekko:pekko-actor-1.0:javaagent"))
3537
testInstrumentation(project(":instrumentation:executors:javaagent"))
3638

instrumentation/pekko/pekko-http-1.0/javaagent/src/test/scala/io/opentelemetry/javaagent/instrumentation/pekkohttp/v1_0/PekkoHttpServerRouteTest.scala

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ import org.junit.jupiter.api.{AfterAll, Test, TestInstance}
3131

3232
import java.net.{URI, URISyntaxException}
3333
import java.util.function.Consumer
34-
import scala.concurrent.Await
34+
import scala.concurrent.{Await, ExecutionContext, Future}
3535
import scala.concurrent.duration.DurationInt
36+
import sttp.tapir._
37+
import sttp.tapir.server.pekkohttp.PekkoHttpServerInterpreter
3638

3739
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
3840
class PekkoHttpServerRouteTest {
@@ -77,6 +79,26 @@ class PekkoHttpServerRouteTest {
7779
test(route, "/test/1", "GET /test/*")
7880
}
7981

82+
@Test def testTapirRoutes(): Unit = {
83+
val interpreter = PekkoHttpServerInterpreter()(system.dispatcher)
84+
def makeRoute(input: EndpointInput[Unit]) = {
85+
interpreter.toRoute(
86+
endpoint.get
87+
.in(input)
88+
.errorOut(stringBody)
89+
.out(stringBody)
90+
.serverLogicPure[Future](_ => Right("ok"))
91+
)
92+
}
93+
94+
val routes = concat(
95+
concat(makeRoute("test" / "1"), makeRoute("test" / "2")),
96+
concat(makeRoute("test" / "3"), makeRoute("test" / "4"))
97+
)
98+
99+
test(routes, "/test/4", "GET")
100+
}
101+
80102
def test(route: Route, path: String, spanName: String): Unit = {
81103
val port = PortUtils.findOpenPort
82104
val address: URI = buildAddress(port)

0 commit comments

Comments
 (0)