加特林:随机进纸器 POST 请求:未找到:值电子邮件(加特林 3.0.0)
Gatling: Random Feeder POST request: not found: value email (Gatling 3.0.0)
**使用加特林机进行随机负载测试**
我想测试我构建的 API 以获得更高的负载,因此,我必须生成大量随机电子邮件(我知道服务器上目前没有电子邮件检查,所以我只是创建随机字符串)。
我使用的工具是 gatling-charts-highcharts-bundle-3.0.0,我查看了其他问题和有关如何解决此问题的网页,并获得了使用馈线的信息。我尝试了以下代码,但我不明白为什么总是有一个值不是错误。
基本上:
我正在尝试创建一个随机字符串馈送器并在 gatling 3.0.0 中使用它,但是当我按照以下方式进行操作时,我总是收到“未找到:值电子邮件”错误:
package computerdatabase
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
import scala.util.Random
class testsimu extends Simulation {
val httpProtocol = http
.baseUrl("http://testurl.com/api") // Here is the root for all relative URLs
.acceptHeader("application/json") // Here are the common headers
.acceptLanguageHeader("en;q=1.0,de-AT;q=0.9")
.acceptEncodingHeader("gzip;q=1.0,compress;q=0.5")
.userAgentHeader("TestApp/1.3.0(com.test.test;build:1;iOS12.1.0)Alamofire/4.7.0")
val headers_10 = Map("Content-Type" -> "application/json") // Note the headers specific to a given request
val feeder = Iterator.continually(Map("email" -> (Random.alphanumeric.take(20).mkString)))
val scn = scenario("Login") // A scenario is a chain of requests and pauses
// Note that Gatling has recorded real time pauses
.feed(feeder)
.exec(http("LoginRequest") // Here's an example of a POST request
.post("/login")
.headers(headers_10)
.body(StringBody(s"""{ "testmail": ${email}, "testmailagain": ${email}, }""")).asJson)
setUp(scn.inject(constantUsersPerSec(10) during(5 seconds) randomized).protocols(httpConf))
}
这里是错误信息:
GATLING_HOME is set to /Users/privat/Documents/test/Development/gatling-charts-highcharts-bundle-3.0.0
15:06:12.819 [ERROR] i.g.c.ZincCompiler$ - /Users/privat/Documents/test/Development/gatling-charts-highcharts-bundle- 3.0.0/user-files/simulations/test/test.scala:45:46: not found: value email
.body(StringBody(s"""{ "testmail": ${email}, "testmailagain": ${email}, }""")).asJson)
^
15:06:12.821 [ERROR] i.g.c.ZincCompiler$ - /Users/privat/Documents/test/Development/gatling-charts-highcharts-bundle-3.0.0/user-files/simulations/higgs/higgs-sim.scala:45:103: not found: value email
.body(StringBody(s"""{ "testmail": ${email}, "testmailagain": ${email}, }""")).asJson)
^
15:06:12.856 [ERROR] i.g.c.ZincCompiler$ - two errors found
15:06:12.858 [ERROR] i.g.c.ZincCompiler$ - Compilation crashed
sbt.internal.inc.CompileFailed: null
...
为什么会出现 "value not found" 错误?
我找到了解决办法:
而不是:
StringBody(s"""{ "testmail": ${email}, "testmailagain": ${email}, }""")).asJson
使用:
StringBody("""{ "testmail": ${email}, "testmailagain": ${email}, }""")).asJson
**使用加特林机进行随机负载测试** 我想测试我构建的 API 以获得更高的负载,因此,我必须生成大量随机电子邮件(我知道服务器上目前没有电子邮件检查,所以我只是创建随机字符串)。 我使用的工具是 gatling-charts-highcharts-bundle-3.0.0,我查看了其他问题和有关如何解决此问题的网页,并获得了使用馈线的信息。我尝试了以下代码,但我不明白为什么总是有一个值不是错误。 基本上: 我正在尝试创建一个随机字符串馈送器并在 gatling 3.0.0 中使用它,但是当我按照以下方式进行操作时,我总是收到“未找到:值电子邮件”错误:
package computerdatabase
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
import scala.util.Random
class testsimu extends Simulation {
val httpProtocol = http
.baseUrl("http://testurl.com/api") // Here is the root for all relative URLs
.acceptHeader("application/json") // Here are the common headers
.acceptLanguageHeader("en;q=1.0,de-AT;q=0.9")
.acceptEncodingHeader("gzip;q=1.0,compress;q=0.5")
.userAgentHeader("TestApp/1.3.0(com.test.test;build:1;iOS12.1.0)Alamofire/4.7.0")
val headers_10 = Map("Content-Type" -> "application/json") // Note the headers specific to a given request
val feeder = Iterator.continually(Map("email" -> (Random.alphanumeric.take(20).mkString)))
val scn = scenario("Login") // A scenario is a chain of requests and pauses
// Note that Gatling has recorded real time pauses
.feed(feeder)
.exec(http("LoginRequest") // Here's an example of a POST request
.post("/login")
.headers(headers_10)
.body(StringBody(s"""{ "testmail": ${email}, "testmailagain": ${email}, }""")).asJson)
setUp(scn.inject(constantUsersPerSec(10) during(5 seconds) randomized).protocols(httpConf))
}
这里是错误信息:
GATLING_HOME is set to /Users/privat/Documents/test/Development/gatling-charts-highcharts-bundle-3.0.0
15:06:12.819 [ERROR] i.g.c.ZincCompiler$ - /Users/privat/Documents/test/Development/gatling-charts-highcharts-bundle- 3.0.0/user-files/simulations/test/test.scala:45:46: not found: value email
.body(StringBody(s"""{ "testmail": ${email}, "testmailagain": ${email}, }""")).asJson)
^
15:06:12.821 [ERROR] i.g.c.ZincCompiler$ - /Users/privat/Documents/test/Development/gatling-charts-highcharts-bundle-3.0.0/user-files/simulations/higgs/higgs-sim.scala:45:103: not found: value email
.body(StringBody(s"""{ "testmail": ${email}, "testmailagain": ${email}, }""")).asJson)
^
15:06:12.856 [ERROR] i.g.c.ZincCompiler$ - two errors found
15:06:12.858 [ERROR] i.g.c.ZincCompiler$ - Compilation crashed
sbt.internal.inc.CompileFailed: null
...
为什么会出现 "value not found" 错误?
我找到了解决办法: 而不是:
StringBody(s"""{ "testmail": ${email}, "testmailagain": ${email}, }""")).asJson
使用:
StringBody("""{ "testmail": ${email}, "testmailagain": ${email}, }""")).asJson