Skip to main content

Data Feeders & Parameterization

A feeder supplies variables to a scenario. Variables are substituted in paths, headers and payloads using ${name}. Use queryParam for URL parameters. A scenario can have several feeders.

FactoryValues
csv("testdata/search.csv")CSV columns become variables, one record per row (RFC 4180).
csv("testdata/search.csv", ';')The same with another field separator (since 1.1.0).
json("testdata/products.json")JSON array of objects, one record per object.
records(List.of(Map.of("tenant", "acme"), ...))In-memory records (since 1.1.0, see In-memory records).
random("userId", 1, 10000)Random integer, both bounds inclusive.
uuid("requestId")New UUID value.
sequence("orderId", 1000, 1)Sequence starting at 1000, incrementing by 1.
constant("tenant", "demo")Fixed string value.

csv, json and records feeders hand out their records according to a strategy; by default they cycle in file order. There are no fromCsv, fromList or fromSupplier factories; use records(..) for a list built in code.

Strategies​

Since 1.1.0. A csv, json or records feeder takes one of four strategies. Each strategy method returns a new feeder over the same records; the feeder you call it on is unchanged. strategy() returns the current one.

MethodStrategyOrderRuns out?
circular() (default)CIRCULARFile order, round-robin: 1, 2, 3, 1, 2, 3, ...Never
queue()QUEUEFile order, each record once per scenario runYes, after the last record
shuffle()SHUFFLEShuffled once per run, then each record once, like a queueYes, after the last record
randomOrder()RANDOMA uniform random pick with replacement: a record can come twice in a rowNever
// each coupon is redeemed once; the users stop when the coupons run out
.feed(LoadTestFeeder.csv("testdata/coupons.csv").queue())

// every account once, in a different order on every run
.feed(LoadTestFeeder.json("testdata/accounts.json").shuffle())

// a random product per iteration, repeats allowed
.feed(LoadTestFeeder.csv("testdata/products.csv").randomOrder())

The random strategy is named randomOrder() so that it does not overload the static random(String, int, int) generator. Neither randomOrder() nor shuffle() takes a seed.

Strategies apply to csv, json and records feeders only. On a generated feeder (random, uuid, sequence, constant) or a custom LoadTestFeeder subclass, the strategy methods throw IllegalStateException ("queue() applies to csv(..), json(..) and records(..) feeders, not to generated or custom feeders"), and strategy() returns null.

The engines never use a feeder's own position. Each run takes a fresh cursor per feeder per scenario, so a queue starts again at the first record in every run and in every scenario that uses it. Calling next() directly on a feeder follows its strategy (a queue returns null after the last record), and reset() rewinds it and shuffles again. The records of csv, json and records feeders are shared between these cursors and are read-only.

When feeders are polled​

  • Users, ramp-up and hold: at the start of every iteration, each feeder is polled once, in declaration order, and the records are merged into the iteration's variables.
  • Workload (Gatling only): each user runs the flow once, so it polls each feeder once.
  • Fresh cursor per run: a circular feeder starts at its first record in every run; a queue hands each record out once per run. A sequence(..) feeder restarts at its start value on every run, on both engines; to keep values unique across two runs in the same JVM, give each run a different start value or use uuid(..).

A record is only taken when an iteration starts. On the JDK engine, a user whose hold has expired no longer takes a record.

Several feeders​

Since 1.1.0. addFeeder(..) appends a feeder; feed(..) keeps replacing every feeder set before:

CallsFeeders used
feed(a).feed(b)b (unchanged from 1.0)
feed(a).addFeeder(b)a, then b
addFeeder(a).addFeeder(b)a, then b
addFeeder(b).feed(a)a

feedCsv(path) and feedJson(path) replace too, like feed(..). feeders() lists the feeders in declaration order; feeder() returns the first one, or null. addFeeder(null) throws IllegalArgumentException, and addFeeder inside a flow-control block throws IllegalStateException, like the other scenario settings.

loadScenario("Orders").users(10)
.feed(LoadTestFeeder.csv("testdata/users.csv")) // username, password
.addFeeder(LoadTestFeeder.sequence("orderId", 1000, 1))
.addFeeder(LoadTestFeeder.records(List.of(
Map.of("region", "eu"), Map.of("region", "us"))).randomOrder())
.step("Order").post("/orders/${orderId}")
.header("X-Region", "${region}")
.body("{\"user\":\"${username}\"}").and()
.run();

Two feeders must not supply the same variable. Before any request, the run is rejected with IllegalArgumentException when a variable comes from two feeders, and the message names both ("feeder variable 'id' comes from both the csv feeder 'a.csv' and the records feeder; ..."). The check covers the variables TestFly can see without consuming a feeder: CSV headers, the keys of JSON and in-memory records, and the variable of a generated feeder. A custom feeder is not checked; if its keys collide with another feeder at runtime, the later feeder in declaration order wins.

When a queue runs out​

When a queue or shuffle feeder has no record left:

  • Users stop starting iterations. The user that found it empty sends nothing more and ends. Every other user ends at its next poll; an iteration already in progress completes. Users that start later, for example in an open workload, end without sending a request.
  • The run is not partial (partial() stays false) and is not failed by it. Every request that was sent has its outcome, so assertions and SLAs evaluate the data that ran. The run usually ends before its hold, and the duration and throughput reflect the time it actually ran.
  • LoadTestMetrics.feederExhausted() is true for that scenario. It is exported to the suite testfly-metrics.json and shown in the HTML, Allure and ReportPortal reports (see Reporting). In a simulation, the global metrics are true when any scenario's feeder ran out.
  • One WARN is logged per scenario: [LoadTest] Scenario 'Redeem': feeder csv 'testdata/coupons.csv' (queue) ran out of records; no new iteration was started (metrics are complete, not partial). Gatling's native queue would crash the run instead.

To fail the test when the data ran out, assert it:

loadScenario("Redeem").users(5).hold(Duration.ofSeconds(30))
.feed(LoadTestFeeder.csv("testdata/coupons.csv").queue())
.step("Redeem").post("/coupons/${code}/redeem").and()
.run()
.assertFeederNotExhausted() // AssertionError if the coupons ran out
.assertP95Below(300);
Closed workloads keep running

With a closed workload (constantConcurrent, rampConcurrent) on Gatling, the users still stop starting iterations when the queue runs out, but Gatling keeps replacing every user that ends until that injection step is over. Gatling 3.16 cannot stop the injection of one population without stopping the whole simulation. Each replacement user waits 100 ms and exits without sending a request, so the run lasts its full injection time, mostly idle. When the run time matters, use an open workload, or a design that cannot run out: enough records for the whole run, or a circular feeder.

With a hold loop a queue nearly always runs out, because every user keeps starting iterations until the hold ends. That is why exhaustion is reported rather than failed: "use each record once" is the normal purpose of a queue.

Difference from Gatling

Gatling's own queue() feeder stops the whole simulation as crashed when it runs out. TestFly does not use Gatling's feed(..): on both engines it polls its own cursor at the start of each iteration and ends only the users that find no record. A queue or shuffle behaves the same on the JDK and Gatling engines.

CSV files (RFC 4180)​

Since 1.1.0. Both engines read CSV files with the same RFC 4180 parser:

  • The file is read as UTF-8. A leading byte order mark (BOM) is removed, so the first header name resolves as ${id}, not with an invisible prefix. Invalid UTF-8 bytes are replaced with U+FFFD (\uFFFD) and one WARN names the file ("is not valid UTF-8: invalid bytes were replaced with U+FFFD"); the file still loads. Save feeder files as UTF-8 to keep every character.
  • A record ends at CRLF, LF or a lone CR. The first record holds the header names. A record that is empty or only whitespace (outside quotes) is skipped.
  • A field that starts with " is quoted. It may contain the separator, line breaks and "" (one literal quote), and its value is kept exactly, without trimming. Spaces and tabs around a quoted field are ignored (a tab is not, when it is the separator): 1, "Alice" gives Alice, and a header "id", "name" gives the keys id and name. Any other character between the closing quote and the next separator is kept as is.
  • Unquoted fields and header names are trimmed. A " inside an unquoted field is an ordinary character. An empty field is the empty string.
testdata/messages.csv
id,text
1,"a,b"
2,"say ""hi"""
3,"line1
line2"

This gives text = a,b, say "hi" and a value with an embedded line break. csv(path, separator) uses another separator, for example ';' or '\t'; it throws IllegalArgumentException only for a separator of ", CR or LF.

Ragged rows. A row with fewer fields than headers has no key for the missing columns; a row with more fields ignores the extra ones. The first short row and the first long row of a file each log one WARN with its line number.

Malformed files. An unterminated quoted field, a duplicate header name or a blank header name makes the file malformed. csv(..) does not throw: it logs a WARN that names the file and the 1-based line where the bad record starts, and gives a feeder without rows. Running the scenario then fails before any request, as for a missing file.

Behaviour change in 1.1.0

The previous parser split every line on commas. Quoted fields with commas or line breaks were cut apart, "" was not unescaped, quoted values were trimmed, a BOM stayed in the first header name, and a duplicate header silently overwrote the earlier column. Files that relied on that behaviour can read differently now.

In-memory records​

Since 1.1.0. records(..) builds a feeder from a list of maps. The list and each map are copied when it is called, so later changes to them do not affect the feeder. Strategies apply as for CSV and JSON files. A null list or a null record throws IllegalArgumentException. An empty list is accepted by records(..), but a scenario with it is rejected before any request, like an empty CSV or JSON file.

LoadTestFeeder tenants = LoadTestFeeder.records(List.of(
Map.of("tenant", "acme", "plan", "pro"),
Map.of("tenant", "globex", "plan", "free")));

loadScenario("Tenants").users(4)
.feed(tenants.queue())
.step("Plan").get("/tenants/${tenant}/plan").and()
.run();

Large files on Gatling​

The Gatling engine runs in a child JVM and normally receives the records inside its run configuration. Above 100,000 records, a csv or json feeder sends its file instead: the child reads the file again with the same parser and separator. The test JVM records the file's size and modification time, and the child fails before starting if either differs, so it never feeds records other than those that were validated. The Gatling run then fails with a non-zero exit code (see Gatling run lifecycle). Do not rewrite a feeder file while a run that uses it is in progress.

Custom feeders​

A custom LoadTestFeeder subclass (your own next(), hasNext() and reset()) works as before and never runs out:

  • JDK engine: next() is called live at the start of every iteration. When hasNext() is false, the last record is used again.
  • Gatling engine: a custom feeder that overrides describe() is sent as its descriptor. Otherwise the feeder is sampled in the test JVM to at most 5000 records, which the users cycle; when the feeder has more, a WARN says that it was cut to its first 5000 records.

Custom feeders have no strategy and are not part of the duplicate-variable check. The JDK engine does not reset a custom feeder, so a second run continues where the first stopped; the Gatling sample is taken after reset() and the feeder is reset again afterwards.

Missing or empty files fail fast​

A csv or json feeder file is looked up in this order: on the classpath, then as a filesystem path, then under src/test/resources/ + path.

If the file is not found, cannot be read, is malformed or has no data rows (for example a CSV with only a header, or an empty JSON array), the run is rejected before any request is sent. It fails with an IllegalArgumentException that names the scenario and the path and says the file was "not found or has no rows: it is missing, unreadable, empty or malformed (see the WARN)". This applies to every feeder of the scenario, on both engines and to every scenario of a simulation.

LoadTestFeeder.csv(..) and json(..) themselves do not throw for file problems: they log a WARN and return the feeder, and the check runs when the scenario is validated.

Behaviour change in 1.1.0

Earlier versions ran a scenario with a missing or empty CSV/JSON feeder anyway, and every ${var} stayed unresolved.

Example​

testdata/search.csv
query,clientId
laptop,client-1
keyboard,client-2
import io.testfly.loadtest.BaseLoadTest;
import io.testfly.loadtest.LoadTestFeeder;
import org.testng.annotations.Test;

public class SearchLoadTest extends BaseLoadTest {
@Test
public void searchWithData() {
loadScenario("Search").users(10)
.feed(LoadTestFeeder.csv("testdata/search.csv"))
.step("Search").get("/search")
.queryParam("q", "${query}")
.header("X-Client-ID", "${clientId}").and()
.run().assertP95Below(300);
}
}

CSV/JSON files may be on the classpath or the filesystem (see the lookup order above). Share synthetic credentials only; do not commit real passwords. See the multi-step example for using a feeder in a JSON login body.