-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathGrpcSyncCallAction.scala
33 lines (28 loc) · 1.2 KB
/
GrpcSyncCallAction.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
package ch.tamedia.gatling.actions.impl
import ch.tamedia.gatling.actions.GrpcExecutableSyncAction
import ch.tamedia.noname.server.grpc.endpoint.log.{LogEndpointGrpc, LogRequest}
import io.grpc.ManagedChannelBuilder
/**
* Sync call action
*/
object GrpcSyncCallAction {
/**
*
* Constructor that needs couple of params in order to create valid gRPC connection
* @param name - function name
* @param host - server host
* @param port - server port
* @param requestMessage - message to be send as request
* @return - GrpcSyncCallAction
*/
def apply(name: String, host: String, port: Int, requestMessage: String): GrpcSyncCallAction = new GrpcSyncCallAction(name, host, port, requestMessage)
}
class GrpcSyncCallAction(val name: String, host: String, port: Int, requestMessage: String) extends GrpcExecutableSyncAction {
var channel = ManagedChannelBuilder.forAddress(host, port).usePlaintext(true).build
val blockingCall = LogEndpointGrpc.blockingStub(channel)
/**
* Create sync call to the server
* @return Option[GeneratedMessage]
*/
override def executeSync = Some(blockingCall.send(new LogRequest(requestMessage)))
}