I want to loadtest a server application that uses Google protocol buffers. Of course all the .proto files (RPC calls, request/response objects) are compiled into .java files that are bundled up into a .JAR. I would like to add this JAR file as a dependency to my Gatling loadtest. I want that Gatling invokes those protobuf RPCs just as any other loadtest.
However, I am unsure if/how this would work with Gatling’s current DSL. My request/response bodies are all binary. And ideally I can hide this as much as possible from the load test. I am looking for a way to use the generated protobuf Java code as much as possible for deserializing and sending requests. But I would like to use Gatling’s DSL to specify which RPCs to call.
How would I add my JAR file as a dependency to the Gatling loadtest?
Assuming my generated code is on Gatling’s classpath, how would I use Gatling’s DSL to test my protobuf-based server?
As protobuf requires you to ship and use the generated serializers, so that’s not something we can have built-in.
Regarding request bodies: you can probably use ByteArrayBody and feed it an Expression[Array[Byte]] that would perform your protobuf serialization.
Regarding response bodies: you can probably use the bodyBytes check, with a transform step that would perform your protobuf deserialization.
Do you mind providing some example Scala code to demonstrate the approach? I have found a code snippet on stackoverflow that contains the ByteArrayBody type you mentioned:
getFirstRequest and getSecondRequest are methods that take a Session and return an Array[Byte] (or better, a Validation[Array[Byte]).
In those, you would populate some POJO with values coming from the Session, and serialize it.
For example:
getFirstRequest(session: Session) =
for {
id ← session(“id”).validate[Int]
name ← session(“id”).validate[String]
email ← session(“id”).validate[String]
} yield Person.newBuilder.setId(id).set(name).set(email).toByteArray