0

I am new to gatling and scala. I am trying to do following thing:-

test.json:
[
  {
    "code": "AML",
    "data": "aaasdfgghh"
  },
  {
    "code": "ABC",
    "data": "aaasdfgghh"
  },
  {
    "code": "SDF",
    "data": "aaasdfgghh"
  }
]

Now i want to read this json key/value in loop. Currently i am doing like this:

Request Body and feeder:-

   val jsonFileFeederFundsDoc: SourceFeederBuilder[Any] = 
                  jsonFile("test.json").circular

   //Saves locally and to S3
   val upload_fund_s3: HttpRequestBuilder =
    http("upload Fund docs Locally")
   .post(onboarding_url_perf + "/document/passfort")
   .headers(basic_headers)
   .headers(auth_headers)
   .body(StringBody(
    """{
      "code":  "${code}",
      "data":  "${data}"
  }"""
  )).asJson
  .check(status.is(200))
  .check(jsonPath("$.id").saveAs("id"))

And My Scenario is :-

val newFundScenario: ScenarioBuilder = scenario("Company Fund Scenarios exists")
.exec(TokenScenario.getCompanyUsersGwtToken).exitHereIfFailed
.exec(CompanyProfileRequest.check_company_exists).exitHereIfFailed
.doIf("${COMPANY_NOT_FOUND}") {
  exec(CompanyProfileRequest.create_company_fund_profile).exitHereIfFailed
}
.feed(UploadFundDocsInPassfort.jsonFileFeederFundsDoc)
.exec(UploadFundDocsInPassfort.upload_fund_s3).exitHereIfFailed
.exec(UploadFundDocsInPassfort.upload_fund_passfort).exitHereIfFailed
.exec(OfficersRequest.create_director).exitHereIfFailed   

And my Test Simulation is :

  class TestCompanySimulation extends Simulation {

   private val generalCompanyTestCases = GeneralCompanyScenarios
    .newFundScenario
    .inject(rampUsers(Integer.getInteger("users", 1)) during 
    (Integer.getInteger("ramp", 1) minutes))

    setUp(
      generalCompanyTestCases.protocols(httpConf),
    )
 }

Now the issue is that for one user i want to read data in loop in my newFundScenario but in this case it just picks 1st value from json file.

Something like

 foreach(read data from json file){
 //Pass Data in run time and execute
 .exec(UploadFundDocsInPassfort.upload_fund_s3).exitHereIfFailed
 .exec(UploadFundDocsInPassfort.upload_fund_passfort).exitHereIfFailed
}

Any help is much appreciated.

Regards, Vikram Pathania

1 Answer 1

1

If you want each user to loop through the feeder, you need to have your feed command inside the loop. For example, if you wanted to make 5 requests...

val upload_fund_s3: ChainBuilder =
repeat(5) {
  feed(jsonFileFeederFundsDoc)
  .exec(
    http("upload Fund docs Locally")
    .post(onboarding_url_perf + "/document/passfort")
    .headers(basic_headers)
    .headers(auth_headers)
    .body(StringBody("""{"code":  "${code}", "data":  "${data}"}""")).asJson
    .check(status.is(200))
    .check(jsonPath("$.id").saveAs("id"))
  )
} //include all the actions you want in the loop

and remove the feed from your scenario definition. This also reads better as your feeder and the actions that use it are defined together.

Be aware that if you start running multiple users in the simulation they will all pull values from the same feeder. You've specified .circular, so it won't run out of values, but each user may be making different requests (which could be fine, depending on what you're modelling)

if your list is small, you could also consider just having a Map and pushing that into the session for iterating over with .foreach

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.