Gatling exec outside scenario scope - POST requests are not called

后端 未结 1 1506
情书的邮戳
情书的邮戳 2021-01-21 11:18

I am trying to write gatling performance test where I am using the before and after blocks of the Gatling Simulation to make one-time HTTP post

1条回答
  •  隐瞒了意图╮
    2021-01-21 12:03

    Based on this - Gatling DSL doesn't work inside hooks. I wish there was a warning or something to not waste time on that.

    I had to perform the actual POST request without using Gatling DSL as below.

     def CallStop(consumerConfig : ConsumerConfig, stopEndpoint : String ) = { 
              
              val jsonBody = consumerConfig.asJson
              val valuedJsonBody = Printer.noSpaces.copy(dropNullValues = true).print(jsonBody)
              println(valuedJsonBody)        
              println("stopEndpoint:" + stopEndpoint) 
        
              val post = new HttpPost(stopEndpoint)
              post.setHeader("Content-type", "application/json")
              post.setEntity(new StringEntity(valuedJsonBody))
              // send the post request
              val client = new DefaultHttpClient
              val response = client.execute(post)
        
              println("Response:" + response)
          }
    

    0 讨论(0)
提交回复
热议问题