From 8eed36d2e3ebe639c9afc5f84a5f0f2871515d8a Mon Sep 17 00:00:00 2001 From: Arnaud Gourlay Date: Fri, 16 Oct 2020 20:09:21 +0200 Subject: [PATCH] http4s ember server --- build.sbt | 2 +- .../cornichon/http/server/MockHttpServer.scala | 14 ++++++-------- .../propertyCheck/stringReverse/ReverseAPI.scala | 10 +++++----- .../propertyCheck/turnstile/TurnstileAPI.scala | 10 +++++----- .../propertyCheck/webShop/WebShopAPI.scala | 10 +++++----- .../superHeroes/server/SuperHeroesHttpAPI.scala | 10 +++++----- 6 files changed, 27 insertions(+), 29 deletions(-) diff --git a/build.sbt b/build.sbt index 0a1259ab2..35954220c 100644 --- a/build.sbt +++ b/build.sbt @@ -316,7 +316,7 @@ lazy val library = val monixReactive = "io.monix" %% "monix-reactive" % Version.monix val sbtTest = "org.scala-sbt" % "test-interface" % Version.sbtTest val http4sClient = "org.http4s" %% "http4s-blaze-client" % Version.http4s - val http4sServer = "org.http4s" %% "http4s-blaze-server" % Version.http4s + val http4sServer = "org.http4s" %% "http4s-ember-server" % Version.http4s val http4sCirce = "org.http4s" %% "http4s-circe" % Version.http4s val http4sDsl = "org.http4s" %% "http4s-dsl" % Version.http4s val fs2Io = "co.fs2" %% "fs2-io" % Version.fs2 diff --git a/cornichon-http-mock/src/main/scala/com/github/agourlay/cornichon/http/server/MockHttpServer.scala b/cornichon-http-mock/src/main/scala/com/github/agourlay/cornichon/http/server/MockHttpServer.scala index 322317e51..263d48a2c 100644 --- a/cornichon-http-mock/src/main/scala/com/github/agourlay/cornichon/http/server/MockHttpServer.scala +++ b/cornichon-http-mock/src/main/scala/com/github/agourlay/cornichon/http/server/MockHttpServer.scala @@ -4,10 +4,9 @@ import java.net.NetworkInterface import com.github.agourlay.cornichon.core.CornichonError import monix.eval.Task -import monix.execution.Scheduler import org.http4s.HttpRoutes import org.http4s.server.Router -import org.http4s.server.blaze.BlazeServerBuilder +import org.http4s.ember.server.EmberServerBuilder import org.http4s.implicits._ import scala.jdk.CollectionConverters._ @@ -19,7 +18,7 @@ class MockHttpServer[A]( interface: Option[String], port: Option[Range], mockService: HttpRoutes[Task], - maxPortBindingRetries: Int)(useFromAddress: String => Task[A])(implicit scheduler: Scheduler) { + maxPortBindingRetries: Int)(useFromAddress: String => Task[A]) { private val selectedInterface = interface.getOrElse(bestInterface()) private val randomPortOrder = port.fold(0 :: Nil)(r => Random.shuffle(r.toList)) @@ -45,12 +44,11 @@ class MockHttpServer[A]( } private def startBlazeServer(port: Int): Task[A] = - BlazeServerBuilder[Task](executionContext = scheduler) - .bindHttp(port, selectedInterface) - .withoutBanner + EmberServerBuilder.default[Task] + .withPort(port) + .withHost(selectedInterface) .withHttpApp(mockRouter) - .withNio2(true) - .resource + .build .use(server => useFromAddress(s"http://${server.address.getHostString}:${server.address.getPort}")) private def bestInterface(): String = diff --git a/cornichon-test-framework/src/test/scala/com/github/agourlay/cornichon/framework/examples/propertyCheck/stringReverse/ReverseAPI.scala b/cornichon-test-framework/src/test/scala/com/github/agourlay/cornichon/framework/examples/propertyCheck/stringReverse/ReverseAPI.scala index 50fda4875..322e0c745 100644 --- a/cornichon-test-framework/src/test/scala/com/github/agourlay/cornichon/framework/examples/propertyCheck/stringReverse/ReverseAPI.scala +++ b/cornichon-test-framework/src/test/scala/com/github/agourlay/cornichon/framework/examples/propertyCheck/stringReverse/ReverseAPI.scala @@ -7,7 +7,7 @@ import org.http4s._ import org.http4s.implicits._ import org.http4s.dsl._ import org.http4s.server.Router -import org.http4s.server.blaze.BlazeServerBuilder +import org.http4s.ember.server.EmberServerBuilder class ReverseAPI extends Http4sDsl[Task] { @@ -25,11 +25,11 @@ class ReverseAPI extends Http4sDsl[Task] { ) def start(httpPort: Int): CancelableFuture[HttpServer] = - BlazeServerBuilder[Task](executionContext = s) - .bindHttp(httpPort, "localhost") - .withoutBanner - .withNio2(true) + EmberServerBuilder.default[Task] + .withPort(httpPort) + .withHost("localhost") .withHttpApp(routes.orNotFound) + .build .allocated .map { case (_, stop) => new HttpServer(stop) } .runToFuture diff --git a/cornichon-test-framework/src/test/scala/com/github/agourlay/cornichon/framework/examples/propertyCheck/turnstile/TurnstileAPI.scala b/cornichon-test-framework/src/test/scala/com/github/agourlay/cornichon/framework/examples/propertyCheck/turnstile/TurnstileAPI.scala index b03224990..051b2b337 100644 --- a/cornichon-test-framework/src/test/scala/com/github/agourlay/cornichon/framework/examples/propertyCheck/turnstile/TurnstileAPI.scala +++ b/cornichon-test-framework/src/test/scala/com/github/agourlay/cornichon/framework/examples/propertyCheck/turnstile/TurnstileAPI.scala @@ -8,7 +8,7 @@ import org.http4s._ import org.http4s.implicits._ import org.http4s.dsl._ import org.http4s.server.Router -import org.http4s.server.blaze.BlazeServerBuilder +import org.http4s.ember.server.EmberServerBuilder class TurnstileAPI extends Http4sDsl[Task] { @@ -38,11 +38,11 @@ class TurnstileAPI extends Http4sDsl[Task] { ) def start(httpPort: Int): CancelableFuture[HttpServer] = - BlazeServerBuilder[Task](executionContext = s) - .bindHttp(httpPort, "localhost") - .withoutBanner - .withNio2(true) + EmberServerBuilder.default[Task] + .withPort(httpPort) + .withHost("localhost") .withHttpApp(routes.orNotFound) + .build .allocated .map { case (_, stop) => new HttpServer(stop) } .runToFuture diff --git a/cornichon-test-framework/src/test/scala/com/github/agourlay/cornichon/framework/examples/propertyCheck/webShop/WebShopAPI.scala b/cornichon-test-framework/src/test/scala/com/github/agourlay/cornichon/framework/examples/propertyCheck/webShop/WebShopAPI.scala index bc5a66ff4..9d4898ed9 100644 --- a/cornichon-test-framework/src/test/scala/com/github/agourlay/cornichon/framework/examples/propertyCheck/webShop/WebShopAPI.scala +++ b/cornichon-test-framework/src/test/scala/com/github/agourlay/cornichon/framework/examples/propertyCheck/webShop/WebShopAPI.scala @@ -14,7 +14,7 @@ import org.http4s.circe._ import org.http4s.implicits._ import org.http4s.dsl._ import org.http4s.server.Router -import org.http4s.server.blaze.BlazeServerBuilder +import org.http4s.ember.server.EmberServerBuilder import scala.collection.concurrent.TrieMap import scala.concurrent.duration.FiniteDuration @@ -127,11 +127,11 @@ class WebShopAPI(maxSyncDelay: FiniteDuration) extends Http4sDsl[Task] { ) def start(httpPort: Int): CancelableFuture[HttpServer] = - BlazeServerBuilder[Task](executionContext = s) - .bindHttp(httpPort, "localhost") - .withoutBanner - .withNio2(true) + EmberServerBuilder.default[Task] + .withPort(httpPort) + .withHost("localhost") .withHttpApp(routes.orNotFound) + .build .allocated .map { case (_, stop) => new HttpServer(stop) } .runToFuture diff --git a/cornichon-test-framework/src/test/scala/com/github/agourlay/cornichon/framework/examples/superHeroes/server/SuperHeroesHttpAPI.scala b/cornichon-test-framework/src/test/scala/com/github/agourlay/cornichon/framework/examples/superHeroes/server/SuperHeroesHttpAPI.scala index 3aac0ba24..fb2be11f4 100644 --- a/cornichon-test-framework/src/test/scala/com/github/agourlay/cornichon/framework/examples/superHeroes/server/SuperHeroesHttpAPI.scala +++ b/cornichon-test-framework/src/test/scala/com/github/agourlay/cornichon/framework/examples/superHeroes/server/SuperHeroesHttpAPI.scala @@ -11,7 +11,7 @@ import monix.eval.Task import monix.eval.Task._ import monix.execution.{ CancelableFuture, Scheduler } import org.http4s.server.{ AuthMiddleware, Router } -import org.http4s.server.blaze.BlazeServerBuilder +import org.http4s.ember.server.EmberServerBuilder import org.http4s.server.middleware.authentication.BasicAuth import org.http4s.server.middleware.authentication.BasicAuth.BasicAuthenticator import org.http4s._ @@ -169,11 +169,11 @@ class SuperHeroesHttpAPI() extends Http4sDsl[Task] { ) def start(httpPort: Int): CancelableFuture[HttpServer] = - BlazeServerBuilder[Task](executionContext = s) - .bindHttp(httpPort, "localhost") - .withoutBanner - .withNio2(true) + EmberServerBuilder.default[Task] + .withPort(httpPort) + .withHost("localhost") .withHttpApp(GZip(routes.orNotFound)) + .build .allocated .map { case (_, stop) => new HttpServer(stop) } .runToFuture