!str handle empty stream toFuture

This commit is contained in:
Roland Kuhn 2014-04-01 19:35:47 +02:00
parent 511392afce
commit e62a61fe91
2 changed files with 16 additions and 1 deletions

View file

@ -74,7 +74,9 @@ private[akka] case class FlowImpl[I, O](producerNode: Ast.ProducerNode[I], ops:
def toFuture(generator: ProcessorGenerator): Future[O] = {
val p = Promise[O]()
transformRecover(0)((x, in) { p complete in; 1 -> Nil }, isComplete = _ == 1).consume(generator)
transformRecover(0)((x, in) { p complete in; 1 -> Nil },
onComplete = _ { p.tryFailure(new NoSuchElementException("empty stream")); Nil },
isComplete = _ == 1).consume(generator)
p.future
}

View file

@ -43,6 +43,19 @@ class FlowToFutureSpec extends AkkaSpec with ScriptedTest {
f.value.get should be(Failure(ex))
}
"yield NoSuchElementExcption for empty stream" in {
val p = StreamTestKit.producerProbe[Int]
val f = Flow(p).toFuture(gen)
val proc = p.expectSubscription
proc.expectRequestMore()
proc.sendComplete()
Await.ready(f, 100.millis)
f.value.get match {
case Failure(e: NoSuchElementException) e.getMessage() should be("empty stream")
case x fail("expected NoSuchElementException, got " + x)
}
}
}
}