title: Akka Stream Graphs - How to test PartitionWith from akka.stream.contrib
body: <p>I wrote a simple test to explore the <code>PartitionWith</code> graph functionality from <code>akka.stream.contrib</code>. Here is the code snippet:</p>
  
  <pre><code>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])] =&gt; (s, l, r) =&gt;
            import GraphDSL.Implicits._
  
            val pw = builder.add(PartitionWith.apply[Either[Int, String], Int, String](identity))
  
            s ~&gt; pw.in
            pw.out0 ~&gt; l.in
            pw.out1 ~&gt; r.in
  
            ClosedShape
        })
  
        val event = flow.run()
        event._2.futureValue shouldBe 1     // first check
        event._3.futureValue shouldBe "one" // second check
      }
  </code></pre>
  
  <p>When I run the above test, it throws me this error:</p>
  
  <pre><code>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.
  </code></pre>
  
  <p>It seems like it fails in the second check because the <code>rightHeadSink</code> is empty. I'm wondering if the <code>Right("one")</code> in <code>Source(List(Left(1), Right("one")))</code> is never processed??</p>
  
  <p>How do I fix this?</p>