A classe CountAllIterations conta o número de vezes em que é executado por todos os usuários virtuais que estão em execução em uma determinada JVM e retorna essa contagem como uma cadeia.
package customcode;
import com.ibm.rational.test.lt.kernel.services.ITestExecutionServices;
/**
* The CountAllIterations class counts the number of times it is executed
* by all virtual users running in a particular JVM and returns this count
* as a string. If all virtual users on an agent are running in the same
* JVM (as would typically be the case), this class will count the number of
* times it is run on the agent.
*/
/**
* @author IBM Custom Code Samples
*/
public class CountAllIterations implements
com.ibm.rational.test.lt.kernel.custom.ICustomCode2 {
private static int numJVMLoops = 0;
/**
* Instances of this will be created using the no-arg constructor.
*/
public CountAllIterations() {
}
public String exec(ITestExecutionServices tes, String[] args) {
return Integer.toString(++numJVMLoops);
}
}
A classe CountUserIterations conta quantas vezes o código é executado por um usuário virtual individual.
package customcode;
import com.ibm.rational.test.lt.kernel.services.ITestExecutionServices;
import com.ibm.rational.test.lt.kernel.IDataArea;
/**
* The CountUserIterations class counts the number of times it is executed
* by an individual virtual user and returns this count as a string.
*/
/**
* @author IBM Custom Code Samples
*/
public class CountUserIterations implements
com.ibm.rational.test.lt.kernel.custom.ICustomCode2 {
/**
* Instances of this will be created using the no-arg constructor.
*/
public CountUserIterations() {
}
public String exec(ITestExecutionServices tes, String[] args) {
IDataArea userDataArea = tes.findDataArea(IDataArea.VIRTUALUSER);
final String KEY = "NumberIterationsPerUser";
Number numPerUser = (Number)userDataArea.get(KEY);
if (numPerUser == null) {
numPerUser = new Number();
userDataArea.put(KEY, numPerUser);
}
numPerUser.value++;
return Integer.toString(numPerUser.value);
}
private class Number {
public int value = 0;
}
}