0
votes

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...

  1. Is there a way to invoke the EL outside of Gatling's DSL?
  2. Or a way to access a Session object via an ActionBuilder?
    • (I see that the Gatling code magically finds a Session object when I use the sessionFunction form, but I can't see whence it comes — even looking at the bytecode is not illuminating)
  3. Or, turning back to the Expression[T] form of exec, is there a way to have an ActionBuilder return a Session object?
  4. Or, still in the 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.)

1
After further inspection, I'm beginning to suspect that the problem is that I'm using code generated (by protoc) for Java, but the gatling-grpc library, somewhat reasonably, appears to assume (in some cases) that the code was generated for scala. IOW: D'ohLarryW

1 Answers

1
votes

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.