Additional tests for async boundaries and GroupBy #24676
This commit is contained in:
parent
d08f31bcdb
commit
dfd8d8aa81
5 changed files with 83 additions and 28 deletions
|
|
@ -4,20 +4,19 @@
|
|||
|
||||
package akka.stream
|
||||
|
||||
import akka.stream.impl.fusing.GraphInterpreter
|
||||
import akka.stream.scaladsl._
|
||||
import akka.stream.testkit.StreamSpec
|
||||
import akka.stream.impl.fusing.GraphInterpreter
|
||||
import akka.event.BusLogging
|
||||
|
||||
class FusingSpec extends StreamSpec {
|
||||
|
||||
final val Debug = false
|
||||
implicit val materializer = ActorMaterializer()
|
||||
|
||||
def graph(async: Boolean) =
|
||||
Source.unfold(1)(x ⇒ Some(x → x)).filter(_ % 2 == 1)
|
||||
.alsoTo(Flow[Int].fold(0)(_ + _).to(Sink.head.named("otherSink")).addAttributes(if (async) Attributes.asyncBoundary else Attributes.none))
|
||||
.via(Flow[Int].fold(1)(_ + _).named("mainSink"))
|
||||
def actorRunningStage = {
|
||||
GraphInterpreter.currentInterpreter.context
|
||||
}
|
||||
|
||||
val snitchFlow = Flow[Int].map(x ⇒ { testActor ! actorRunningStage; x }).async
|
||||
|
||||
"SubFusingActorMaterializer" must {
|
||||
|
||||
|
|
@ -33,41 +32,56 @@ class FusingSpec extends StreamSpec {
|
|||
}
|
||||
|
||||
"use multiple actors when there are asynchronous boundaries in the subflows (manual)" in {
|
||||
def ref = {
|
||||
val bus = GraphInterpreter.currentInterpreter.log.asInstanceOf[BusLogging]
|
||||
bus.logSource
|
||||
}
|
||||
val async = Flow[Int].map(x ⇒ { testActor ! ref; x }).async
|
||||
val async = Flow[Int].map(x ⇒ { testActor ! actorRunningStage; x }).async
|
||||
Source(0 to 9)
|
||||
.map(x ⇒ { testActor ! ref; x })
|
||||
.via(snitchFlow.async)
|
||||
.flatMapMerge(5, i ⇒ Source.single(i).via(async))
|
||||
.grouped(1000)
|
||||
.runWith(Sink.head)
|
||||
.futureValue
|
||||
.sorted should ===(0 to 9)
|
||||
val refs = receiveN(20)
|
||||
withClue(s"refs=\n${refs.mkString("\n")}") {
|
||||
refs.toSet.size should ===(11) // main flow + 10 subflows
|
||||
}
|
||||
refs.toSet should have size (11) // main flow + 10 subflows
|
||||
}
|
||||
|
||||
"use multiple actors when there are asynchronous boundaries in the subflows (combinator)" in {
|
||||
def ref = {
|
||||
val bus = GraphInterpreter.currentInterpreter.log.asInstanceOf[BusLogging]
|
||||
bus.logSource
|
||||
}
|
||||
val flow = Flow[Int].map(x ⇒ { testActor ! ref; x })
|
||||
Source(0 to 9)
|
||||
.map(x ⇒ { testActor ! ref; x })
|
||||
.flatMapMerge(5, i ⇒ Source.single(i).via(flow.async))
|
||||
.via(snitchFlow)
|
||||
.flatMapMerge(5, i ⇒ Source.single(i).via(snitchFlow.async))
|
||||
.grouped(1000)
|
||||
.runWith(Sink.head)
|
||||
.futureValue
|
||||
.sorted should ===(0 to 9)
|
||||
val refs = receiveN(20)
|
||||
withClue(s"refs=\n${refs.mkString("\n")}") {
|
||||
refs.toSet.size should ===(11) // main flow + 10 subflows
|
||||
}
|
||||
refs.toSet should have size (11) // main flow + 10 subflows
|
||||
}
|
||||
|
||||
"use one actor per grouped substream when there is an async boundary around the flow (manual)" in {
|
||||
val in = 0 to 9
|
||||
Source(in)
|
||||
.via(snitchFlow)
|
||||
.groupBy(in.size, identity)
|
||||
.via(snitchFlow.async)
|
||||
.mergeSubstreams
|
||||
.runWith(Sink.seq)
|
||||
.futureValue.sorted should ===(in)
|
||||
val refs = receiveN(in.size + in.size) // each element through the first map, then the second map
|
||||
|
||||
refs.toSet should have size (in.size + 1) // outer/main actor + 1 actor per subflow
|
||||
}
|
||||
|
||||
"use one actor per grouped substream when there is an async boundary around the flow (combinator)" in {
|
||||
val in = 0 to 9
|
||||
Source(in)
|
||||
.via(snitchFlow)
|
||||
.groupBy(in.size, identity)
|
||||
.via(snitchFlow)
|
||||
.async
|
||||
.mergeSubstreams
|
||||
.runWith(Sink.seq)
|
||||
.futureValue.sorted should ===(in)
|
||||
val refs = receiveN(in.size + in.size) // each element through the first map, then the second map
|
||||
refs.toSet should have size (in.size + 1) // outer/main actor + 1 actor per subflow
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue