Gatling2 Using session counter

Dear developers,

I tried to use the session counter like this:

session.initCounter(“vehicle”)

session.incrementCounter(“vehicle”)

I got following error, which did not directly help me :slight_smile:

18:11:33.258 [ERROR] i.g.c.s.Session - incrementCounter called but attribute for counterName vehicle is missing, please report.

What is the best way to just have a incrementing counter per user?

Kind Regards

Anton

Hey,

I’m just using now:
val incrementer: AtomicInteger = new AtomicInteger (0);

maybe there is a better way?

For my case I think it should work, since I have a few seconds ramp up time and only need one value per user.

Greetz

Anton

Those methods are not documented and are not intended for public use.
They are subject to changes.

This is the second time this month I see people use them.
If you guys need a counter API, let’s open an issue and discuss it there!

Hey Stéphane,

if they are not for public use, maybe you can make them private?

When you are new to a project, you just look on the possible methods and try them :slight_smile: The eclipse integration is sometimes not really working good, so most methods have no java doc for me.

I do not know if really a counter is necessary for gatling. I’m fine with the AtomicInteger.

Kind regards

Anton

if they are not for public use, maybe you can make them private?

Already done actually:
https://github.com/excilys/gatling/commit/960f6c19d112c3e7cca1c0431257c217d61105c7

When you are new to a project, you just look on the possible methods and
try them :slight_smile:

Yeah, I know. I had left them public because sometimes people come up with
very unexpected use cases and having those public helped hacking around.
But now, I think the APIs are more mature so we can better tell appart
what's to be public and what's to remain private.
Also, once we'll enter RC phase, we'll start release often like we used to.

Hi Stepane ,
I have a use case where I want to use counter value and save in variable by appending to a String.I want to save the dynamic elements based on some elements found in json EFile.The number of elements can vary ,so want to use counter logic.Can this be supported or is this already supported?

Thanks
Sandeep

See how nicely repeat loop counter is manipulated ,It will be great if we can manipulate foreach counter like repeat counter
val scn = scenario(“PetStoreSimulation”) .exec(http(“Homepage”).get("/actions/Catalog.action")) .foreach(csvRecords, “category”) { exec(flattenMapIntoAttributes("${category}")) .exec(categoryRequest) .repeat(session => session(“productIds”).as[List[Any]].size, “productIndex”){ exec(session => { val productIds = session(“productIds”).as[List[Any]] val productIndex = session(“productIndex”).as[Int] session.set(“productId”, productIds(productIndex)) }) .exec(productRequest) } }