2014-09-09 14:39:45 +02:00
|
|
|
/**
|
|
|
|
|
* Copyright (C) 2014 Typesafe Inc. <http://www.typesafe.com>
|
|
|
|
|
*/
|
2014-10-27 14:35:41 +01:00
|
|
|
package akka.stream.scaladsl
|
2014-09-09 14:39:45 +02:00
|
|
|
|
|
|
|
|
import scala.concurrent.Await
|
2014-09-30 02:08:49 +02:00
|
|
|
import scala.util.control.NoStackTrace
|
2014-10-27 14:35:41 +01:00
|
|
|
|
2014-12-03 10:33:21 +01:00
|
|
|
import akka.stream.{ OverflowStrategy, FlowMaterializer }
|
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-06 14:46:52 +02:00
|
|
|
val future = Source(input).fold(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-06 14:46:52 +02:00
|
|
|
val future = Source[Unit](() ⇒ throw error).fold(())((_, _) ⇒ ())
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|