I have to test in IBM cloudant db maximum acceptable JSON size through Jmeter. I have created a JSON file and I need to increase the no of the citizen details in the JSON file in JMeter. Take an example, I have created a JSON file and passing information of one citizen in the first iteration the next iteration it should be two citizens and it will keep increasing... and nth iteration it should be n no of citizen details.( JSON size also increase if I increase the body). How I can do this can anyone please suggest.
"docs": [
{
"name": "Nicholas",
"age": 45,
"gender": "male",
"_attachments": {
}
},
{
"name": "Taylor",
"age": 50,
"gender": "male",
"_attachments": {
}
}
]
}
If you want to add new entry to the JSON payload on each iteration of the Thread Group:
Put the following code into "Script" area:
import groovy.json.JsonBuilder
import groovy.json.internal.LazyMap
import org.apache.commons.lang3.RandomStringUtils
import org.apache.commons.lang3.RandomUtils
def data = []
0.upto(vars.get('__jm__Thread Group__idx') as int, {
def entry = new LazyMap()
entry.put('name', RandomStringUtils.randomAlphabetic(10))
entry.put('age', RandomUtils.nextInt(18, 99))
entry.put('gender', 'male')
entry.put('__attachments', {})
data.add(entry)
})
def builder = new JsonBuilder()
builder(docs: data.collect {
[name: it.get('name'), age: it.get('age'), gender: it.get('gender'), __attachments: it.get('__attachments')]
})
sampler.getArguments().removeAllArguments()
sampler.addNonEncodedArgument('', builder.toPrettyString(), '')
sampler.setPostBodyRaw(true)
References:
Test Plan structure: