Hi,
The JMeter script is attach to this post.
I use a beanshell and test to shutdown at this end the http sampler to test is time to stop.
Like this :
1) Thread Group with Infinity Loop (no sheduler)
2) A User Defined Variables with a variable call DURATION_BEFORE_STOP value 300 s (300 s or 5mn before gradual exiting)
3) After the logout (the last http sampler) corresponding to the end of the user navigation, i add a benshell sampler bsh verify if it is time to stop
The java code to set a variable call STATUS_THREAD to the value NEED_TO_STOP is the duration of the test is greather than DURATION_BEFORE_STOP, if it's not the time to stop the thread the STATUS_THREAD is set to CONTINUE
Java code in the beanshell sampler
startTest = props.getProperty("TESTSTART.MS");
long lStartTest = Long.parseLong(startTest);
// log.info("lStartTest = " + lStartTest);
sDURATION_BEFORE_STOP = vars.get("DURATION_BEFORE_STOP");
//log.info("sDURATION_BEFORE_STOP=" + sDURATION_BEFORE_STOP);
long lDurationBeforeStop = Long.parseLong(sDURATION_BEFORE_STOP) * 1000;
// log.info("lDurationBeforeStop=" + lDurationBeforeStop);
// log.info("lStartTest + lDurationBeforeStop=" + (lStartTest + lDurationBeforeStop));
// log.info("System.currentTimeMillis()=" +System.currentTimeMillis());
if ((lStartTest + lDurationBeforeStop) < System.currentTimeMillis()) {
vars.put("STATUS_THREAD","NEED_TO_STOP");
log.info("STATUS_THREAD = NEED_TO_STOP");
}
else {
vars.put("STATUS_THREAD","CONTINUE");
log.info("STATUS_THREAD = CONTINUE");
}4) An if controler that checks if
STATUS_THREAD == NEED_TO_STOP
IF Controler condition
"${STATUS_THREAD}" == "NEED_TO_STOP"
5) Then "Test Action" set to Stop
Stop the current thread
Regards
Vincent D.