Skip to content

Commit

Permalink
Bumps akka-grpc and play-grpc (lagom#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
ignasi35 authored and dwijnand committed Mar 8, 2019
1 parent bf4ded2 commit 7fc97f1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 47 deletions.
5 changes: 3 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ scalaVersion in ThisBuild := "2.12.8"
lagomServiceEnableSsl in ThisBuild := true
val `hello-impl-HTTPS-port` = 11000

resolvers in ThisBuild += Resolver.bintrayRepo("akka", "maven") // for snapshot akka-grpc
val lagomGrpcTestkit = "com.lightbend.play" %% "lagom-javadsl-grpc-testkit" % "0.6.0"

lazy val `lagom-java-grpc-example` = (project in file("."))
.aggregate(`hello-api`, `hello-impl`, `hello-proxy-api`, `hello-proxy-impl`)
Expand Down Expand Up @@ -45,7 +45,8 @@ lazy val `hello-impl` = (project in file("hello-impl"))

libraryDependencies ++= Seq(
lagomJavadslTestKit,
lagomLogback
lagomLogback,
lagomGrpcTestkit
)
).settings(lagomForkedTestSettings: _*)
.dependsOn(`hello-api`)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
package com.example.hello.impl;

import akka.grpc.GrpcClientSettings;
import akka.grpc.javadsl.AkkaGrpcClient;
import akka.japi.function.Function3;
import akka.japi.function.Procedure;
import akka.stream.Materializer;
import com.example.hello.api.HelloService;
import com.lightbend.lagom.javadsl.testkit.ServiceTest;
import com.lightbend.lagom.javadsl.testkit.grpc.AkkaGrpcClientHelpers;
import example.myapp.helloworld.grpc.GreeterServiceClient;
import example.myapp.helloworld.grpc.HelloReply;
import example.myapp.helloworld.grpc.HelloRequest;
import org.junit.Test;
import scala.concurrent.ExecutionContext;

import static com.lightbend.lagom.javadsl.testkit.ServiceTest.defaultSetup;
import static com.lightbend.lagom.javadsl.testkit.ServiceTest.withServer;
Expand All @@ -34,43 +28,19 @@ public void shouldSayHelloUsingALagomClient() throws Exception {
@Test
public void shouldSayHelloUsingGrpc() throws Exception {
withServer(defaultSetup().withSsl(), server -> {
withGrpcClient(
server,
GreeterServiceClient::create,
serviceClient -> {
HelloReply reply =
serviceClient.sayHello(HelloRequest.newBuilder().setName("Steve").build())
.toCompletableFuture().get(5, SECONDS);
assertEquals("Hi Steve (gRPC)", reply.getMessage());
});
AkkaGrpcClientHelpers
.withGrpcClient(
server,
GreeterServiceClient::create,
serviceClient -> {
HelloRequest request =
HelloRequest.newBuilder().setName("Steve").build();
HelloReply reply = serviceClient
.sayHello(request)
.toCompletableFuture()
.get(5, SECONDS);
assertEquals("Hi Steve (gRPC)", reply.getMessage());
});
});
}

private <T extends AkkaGrpcClient> void withGrpcClient(
ServiceTest.TestServer server,
Function3<GrpcClientSettings, Materializer, ExecutionContext, T> clientFactory,
Procedure<T> block
) throws Exception {
int sslPort = server.portSsl().get();

GrpcClientSettings settings =
GrpcClientSettings
.connectToServiceAt("127.0.0.1", sslPort, server.system())
.withSSLContext(server.clientSslContext().get())
.withOverrideAuthority("localhost");
T grpcClient = null;
try {
grpcClient = clientFactory.apply(
settings,
server.materializer(),
server.system().dispatcher()
);
block.apply(grpcClient);
} finally {
if (grpcClient != null) {
grpcClient.close();
}

}
}
}
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
addSbtPlugin("com.lightbend.lagom" % "lagom-sbt-plugin" % "1.5.0-RC2")

// Akka GRPC
addSbtPlugin("com.lightbend.akka.grpc" %% "sbt-akka-grpc" % "0.5.0+14-c97a24a0")
addSbtPlugin("com.lightbend.akka.grpc" %% "sbt-akka-grpc" % "0.6.0")
resolvers ++= Seq( // for the snapshot ^
Resolver.bintrayIvyRepo("akka", "sbt-plugin-releases"),
Resolver.bintrayRepo("akka", "maven"),
Expand Down

0 comments on commit 7fc97f1

Please sign in to comment.