main work by @drewhk with contributions from @2m and @rkuhn This work uncovered many well-hidden bugs in existing Stages, in particular StatefulStage. These were hidden by the behavior of OneBoundedInterpreter that normally behaves more orderly than it guarantees in general, especially with respect to the timeliness of delivery of upstream termination signals; the bugs were then that internal state was not flushed when onComplete arrived “too early”.
49 lines
1.2 KiB
Scala
49 lines
1.2 KiB
Scala
package docs.stream.cookbook
|
|
|
|
import akka.stream.scaladsl.{ Flow, Sink, Source }
|
|
import akka.stream.testkit._
|
|
import scala.concurrent.duration._
|
|
import akka.testkit.TestLatch
|
|
import scala.concurrent.Await
|
|
|
|
class RecipeSimpleDrop extends RecipeSpec {
|
|
|
|
"Recipe for simply dropping elements for a faster stream" must {
|
|
|
|
"work" in {
|
|
|
|
//#simple-drop
|
|
val droppyStream: Flow[Message, Message, Unit] =
|
|
Flow[Message].conflate(seed = identity)((lastMessage, newMessage) => newMessage)
|
|
//#simple-drop
|
|
val latch = TestLatch(2)
|
|
val realDroppyStream =
|
|
Flow[Message].conflate(seed = identity)((lastMessage, newMessage) => { latch.countDown(); newMessage })
|
|
|
|
val pub = TestPublisher.probe[Message]()
|
|
val sub = TestSubscriber.manualProbe[Message]()
|
|
val messageSource = Source(pub)
|
|
val sink = Sink(sub)
|
|
|
|
messageSource.via(realDroppyStream).to(sink).run()
|
|
|
|
val subscription = sub.expectSubscription()
|
|
sub.expectNoMsg(100.millis)
|
|
|
|
pub.sendNext("1")
|
|
pub.sendNext("2")
|
|
pub.sendNext("3")
|
|
|
|
Await.ready(latch, 1.second)
|
|
|
|
subscription.request(1)
|
|
sub.expectNext("3")
|
|
|
|
pub.sendComplete()
|
|
subscription.request(1)
|
|
sub.expectComplete()
|
|
}
|
|
|
|
}
|
|
|
|
}
|