I tried to implement gatling with Grpc as the following script, by phiSgr:
package load
import com.github.phisgr.gatling.grpc.Predef._
import example.myapp.helloworld.grpc.hello_world.{GreeterServiceGrpc, HelloRequest}
import io.gatling.core.Predef.{stringToExpression => _, _}
import io.grpc.Status
import load.Constants.grpcPsgConf
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._
import scala.concurrent.duration.DurationInt
import scala.language.postfixOps
class GrpcSimulation extends Simulation {
val scn = scenario("Make Hello Request and Get Response")
.exec(grpc("Hello Request")
.rpc(GreeterServiceGrpc.METHOD_SAY_HELLO)
.payload(HelloRequest("Gatling Load Test"))
.extract(_.message.some)(_ saveAs "message")
.check(statusCode is Status.Code.OK)
)
.exec(grpc("Hello Request with parameter from session")
.rpc(GreeterServiceGrpc.METHOD_SAY_HELLO)
.payload(session => HelloRequest(session.attributes("message").asInstanceOf[String]))
.check(statusCode is Status.Code.OK)
)
setUp(scn.inject(rampUsersPerSec(1) to (2) during (20 seconds)).protocols(grpcPsgConf.shareChannel))
}
When I run sbt compile it can be done successfully, however when I use *sbt "Gatling / testOnly .GrpcSimulation" it will return me these 2 errors:
[error] C:\Users\TriNP\Desktop\gatlingGrpc\gatling-grpc-tests-sample\src\test\scala\load\BiDiStreamingSimulation.scala:16:23: Symbol 'type io.gatling.core.check.FindCheckBuilder' is missing from the classpath.
[error] This symbol is required by 'value com.github.phisgr.gatling.grpc.check.GrpcCheckSupport.findCheckBuilder'.
[error] Make sure that type FindCheckBuilder is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
[error] A full rebuild may help if 'GrpcCheckSupport.class' was compiled against an incompatible version of io.gatling.core.check.
[error] val bidiCall = grpc("BiDi call").bidiStream("bidi")
[error] ^
[error] C:\Users\TriNP\Desktop\gatlingGrpc\gatling-grpc-tests-sample\src\test\scala\load\GrpcSimulation.scala:20:28: Symbol 'type io.gatling.core.check.FindCheckBuilder' is missing from the classpath.
[error] This symbol is required by 'value com.github.phisgr.gatling.grpc.request.CallDefinition.ts'.
[error] Make sure that type FindCheckBuilder is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
[error] A full rebuild may help if 'CallDefinition.class' was compiled against an incompatible version of io.gatling.core.check.
[error] .payload(HelloRequest("Gatling Load Test"))
[error] ^
[error] two errors found
[error] (Test / compileIncremental) Compilation failed
[error] Total time: 1 s, completed 09:20:29, 25 thg 9, 2023
sbt:gatling-grpc-tests-sample> reload
[info] welcome to sbt 1.9.6 (Oracle Corporation Java 17.0.8)
[info] loading settings for project gatling-grpc-tests-sample-build from assembly.sbt,gatling.sbt,plugins.sbt,scalapb.sbt ...
[info] loading project definition from C:\Users\TriNP\Desktop\gatlingGrpc\gatling-grpc-tests-sample\project
[info] compiling 1 Scala source to C:\Users\TriNP\Desktop\gatlingGrpc\gatling-grpc-tests-sample\project\target\scala-2.12\sbt-1.0\classes ...
[error] C:\Users\TriNP\Desktop\gatlingGrpc\gatling-grpc-tests-sample\project\Dependencies.scala:2:11: object gatling is not a member of package sbt.io
[error] import io.gatling.core.Predef._
[error] ^
[error] one error found
[error] (Compile / compileIncremental) Compilation failed
the build.sbt I'm using:
import Dependencies._
name := "gatling-grpc-tests-sample"
version := "0.1"
scalaVersion := "2.13.12"
libraryDependencies ++= gatlingDependencies ++ loggingDependencies ++ grpcDependencies ++
Seq(
"com.github.daddykotex" %% "courier" % "3.0.0-M2a",
"com.typesafe" % "config" % "1.4.1",
"com.google.guava" % "guava" % "30.1.1-jre",
"com.typesafe.akka" %% "akka-actor-typed" % "2.6.10",
"com.typesafe.akka" %% "akka-protobuf-v3" % "2.6.10",
"com.typesafe.akka" %% "akka-stream" % "2.6.10"
)
enablePlugins(GatlingPlugin)
PB.targets in Compile := Seq(
scalapb.gen() -> (Compile / sourceManaged).value / "scalapb"
)
gatling.sbt:
addSbtPlugin("io.gatling" % "gatling-sbt" % "4.5.0")
plugins.sbt:
addSbtPlugin("com.lightbend.akka.grpc" % "sbt-akka-grpc" % "1.1.1")
scalapb.sbt"
addSbtPlugin("com.thesamet" % "sbt-protoc" % "1.0.0")
libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.10.10"
How do I fix this issue and can someone explain me the root cause ? any help would be appreciated.
Change the gatling and sbt version to match with current using.
This is obviously incompatible dependency versions.
In the comment OP said
A possible cause is that the versions are changed, but the build tool is still using the old version.
And in this error log, we can see why.
For some reason OP added
import io.gatling.core.Predef._, an import line for the test code, to a file of the build script -project/Dependencies.scala. And this error prevented sbt from reloading and getting correct the dependency versions.Once again, as I have noted in the previous answer, one doesn't have to use
sbtor write Scala to use Gatling. And given OP's confusion, they should stick with more mainstream tools like Gradle/Maven.