2

I am new to Gatling and Scala and I am trying to create a test that has a custom 'feeder' which would allow each load test thread to use (and reuse) one of about 250 json data files as a post payload.

Each post payload file has 1000 records of this form:

[{
    "zip": "66221-2115",
    "recordId": "18378e10-e046-4ad3-9293-0847f8a05b2f",
    "firstName": "ANGELA",
    "lastName": "MADEUP",
    "city": "Springfield",
    "street": "123 Fake St",
    "state": "KS",
    "email": "AMADEUP@GMAIL.COM"
 }, 
 ...
]

(files are about 250kB each)

Ideally, I would like to read them in at the start of the test kind of like this:

int fileCount = 3;

ClassLoader classLoader = getClass().getClassLoader();
List<File> files = new ArrayList<>();

for (int i =0; i<=fileCount; i++){
  String fileName = String.format("identityMatching/address_data_%d.json", i);
  File file = new File(classLoader.getResource(fileName).getFile());
  files.add(file);
}

and then get the file contents with something like:

FileUtils.readFileToString(files.get(1), StandardCharsets.UTF_8)

I am now fiddling with getting this code working in scala but am wondering a couple things:

1) Can I make this code into a feeder so that I can use it like a CSV feeder?

2) When should I load the json from the files into memory? At the start of the test or when each thread needs the data?

chrismead
  • 2,163
  • 3
  • 24
  • 36

1 Answers1

2

I haven't received any answers so I will post what I have learned.

1) I was able to use a feeder with the filenames in it (not the file content)

2) I think that the best approach for reading the data in is:

.body(RawFileBody(jsonMessage))

RawFileBody(path: Expression[String]) where path is the location of a file that will be uploaded as is (from https://gatling.io/docs/current/http/http_request)

chrismead
  • 2,163
  • 3
  • 24
  • 36