【问题标题】:How to resolve type mismatch error in Gatling?如何解决 Gatling 中的类型不匹配错误?
【发布时间】:2016-11-23 11:16:27
【问题描述】:

“登录”请求.formParam 中传递session => 时出错。任何人都可以帮忙吗?谢谢:-)

这是我的脚本,

// Random user login logout
import scala.concurrent.duration._
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._
import io.gatling.core.validation._

class mamLoginLogout extends Simulation {

    val testServerUrl = System.getProperty("testServerUrl", "https://url")
    val username = System.getProperty("username", "TestUser")
    val password = System.getProperty("password", "passwd")
    val userCount = Integer.getInteger("userCount", 10).toInt
    val accountname = System.getProperty("accountname", "testrp")
    val endNum = Integer.getInteger("EndNumber", 10).toInt

    val httpProtocol = http
        .baseURL(testServerUrl)

    val scn = scenario("Login => Browse => Logout")
        .exec(http("Login")
            .post("/ma/a/" + accountname + "/login")
            .headers(headers_6)
            .formParam("username", session => username +  ThreadLocalRandom.current.nextInt(endNum))
            .formParam("password", session => password)
            // This script Runs perfact if I use below formParam (So its clear the problem is in above formParam with session =>, I think it conflicts with below session which is used in .foreach())
            //.formParam("username", username)
            //.formParam("password", password)
            )

    .exec(http("Browse")
            .get("/ma/assets/type=media%ofset=1%3Blimit=8")
            .headers(headers_12)
            .check(jsonPath("$..keyframeId").findAll.saveAs("IdList"))
            )

    .foreach("${IdList}", "id") {
            doIf(session => session("id").as[String] != "-1")
            {
                exec(http("Set_Keyframes")
                .get("/ma/keyframes/${id};width=185;height=103")
                )
            }
    }

    .exec(http("Logout")
        .get("/ma/logout")
        .headers(headers_80))       

    setUp(scn.inject(atOnceUsers(userCount))).protocols(httpProtocol)
}

编译失败,错误如下:

3674 [main] ERROR io.gatling.compiler.ZincCompiler$ - scala:68: type mismatch;
 found   : String("${IdList}")
 required: ?{def apply: ?}
Note that implicit conversions are not applicable because they are ambiguous:
 both method augmentString in object Predef of type (x: String)scala.collection.immutable.StringOps
 and method stringToExpression in object Predef of type [T](string: String)(implicit evidence$1: scala.reflect.ClassTag[T])io.gatling.core.session.Expression[T]
 are possible conversion functions from String("${IdList}") to ?{def apply: ?}

3674 [main] ERROR io.gatling.compiler.ZincCompiler$ -       .foreach("${IdList}", "id") {
3684 [main] ERROR io.gatling.compiler.ZincCompiler$ -                ^
3695 [main] ERROR io.gatling.compiler.ZincCompiler$ - scala:68: type mismatch;
 found   : String("id")
 required: ?{def apply: ?}
Note that implicit conversions are not applicable because they are ambiguous:
 both method augmentString in object Predef of type (x: String)scala.collection.immutable.StringOps
 and method stringToExpression in object Predef of type [T](string: String)(implicit evidence$1: scala.reflect.ClassTag[T])io.gatling.core.session.Expression[T]
 are possible conversion functions from String("id") to ?{def apply: ?}
3695 [main] ERROR io.gatling.compiler.ZincCompiler$ -       .foreach("${IdList}", "id") {
3695 [main] ERROR io.gatling.compiler.ZincCompiler$ -                             ^
3994 [main] ERROR io.gatling.compiler.ZincCompiler$ - scala:53: not found: value ThreadLocalRandom
3995 [main] ERROR io.gatling.compiler.ZincCompiler$ -           .formParam("username", session => username +  ThreadLocalRandom.current.nextInt(endNum))
3995 [main] ERROR io.gatling.compiler.ZincCompiler$ -                                                         ^
4047 [main] ERROR io.gatling.compiler.ZincCompiler$ - three errors found
4048 [main] DEBUG io.gatling.compiler.ZincCompiler$ - Compilation failed (CompilerInterface)

【问题讨论】:

    标签: scala performance-testing load-testing gatling


    【解决方案1】:

    导入 java.util.concurrent.ThreadLocalRandom :-)

    【讨论】:

      【解决方案2】:

      解决了。忘记加了

      import java.util.concurrent.ThreadLocalRandom
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-05-04
        • 1970-01-01
        • 1970-01-01
        • 2016-11-14
        • 2020-08-21
        • 2016-08-09
        • 1970-01-01
        相关资源
        最近更新 更多