【问题标题】:Gatling & Scala : How to split values in loop?Gatling & Scala:如何在循环中拆分值?
【发布时间】:2017-03-01 13:46:37
【问题描述】:

我想在循环中拆分一些值。我在检查中使用了拆分方法,它对我有用。但是,两种不同类型的值超过 25 个。 所以,我正在scala中实现循环并苦苦挣扎。 考虑以下场景:

import scala.concurrent.duration._
import io.gatling.core.Predef._
import io.gatling.http.Predef._

class testSimulation extends Simulation {

    val httpProtocol = http
    .baseURL("https://website.com")
    .doNotTrackHeader("1")
    .disableCaching

val uri1 = "https://website.com"

val scn = scenario("EditAttribute")
    .exec(http("LogIn")
        .post(uri1 + "/web/guest/")
        .headers(headers_0)
    .exec(http("getPopupData")
        .post("/website/getPopupData")
        .check(jsonPath("$.data[0].pid").transform(_.split('#').toSeq).saveAs("pID")))  // Saving splited value
    .exec(http("Listing")
        .post("/website/listing")
        .check(jsonPath("$.data[*].AdId").findAll.saveAs("aID"))                        // All values are collected in vector 
//      .check(jsonPath("$.data[*].AdId").transform(_.split('#').toSeq).saveAs("aID"))  // Split method Not working for batch
//      .check(jsonPath("$.data[*].AdId").findAll.saveAs("aID"))                        // To verify the length of array (vector)
        .check(jsonPath("$.data[0].RcId").findAll.saveAs("rID")))
    .exec(http("UpdatedDataListing")
        .post("/website/search")
        .formParam("entityTypeId", "${pId(0)}")                                 // passing splited value,  perfectly done
        .formParam("action_id", "${aId(0)},${aId(1)},${aId(2)},..and so on)      // need to pass splitted values which is not happening
        .formParam("userId", "${rID}")
// To verify values on console (What value I m getting after splitting)...
    .exec(  session =>  {
            val abc = session("pID").as[Seq[String]]
            val xyz = session("aID").as[Seq[String]]
            println("Separated pId ===>  "   +abc(0))               // output - first splitted value
            println("Separated pId ===>  "   +abc(1))               // split separater
            println("Separated pId ===>  "   +abc(2))               // second splitted value
            println("Length  ===>   "   +abc.length)                // output - 3
            println("Length  ===>   "   +xyz.length)                // output - 25
            session
                        }
         )
    .exec(http("logOut")
        .get("https://" + uri1 + "/logout")
        .headers(headers_0))

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

我想实现一个循环,在会话中执行所有 (25) 个值的拆分。我不想做硬编码。 我也是 scala 和 Gatling 的新手。

【问题讨论】:

    标签: scala performance-testing load-testing gatling


    【解决方案1】:

    由于它是一个会话函数,下面的 sn-p 将给出一个继续的方向,就像你在 Java 中一样使用 split :-

      exec { session =>
        var requestIdValue = new scala.util.Random().nextInt(Integer.MAX_VALUE).toString();
        var length = jobsQue.length
        try {
          var reportElement = jobsQue.pop()
          jobData = reportElement.getData;
          xml = Configuration.XML.replaceAll("requestIdValue", requestIdValue);
    
          println(s"For Request Id : $requestIdValue  .Data Value from feeder is : $jobData Current size of jobsQue : $length");
        } catch {
          case e: NoSuchElementException => print("Erorr")
        }
    
        session.setAll(
          "xmlRequest" -> xml)
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-18
      • 1970-01-01
      • 1970-01-01
      • 2022-10-08
      • 2021-09-11
      • 1970-01-01
      相关资源
      最近更新 更多