Skip to content

fix: honour the Materializer passed to Java DSL Route.flow - #1276

Open
pjfanning wants to merge 1 commit into
apache:mainfrom
pjfanning:route-adapter-flow-materializer
Open

fix: honour the Materializer passed to Java DSL Route.flow#1276
pjfanning wants to merge 1 commit into
apache:mainfrom
pjfanning:route-adapter-flow-materializer

Conversation

@pjfanning

Copy link
Copy Markdown
Member

Motivation

RouteAdapter.flow(system, materializer) — the implementation behind the Java DSL Route.flow(ActorSystem, Materializer) — accepted a Materializer but only used the ActorSystem. The flow was built through the implicit RouteResult.routeToFlow conversion, and Route.toFunction hardcodes SystemMaterializer(system).materializer into the RequestContext, so the materializer supplied by Java users was silently discarded. Routes saw the system materializer in extractMaterializer, in entity(...) unmarshalling, and in any stream run from a directive.

Modification

  • scaladsl/server/Route.scala: added a private[pekko] toFunction(route, materializer) overload holding the existing body; the public toFunction(route) now delegates to it with SystemMaterializer(system).materializer, so its behaviour is unchanged.
  • javadsl/server/directives/RouteAdapter.scala: scalaFlow builds its handler with that overload and does the mapAsync(1) itself, so the given materializer reaches the RequestContext.

No copied code.

Result

Route.flow(system, materializer) runs the route with the materializer it was given. The flow(system) overload is unaffected — it already passed SystemMaterializer(system).materializer explicitly. Binary compatibility is preserved: the new method is private[pekko] and purely additive.

Tests

  • sbt "http-tests/testOnly org.apache.pekko.http.javadsl.server.RouteFlowMaterializerTest" — 2 passed. New test asserts the materializer observed by extractMaterializer for both the explicit-materializer and system-materializer overloads. Directional: with the RouteAdapter change reverted, flowUsesTheGivenMaterializer fails with expected: <270352276> but was: <1155460560>.
  • sbt "http/scalafmt" "http-tests/Test/javafmt" "http/mimaReportBinaryIssues" — clean (MiMa scoped to the changed module).
  • sbt headerCreateAll — header added to the new test file.
  • git diff --check — clean.

References

None - Java DSL Route.flow(system, materializer) ignored its materializer argument.

Motivation:
RouteAdapter.flow(system, materializer) accepted a Materializer but only
used the ActorSystem. The flow was built through the implicit
RouteResult.routeToFlow conversion, and Route.toFunction hardcodes
SystemMaterializer(system).materializer into the RequestContext, so the
materializer supplied by Java users was silently discarded. Routes saw
the system materializer in extractMaterializer, entity unmarshalling and
any stream run from a directive.

Modification:
Added a private[pekko] Route.toFunction(route, materializer) overload
holding the existing body; the public toFunction(route) now delegates to
it with SystemMaterializer(system).materializer, so its behaviour is
unchanged. RouteAdapter.scalaFlow builds its handler with that overload
and does the mapAsync(1) itself, so the given materializer reaches the
RequestContext.

Result:
Route.flow(system, materializer) runs the route with the materializer it
was given. flow(system) is unaffected: it already passed
SystemMaterializer(system).materializer explicitly.

Tests:
- sbt "http-tests/testOnly org.apache.pekko.http.javadsl.server.RouteFlowMaterializerTest" - 2 passed; directional: with RouteAdapter reverted, flowUsesTheGivenMaterializer fails (expected: <270352276> but was: <1155460560>)
- sbt "http/scalafmt" "http-tests/Test/javafmt" "http/mimaReportBinaryIssues" - clean
- sbt headerCreateAll - header added to the new test file

References:
None - reported by a maintainer against main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant