Check - response time as a proportion of bodyString length

Hi - I am a Java developer with some experience of JMeter, and I started to learn Gatling five days ago. I have a question below, the answer to which is ‘go and learn Scala’, and I am indeed doing so, but thought I would also post the question here in case I am going in the wrong direction.

I need to add an assertion on the reponse. The response time must be no more than 100 ms per 1MB response body. In order to do that I will capture the response time using check().saveAs(). I can access the response length using bodyString.transform(s => s.length).is(length)), and I’ll have to see how to save that as a variable. And then I’ll have to combine these two pieces of information in an expression that can be inserted into a check(). I expect that expression will be a function.

Thanks for any hints

/Martin

story so far is that the following expression doesn’t resolve the saveAs variable

`
.check(responseTimeInMillis.lessThan(("${responseBodyLength}".toInt)/10000))

`
are saveAs variables accessible within a check()?

You are close.

Try this (untested):

.check( bodyString.transform( s => (s.length / (1024*1024) ) * 100 ) .saveAs( “TARGET_RESPONSE_TIME” )
.check( responseTimeInMillis.transform( t, session => t < session(“TARGET_RESPONSE_TIME”).as[Int] ).is( true )

Thanks John.

I had this

`
.check(responseTimeInMillis.saveAs(“responseTimeInMillis”))
.check(responseTimeInMillis.lessThanOrEqual((session) => {
((session(“responseBodyStringLength”)).as[Int])/10000

`

I’ll now go through your answer - a good learning opportunity

Cheers

/Martin

Just a note that I couldn’t get the second line to compile - a problem with variable t.

At the moment I now have the following

`
.check(responseTimeInMillis.transform { (t:Long, session:Session) =>
(t < session(“TARGET_RESPONSE_TIME”).as[Int])
})

`