Implementing Conditional CSV Data Retrieval in JMeter
System Requirements
- OS: Windows 10
- JMeter Version: 5.4.1
Scenario Overview
To conduct performance testing on a warehouse management system (WMS) cancel allocation endpoint, the workflow requires authentication followed by warehouse selection. The request payload structure is:
{
"targetOrders": ["ORD-9901", "ORD-9902"],
"facilityID": "WH-001"
}
The constraint is that the facilityID must match the authenticated user's assigned warehouse, and the targetOrders must belong specifically to that facility. Each order identifier should be processed only once during the test.
Test Logic Implementation
-
User Credentials Setup: Store acccount credentials and assigned warehouse codes in
user_vault.csv.user_vault.csv
account,secret,facilityID user_A,pass123,WH-001 user_B,pass456,WH-002 -
Segmented Order Data: Group orders into separate files based on the facility code to ensure data integrity during parallel execution.
WH-001_orders.csv
facility,orderList WH-001,"ORD-101,ORD-102" WH-001,"ORD-103,ORD-104" -
Conditional Logic Execution: Utilize the 'If Controller' to match the
facilityIDobtained during authentication with the corresponding order data file. This ensures that a user only selects from orders mapped to their authorized facility. -
Data Exclusivity and Thread Management: To prevent order reuse, configure the CSV Data Set element with
Recycle on EOF: FalseandStop thread on EOF: True. Because JMeter threads may continue to cycle brief before identifying the end-of-file condition, insert a JSR223 Sampler after the data read step to enforce an immediate stop when the record limit is reached.Use the following Groovy logic in the sampler to monitor thread termination:
def currentReadIndex = vars.get('readCounter') as long def maxRecords = vars.get('totalAvailableRecords') as long if (currentReadIndex > maxRecords) { ctx.getThread().stop() }
By encapsulating the CSV access within an If Controller and implementing explicit counter validation, you maintain strict synchronization between user identity, assigned facility, and the associated order dataset.