Newbie Gatling+Scala question: I’m using George Leung's gatling-grpc library (which is modeled after the http library) and trying to pass a value from the session (generated in a feeder), into a non-DSL, non-Gatling method call, specifically calls populating the gRPC payload object.
Before I start, let me add that it seems I can’t use the sessionFunction (Expression[T]
) form of exec
, which would resolve my issue:
.exec{ session => { … grpc(…).rpc(…)… }}
…because, AFAICT, the grpc
call must be the last thing in the block, or else it’s never evaluated ... yet it can’t be the last thing in the block because there’s no way to coerce it to return a Session object (again, AFAICT).
Therefore, I have to use the ActionBuilder
form of exec
(grpc(...)
returns a Call
so this is as designed):
.exec( grpc(…).rpc(…)... )
and this works… until I have a gRPC payload (i.e., non-Gatling) method call to which I need to pass a non-constant value (from a feeder).
In this context, I have no access to a Session
object, and the Gatling Expression Language is not applied because the library defining the gRPC types I need to use (to generate the payload) has no knowledge of Gatling.
So, in this fragment:
.header(transactionIdHeader)("${tid}.SAVE")
.payload(Student.newBuilder()
.setId(GlobalId.newBuilder().setValue("${authid}_${uniqId}").build()).build())
)
…the first call evaluates ${tid}
because the param in the second parens is Expression[T]
, and hence is evaluated as Expression Language, but the second call fails to evaluate ${authid}
or ${uniqId}
because the external, generated library that defines the gRPC type GlobalId has no knowledge of Gatling.
So...
Session
object via an ActionBuilder
?
Expression[T]
form of exec
, is there a way to have an ActionBuilder
return a Session
object?Expression[T]
form, I could trivially pass back the existing Session
object, if I had a way to ensure the grpc()...
expression was evaluated (i.e., imperative programming).Gatling 3.3.1, Scala 2.12.10
The gatling-grpc library is at phiSgr/gatling-grpc; I'm using version 0.7.0 (com.github.phisgr:gatling-grpc
).
(The gRPC Java code is generated from .proto files, of course.)
You need the Gatling-JavaPB integration.
To see that in action, see here.
The .payload
method takes an Expression[T]
, which is an alias for Session => Validation[T]
. In plain English, that is a function that constructs the payload from the session with a possibility of failure.
Much of your frustration is not knowing how to get hold of a Session
. I hope this clears up the confusion.
In the worst case one can write a lambda to create an expression. But for string interpolation or accessing one single object, Gatling provides an implicit conversation to turn an EL String
into an Expression
.
The problem is you want to construct well-typed payloads and Gatling's EL cannot help with that. The builders’ setters want a T
, but you only have an Expression[T]
(either from EL or the $
function). The library mentioned above is created to handle that plumbing.
After importing com.github.phisgr.gatling.javapb._
, you should write the following.
...
.payload(
Student.getDefaultInstance
.update(_.getIdBuilder.setValue)("${authid}_${uniqId}")
)
For the sake of completeness, see the warning in Gatling's documentation for why defining actions in .exec(sessionFunction)
is not going to work.