title: Testing Akka Reactive Streams
body: <p>I'm testing code which streams messages over an outgoing stream TCP connection obtained via:</p>
  
  <pre><code>(IO(StreamTcp) ? StreamTcp.Connect(settings, address))
  .mapTo[StreamTcp.OutgoingTcpConnection]
  .map(_.outputStream)
  </code></pre>
  
  <p>In my tests, I substitute the resulting <code>Subscriber[ByteString]</code> with a dummy subscriber, trigger some outgoing messages, and assert that have arrived as expected. I use the method below to produce the dummy subscriber and stream result future. (So far, so good)</p>
  
  <pre><code>def testSubscriber[T](settings: FlowMaterializer)(implicit ec: ExecutionContext): (Subscriber[T], Future[Seq[T]]) = {
    var sent = Seq.empty[T]
    val (subscriber, streamComplete) = 
      Duct[T].foreach( bs =&gt; sent = sent :+ bs)(settings)
    (subscriber, streamComplete.map( _ =&gt; sent ))
  }
  </code></pre>
  
  <p>My question is this: is there some canonical method for testing that streams output the expected values, something similar to Akka's <code>TestActorRef</code>? And if not, is there some library function similar to the above function?</p>