diff --git a/e2e/src/test/resources/service_config.json b/e2e/src/test/resources/service_config.json deleted file mode 100644 index 00e3a3c2a..000000000 --- a/e2e/src/test/resources/service_config.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "methodConfig": [ - { - "name": [ - { - "service": "scalapb.zio_grpc.TestService", - "method": "Unary" - } - ], - - "retryPolicy": { - "maxAttempts": 5, - "initialBackoff": "0.1s", - "maxBackoff": "30s", - "backoffMultiplier": 1, - "retryableStatusCodes": [ - "UNAVAILABLE" - ] - } - } - ] -} \ No newline at end of file diff --git a/e2e/src/test/scalajvm/scalapb/zio_grpc/TestServiceSpec.scala b/e2e/src/test/scalajvm/scalapb/zio_grpc/TestServiceSpec.scala index c8532073a..a7f221ea2 100644 --- a/e2e/src/test/scalajvm/scalapb/zio_grpc/TestServiceSpec.scala +++ b/e2e/src/test/scalajvm/scalapb/zio_grpc/TestServiceSpec.scala @@ -1,8 +1,7 @@ package scalapb.zio_grpc -import com.google.gson.Gson -import com.google.gson.stream.JsonReader import io.grpc.{ManagedChannelBuilder, ServerBuilder, Status, StatusException} +import scala.jdk.CollectionConverters._ import scalapb.zio_grpc.server.TestServiceImpl import scalapb.zio_grpc.testservice.Request.Scenario import scalapb.zio_grpc.testservice.ZioTestservice.TestServiceClient @@ -18,20 +17,26 @@ object TestServiceSpec extends ZIOSpecDefault with CommonTestServiceSpec { val serverLayer: ZLayer[TestServiceImpl, Throwable, Server] = ServerLayer.fromEnvironment[TestServiceImpl.Service](ServerBuilder.forPort(0)) + // https://github.com/grpc/proposal/blob/master/A6-client-retries.md + val serviceConfig = Map( + "methodConfig" -> Map( + "name" -> List(Map("service" -> "scalapb.zio_grpc.TestService", "method" -> "Unary").asJava).asJava, + "retryPolicy" -> Map[String, Any]( + "maxAttempts" -> 5, + "initialBackoff" -> "0.1s", + "maxBackoff" -> "30s", + "backoffMultiplier" -> 1, + "retryableStatusCodes" -> List("UNAVAILABLE").asJava + ).asJava + ).asJava + ).asJava + val clientLayer: ZLayer[Server, Nothing, TestServiceClient] = ZLayer.scoped[Server] { for { ss <- ZIO.service[Server] port <- ss.port.orDie - ch = ManagedChannelBuilder - .forAddress("localhost", port) - .defaultServiceConfig( - new Gson().fromJson( - new JsonReader(scala.io.Source.fromResource("service_config.json").reader()), - classOf[java.util.Map[String, Any]] - ) - ) - .usePlaintext() + ch = ManagedChannelBuilder.forAddress("localhost", port).defaultServiceConfig(serviceConfig).usePlaintext() client <- TestServiceClient.scoped(ZManagedChannel(ch)).orDie } yield client } @@ -60,11 +65,9 @@ object TestServiceSpec extends ZIOSpecDefault with CommonTestServiceSpec { } yield assert(r)(fails(hasStatusCode(Status.DEADLINE_EXCEEDED))) && assert(exit.get.isInterrupted)(isTrue) } @@ flaky(100) @@ withLiveClock, test("let clients retry") { - assertZIO( - TestServiceClient - .unary(Request(Request.Scenario.UNAVAILABLE, in = 12)) - .exit - )(fails(hasStatusCode(Status.UNAVAILABLE) && hasDescription("5"))) + assertZIO(TestServiceClient.unary(Request(Request.Scenario.UNAVAILABLE, in = 12)).exit) { + fails(hasStatusCode(Status.UNAVAILABLE) && hasDescription("5")) + } } )