-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGreeterServiceApiTest.scala
60 lines (46 loc) · 2.16 KB
/
GreeterServiceApiTest.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package example.myapp.helloworld
import akka.actor.ActorSystem
import akka.grpc.GrpcClientSettings
import akka.stream.scaladsl.{Sink, Source}
import example.myapp.example.myapp.helloworld.grpc.{GreeterService, GreeterServiceClient, HelloRequest}
import example.myapp.helloworld.Utils.{getRandomList, getRandomValue}
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import org.scalatest.time.{Millis, Minutes, Span}
class GreeterServiceApiTest extends AnyFlatSpec with Matchers with ScalaFutures {
val host = "127.0.0.1"
val port = 8080
implicit override val patienceConfig: PatienceConfig =
PatienceConfig(timeout = Span(3, Minutes), interval = Span(10, Millis))
implicit protected val system: ActorSystem = ActorSystem("api-test")
val clientSettings: GrpcClientSettings = GrpcClientSettings.connectToServiceAt(host, port)
.withTls(false)
val client: GreeterService = GreeterServiceClient(clientSettings)
"Greeter Service" should "handle unary requests and response" in {
val name = getRandomValue
val response = client.sayHello(HelloRequest(name)).futureValue
response.getTimestamp should not be null
response.message should be(s"Hello, $name")
}
"Greeter Service" should "handle client streaming" in {
val data = getRandomList(3)
val response = client.itKeepsTalking(Source(data.map(HelloRequest(_)))).futureValue
response.timestamp should not be null
response.message should be(s"Hello, ${data.mkString(", ")}")
}
"Greeter Service" should "handle server streaming" in {
val name = getRandomValue
val responses = client.itKeepsReplying(HelloRequest(name)).runWith(Sink.seq).futureValue
responses should not be empty
val messages = responses.map(_.message).toList
all(messages) should not be ""
}
"Greeter Service" should "handle bi-directional streaming" in {
val data = getRandomList(3)
val responses = client.streamHellos(Source(data.map(HelloRequest(_)))).runWith(Sink.seq).futureValue
responses should not be empty
val messages = responses.map(_.message).toList
all(messages) should not be ""
}
}