How should I do use existed simulation?

I know read https://gatling.io/docs/current/advanced_tutorial

I have three simulation:
KlassASimulation extends Simulation {}
KlassBSimulation extends Simulation {}
KlassCSimulation extends Simulation {}

they can run.

Now, I want to run the tree simulations at the same time, but I don’t want rewrite code.

can I import them and use?
thanks!

You can’t do what you want, not without some minor code changes. But if you are willing to make some tweaks, you can make it work.

In KlassASimulation, you have code that looks something like this:

setUp( .inject( ) )…

I suggest you do a minor refactor to define your scenario as a separate function:

def behavior = scenario( name ) …

And similarly, define a function to return or apply your injection profile. If you want to return it, you might do something like this:

def profile = List(
rampUsersPerSec( 1 ) to ( 1000 ) during ( 30 minutes ) randomized,
constantUsersPerSec( 1000 ) during ( 30 minutes ) randomized,
rampUsersPerSec( 1000 ) to ( 0 ) during ( 5 minutes ) randomized
)
setUp( behavior.inject( profile ) )…

Or if the function applies the profile, it might look more like this:

def profile = ( scn : ScenarioBuilder ) =>
scn.inject(
rampUsersPerSec( 1 ) to ( 1000 ) during ( 30 minutes ) randomized,
constantUsersPerSec( 1000 ) during ( 30 minutes ) randomized,
rampUsersPerSec( 1000 ) to ( 0 ) during ( 5 minutes ) randomized
)

setUp( profile( behavior ) )…

It is a minor refactor, but if you make those functions static, you can then access them from another simulation, e.g. ABCsimulation:

class ABCsimulation extends Simulation {
setUp(
KlassASimulation.behavior.inject( KlassASimulation.profile ),
KlassBSimulation.behavior.inject( KlassBSimulation.profile ),
KlassCSimulation.behavior.inject( KlassCSimulation.profile )
) …

Now, assuming you want the combined simulation to run with the same injection profiles, you’re good to go. If you want to run it with a different profile when it is run concurrently, adjust accordingly. And if you get creative, you can define the injection profiles using reusable functions to make it easier to understand and modify.

Hope that helps.

thanks!
I refactor my code using ChainBuilder, it’s ok.

在 2019年11月30日星期六 UTC+8下午5:25:58,田欧写道: