Using ChainBuilders from older scala "helpers" in new Java scripts

We have several Scala-based “helpers” that we’ve written over the years and were hoping to continue to leverage them in newer Java-based scripts without re-writing them.

For example, our “helpers” usually look something like…

ScalaHelper.scala file

object ScalaHelper {
  def performSomeChain(String param): ChainBuilder =
    exec(...)
   .exec(...)
}

If I simply try call this chain inside our newer Java scripts, I get the something like the following…

LoadTest.java

...
.exec(ScalaHelper.peformSomeChain("value"))
...

no suitable method found for exec(io.gatling.core.structure.ChainBuilder)
method io.gatling.javaapi.core.exec.Execs.exec(java.util.function.Function<io.gatling.javaapi.core.Session,io.gatling.javaapi.core.Session>) is not applicable
(argument mismatch; io.gatling.core.structure.ChainBuilder cannot be converted to java.util.function.Function<io.gatling.javaapi.core.Session,io.gatling.javaapi.core.Session>)
method io.gatling.javaapi.core.exec.Execs.exec(io.gatling.javaapi.core.ActionBuilder) is not applicable
(argument mismatch; io.gatling.core.structure.ChainBuilder cannot be converted to io.gatling.javaapi.core.ActionBuilder)
method io.gatling.javaapi.core.exec.Execs.exec(io.gatling.javaapi.core.StructureBuilder<?,WB>…) is not applicable
(cannot infer type-variable(s) WB
(varargs mismatch; io.gatling.core.structure.ChainBuilder cannot be converted to io.gatling.javaapi.core.StructureBuilder<?,WB>))
method io.gatling.javaapi.core.exec.Execs.exec(java.util.List<io.gatling.javaapi.core.StructureBuilder<?,WB>>) is not applicable
(cannot infer type-variable(s) WB
(argument mismatch; io.gatling.core.structure.ChainBuilder cannot be converted to java.util.List<io.gatling.javaapi.core.StructureBuilder<?,WB>>))
feed(feeder)

Is there a general pattern for wrappering/converting these that we can use in this situation?

Thanks…

–Chris

Hi Chris,

If you want to go with Java instead of Scala, have you tried to estimate the effort required to migrate your whole existing Gatling code base to Java?
If it’s not that much, probably a matter of hours, it’s probably the easiest way.

And if you don’t feel like handling this yourself, that’s something we could help with a consulting contract.

Hi Stephane, I came here to post this same question. Ours is a class only but still a blocker to update. If there’s any guidance you can provide that would be much appreciated. Thanks very much.

@francislainy That’s not possible and not a path we want to follow atm.

Why don’t you migrate your helpers to Java too and use io.gatling.javaapi.core.ChainBuilder instead of io.gatling.core.structure.ChainBuilder?

Thanks for your reply. The helpers come from a maven dependency outside the project.

The helpers come from a maven dependency outside the project.

Sorry, but I don’t get the point. This dependency most likely belongs to your company. You could migrate it as well.

Yes, but it’s not maintained by our team. I can try and see what is required to request it to be updated.

Got the code for the dependency and as suggested we’ll try to update that to Java as well. However, I don’t think it will be a very straightforward task and there will probably be a few more questions coming your guys way. Hope it’s okay. Thank you.

Sure, we can help with simple questions. Then, for more complex tasks, such as reviewing and migrating complex code, that’s something we can only help with a contract.