A Gatling load test plugin for gRPC.
Because of gRPC's need of code generation, I assume you are running the tests using the SBT plugin. For a quickstart guide, see this Medium article.
To use this library, add this library to the test dependencies along with the two required by Gatling.
libraryDependencies ++= Seq(
"io.gatling.highcharts" % "gatling-charts-highcharts" % gatlingVersion % "test",
"io.gatling" % "gatling-test-framework" % gatlingVersion % "test",
"com.github.phisgr" %% "gatling-grpc" % "0.7.0" % "test"
)
enablePlugins(GatlingPlugin)
For setting up the code generation, see the documentation in ScalaPB.
If your protobuf files are in src/test/protobuf
instead of src/main/protobuf
, change Compile
to Test
.
PB.targets in Test := Seq(
scalapb.gen() -> (sourceManaged in Test).value
)
To make a gRPC call:
exec(
grpc("my_request")
.rpc(GreetServiceGrpc.METHOD_GREET)
.payload(HelloWorld(
username = "myUserName",
name = "My name"
))
)
For a complete demo and various examples,
see GrpcExample
in test.
There are helper methods in gatling-grpc
for
generating dynamic ScalaPB objects with Lens
es,
as demonstrated in the example linked above.
If you want to use Java Protobuf classes,
you can use the gatling-javapb
library.
In logback.xml
, add
<logger name="com.github.phisgr.gatling.grpc" level="DEBUG" />
to log the requests and responses that are failed (KO in Gatling)
and with a non-OK gRPC status code.
sbt clean coverage test gatling:test coverageReport
for a coverage report.
sbt bench/clean 'bench/jmh:run -i 10 -wi 5 -f1 -t1'
for JMH tests.