{
log.info("Running the test!");
running = true;
testList = new ArrayList();
SearchByClass testPlan = new SearchByClass(TestPlan.class);
getTestTree().traverse(testPlan);
Object[] plan = testPlan.getSearchResults().toArray();
if (plan.length == 0){
System.err.println("Could not find the TestPlan!");
log.error("Could not find the TestPlan!");
System.exit(1);
}
if (((TestPlan) plan[0]).isSerialized())
{
serialized = true;
}
compileTree();
/**
* Notification of test listeners needs to happen after function replacement, but before
* setting RunningVersion to true.
*/
testListeners = new SearchByClass(TestListener.class);
getTestTree().traverse(testListeners);
log.info("About to call test listeners");
Collection col = testListeners.getSearchResults();
col.addAll(testList);
testList=null;
notifyTestListenersOfStart();
getTestTree().traverse(new TurnElementsOn());
List testLevelElements =
new LinkedList(getTestTree().list(getTestTree().getArray()[0]));
removeThreadGroups(testLevelElements);
SearchByClass searcher = new SearchByClass(ThreadGroup.class);
setMode();
getTestTree().traverse(searcher);
TestCompiler.initialize();
//for each thread group, generate threads
// hand each thread the sampler controller
// and the listeners, and the timer
JMeterThread[] threads;
Iterator iter = searcher.getSearchResults().iterator();
/*
* Here's where the test really starts. Run a Full GC now: it's no
* harm at all (just delays test start by a tiny amount) and
* hitting one too early in the test can impair results for short
* tests.
*/
System.gc();
notifier = new ListenerNotifier();
schcdule_run = true;
JMeterContextService.getContext().setSamplingStarted(true);
int groupCount = 0;
while (iter.hasNext())
{
groupCount++;
ThreadGroup group = (ThreadGroup) iter.next();
int numThreads = group.getNumThreads();
boolean onErrorStopTest = group.getOnErrorStopTest();
boolean onErrorStopThread = group.getOnErrorStopThread();
String groupName = group.getName();
int rampUp = group.getRampUp();
float perThreadDelay = ((float) (rampUp * 1000) / (float) numThreads);
threads = new JMeterThread[numThreads];
log.info("Starting " + numThreads + " threads for group "+ groupName
+ ". Ramp up = "+ rampUp + ".");
if (onErrorStopTest) {
log.info("Test will stop on error");
} else if (onErrorStopThread) {
log.info("Thread will stop on error");
} else {
log.info("Continue on error");
}
for (int i = 0; running && i < threads.length; i++)
{
ListedHashTree threadGroupTree =
(ListedHashTree) searcher.getSubTree(group);
threadGroupTree.add(group, testLevelElements);
threads[i] =
new JMeterThread(
cloneTree(threadGroupTree),
this,