Skip to content

Commit

Permalink
Improve PlayServerInterpreter.toRoutes (#3838)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmtran-g authored Jun 13, 2024
1 parent 8660b71 commit c5c59e1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion perf-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ sbt -Dtapir.perf.user-count=100 -Dtapir.perf.duration-seconds=60
```
or within an already running interactive sbt session:
```
set ThisBuild/javaOptions += ""-Dtapir.perf.user-count=100"
set ThisBuild/javaOptions += "-Dtapir.perf.user-count=100"
```
If not set, default values will be used (see `sttp.tapir.perf.CommonSimulations`).

Expand Down
8 changes: 4 additions & 4 deletions perf-tests/src/test/scala/sttp/tapir/perf/Simulations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ object CommonSimulations {
)
.exec(handleLatencyHistogram(histogram, warmup))

scenario(s"Repeatedly invoke POST with short string body")
scenario(s"${namePrefix(warmup)} Repeatedly invoke POST with short string body")
.during(duration(warmup))(execHttpPost)
.inject(atOnceUsers(userCount))
.protocols(httpProtocol)
Expand All @@ -92,7 +92,7 @@ object CommonSimulations {
)
.exec(handleLatencyHistogram(histogram, warmup))

scenario(s"Repeatedly invoke POST with short byte array body")
scenario(s"${namePrefix(warmup)} Repeatedly invoke POST with short byte array body")
.during(duration(warmup))(execHttpPost)
.inject(atOnceUsers(userCount))
.protocols(httpProtocol)
Expand All @@ -108,7 +108,7 @@ object CommonSimulations {
)
.exec(handleLatencyHistogram(histogram, warmup))

scenario(s"Repeatedly invoke POST with large byte array")
scenario(s"${namePrefix(warmup)} Repeatedly invoke POST with large byte array")
.during(duration(warmup))(execHttpPost)
.inject(atOnceUsers(userCount))
.protocols(httpProtocol)
Expand All @@ -124,7 +124,7 @@ object CommonSimulations {
)
.exec(handleLatencyHistogram(histogram, warmup))

scenario(s"Repeatedly invoke POST with large byte array, interpreted to a String")
scenario(s"${namePrefix(warmup)} Repeatedly invoke POST with large byte array, interpreted to a String")
.during(duration(warmup))(execHttpPost)
.inject(atOnceUsers(userCount))
.protocols(httpProtocol)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ trait PlayServerInterpreter {
val filterServerEndpoints = FilterServerEndpoints(serverEndpoints)
val singleEndpoint = serverEndpoints.size == 1

implicit val bodyListener: BodyListener[Future, PlayResponseBody] = new PlayBodyListener

val interpreter = new ServerInterpreter(
filterServerEndpoints,
new PlayRequestBody(playServerOptions),
new PlayToResponseBody,
playServerOptions.interceptors,
playServerOptions.deleteFile
)

new PartialFunction[RequestHeader, Handler] {
override def isDefinedAt(request: RequestHeader): Boolean = {
val filtered = filterServerEndpoints(PlayServerRequest(request, request))
Expand Down Expand Up @@ -76,15 +86,7 @@ trait PlayServerInterpreter {
header: RequestHeader,
request: Request[PekkoStreams.BinaryStream]
): Future[Either[Result, Flow[Message, Message, Any]]] = {
implicit val bodyListener: BodyListener[Future, PlayResponseBody] = new PlayBodyListener
val serverRequest = PlayServerRequest(header, request)
val interpreter = new ServerInterpreter(
filterServerEndpoints,
new PlayRequestBody(playServerOptions),
new PlayToResponseBody,
playServerOptions.interceptors,
playServerOptions.deleteFile
)

interpreter(serverRequest)
.map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ trait PlayServerInterpreter {
val filterServerEndpoints = FilterServerEndpoints(serverEndpoints)
val singleEndpoint = serverEndpoints.size == 1

implicit val bodyListener: BodyListener[Future, PlayResponseBody] = new PlayBodyListener

val interpreter = new ServerInterpreter(
filterServerEndpoints,
new PlayRequestBody(playServerOptions),
new PlayToResponseBody,
playServerOptions.interceptors,
playServerOptions.deleteFile
)

new PartialFunction[RequestHeader, Handler] {
override def isDefinedAt(request: RequestHeader): Boolean = {
val filtered = filterServerEndpoints(PlayServerRequest(request, request))
Expand Down Expand Up @@ -76,15 +86,7 @@ trait PlayServerInterpreter {
header: RequestHeader,
request: Request[AkkaStreams.BinaryStream]
): Future[Either[Result, Flow[Message, Message, Any]]] = {
implicit val bodyListener: BodyListener[Future, PlayResponseBody] = new PlayBodyListener
val serverRequest = PlayServerRequest(header, request)
val interpreter = new ServerInterpreter(
filterServerEndpoints,
new PlayRequestBody(playServerOptions),
new PlayToResponseBody,
playServerOptions.interceptors,
playServerOptions.deleteFile
)

interpreter(serverRequest)
.map {
Expand Down

0 comments on commit c5c59e1

Please sign in to comment.