gpt4 book ai didi

java - 如何在 session 中提取 vector ?

转载 作者:行者123 更新时间:2023-12-02 13:34:32 25 4
gpt4 key购买 nike

我已在 session 中保存 vector ,我想使用 vector 中的随机值,但不知道如何在 session 中提取值。

错误:

'httpRequest-6' failed to execute: Vector(437420, 443940, 443932, 437437, 443981, 443956, 443973, 443915, 437445) named 'termIds' does not support .random function

还有

In 2nd scenario It passes vector in get request like this way, http://someurl/api/thr/Vector(435854)/terms/Vector(437420, 443940, 443932, 437437, 443981, 443956, 443973, 443915, 437445)

而不是使用 http://someurl/api/thr/435854/terms/443973

::这是我的脚本::

class getTerm extends Simulation {


val repeatCount = Integer.getInteger("repeatCount", 1).toInt
val userCount = Integer.getInteger("userCount", 1).toInt
val turl = System.getProperty("turl", "some url")

val httpProtocol = http
.baseURL("http://" + turl)

val headers_10 = Map("Content-Type" -> """application/json""")

var thrIds = ""
var termIds = ""


// Scenario - 1
val getTerms = scenario("Scn 1")
.exec(http("list_of_term")
.get("/api/abc")
.headers(headers_10)
.check(jsonPath("$[*].id")
.findAll.saveAs("thrIds"))
)

.exec(http("get_all_terms")
.get("""/api/thr/${thrIds.random()}/terms""")
.headers(headers_10)
.check(jsonPath("$[*].id")
.findAll.saveAs("termIds"))
)

.exec(session => {
thrIds = session("thrIds").as[Long].toString
termIds = session("termIds").as[Long].toString
println("***************************************")
println("Session ====>>>> " + session)
println("Ths ID ====>>>> " + thrIds)
println("Term ID ====>>>> " + termIds)
println("***************************************")
session}
)

// Scenario - 2
// Want to extract vectors here and pass its value into get call
val getKnownTerms = scenario("Get Known Term")
.exec(_.set("thrIds", thrIds))
.exec(_.set("termIds", termIds))

.repeat (repeatCount){
exec(http("get_k_term")
.get("""/api/thr/${thrIds}/terms/${termIds.random()}""")
.headers(headers_10))
}

val scn = List(getTerms.inject(atOnceUsers(1)), getKnownTerms.inject(nothingFor(20 seconds), atOnceUsers(userCount)))
setUp(scn).protocols(httpProtocol)

}

最佳答案

这是可能对其他人有帮助的解决方案。

class getTerm extends Simulation {

val repeatCount = Integer.getInteger("repeatCount", 1).toInt
val userCount = Integer.getInteger("userCount", 1).toInt
val turl = System.getProperty("turl", "some url")

val httpProtocol = http
.baseURL("http://" + turl)

val headers_10 = Map("Content-Type" -> """application/json""")

// Change - 1
var thrIds: Seq[String] = _
var termIds: Seq[String] = _

// Scenario - 1
val getTerms = scenario("Scn 1")
.exec(http("list_of_term")
.get("/api/abc")
.headers(headers_10)
.check(jsonPath("$[*].id")
.findAll
.transform { v => thrIds = v; v }
.saveAs("thrIds"))
)

.exec(http("get_all_trms")
.get("""/api/thr/${thrIds.random()}/terms""")
.headers(headers_10)
.check(jsonPath("$[*].id")
.findAll
.transform { v => termIds = v; v }
.saveAs("termIds"))
)

// Scenario - 2
val getKnownTerms = scenario("Get Known Term")
.exec(_.set("thrIds", thrIds))
.exec(_.set("termIds", termIds))

.repeat (repeatCount){
exec(http("get_k_term")
.get("""/api/thr/${thrIds.random()}/terms/${termIds.random()}""")
.headers(headers_10))
}

val scn = List(getTerms.inject(atOnceUsers(1)), getKnownTerms.inject(nothingFor(20 seconds), atOnceUsers(userCount)))
setUp(scn).protocols(httpProtocol)

}

关于java - 如何在 session 中提取 vector ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43073873/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com