=htp #16934 s/ActorFlowMaterializer/FlowMaterializer where possible, smaller cleanups

This commit is contained in:
Mathias 2015-03-02 13:51:20 +01:00
parent abea2c88ef
commit ef208bfa8b
10 changed files with 45 additions and 52 deletions

View file

@ -4,25 +4,23 @@
package akka.http.testkit
import akka.http.unmarshalling.{ Unmarshal, FromEntityUnmarshaller }
import scala.concurrent.duration._
import scala.concurrent.{ ExecutionContext, Await }
import akka.http.unmarshalling.{ Unmarshal, FromEntityUnmarshaller }
import akka.http.marshalling._
import akka.http.model.HttpEntity
import akka.stream.ActorFlowMaterializer
import akka.stream.FlowMaterializer
import scala.util.Try
trait MarshallingTestUtils {
def marshal[T: ToEntityMarshaller](value: T)(implicit ec: ExecutionContext, mat: ActorFlowMaterializer): HttpEntity.Strict =
def marshal[T: ToEntityMarshaller](value: T)(implicit ec: ExecutionContext, mat: FlowMaterializer): HttpEntity.Strict =
Await.result(Marshal(value).to[HttpEntity].flatMap(_.toStrict(1.second)), 1.second)
def unmarshalValue[T: FromEntityUnmarshaller](entity: HttpEntity)(implicit ec: ExecutionContext, mat: ActorFlowMaterializer): T =
def unmarshalValue[T: FromEntityUnmarshaller](entity: HttpEntity)(implicit ec: ExecutionContext, mat: FlowMaterializer): T =
unmarshal(entity).get
def unmarshal[T: FromEntityUnmarshaller](entity: HttpEntity)(implicit ec: ExecutionContext, mat: ActorFlowMaterializer): Try[T] = {
def unmarshal[T: FromEntityUnmarshaller](entity: HttpEntity)(implicit ec: ExecutionContext, mat: FlowMaterializer): Try[T] = {
val fut = Unmarshal(entity).to[T]
Await.ready(fut, 1.second)
fut.value.get

View file

@ -9,7 +9,7 @@ import scala.collection.immutable
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext
import akka.http.util._
import akka.stream.ActorFlowMaterializer
import akka.stream.FlowMaterializer
import akka.stream.scaladsl._
import akka.http.model.HttpEntity.ChunkStreamPart
import akka.http.server._
@ -22,7 +22,7 @@ trait RouteTestResultComponent {
/**
* A receptacle for the response or rejections created by a route.
*/
class RouteTestResult(timeout: FiniteDuration)(implicit fm: ActorFlowMaterializer) {
class RouteTestResult(timeout: FiniteDuration)(implicit fm: FlowMaterializer) {
private[this] var result: Option[Either[immutable.Seq[Rejection], HttpResponse]] = None
private[this] val latch = new CountDownLatch(1)

View file

@ -4,15 +4,14 @@
package akka.http.testkit
import akka.http.model.HttpEntity
import akka.http.unmarshalling.FromEntityUnmarshaller
import akka.stream.ActorFlowMaterializer
import scala.util.Try
import scala.concurrent.{ ExecutionContext, Future, Await }
import scala.concurrent.duration._
import org.scalatest.Suite
import org.scalatest.matchers.Matcher
import scala.concurrent.duration._
import scala.concurrent.{ ExecutionContext, Future, Await }
import scala.util.Try
import akka.http.model.HttpEntity
import akka.http.unmarshalling.FromEntityUnmarshaller
import akka.stream.FlowMaterializer
trait ScalatestUtils extends MarshallingTestUtils {
import org.scalatest.Matchers._
@ -22,10 +21,10 @@ trait ScalatestUtils extends MarshallingTestUtils {
def haveFailedWith(t: Throwable): Matcher[Future[_]] =
equal(t).matcher[Throwable] compose (x Await.result(x.failed, 1.second))
def unmarshalToValue[T: FromEntityUnmarshaller](value: T)(implicit ec: ExecutionContext, mat: ActorFlowMaterializer): Matcher[HttpEntity] =
def unmarshalToValue[T: FromEntityUnmarshaller](value: T)(implicit ec: ExecutionContext, mat: FlowMaterializer): Matcher[HttpEntity] =
equal(value).matcher[T] compose (unmarshalValue(_))
def unmarshalTo[T: FromEntityUnmarshaller](value: Try[T])(implicit ec: ExecutionContext, mat: ActorFlowMaterializer): Matcher[HttpEntity] =
def unmarshalTo[T: FromEntityUnmarshaller](value: Try[T])(implicit ec: ExecutionContext, mat: FlowMaterializer): Matcher[HttpEntity] =
equal(value).matcher[Try[T]] compose (unmarshal(_))
}