I am trying to pass the session ArrayBuffer element to exec http method directly . However this exec http is getting called at all.
Session output is below :
Session(6UsersAtOnce,6,1606715840791,Map(gatling.http.cache.baseUrl -> https://dbp-services-gateway-dk0859-a.uki1f.paas.intranet.db.com/pace-cake-servic
e, email -> [email protected], gatling.http.cache.dns -> io.gatling.http.cache.DnsCacheSupport$$anon$1@1c2c0d4d, sliceSubGrps -> ArrayBuffer(57,59,
1,62, 63,2, 3,24, 61,0), id -> type5-dbpalace-6, gatling.http.ssl.sslContexts -> SslContexts(io.netty.handler.ssl.ReferenceCountedOpenSslClientContext@7
71aed4f,None), slices -> [57,59,1,62,63,2,3,24,61,0]),28,OK,List(),io.gatling.core.protocol.ProtocolComponentsRegistry$$Lambda$562/0x00000008005fe840@2e
84544c)
Here is the code that I am using.
rest call to fetch slice information. "slices" is the response and sample value is [57,59,1,62,63,2,3,24,61,0] which is saved in session
def metadata() = http("metadata")
.get("/data/metadata/" + cob + "?filter_name=Full%20Entitlements&request_id=${id}")
.check(status.is(200))
.check(jsonPath("$.slices")
.saveAs("**slices**"))
rest call to chunk to fetch table data input to this rest call is slices fetched from above metadata REST call.
def chunk(chunk: Int, slices: String) = http("chunk_" + chunk)
.get("/data/chunk/csv/" + cob + "?slices=" + slices + "&request_id=${id}")
.check(status.is(200))
ChainBuilder which will build the chain of command.
val loadOnce: ChainBuilder = feed(userFeeder)
.exec(session =>
session.set("id", session.attributes("email").toString
.replace("@db.com", "-")
.replace(".", "-")
+ session.userId.toString)
)
.exec(metadata())
.pause(100.milliseconds)
.exec(session => {
val sliceList = session("slices").as[String]
.replace("[", "")
.replace("]", "")
.split(",")
val noofSlicesPerChunkRequests = (sliceList.length+TOTAL_REQUESTS-1)/TOTAL_REQUESTS
var sliceSubGrp = ""
var varSliceSubGrps = ArrayBuffer[String]()
var i=0
var j=0
for (slice <- sliceList) {
sliceSubGrp = sliceSubGrp + slice
i+=1
j+=1
if(i < noofSlicesPerChunkRequests && j<sliceList.length){
sliceSubGrp = sliceSubGrp + ","
}else{
varSliceSubGrps += sliceSubGrp
sliceSubGrp=""
i=0
}
}
val sliceSubGrps = varSliceSubGrps
session.set("sliceSubGrps", sliceSubGrps)
}).exec(session => {
val sliceArray = session("sliceSubGrps").as[ArrayBuffer[String]]
println(sliceArray)
println(s"Element at index 0 = ${sliceArray(0)}")
session
}).exec(chunk(1, s"${session("sliceSubGrps").as[ArrayBuffer[String]](0)}"))
.pause(100.milliseconds)
How to pass sliceSubGrps elements one by one to exec(chunk()) method? the java version would look like below for(int i=0;i<sliceSubGrps.size();i++) { exec(chunk(1,sliceSubGrps(i))) } how to achieve this ?
Your last block is wrong:
The
s""
is Scala String interpolation, not Gatling Expression Language. It won't compile because there's nosession
reference in scope.Please properly read the Gatling EL documentation.
You have to redesign your chunk method so that you pass Gatling expressions to the Gatling DSL methods, eg: