=str #18902 in tests (due to grouped+Sink.head) empty response stream would throw
This commit is contained in:
parent
e50a5ee6fc
commit
985e3b1c2f
2 changed files with 38 additions and 3 deletions
|
|
@ -5,9 +5,11 @@
|
|||
package akka.http.scaladsl.testkit
|
||||
|
||||
import java.util.concurrent.CountDownLatch
|
||||
import akka.dispatch.ExecutionContexts
|
||||
|
||||
import scala.collection.immutable
|
||||
import scala.concurrent.duration._
|
||||
import scala.concurrent.ExecutionContext
|
||||
import scala.concurrent.{ Await, ExecutionContext }
|
||||
import akka.stream.Materializer
|
||||
import akka.stream.scaladsl._
|
||||
import akka.http.scaladsl.model.HttpEntity.ChunkStreamPart
|
||||
|
|
@ -95,7 +97,11 @@ trait RouteTestResultComponent {
|
|||
private def failNeitherCompletedNorRejected(): Nothing =
|
||||
failTest("Request was neither completed nor rejected within " + timeout)
|
||||
|
||||
private def awaitAllElements[T](data: Source[T, _]): immutable.Seq[T] =
|
||||
data.grouped(100000).runWith(Sink.head).awaitResult(timeout)
|
||||
private def awaitAllElements[T](data: Source[T, _]): immutable.Seq[T] = {
|
||||
data.grouped(100000).runWith(Sink.head).recover({
|
||||
case e: NoSuchElementException ⇒ Nil
|
||||
})(ExecutionContexts.sameThreadExecutionContext)
|
||||
.awaitResult(timeout)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
|
||||
*/
|
||||
|
||||
package akka.http.scaladsl.server
|
||||
|
||||
import akka.http.scaladsl.model.{ ContentTypes, HttpEntity, HttpResponse, StatusCodes }
|
||||
import akka.stream.scaladsl.Source
|
||||
import akka.util.ByteString
|
||||
|
||||
class StreamingResponseSpecs extends RoutingSpec {
|
||||
|
||||
"streaming ByteString responses" should {
|
||||
"should render empty string if stream was empty" in {
|
||||
import StatusCodes._
|
||||
|
||||
val src = Source.empty[ByteString]
|
||||
val entity = HttpEntity.Chunked.fromData(ContentTypes.`application/json`, src)
|
||||
val response = HttpResponse(status = StatusCodes.OK, entity = entity)
|
||||
val route = complete(response)
|
||||
|
||||
Get() ~> route ~> check {
|
||||
status should ===(OK)
|
||||
responseAs[String] shouldEqual ""
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue