Skip to content

Commit

Permalink
don't use TLS in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
octonato committed Nov 27, 2020
1 parent 58e55e5 commit fea27b6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import akka.grpc.GrpcClientSettings;
import com.example.hello.api.HelloService;
import com.lightbend.lagom.javadsl.testkit.grpc.AkkaGrpcClientHelpers;
import com.lightbend.lagom.javadsl.testkit.ServiceTest;
import example.myapp.helloworld.grpc.GreeterServiceClient;
import example.myapp.helloworld.grpc.HelloReply;
import example.myapp.helloworld.grpc.HelloRequest;
Expand All @@ -28,20 +28,16 @@ public void shouldSayHelloUsingALagomClient() throws Exception {

@Test
public void shouldSayHelloUsingGrpc() throws Exception {
withServer(defaultSetup().withSsl(), server -> {
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());
});
withServer(defaultSetup(), server -> {
GreeterServiceClient serviceClient = createServiceClient(server);

HelloRequest request =
HelloRequest.newBuilder().setName("Steve").build();
HelloReply reply = serviceClient
.sayHello(request)
.toCompletableFuture()
.get(5, SECONDS);
assertEquals("Hi Steve (gRPC)", reply.getMessage());
});
}

Expand All @@ -51,11 +47,7 @@ public void shouldSayHelloUsingGrpc() throws Exception {
@Test
public void shouldSayHelloUsingGrpcNoSsl() throws Exception {
withServer(defaultSetup(), server -> {
GrpcClientSettings settings = GrpcClientSettings
.connectToServiceAt("127.0.0.1", server.port(), server.system())
.withTls(false);
GreeterServiceClient serviceClient = GreeterServiceClient.create(settings, server.system());

GreeterServiceClient serviceClient = createServiceClient(server);
HelloRequest request =
HelloRequest.newBuilder().setName("Steve").build();
HelloReply reply = serviceClient
Expand All @@ -66,4 +58,10 @@ public void shouldSayHelloUsingGrpcNoSsl() throws Exception {
});
}

private GreeterServiceClient createServiceClient(ServiceTest.TestServer server) {
GrpcClientSettings settings = GrpcClientSettings
.connectToServiceAt("127.0.0.1", server.port(), server.system())
.withTls(false);
return GreeterServiceClient.create(settings, server.system());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ public class HelloProxyServiceImplTest {
@BeforeClass
public static void setUp() {
ServiceTest.Setup setup = defaultSetup()
.withCluster(false)
.withSsl(false)
.configureBuilder(builder ->
builder
.disable(AkkaGrpcClientModule.class)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
package com.example.hello.impl

import akka.actor.ActorSystem
import akka.grpc.GrpcClientSettings
import com.example.hello.api._
import com.lightbend.lagom.scaladsl.server.LocalServiceLocator
import com.lightbend.lagom.scaladsl.testkit.ServiceTest
import com.lightbend.lagom.scaladsl.testkit.grpc.AkkaGrpcClientHelpers
import example.myapp.helloworld.grpc.{ GreeterServiceClient, HelloRequest }
import example.myapp.helloworld.grpc.{GreeterServiceClient, HelloRequest}
import org.scalatest.BeforeAndAfterAll
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AsyncWordSpec

class HelloServiceSpec extends AsyncWordSpec with Matchers with BeforeAndAfterAll {

private val server: ServiceTest.TestServer[HelloApplication with LocalServiceLocator] = ServiceTest.startServer(
ServiceTest.defaultSetup.withSsl(true)
) { ctx =>
new HelloApplication(ctx) with LocalServiceLocator
}
private val server: ServiceTest.TestServer[HelloApplication with LocalServiceLocator] =
ServiceTest.startServer(ServiceTest.defaultSetup) { ctx =>
new HelloApplication(ctx) with LocalServiceLocator
}

implicit val sys: ActorSystem = server.actorSystem

val client: HelloService = server.serviceClient.implement[HelloService]
val grpcClient: GreeterServiceClient = AkkaGrpcClientHelpers.grpcClient(
server,
GreeterServiceClient.apply,
)
val grpcClient: GreeterServiceClient = {
val httpPort = server.playServer.httpPort.get

val settings = GrpcClientSettings
.connectToServiceAt("127.0.0.1", httpPort)(server.actorSystem)
.withTls(false)

GreeterServiceClient(settings)
}


override protected def afterAll(): Unit = {
Expand Down

0 comments on commit fea27b6

Please sign in to comment.