Not able to update value in condition in Gatling script

Hi All,

I have a REST API call which gives 1 Million values in response and on that 1 million values I have to set another values, means 1 value for each value. So total 2 million values. If I triggers this in single call to set values, It affects to my environment it would be down or will fail. So I have to divide this task in chunks like,

  1. Step 1 on 1st call I want to fetch Total values (may increases in future so creating dynamic) from REST with limit of 0.
  2. Step 2 Now divide Total Values by Limit which gives value of ‘offset’ then
  3. Step 3 on next rest call value of offset would be Limit + offsetValue it loops until it equals to (totalvalues/limit)

like,;limit=5;offset=0 (1st call will start from 0 offset everytime - Must);limit=5;offset=5 (2nd call, limit + offsetvalue 0 + 5 =5);limit=5;offset=10 (3rd call, limit + offsetvalue 5 + 5 = 10) like so on… till it equals to (totalvalues/limit) which is (10,00,000/5)=200,000

The problem I am facing is, offsetValue is not updating here. It takes 0 as offservalue for all the calls “”"/api/assets;limit=$limit;offset=${offsetValue}""" and also unable to set offsetvalue in this condition .asLongAs(session => offsetValue < 10)

Here is the code,

import scala.concurrent.duration._
import io.gatling.core.Predef._
import io.gatling.http.Predef._

class testAPI extends Simulation {
    val geturl = System.getProperty("geturl", "")
    val username = System.getProperty("username", "user")
    val password = System.getProperty("password", "user")

    // How many records want to fetch in a request
    val limit = Integer.getInteger("limit", 5).toInt

    // Starts 1st request with 0 Page then increases to offsetValue + limit like 1st offsetValue=0 then 0+5=5 offsetValue, then 5+5=10 offsetValue increases till its not equal to (total/limit)
    val offsetValue = 0

    val httpProtocol = http
        .basicAuth(username, password)

    //Step 1
    val scn = scenario("Get Total")
            .exec(http("Total Numbers")

    //Step 2
    //.asLongAs(session => offsetValue <= ("${total}/$limit")) // NOT WORKING, could you pls help to correct this condition?
    .asLongAs(session => offsetValue < 10) // Temporary took 10 as static
        exec(http("List of Assets")
            .get(session =>s"""/api/assets;limit=$limit;offset=${offsetValue}""")

        .foreach("${IdList}", "idlist") {
                .body(StringBody(session =>s"""{"mAnn": {"originCorrelationId": 1, "timeIn" : 111, "timeOut" : 222, "meta": {"title" : "test-title1"}}}"""))

    //Step 3        
    .exec(session => {
            session.set("offsetValue", offsetValue.get + limit.get)
            println("********offsetValue************: ====>>> " + offsetValue)