How do I increment a UUID gatling feeder
Asked Answered
F

2

7

I am new to gatling and scala, so this is definitely a n00b question but I am struggling to figure this out. I found this great blog post to be able to use a UUID feeder http://www.andrewgorton.uk/blog/gatling-uuid-feeder/

object UuidFeeder {
    val feeder = new Feeder[String] {
        override def hasNext = true

        override def next: Map[String, String] = {
            Map("uuid" -> UUID.randomUUID.toString());
        }
    }
}

This works great, my issue is that I can't figure out how to get a new value, when I put it into a loop.

I am using it like this -

val scn = scenario("Test Scenario")
  .feed(UuidFeeder.feeder)
    .exec(http("get stuff")
                .post("/stuff")
                .body(StringBody(
                """{
                   "uuid": "${uuid}",
                }""")).asJSON
                .check(status.is(201)))

If I use ${uuid} in a subsequent test, it will be the same value. How do I get a new value for the next call?

Flotsam answered 22/10, 2015 at 1:25 Comment(4)
where do you call UuidFeeder.feeder? can you show us what is before the exec?Gilda
I added it. it is inside the scenarioFlotsam
I get a "not found: type Feeder" error relating to this piece of code. new Feeder[String] Presumably, I need to import something, but cannot for the life of me find out what.Tantalus
I found it! :) import io.gatling.core.feeder._Tantalus
O
4

Your code looks fine to me and should generate different UUIDs for each virtual user every time they reach the feed action.

Official answered 29/10, 2015 at 16:22 Comment(1)
Seems like this was due to my misunderstanding of how feeds worked, i just needed to call the feed before i used it again it seems. Thanks for the help.Flotsam
E
6

I prefer using the Iterator.continually helper instead like so:

object UuidFeeder {
    val feeder = Iterator.continually(Map("uuid" -> java.util.UUID.randomUUID.toString()))
}

usage would be the same as before.. hope it helps :)

// Usage
//
// scenario("My Scenario")
//      .feed(UuidFeeder.feeder)
//      .exec(http("MyCall"))
//    ...// rest of code
Eddings answered 6/4, 2017 at 6:55 Comment(1)
Why the down vote.. if I've done something wrong at least let me know..Eddings
O
4

Your code looks fine to me and should generate different UUIDs for each virtual user every time they reach the feed action.

Official answered 29/10, 2015 at 16:22 Comment(1)
Seems like this was due to my misunderstanding of how feeds worked, i just needed to call the feed before i used it again it seems. Thanks for the help.Flotsam

© 2022 - 2024 — McMap. All rights reserved.