Extrapolate stage and expand redoc #23804
This commit is contained in:
parent
26f0f86088
commit
00068e2d1d
13 changed files with 670 additions and 82 deletions
|
|
@ -58,11 +58,11 @@ class RateTransformationDocSpec extends AkkaSpec {
|
|||
fut.futureValue
|
||||
}
|
||||
|
||||
"expand should repeat last" in {
|
||||
//#expand-last
|
||||
"extrapolate should repeat last" in {
|
||||
//#extrapolate-last
|
||||
val lastFlow = Flow[Double]
|
||||
.expand(Iterator.continually(_))
|
||||
//#expand-last
|
||||
.extrapolate(Iterator.continually(_))
|
||||
//#extrapolate-last
|
||||
|
||||
val (probe, fut) = TestSource.probe[Double]
|
||||
.via(lastFlow)
|
||||
|
|
@ -71,9 +71,52 @@ class RateTransformationDocSpec extends AkkaSpec {
|
|||
.run()
|
||||
|
||||
probe.sendNext(1.0)
|
||||
val expanded = fut.futureValue
|
||||
expanded.size shouldBe 10
|
||||
expanded.sum shouldBe 10
|
||||
val extrapolated = fut.futureValue
|
||||
extrapolated.size shouldBe 10
|
||||
extrapolated.sum shouldBe 10
|
||||
}
|
||||
|
||||
"extrapolate should send seed first" in {
|
||||
//#extrapolate-seed
|
||||
val initial = 2.0
|
||||
val seedFlow = Flow[Double]
|
||||
.extrapolate(Iterator.continually(_), Some(initial))
|
||||
//#extrapolate-seed
|
||||
|
||||
val fut = TestSource.probe[Double]
|
||||
.via(seedFlow)
|
||||
.grouped(10)
|
||||
.runWith(Sink.head)
|
||||
|
||||
val extrapolated = Await.result(fut, 100.millis)
|
||||
extrapolated.size shouldBe 10
|
||||
extrapolated.sum shouldBe 10 * initial
|
||||
}
|
||||
|
||||
"extrapolate should track drift" in {
|
||||
//#extrapolate-drift
|
||||
val driftFlow = Flow[Double].map(_ -> 0)
|
||||
.extrapolate[(Double, Int)] { case (i, _) ⇒ Iterator.from(1).map(i -> _) }
|
||||
//#extrapolate-drift
|
||||
val latch = TestLatch(2)
|
||||
val realDriftFlow = Flow[Double].map(d ⇒ { latch.countDown(); d -> 0; })
|
||||
.extrapolate[(Double, Int)] { case (d, _) ⇒ latch.countDown(); Iterator.from(1).map(d -> _) }
|
||||
|
||||
val (pub, sub) = TestSource.probe[Double]
|
||||
.via(realDriftFlow)
|
||||
.toMat(TestSink.probe[(Double, Int)])(Keep.both)
|
||||
.run()
|
||||
|
||||
sub.request(1)
|
||||
pub.sendNext(1.0)
|
||||
sub.expectNext((1.0, 0))
|
||||
|
||||
sub.requestNext((1.0, 1))
|
||||
sub.requestNext((1.0, 2))
|
||||
|
||||
pub.sendNext(2.0)
|
||||
Await.ready(latch, 1.second)
|
||||
sub.requestNext((2.0, 0))
|
||||
}
|
||||
|
||||
"expand should track drift" in {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue