0

I'm experimenting with the Test Compatability Kit (tck) for reactive Streams, and having tested a few Publishers myself, I wanted to test an akka Source. But in order to do so I need to convert a Source (or Source + Processor(s)) to a java.util.concurrent.Flow.Publisher.

@Override
public Flow.Publisher<Integer> createFlowPublisher(long elements) {
    return new FlowPublisher((int) elements);  // <-- how to test an akka.Source?
}

class FlowPublisher implements java.util.concurrent.Flow.Publisher {
    ...

And I can't find anywhere how to do this.

Is there somehwere some documentation on this, or does someone know the answer by heart?

dr jerry
  • 9,768
  • 24
  • 79
  • 122

1 Answers1

1

you can convert akka-streams Source to org.reactivestreams.Publisher (which is the same as java.util.concurrent.Flow according to reactive-streams):

implicit val sys: ActorSystem = ActorSystem()
implicit val mat: ActorMaterializer = ActorMaterializer()

val source = Source.single(1) // some random source
val publisher: Publisher[Int] = source.runWith(Sink.asPublisher(false))

you can find details in the official akka-streams docs - Integrating with Reactive Streams


the thing to note is that akka-streams has documention and some kits for testing its' component - Testing streams. i would say that it's better to test akka-streams components with akka-streams testing kit, because you don't need to make additional conversions to org.reactivestreams.* entities and the testing code will be much cleaner, simpler and reliable