How to create a source that is not affected by backpressure
I want to test some of the Akka stream features like conflate
. For this, I need to create a source that is not affected by back pressure in a simple unit test. Naive attempts like
Source.tick(1.milli, 1.milli, "tick").map(_ => Random.nextDouble())
do not work due to back pressure. OTOH over HTTP is probably overkill.
How to create a simple Source
unit test that is not affected by back pressure?
source to share
You can use Source.actorRef
which is by design and not backpressure. See example below:
val actorRef: ActorRef = Source.actorRef(0, OverflowStrategy.dropNew)
.map(_ => Random.nextDouble())
.to(yourSink).run()
system.scheduler.schedule(1.milli, 1.milli, actorRef, "tick")(system.dispatcher)
The bufferSize parameters and the overflow strategy are randomly selected here, you will need to adjust them to your test needs.
More details Source.actorRef
can be found in the docs .
source to share