I have an akka-http route which is returning a Source
containing an infinite stream of entities. How can I test that using the route testkit? I'd like to inspect just the first n elements of the stream, but I've taken a look at the testkit code, and it looks like there's no direct way to access the Source
in the response. It's always converted to a sequence of ByteString
s, which in my case just causes a TimeoutException
, since the stream never terminates.
For reference, the problem can be reproduced with a route looking something like this:
case class Bar(wibble: String, wobble: String)
path("stream") {
get {
complete {
import JsonSupport._
implicit val streamingSupport = EntityStreamingSupport.json()
Source.unfold(1) { i =>
Thread.sleep(10)
Some((i + 1, Bar(i.toString, (i + 1).toString)))
}
}
}
}
JsonSupport
?? – sarveshseriJsonSupport
is defined as: object JsonSupport extends SprayJsonSupport with DefaultJsonProtocol { implicit val barFormat = jsonFormat2(Bar) } – Andrew Brett