Я написал простой тест для изучения PartitionWith
функций графика из akka.stream.contrib
. Вот фрагмент кода:
class Scratch
extends TestKit(ActorSystem("PartitionWith"))
with WordSpecLike
with ScalaFutures
with Eventually
with Matchers {
"PartitionWith" should {
"split source" in {
val source: Source[Either[Int, String], NotUsed] = Source(List(Left(1), Right("one")))
val leftHeadSink = Sink.head[Int]
val rightHeadSink = Sink.head[String]
val flow = RunnableGraph.fromGraph(GraphDSL.create(source, leftHeadSink, rightHeadSink)((_, _, _)) {
implicit builder: GraphDSL.Builder[(NotUsed, Future[Int], Future[String])] => (s, l, r) =>
import GraphDSL.Implicits._
val pw = builder.add(PartitionWith.apply[Either[Int, String], Int, String](identity))
s ~> pw.in
pw.out0 ~> l.in
pw.out1 ~> r.in
ClosedShape
})
val event = flow.run()
event._2.futureValue shouldBe 1 // first check
event._3.futureValue shouldBe "one" // second check
}
Когда я запускаю вышеуказанный тест, он выдает мне эту ошибку:
The future returned an exception of type: java.util.NoSuchElementException, with message: head of empty stream.
org.scalatest.exceptions.TestFailedException: The future returned an exception of type: java.util.NoSuchElementException, with message: head of empty stream.
Кажется, что во второй проверке он не работает, потому что rightHeadSink
пуст. Мне интересно, Right("one")
в Source(List(Left(1), Right("one")))
никогда не обрабатывается ??
Как это исправить?