0

I have saved vector in session and I want to use random value from the vector but dont know how to extract value in session.

Errors:

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

And

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)

instead of using http://someurl/api/thr/435854/terms/443973

::Here is my script::

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)

}
Peter
  • 855
  • 2
  • 15
  • 35

1 Answers1

1

Here is the solution which may help others.

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)

}
Peter
  • 855
  • 2
  • 15
  • 35