如何通过JSON Feed用户将其加特林安装

时间:2019-02-13 00:21:02

标签: performance gatling scala-gatling gatling-jsonpath

我有这个input.json文件

[
  {
    "url": "https://api.origin.cloud/dev/battledriver/Organizations/",
    "user":100

  }
]

现在我正在通过Json馈送器将网址发送到加特林代码,现在将用户发送到下面的加特林脚本的语法应该是什么 包装模拟

import baseConfig.BaseSimulation
import io.gatling.core.Predef._
import io.gatling.http.Predef._

import scala.concurrent.duration.DurationInt

class OgreBattleDriverWithJsoniterator extends BaseSimulation {

  val usersDataSource = jsonFile("input.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 getSpecificOgreID() = {
    repeat(100) {
      exec(flushHttpCache)
       feed(usersDataSource)
           .feed(customFeeder).
        exec(http("Get Specific Driver Org Id")
        .get("${url}"+"${orgId}")

          .check(status.is(200)) // check for a specific status
          .check(jsonPath(path = "$.name").saveAs(key = "name"))) // check for a specific status
        .exec { session => println(session); session } // parameter for the orgId goes here
        .pause(1)

    }
  }



  val scn = scenario("Ogre Battle Driver Event")

    .forever() {exec(getSpecificOgreID())

      .pause(5)
      //.pause(5)
    }

  // Run for a fixed duration
  setUp(
    scn.inject(
      nothingFor(5 seconds),

      atOnceUsers(StringBody("${user}"))
     // atOnceUsers(100)
      // rampUsers(300) during (60 second)
      //rampUsers(1) during  (20 second)
    ).protocols(httpConf.inferHtmlResources()))
    .maxDuration(1 minute)

}

上述代码的问题是atOnceUsers(StringBody(“ $ {user}”))在IntelliJ编辑器上抛出错误以进行语法校正?请提供解决方案,如何将用户从JSON文件发送到Gatling设置部分?

0 个答案:

没有答案