=doc #17291 grammar fixes and Await.result instead of Await.ready
This commit is contained in:
parent
5671bbe696
commit
4841b17ca2
3 changed files with 12 additions and 15 deletions
|
|
@ -19,11 +19,11 @@ Testing a custom sink can be as simple as attaching a source that emits elements
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/stream/StreamTestKitDocTest.java#strict-collection
|
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/stream/StreamTestKitDocTest.java#strict-collection
|
||||||
|
|
||||||
The same strategy can be applied for sources as well. In the next example we have a source that produces an infinite stream of elements. Such source can be tested by asserting that first arbitrary number of elements hold some condition. Here :code:`grouped` combinator and :code:`Sink.head` are very useful.
|
The same strategy can be applied for sources as well. In the next example we have a source that produces an infinite stream of elements. Such source can be tested by asserting that first arbitrary number of elements hold some condition. Here the :code:`grouped` combinator and :code:`Sink.head` are very useful.
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/stream/StreamTestKitDocTest.java#grouped-infinite
|
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/stream/StreamTestKitDocTest.java#grouped-infinite
|
||||||
|
|
||||||
When testing a flow we need to attach a source and a sink. As both stream ends are under our control, we can choose sources that tests various edge cases of the flow and sinks that eases assertions.
|
When testing a flow we need to attach a source and a sink. As both stream ends are under our control, we can choose sources that tests various edge cases of the flow and sinks that ease assertions.
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/stream/StreamTestKitDocTest.java#folded-stream
|
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/stream/StreamTestKitDocTest.java#folded-stream
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,7 @@ class StreamTestKitDocSpec extends AkkaSpec {
|
||||||
val sinkUnderTest = Flow[Int].map(_ * 2).toMat(Sink.fold(0)(_ + _))(Keep.right)
|
val sinkUnderTest = Flow[Int].map(_ * 2).toMat(Sink.fold(0)(_ + _))(Keep.right)
|
||||||
|
|
||||||
val future = Source(1 to 4).runWith(sinkUnderTest)
|
val future = Source(1 to 4).runWith(sinkUnderTest)
|
||||||
Await.ready(future, 100.millis)
|
val result = Await.result(future, 100.millis)
|
||||||
val Success(result) = future.value.get
|
|
||||||
assert(result == 20)
|
assert(result == 20)
|
||||||
//#strict-collection
|
//#strict-collection
|
||||||
}
|
}
|
||||||
|
|
@ -34,8 +33,7 @@ class StreamTestKitDocSpec extends AkkaSpec {
|
||||||
val sourceUnderTest = Source.repeat(1).map(_ * 2)
|
val sourceUnderTest = Source.repeat(1).map(_ * 2)
|
||||||
|
|
||||||
val future = sourceUnderTest.grouped(10).runWith(Sink.head)
|
val future = sourceUnderTest.grouped(10).runWith(Sink.head)
|
||||||
Await.ready(future, 100.millis)
|
val result = Await.result(future, 100.millis)
|
||||||
val Success(result) = future.value.get
|
|
||||||
assert(result == Seq.fill(10)(2))
|
assert(result == Seq.fill(10)(2))
|
||||||
//#grouped-infinite
|
//#grouped-infinite
|
||||||
}
|
}
|
||||||
|
|
@ -45,8 +43,7 @@ class StreamTestKitDocSpec extends AkkaSpec {
|
||||||
val flowUnderTest = Flow[Int].takeWhile(_ < 5)
|
val flowUnderTest = Flow[Int].takeWhile(_ < 5)
|
||||||
|
|
||||||
val future = Source(1 to 10).via(flowUnderTest).runWith(Sink.fold(Seq.empty[Int])(_ :+ _))
|
val future = Source(1 to 10).via(flowUnderTest).runWith(Sink.fold(Seq.empty[Int])(_ :+ _))
|
||||||
Await.ready(future, 100.millis)
|
val result = Await.result(future, 100.millis)
|
||||||
val Success(result) = future.value.get
|
|
||||||
assert(result == (1 to 4))
|
assert(result == (1 to 4))
|
||||||
//#folded-stream
|
//#folded-stream
|
||||||
}
|
}
|
||||||
|
|
@ -64,14 +61,15 @@ class StreamTestKitDocSpec extends AkkaSpec {
|
||||||
|
|
||||||
"sink actor ref" in {
|
"sink actor ref" in {
|
||||||
//#sink-actorref
|
//#sink-actorref
|
||||||
val sourceUnderTest = Source(0.seconds, 200.millis, ())
|
case object Tick
|
||||||
|
val sourceUnderTest = Source(0.seconds, 200.millis, Tick)
|
||||||
|
|
||||||
val probe = TestProbe()
|
val probe = TestProbe()
|
||||||
val cancellable = sourceUnderTest.to(Sink.actorRef(probe.ref, "completed")).run()
|
val cancellable = sourceUnderTest.to(Sink.actorRef(probe.ref, "completed")).run()
|
||||||
|
|
||||||
probe.expectMsg(1.second, ())
|
probe.expectMsg(1.second, Tick)
|
||||||
probe.expectNoMsg(100.millis)
|
probe.expectNoMsg(100.millis)
|
||||||
probe.expectMsg(200.millis, ())
|
probe.expectMsg(200.millis, Tick)
|
||||||
cancellable.cancel()
|
cancellable.cancel()
|
||||||
probe.expectMsg(200.millis, "completed")
|
probe.expectMsg(200.millis, "completed")
|
||||||
//#sink-actorref
|
//#sink-actorref
|
||||||
|
|
@ -89,8 +87,7 @@ class StreamTestKitDocSpec extends AkkaSpec {
|
||||||
ref ! 3
|
ref ! 3
|
||||||
ref ! akka.actor.Status.Success("done")
|
ref ! akka.actor.Status.Success("done")
|
||||||
|
|
||||||
Await.ready(future, 100.millis)
|
val result = Await.result(future, 100.millis)
|
||||||
val Success(result) = future.value.get
|
|
||||||
assert(result == "123")
|
assert(result == "123")
|
||||||
//#source-actorref
|
//#source-actorref
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,11 +19,11 @@ Testing a custom sink can be as simple as attaching a source that emits elements
|
||||||
|
|
||||||
.. includecode:: code/docs/stream/StreamTestKitDocSpec.scala#strict-collection
|
.. includecode:: code/docs/stream/StreamTestKitDocSpec.scala#strict-collection
|
||||||
|
|
||||||
The same strategy can be applied for sources as well. In the next example we have a source that produces an infinite stream of elements. Such source can be tested by asserting that first arbitrary number of elements hold some condition. Here :code:`grouped` combinator and :code:`Sink.head` are very useful.
|
The same strategy can be applied for sources as well. In the next example we have a source that produces an infinite stream of elements. Such source can be tested by asserting that first arbitrary number of elements hold some condition. Here the :code:`grouped` combinator and :code:`Sink.head` are very useful.
|
||||||
|
|
||||||
.. includecode:: code/docs/stream/StreamTestKitDocSpec.scala#grouped-infinite
|
.. includecode:: code/docs/stream/StreamTestKitDocSpec.scala#grouped-infinite
|
||||||
|
|
||||||
When testing a flow we need to attach a source and a sink. As both stream ends are under our control, we can choose sources that tests various edge cases of the flow and sinks that eases assertions.
|
When testing a flow we need to attach a source and a sink. As both stream ends are under our control, we can choose sources that tests various edge cases of the flow and sinks that ease assertions.
|
||||||
|
|
||||||
.. includecode:: code/docs/stream/StreamTestKitDocSpec.scala#folded-stream
|
.. includecode:: code/docs/stream/StreamTestKitDocSpec.scala#folded-stream
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue