Custom Feeders with multi values

Hi

I have a request where 3 header parameters need to be generated dynamically.

Example: timestamp, userid , token

token is calculated based on userid and timestamp.

val getUserScenario = scenario(“Get User”)
.feed(customFeeder)
.exec(

http(“Get User”)
.get("/user")
.header(“timestamp”,"${timeStampStr}")
.header(“userid”, “${userid}”)
.header(“token”, “${token}”)
.check(status.is(200))

I am trying to use custom Feeder for this by over riding default feeder

object customFeed {

val customFeeder = new Feeder[String] {

override def hasNext = true

override def next: Map[String, String] = {

val sdf = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss.SSS”)
sdf.setTimeZone(TimeZone.getTimeZone(“UTC”))

val strUserid = abs(ThreadLocalRandom.current().nextLong(10000000000L)).toString

val timeStamp = DateTime.now()
val now = new Date(timeStamp.getMillis())
val timeStampStr = sdf.format(now)




val timeStampStr = sdf.format(now)
val strUserid = abs(ThreadLocalRandom.current().nextLong(10000000000L)).toString
val token : String = … Calculated by complex math…based on timestamp and userid

Map(“timeStampStr” → timeStampStr)
Map(“token”-> token)
Map(“userid” → strUserid**)**

}

}

When i try to use this in get Call mentioned above, it only recognizes the last parameter in Map. That is Map(“upmId” → strUpmId). It is not recognizing timStampStr attribute and hashedToken attribute.

Please help me with is scenario.

Regards,
Santhosh

//Do this:

val myFeeder = Iterator.continually( myFun() )
.map(s => Map[String, String](s._1 → s._2, s._3 → s._4, s._5 → s._6)

//Now you just need a function, myFunction() which returns a 6-tuple containing:

def myFun: (String, String, String, String, String, String) = {
(“timeStampStr”, timeStampStrFunction(), “token”, tokenFunction(), “userid”, userIdStrFunction())
}

//Now you need those functions . . .

def timeStampStrFunction(): String = {}
def tokenFunction(): String = {}

def userIdStrFunction(): String = {}

//Just make sure those functons return the strings you want, and everything will be evaluated when you call next on the iterator, so you get correct results regarding time and stuff

//Also, on a side note, I didn’t test any of this or whatever, so I might’ve made some syntax error or something somewhere

Thank you :slight_smile: exactly what i am looking for

That worked like a charm. !!!

Cheers
Santhosh