diff --git a/plugin-tester-java/build.gradle b/plugin-tester-java/build.gradle index 683de2a6d..2afc2696d 100644 --- a/plugin-tester-java/build.gradle +++ b/plugin-tester-java/build.gradle @@ -19,6 +19,7 @@ plugins { id 'scala' id 'com.lightbend.akka.grpc.gradle' version "${akkaGrpcVersion}" } + akkaGrpc { generateClient = true generateServer = true @@ -37,11 +38,13 @@ repositories { def scalaVersion = org.gradle.util.VersionNumber.parse(System.getenv("TRAVIS_SCALA_VERSION") ?: "2.13") def scalaBinaryVersion = "${scalaVersion.major}.${scalaVersion.minor}" +def akkaHttpVersion = "10.5.0" def akkaVersion = "2.9.0" dependencies { implementation group: 'ch.megard', name: "akka-http-cors_${scalaBinaryVersion}", version: '1.1.3' testImplementation "com.typesafe.akka:akka-stream-testkit_${scalaBinaryVersion}:${akkaVersion}" + testImplementation "com.typesafe.akka:akka-http-spray-json_${scalaBinaryVersion}:${akkaHttpVersion}" implementation "com.typesafe.akka:akka-pki_${scalaBinaryVersion}:${akkaVersion}" testImplementation "org.scalatest:scalatest_${scalaBinaryVersion}:3.2.12" testImplementation "org.scalatestplus:junit-4-12_${scalaBinaryVersion}:3.2.2.0" diff --git a/plugin-tester-java/src/test/scala/example/myapp/shelf/ShelfServiceHttpTranscodingSpec.scala b/plugin-tester-java/src/test/scala/example/myapp/shelf/ShelfServiceHttpTranscodingSpec.scala index b2ff0c758..4b06eb467 100644 --- a/plugin-tester-java/src/test/scala/example/myapp/shelf/ShelfServiceHttpTranscodingSpec.scala +++ b/plugin-tester-java/src/test/scala/example/myapp/shelf/ShelfServiceHttpTranscodingSpec.scala @@ -4,26 +4,39 @@ package example.myapp.shelf -import akka.actor.testkit.typed.scaladsl.ScalaTestWithActorTestKit +import akka.actor.ActorSystem import akka.http.scaladsl.Http import akka.http.scaladsl.client.RequestBuilding.Get -import akka.http.scaladsl.unmarshalling.Unmarshal import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._ +import akka.http.scaladsl.unmarshalling.Unmarshal +import com.typesafe.config.ConfigFactory import org.scalatest.BeforeAndAfterAll +import org.scalatest.concurrent.ScalaFutures +import org.scalatest.matchers.should.Matchers +import org.scalatest.time.Span import org.scalatest.wordspec.AnyWordSpecLike -import spray.json.JsObject import spray.json.DefaultJsonProtocol._ +import spray.json.JsObject import scala.concurrent.ExecutionContextExecutor -import scala.compat.java8.FutureConverters._ +import scala.concurrent.duration._ -class ShelfServiceHttpTranscodingSpec - extends ScalaTestWithActorTestKit(config = "akka.http.server.enable-http2 = on") - with AnyWordSpecLike - with BeforeAndAfterAll { - implicit val ec: ExecutionContextExecutor = system.executionContext +class ShelfServiceHttpTranscodingSpec extends AnyWordSpecLike with Matchers with ScalaFutures with BeforeAndAfterAll { + + implicit val patience: PatienceConfig = + PatienceConfig(5.seconds, Span(100, org.scalatest.time.Millis)) + + implicit val serverSystem: ActorSystem = { + // important to enable HTTP/2 in server ActorSystem's config + val conf = + ConfigFactory.parseString("akka.http.server.enable-http2 = on").withFallback(ConfigFactory.defaultApplication()) + val sys = ActorSystem("ShelfServer", conf) + // make sure servers are bound before using client + ShelfServer.run(sys).toCompletableFuture.get + sys + } - val serverWithHttpTranscoding = ShelfServer.run(system.classicSystem).toScala.futureValue + implicit val ec: ExecutionContextExecutor = serverSystem.dispatcher "a gRPC server with HTTP transcoding enabled" should {