2014-09-09 14:39:45 +02:00
|
|
|
/**
|
|
|
|
|
* Copyright (C) 2014 Typesafe Inc. <http://www.typesafe.com>
|
|
|
|
|
*/
|
|
|
|
|
package akka.stream.scaladsl2
|
|
|
|
|
|
|
|
|
|
import scala.concurrent.Await
|
2014-09-30 02:08:49 +02:00
|
|
|
import scala.util.control.NoStackTrace
|
2014-09-09 14:39:45 +02:00
|
|
|
import akka.stream.testkit.AkkaSpec
|
2014-09-30 02:08:49 +02:00
|
|
|
import akka.testkit.DefaultTimeout
|
2014-09-09 14:39:45 +02:00
|
|
|
|
2014-09-30 02:08:49 +02:00
|
|
|
class FlowFoldSpec extends AkkaSpec with DefaultTimeout {
|
2014-09-09 14:39:45 +02:00
|
|
|
implicit val mat = FlowMaterializer()
|
|
|
|
|
|
|
|
|
|
"A Fold" must {
|
|
|
|
|
|
|
|
|
|
"fold" in {
|
|
|
|
|
val input = 1 to 100
|
2014-10-02 13:34:27 +02:00
|
|
|
val future = Source(input).runWith(FoldDrain[Int, Int](0)(_ + _))
|
2014-09-09 14:39:45 +02:00
|
|
|
val expected = input.fold(0)(_ + _)
|
2014-09-30 02:08:49 +02:00
|
|
|
Await.result(future, timeout.duration) should be(expected)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"propagate an error" in {
|
|
|
|
|
val error = new Exception with NoStackTrace
|
2014-10-02 13:34:27 +02:00
|
|
|
val future = Source[Unit](() ⇒ throw error).runWith(FoldDrain[Unit, Unit](())((_, _) ⇒ ()))
|
2014-09-30 02:08:49 +02:00
|
|
|
the[Exception] thrownBy Await.result(future, timeout.duration) should be(error)
|
2014-09-09 14:39:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|