Reputation: 67
Problem statement: I have a variable that needs to be updated every 4 hours based on time in JMeter with out stopping the test, any logic suggestions
any alternative other than this: https://www.blazemeter.com/blog/how-to-change-jmeters-load-during-runtime
Upvotes: 0
Views: 587
Reputation: 67
Current solution: we have added a jsr223 sampler with the following code:
StartTime = 1637666165643;
int CsvNo;
def CurrentTime = System.currentTimeMillis();
TimeDiff = (CurrentTime - (StartTime as long));
log.info("Time Difference = "+TimeDiff);
CsvNo = TimeDiff/14400000 + 1;
log.info("Csv File No = "+CsvNo);
String MasterCSVFile1 = '<path to csv>test'+CsvNo;
log.info(''+MasterCSVFile1);
vars.put('Path_Final',''+MasterCSVFile1);
vars.put('myVariable','${__CSVRead(${Path_Final}.csv,0)}${__CSVRead(${Path_Final}.csv,next)}')
Upvotes: 0
Reputation: 168092
It's possible with a little bit of Groovy scripting, the following code placed in any of JSR223 Test Elements will update the myVariable
JMeter Variable name with the number of current Thread Group iteration each 4 hours:
def lastUpdateTime = displayName = vars.get('lastUpdateTime') ?: vars.get('START.MS')
def currentTime = System.currentTimeMillis()
if ((currentTime - (lastUpdateTime as long)) > 14400000) {
vars.put('myVariable', 'myValue_' + vars.getIteration())
vars.put('lastUpdateTime', currentTime as String)
}
Upvotes: 1