我所試圖做的是:爲什麼這個加特林作業不能順序運行?
- 進行GET調用來獲得
id
- 對於所有這些ID的列表進行一系列的另一GET來電
這裏是我的代碼爲此:
/** *創建者:pbane3於11/10/16。 */
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
import scala.concurrent.forkjoin.ThreadLocalRandom
import scala.collection.mutable
import scala.collection.Map
class RunWithMePerfTest extends Simulation {
var idList = List[String]()
var count = 0;
def idFeeder(idString:String):Unit = {
idList = idString.split(",").map(_.trim).toList;
println(idList)
}
def getRunId() : String = {
println(count)
var id = idList(count);
count = count+1;
return id;
}
object GetAllRunDetails {
val getAllRunDetails = exec(http("Get Run Ids")
.get("**/**")
.check(status in (200 to 209))
// .check(bodyString.saveAs("GetResponse"))
.check(jsonPath("$..id").ofType[String].findAll.transform(_.mkString(",")).saveAs("runId")))
.exec(
session => {
var getJson = session.get("GetResponse").asOption[String];
var runId = session.get("runId").asOption[String]
// println("Run ID === ")
// println(runId.get)
idFeeder(runId.get)
session
}
)
}
object GetRunIdDetails{
println("Length=" + idList.length)
val getRunIdDetails = repeat(idList.length) {
exec(http("Getting Run Details")
.get(s"****/***" + getRunId())
.check(status in (200 to 209))
.check(bodyString.saveAs("GetRunIdResponse"))
)
.exec(
session => {
var getResponse = session.get("GetRunIdResponse").asOption[String];
println("Response from Get" + getResponse.get)
session
}
)
}
}
val scn = scenario("All run details")
.exec(GetAllRunDetails.getAllRunDetails, GetRunIdDetails.getRunIdDetails)
setUp(scn.inject(atOnceUsers(1)));
}
但這裏爲什麼GetAllRunDetails.getAllRunDetails
不GetRunIdDetails.getRunIdDetails
之前運行?這是我的idList永遠不會被定義。
,我得到的錯誤是這樣的:
Length=0
0
Exception in thread "main" java.lang.IndexOutOfBoundsException: 0
at scala.collection.LinearSeqOptimized$class.apply(LinearSeqOptimized.scala:65)
at scala.collection.immutable.List.apply(List.scala:84)
at nike.runwithme.performance.RunWithMePerfTest.getRunId(RunWithMePerfTest.scala:27)
at nike.runwithme.performance.RunWithMePerfTest$GetRunIdDetails$.<init>(RunWithMePerfTest.scala:57)
at nike.runwithme.performance.RunWithMePerfTest.GetRunIdDetails$lzycompute(RunWithMePerfTest.scala:51)
at nike.runwithme.performance.RunWithMePerfTest.GetRunIdDetails(RunWithMePerfTest.scala:51)
at nike.runwithme.performance.RunWithMePerfTest.<init>(RunWithMePerfTest.scala:73)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at io.gatling.app.Gatling$.io$gatling$app$Gatling$$$anonfun$1(Gatling.scala:41)
at io.gatling.app.Gatling$lambda$1.apply(Gatling.scala:41)
at io.gatling.app.Gatling$lambda$1.apply(Gatling.scala:41)
at io.gatling.app.Gatling.run(Gatling.scala:92)
at io.gatling.app.Gatling.runIfNecessary(Gatling.scala:75)
at io.gatling.app.Gatling.start(Gatling.scala:65)
at io.gatling.app.Gatling$.start(Gatling.scala:57)
at io.gatling.app.Gatling$.fromArgs(Gatling.scala:49)
at io.gatling.app.Gatling$.main(Gatling.scala:43)
at io.gatling.app.Gatling.main(Gatling.scala)
試過這個,沒有工作。 –
好的,進一步看,你的exec在你運行之前得到初始化。當你調用.get(s「****/***」+ getRunId())方法時,那裏還沒有數據,所以你的運行在它開始之前就會失敗。您可以添加另一個將數據放入會話中的exec,然後才能在您的獲取調用中使用它。 –
這沒有奏效。所以從循環開始就添加了會話。 –