2017-03-28 40 views
0

我在会话中保存了矢量,我想从矢量中使用随机值,但不知道如何在会话中提取值。如何在会话中提取矢量?

错误:

'的HttpRequest-6' 未能执行:矢量(437420,443940,443932, 437437,443981,443956,443973,443915,437445)命名为 'termIds' 确实 不支持.random功能

而且

在第二个方案中它传递载体,GE像这样,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) 

} 

回答

1

以下是可以帮助他人的解决方案。

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) 

}