fix: honour the Materializer passed to Java DSL Route.flow - #1276
Open
pjfanning wants to merge 1 commit into
Open
fix: honour the Materializer passed to Java DSL Route.flow#1276pjfanning wants to merge 1 commit into
pjfanning wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
RouteAdapter.flow(system, materializer)— the implementation behind the Java DSLRoute.flow(ActorSystem, Materializer)— accepted aMaterializerbut only used theActorSystem. The flow was built through the implicitRouteResult.routeToFlowconversion, andRoute.toFunctionhardcodesSystemMaterializer(system).materializerinto theRequestContext, so the materializer supplied by Java users was silently discarded. Routes saw the system materializer inextractMaterializer, inentity(...)unmarshalling, and in any stream run from a directive.Modification
scaladsl/server/Route.scala: added aprivate[pekko] toFunction(route, materializer)overload holding the existing body; the publictoFunction(route)now delegates to it withSystemMaterializer(system).materializer, so its behaviour is unchanged.javadsl/server/directives/RouteAdapter.scala:scalaFlowbuilds its handler with that overload and does themapAsync(1)itself, so the given materializer reaches theRequestContext.No copied code.
Result
Route.flow(system, materializer)runs the route with the materializer it was given. Theflow(system)overload is unaffected — it already passedSystemMaterializer(system).materializerexplicitly. Binary compatibility is preserved: the new method isprivate[pekko]and purely additive.Tests
sbt "http-tests/testOnly org.apache.pekko.http.javadsl.server.RouteFlowMaterializerTest"— 2 passed. New test asserts the materializer observed byextractMaterializerfor both the explicit-materializer and system-materializer overloads. Directional: with theRouteAdapterchange reverted,flowUsesTheGivenMaterializerfails withexpected: <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.