Akka Streams comes with an akka-stream-testkit module that provides tools which can be used for controlling and asserting various parts of the stream pipeline.
Using probe as a Sink allows manual control over demand and assertions over elements coming downstream. Streams testkit provides a sink that materializes to a TestSubscriber.Probe.
Source(1 to 4) .filter(_ % 2 == 0) .map(_ * 2) .runWith(TestSink.probe[Int]) .request(2) .expectNext(4, 8) .expectComplete()
A source that materializes to TestPublisher.Probe can be used for asserting demand or controlling when stream is completed or ended with an error.
TestSource.probe[Int] .toMat(Sink.cancelled)(Keep.left) .run() .expectCancellation()
List by example various operations on probes. Using probes without a sink.