加特林:随机Feeder POST请求:找不到:值电子邮件(加特林3.0.0)

时间:2018-11-18 14:25:47

标签: scala gatling scala-gatling zinc

**带加特林的随机负载测试** 我想测试内置API的负载,因此,我必须生成大量随机电子邮件(我知道服务器上目前没有电子邮件检查功能,因此我只创建随机字符串)。 我使用的工具是gatling-charts-highcharts-bundle-3.0.0,我检查了有关如何解决此问题的其他问题和网页,并获得了使用供料器的信息。我尝试了下面的代码,但我不明白为什么总是会有值不出错。 基本上: 我正在尝试创建一个随机的字符串供稿器,并将其用于加特林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
    ...

为什么会出现“找不到值”错误?

1 个答案:

答案 0 :(得分:0)

我找到了解决方案: 代替:

{
    position: absolute;
    left: 0px;
    top: 0px;
    z-index: -1;
}

使用:

StringBody(s"""{ "testmail": ${email}, "testmailagain": ${email}, }""")).asJson