2014-09-10 16:56:41 +03:00
|
|
|
/**
|
|
|
|
|
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
|
|
|
|
|
*/
|
|
|
|
|
package akka.stream.scaladsl2
|
|
|
|
|
|
|
|
|
|
import akka.actor.ActorSystem
|
|
|
|
|
import akka.stream.MaterializerSettings
|
|
|
|
|
import akka.stream.testkit.{ AkkaSpec, StreamTestKit }
|
|
|
|
|
import org.reactivestreams.Subscriber
|
|
|
|
|
import org.scalatest.Matchers
|
|
|
|
|
|
|
|
|
|
class FlowAppendSpec extends AkkaSpec with River {
|
|
|
|
|
|
|
|
|
|
val settings = MaterializerSettings(system)
|
|
|
|
|
implicit val materializer = FlowMaterializer(settings)
|
|
|
|
|
|
2014-10-02 17:32:08 +02:00
|
|
|
"Flow" should {
|
|
|
|
|
"append Flow" in riverOf[String] { subscriber ⇒
|
|
|
|
|
val flow = Flow[Int].connect(otherFlow)
|
|
|
|
|
Source(elements).connect(flow).publishTo(subscriber)
|
2014-09-10 16:56:41 +03:00
|
|
|
}
|
|
|
|
|
|
2014-10-02 17:32:08 +02:00
|
|
|
"append Sink" in riverOf[String] { subscriber ⇒
|
|
|
|
|
val sink = Flow[Int].connect(otherFlow.connect(SubscriberDrain(subscriber)))
|
|
|
|
|
Source(elements).connect(sink).run()
|
2014-09-10 16:56:41 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-02 17:32:08 +02:00
|
|
|
"Source" should {
|
|
|
|
|
"append Flow" in riverOf[String] { subscriber ⇒
|
|
|
|
|
Source(elements)
|
|
|
|
|
.connect(otherFlow)
|
2014-09-10 16:56:41 +03:00
|
|
|
.publishTo(subscriber)
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-02 17:32:08 +02:00
|
|
|
"append Sink" in riverOf[String] { subscriber ⇒
|
|
|
|
|
Source(elements)
|
|
|
|
|
.connect(otherFlow.connect(SubscriberDrain(subscriber)))
|
2014-09-10 16:56:41 +03:00
|
|
|
.run()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
trait River { self: Matchers ⇒
|
|
|
|
|
|
|
|
|
|
val elements = (1 to 10)
|
2014-10-02 17:32:08 +02:00
|
|
|
val otherFlow = Flow[Int].map(_.toString)
|
2014-09-10 16:56:41 +03:00
|
|
|
|
|
|
|
|
def riverOf[T](flowConstructor: Subscriber[T] ⇒ Unit)(implicit system: ActorSystem) = {
|
|
|
|
|
val subscriber = StreamTestKit.SubscriberProbe[T]()
|
|
|
|
|
|
|
|
|
|
flowConstructor(subscriber)
|
|
|
|
|
|
|
|
|
|
val subscription = subscriber.expectSubscription()
|
|
|
|
|
subscription.request(elements.size)
|
|
|
|
|
subscriber.probe.receiveN(elements.size) should be(elements.map(_.toString).map(StreamTestKit.OnNext(_)))
|
|
|
|
|
subscription.request(1)
|
|
|
|
|
subscriber.expectComplete()
|
|
|
|
|
}
|
|
|
|
|
}
|