Randomising eventId of Post body with random ${orgId} but getting error as The input was not valid

时间:2019-04-16 22:21:30

标签: gatling scala-gatling

I am trying to generate a random eventid with orgId but getting this below error ,this error clearly states that input data to the event in invalid,when i change the evnet id to 1 ,code works fine ,only when i try to randomise it ,i am getting the below error message

14:59:36.475 [WARN ] i.g.h.a.ResponseProcessor - Request 'CreateEventRound-GameKeeper' failed: status.find.in(200,201), but actually found 400
Session(Game Keeper Post Orgs ,1,Map(access_token -> eyJhbGciOiJSUzI1NiIsImtpZCI6IjM0NmM4YTY1NTBlZGI5MDRjM2IyNWI3ODlmOTllNjU3ODA4MGJiOTUiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJpa3J3dWdoMzg3MWdodzhyZ243cTgzZ2giLCJleHAiOjE1NTU0NTI4NjgsImlhdCI6MTU1NTQ1MTk2OCwiaXNzIjoiNzZIRktZNzVHUkEyTFBHQ1pETVZYUTY2SEEiLCJzdWIiOiJZTUdDWFA2SVVCSE9QRkdLNDVYUUdON1RWNCIsIndvdGMtbmFtZSI6IktvemlsZWtzVHJhbnNsYXRvckRldiM1MjIxMyIsIndvdGMtZG9tbiI6InRhYmxldG9wIiwid290Yy1nYW1lIjoiZXZlbnRyZXBvcnRlcmRldiIsIndvdGMtZmxncyI6MCwid290Yy1yb2xzIjpbXSwid290Yy1wcm1zIjpbXSwid290Yy1zY3BzIjpbImZpcnN0LXBhcnR5Il19.SqMnINmD7q2FC1Zyf34xbaWOP3LhRtdbL44ZkY3vDKa2-E2yEv4fX1-f8dJTWzOVDNOJYLkHZCrKu8YkVqvO1u9RP5d-Kyfpm1GMVqV9duFPKOuRkgg6p8xxDy3jg0o-ItMZa3fYNNe-3GQ2BdGmxPv7fnoov-OSIY6F7XQAEdnGUc5uMxID_4BrKYZmpBDuzi3LPPaUJeHGdh_nOJvhq-sIUHFmIpp3e70VE9xLvjQ8uS8vJI1fGCq7tDvpXtFFtCPTQ05LLD_SIvt2uPULn80SHA8aH37cI0Zpu4eeDyy0sBjRSPXSK8vKEwhUDsbt_u02s-8O9BPeCJ4RLu8EfQ, gatling.http.cache.dns -> io.gatling.http.resolver.ShuffleJdkNameResolver@319ab5e5, gatling.http.cache.contentCache -> io.gatling.core.util.cache.Cache@619cf254, token_type -> Bearer, orgId -> 29, eventId -> ["The input was not valid.","The input was not valid."], 721cad9b-2343-46f4-8f2f-766319bc197b -> 8, e803e068-608b-4826-a7ab-7f7eff07fadb -> 0),1555451967893,23,KO,List(ExitOnCompleteLoopBlock(721cad9b-2343-46f4-8f2f-766319bc197b), ExitOnCompleteLoopBlock(e803e068-608b-4826-a7ab-7f7eff07fadb)),io.gatling.core.protocol.ProtocolComponentsRegistry$$Lambda$412/1842952737@70e2ec5d)
14:59:37.484 [WARN ] i.g.h.a.ResponseProcessor - Request 'CreateEventRound-GameKeeper' failed: status.find.in(200,201), but actually found 400
 Session(Game Keeper Post Orgs ,1,Map(access_token -> eyJhbGciOiJSUzI1NiIsImtpZCI6IjM0NmM4YTY1NTBlZGI5MDRjM2IyNWI3ODlmOTllNjU3ODA4MGJiOTUiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJpa3J3dWdoMzg3MWdodzhyZ243cTgzZ2giLCJleHAiOjE1NTU0NTI4NjgsImlhdCI6MTU1NTQ1MTk2OCwiaXNzIjoiNzZIRktZNzVHUkEyTFBHQ1pETVZYUTY2SEEiLCJzdWIiOiJZTUdDWFA2SVVCSE9QRkdLNDVYUUdON1RWNCIsIndvdGMtbmFtZSI6IktvemlsZWtzVHJhbnNsYXRvckRldiM1MjIxMyIsIndvdGMtZG9tbiI6InRhYmxldG9wIiwid290Yy1nYW1lIjoiZXZlbnRyZXBvcnRlcmRldiIsIndvdGMtZmxncyI6MCwid290Yy1yb2xzIjpbXSwid290Yy1wcm1zIjpbXSwid290Yy1zY3BzIjpbImZpcnN0LXBhcnR5Il19.SqMnINmD7q2FC1Zyf34xbaWOP3LhRtdbL44ZkY3vDKa2-E2yEv4fX1-f8dJTWzOVDNOJYLkHZCrKu8YkVqvO1u9RP5d-Kyfpm1GMVqV9duFPKOuRkgg6p8xxDy3jg0o-ItMZa3fYNNe-3GQ2BdGmxPv7fnoov-OSIY6F7XQAEdnGUc5uMxID_4BrKYZmpBDuzi3LPPaUJeHGdh_nOJvhq-sIUHFmIpp3e70VE9xLvjQ8uS8vJI1fGCq7tDvpXtFFtCPTQ05LLD_SIvt2uPULn80SHA8aH37cI0Zpu4eeDyy0sBjRSPXSK8vKEwhUDsbt_u02s-8O9BPeCJ4RLu8EfQ, gatling.http.cache.dns -> io.gatling.http.resolver.ShuffleJdkNameResolver@319ab5e5, gatling.http.cache.contentCache -> io.gatling.core.util.cache.Cache@619cf254, token_type -> Bearer, orgId -> 30, eventId -> ["The input was not valid.","The input was not valid."], 721cad9b-2343-46f4-8f2f-766319bc197b -> 9, e803e068-608b-4826-a7ab-7f7eff07fadb -> 0),1555451967893,17,KO,List(ExitOnCompleteLoopBlock(721cad9b-2343-46f4-8f2f-766319bc197b), ExitOnCompleteLoopBlock(e803e068-608b-4826-a7ab-7f7eff07fadb)),io.gatling.core.protocol.ProtocolComponentsRegistry$$Lambda$412/1842952737@70e2ec5d)

 ================================================================================
 2019-04-16 14:59:37                                          16s elapsed
 ---- Requests ------------------------------------------------------------------
> Global                                                   (OK=3      KO=10    )
> Event-Reservations-Web-Image-Login                       (OK=1      KO=0     )
> Http Header Token Authentication Url                     (OK=1      KO=0     )
> Token Generation Url For Post                            (OK=1      KO=0     )
> CreateEventRound-GameKeeper                              (OK=0      KO=10    )
---- Errors --------------------------------------------------------------------
> status.find.in(200,201), but actually found 400                    10 (100.0%)

Here is the code

val usersDataSource  =jsonFile("C:/Gatling2/gatling3james/src/gatling/resources/dat 
 a/input-gamekeeper.json").circular
  val nameDataSource
=jsonFile("C:/Gatling2/gatling3james/src/gatling/resources/data 

 /input-gamekeeper-StringBody.json").random

  var idNumbers=(21 to 33).iterator

  def getNextOrgId()=
 {
    if(!idNumbers.hasNext)
    idNumbers=(21 to 33).iterator
    Map("orgId"->idNumbers.next())
 }

val customFeeder=Iterator.continually(getNextOrgId())

def createEventRound()={
repeat(990000000){

  exec(flushHttpCache)
  feed(customFeeder)
    .exec(http("CreateEventRound-GameKeeper")

      //exec(http("CreateEventRound-GameKeeper")
      .post("https://api.tabletop-stage.tiamat-origin.cloud/dev/gamekeeper/Round")
      .headers(headers_10)


       .body(StringBody(session =>
       """
         |{
         |  "eventId": ${orgId},
         |  "roundStart": "2019-04-16T18:22:50.388Z",
         |  "roundEnd": "2019-04-16T18:22:50.388Z",
         |  "currentTime": "2019-04-16T18:22:50.388Z",
         |  "roundNumber": 1,
         |  "matches": [
         |    {
         |      "matchId": 0,
         |      "isBye": true,
         |      "tableNumber": "string",
         |      "teams": [
         |        {
         |          "teamId": 0,
         |          "teamName": "string",
         |          "players": [
         |            {
         |              "personaId": "string",
         |              "displayName": "string"
         |            }
         |          ]
         |        }
         |      ]
         |    }
         |  ]
         |}
    """.stripMargin)).asJSON

      .check(status.in(200,201))//checkforaspecificstatus
      .check(jsonPath(path="$.roundNumber").is("1"))
      .check(jsonPath(path="$.eventId").saveAs(key="eventId")))
     // 
 .check(jsonPath(path="$.displayName").
saveAs(key="displayName")))//checkforaspecificstatus
    .exec{session=>println(session);session}
 //parameterfortheorgIdgoeshere
    .pause(1)

}

}

  // add a scenario
  val scenario2 = scenario("Game Keeper Post Orgs ")
 .exec(http("Event-Reservations-Web-Image-Login")
  .get("https://api.origin.cloud/dev/event-reservations- 

 web/img/loading.dfbfd678.svg")
  .headers(headers_1)
  .resources(http("Http Header Token Authentication Url")
    .options(uri03 + "/auth/oauth/token")
    .headers(headers_7),
    http("Token Generation Url For Post")
      .post(uri03 + "/auth/oauth/token")
      .headers(headers_8)
      .formParam("grant_type", "password")
      .formParam("username", "zyz@wss.com")
      .formParam("password", "fJC2RuVdvmHB")
      .basicAuth("ikrwugh3871ghw8rgn7q83gh","NbnEEqmDLSfno315o87ghFGYr3jybtzbi76sr")
      .check(jsonPath("$.access_token").exists.saveAs("access_token"))
      .check(jsonPath("$.token_type").exists.saveAs("token_type"))
  ))
.forever() { // add in the forever() method - users now loop forever
  exec(createEventRound())
}

  // setup the load profile
  // example command line: ./gradlew gatlingRun- 
simulations.RuntimeParameters -DUSERS=10 -DRAMP_DURATION=5 -DDURATION=30
setUp(

scenario2.inject(
  nothingFor(5 seconds),
  rampUsers(userCount) over ( rampDuration ))
  .protocols(httpConf))


.maxDuration(testDuration)

}

Please note if i simply remove the ${orgId} with 1,code works fine,but only i see error when i use ${orgId},kindly suggest where am i going wrong?

1 个答案:

答案 0 :(得分:0)

I suspect your issue is in your use of

.body(StringBody(session =>

in "createEventRound" which results in the string literal "${orgId}" being submitted

in your example, you're not looking to do any manual manipulation of session values, you just want to retrieve the value of ${orgId}. You could do this by just providing an Expression string to the StringBody.

So...

.body(StringBody( """
     |{
     |  "eventId": ${orgId},
     ...
     }""".stripMargin)).asJSON