Using gatling feeders

I am trying to use two gatling feeders to generate HTTP request data:

The first file contains some fields. One of them is a counter. With this value I would like to add a body to my message, as far as the lines from the second feeder.

For example:

fileA.csv
---------
fileAId,counter
value,3

fileB.csv
---------
fileBId
stack
overflow

      

I want to build this line: "value stack".

I created a script:

object Actions {
    val search = forever() {
        group("Test") {
            exec(feed(FeederUtils.fileAFeeder))
            .exec(  
                http("Test")                                            
                    .post(uri)                          
                    .body(StringBody("""${fileAId} """ +     FeederUtils.generateItems(${counter}.toInt)))
                )
                .pause(20 seconds)
            }
        }
}   

      

And the FeederUtils object:

object FeederUtils {
    val fileAFeeder= csv("fileA.csv").circular

    var fileBFeeder = csv("fileB.csv").circular

    def generateItems(itemsNumber: Int) : String = {
        var i = 0;
        var returnedString = "";
        for(i <- 0 to itemsNumber) {
            exec(feed(fileBFeeder))
            returnedString = returnedString + """${fileBId} """
        }

        return returnedString ;
    }
}

      

I have two problems, the function call is not compiled (not found: $ value) and the feeder variables do not exist in generateItems.

I'm new to Gatling and Scala, so I think it's obvious, but I don't understand how the exec and feed functions work.

Thank!

EDIT: Functional code below:

object FeederUtils {
    val fileAFeeder= csv("fileA.csv").circular

    var fileBVector = csv("fileB.csv").records

    var fileBIterator = 0;

    def generateItems(itemsNumber: Int) : String = {
        var i = 0;
        var returnedString = "";
        for(i <- 0 to itemsNumber) {
            var currentItem = fileBVector(fileBIterator)

            //Circular read
            if (fileBIterator < fileBVector.size) { 
              fileBIterator+=1
            } else {
              fileBIterator=0
            }

            returnedString = returnedString + currentItem("fileBId")
        }

        return returnedString ;
   }
}

object Actions {
    val search = forever() {
        group("Test") {
            exec(feed(FeederUtils.fileAFeeder))
            .exec({session => session.set("generatedString",feederUtils.generateItems(session("counter").as[String].toInt))})
            .exec(  
                http("Test")                                            
                    .post(uri)                          
                    .body(StringBody("""${fileAId} ${generatedString}"""))
                )
                .pause(20 seconds)
            }
        }
} 

      

Following is the concept: The feed function stores data in session attributes, which can be read from EL Gatling expressions or manually using the Session API. I had to combine both.

Links:

Session API

EL expressions

Handling a session with exec

+3


source to share


1 answer


You cannot use the feeder for the second file. At best, you can pull multiple records at once, but the names will be translated (fileBId1, fileBId2 ...).

Load the second file using the Gatling csv parser so you can access the records (by the records field) and save it globally.

Feed from the first file.



Then write exec (function) where you are:

  • select counter from session
  • generate a random offset (ThreadLocalRandom) if you want something like a random strategy or an AtomicInteger that you increment if you want something like a circular strategy.
  • fetches records from the second file (modulo the size of the vector of records to get the correct indices)
  • calculate the final string

Don't try to use Gatling EL in custom code. See doc .

+1


source







All Articles