use of org.apache.jmeter.threads.ListenerNotifier in project jmeter-plugins by undera.
the class ConcurrencyThreadGroupTest method testSetDoneThreadsAfterHold.
// WAP-9261
@Test(timeout = 25000)
public void testSetDoneThreadsAfterHold() throws Exception {
JMeterContextService.getContext().setVariables(new JMeterVariables());
TestSampleListener listener = new TestSampleListener();
DebugSampler sampler = new DebugSampler();
sampler.setName("Sampler");
ConstantTimer timer = new ConstantTimer();
timer.setDelay("2000");
timer.setName("timer");
LoopController loopController = new LoopController();
loopController.setContinueForever(true);
loopController.setLoops(-1);
loopController.setName("loop c");
ConcurrencyThreadGroupExt ctg = new ConcurrencyThreadGroupExt();
ctg.setName("CTG");
ctg.setRampUp("5");
ctg.setTargetLevel("3");
ctg.setSteps("1");
// TODO: increase this value for debugging
ctg.setHold("10");
ctg.setIterationsLimit("");
ctg.setUnit("S");
ListedHashTree loopTree = new ListedHashTree();
loopTree.add(loopController, timer);
loopTree.add(loopController, sampler);
loopTree.add(loopController, listener);
ListedHashTree hashTree = new ListedHashTree();
hashTree.add(ctg, loopTree);
TestCompiler compiler = new TestCompiler(hashTree);
// this hashTree can be save to *jmx
hashTree.traverse(compiler);
ListenerNotifier notifier = new ListenerNotifier();
long startTime = System.currentTimeMillis();
ctg.start(1, notifier, hashTree, new StandardJMeterEngine());
Thread threadStarter = ctg.getThreadStarter();
threadStarter.join();
long endTime = System.currentTimeMillis();
// wait when all thread stopped
Thread.currentThread().sleep(5000);
assertTrue((endTime - startTime) < 20000);
// ALL threads must be stopped
assertEquals(0, ctg.getNumberOfThreads());
}
use of org.apache.jmeter.threads.ListenerNotifier in project jmeter by apache.
the class StandardJMeterEngine method run.
@Override
public void run() {
log.info("Running the test!");
running = true;
/*
* Ensure that the sample variables are correctly initialised for each run.
*/
SampleEvent.initSampleVariables();
JMeterContextService.startTest();
try {
PreCompiler compiler = new PreCompiler();
test.traverse(compiler);
} catch (RuntimeException e) {
log.error("Error occurred compiling the tree:", e);
JMeterUtils.reportErrorToUser("Error occurred compiling the tree: - see log file", e);
// no point continuing
return;
}
/**
* Notification of test listeners needs to happen after function
* replacement, but before setting RunningVersion to true.
*/
// TL - S&E
SearchByClass<TestStateListener> testListeners = new SearchByClass<>(TestStateListener.class);
test.traverse(testListeners);
// Merge in any additional test listeners
// currently only used by the function parser
testListeners.getSearchResults().addAll(testList);
// no longer needed
testList.clear();
test.traverse(new TurnElementsOn());
notifyTestListenersOfStart(testListeners);
List<?> testLevelElements = new ArrayList<>(test.list(test.getArray()[0]));
removeThreadGroups(testLevelElements);
SearchByClass<SetupThreadGroup> setupSearcher = new SearchByClass<>(SetupThreadGroup.class);
SearchByClass<AbstractThreadGroup> searcher = new SearchByClass<>(AbstractThreadGroup.class);
SearchByClass<PostThreadGroup> postSearcher = new SearchByClass<>(PostThreadGroup.class);
test.traverse(setupSearcher);
test.traverse(searcher);
test.traverse(postSearcher);
TestCompiler.initialize();
// for each thread group, generate threads
// hand each thread the sampler controller
// and the listeners, and the timer
Iterator<SetupThreadGroup> setupIter = setupSearcher.getSearchResults().iterator();
Iterator<AbstractThreadGroup> iter = searcher.getSearchResults().iterator();
Iterator<PostThreadGroup> postIter = postSearcher.getSearchResults().iterator();
ListenerNotifier notifier = new ListenerNotifier();
int groupCount = 0;
JMeterContextService.clearTotalThreads();
if (setupIter.hasNext()) {
log.info("Starting setUp thread groups");
while (running && setupIter.hasNext()) {
// for each setup thread group
AbstractThreadGroup group = setupIter.next();
groupCount++;
String groupName = group.getName();
log.info("Starting setUp ThreadGroup: {} : {} ", groupCount, groupName);
startThreadGroup(group, groupCount, setupSearcher, testLevelElements, notifier);
if (serialized && setupIter.hasNext()) {
log.info("Waiting for setup thread group: {} to finish before starting next setup group", groupName);
group.waitThreadsStopped();
}
}
log.info("Waiting for all setup thread groups to exit");
// wait for all Setup Threads To Exit
waitThreadsStopped();
log.info("All Setup Threads have ended");
groupCount = 0;
JMeterContextService.clearTotalThreads();
}
// The groups have all completed now
groups.clear();
/*
* 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.
*/
JMeterUtils.helpGC();
JMeterContextService.getContext().setSamplingStarted(true);
// still running at this point, i.e. setUp was not cancelled
boolean mainGroups = running;
while (running && iter.hasNext()) {
// for each thread group
AbstractThreadGroup group = iter.next();
// future Thread Group objects wouldn't execute.
if (group instanceof SetupThreadGroup || group instanceof PostThreadGroup) {
continue;
}
groupCount++;
String groupName = group.getName();
log.info("Starting ThreadGroup: {} : {}", groupCount, groupName);
startThreadGroup(group, groupCount, searcher, testLevelElements, notifier);
if (serialized && iter.hasNext()) {
log.info("Waiting for thread group: {} to finish before starting next group", groupName);
group.waitThreadsStopped();
}
}
// end of thread groups
if (groupCount == 0) {
// No TGs found
log.info("No enabled thread groups found");
} else {
if (running) {
log.info("All thread groups have been started");
} else {
log.info("Test stopped - no more thread groups will be started");
}
}
// wait for all Test Threads To Exit
waitThreadsStopped();
// The groups have all completed now
groups.clear();
if (postIter.hasNext()) {
groupCount = 0;
JMeterContextService.clearTotalThreads();
log.info("Starting tearDown thread groups");
if (mainGroups && !running) {
// i.e. shutdown/stopped during main thread groups
// re-enable for tearDown if necessary
running = tearDownOnShutdown;
}
while (running && postIter.hasNext()) {
// for each setup thread group
AbstractThreadGroup group = postIter.next();
groupCount++;
String groupName = group.getName();
log.info("Starting tearDown ThreadGroup: {} : {}", groupCount, groupName);
startThreadGroup(group, groupCount, postSearcher, testLevelElements, notifier);
if (serialized && postIter.hasNext()) {
log.info("Waiting for post thread group: {} to finish before starting next post group", groupName);
group.waitThreadsStopped();
}
}
// wait for Post threads to stop
waitThreadsStopped();
}
notifyTestListenersOfEnd(testListeners);
JMeterContextService.endTest();
if (JMeter.isNonGUI() && SYSTEM_EXIT_FORCED) {
log.info("Forced JVM shutdown requested at end of test");
// NOSONAR Intentional
System.exit(0);
}
}
use of org.apache.jmeter.threads.ListenerNotifier in project jmeter by apache.
the class TestTransactionController method testIssue57958.
@Test
public void testIssue57958() throws Exception {
JMeterContextService.getContext().setVariables(new JMeterVariables());
TestSampleListener listener = new TestSampleListener();
TransactionController transactionController = new TransactionController();
transactionController.setGenerateParentSample(true);
ResponseAssertion assertion = new ResponseAssertion();
assertion.setTestFieldResponseCode();
assertion.setToEqualsType();
assertion.addTestString("201");
DebugSampler debugSampler = new DebugSampler();
debugSampler.addTestElement(assertion);
LoopController loop = new LoopController();
loop.setLoops(1);
loop.setContinueForever(false);
ListedHashTree hashTree = new ListedHashTree();
hashTree.add(loop);
hashTree.add(loop, transactionController);
hashTree.add(transactionController, debugSampler);
hashTree.add(transactionController, listener);
hashTree.add(debugSampler, assertion);
TestCompiler compiler = new TestCompiler(hashTree);
hashTree.traverse(compiler);
ThreadGroup threadGroup = new ThreadGroup();
threadGroup.setNumThreads(1);
ListenerNotifier notifier = new ListenerNotifier();
JMeterThread thread = new JMeterThread(hashTree, threadGroup, notifier);
thread.setThreadGroup(threadGroup);
thread.setOnErrorStopThread(true);
thread.run();
assertEquals("Must one transaction samples with parent debug sample", 1, listener.events.size());
assertEquals("Number of samples in transaction : 1, number of failing samples : 1", listener.events.get(0).getResult().getResponseMessage());
}
use of org.apache.jmeter.threads.ListenerNotifier in project jmeter-plugins by undera.
the class ConcurrencyThreadGroupTest method testStartNextLoop.
@Test
public void testStartNextLoop() throws Exception {
JMeterContextService.getContext().setVariables(new JMeterVariables());
TestSampleListener listener = new TestSampleListener();
DebugSampler beforeSampler = new DebugSamplerExt();
beforeSampler.setName("Before Test Action sampler");
TestAction testAction = new TestAction();
testAction.setAction(TestAction.RESTART_NEXT_LOOP);
DebugSampler afterSampler = new DebugSamplerExt();
afterSampler.setName("After Test Action sampler");
ConcurrencyThreadGroup ctg = new ConcurrencyThreadGroup();
ctg.setProperty(new StringProperty(AbstractThreadGroup.ON_SAMPLE_ERROR, AbstractThreadGroup.ON_SAMPLE_ERROR_CONTINUE));
ctg.setRampUp("0");
ctg.setTargetLevel("1");
ctg.setSteps("0");
// TODO: increase this value for debugging
ctg.setHold("5");
ctg.setIterationsLimit("10");
ctg.setUnit("S");
ListedHashTree hashTree = new ListedHashTree();
hashTree.add(ctg);
hashTree.add(ctg, beforeSampler);
hashTree.add(ctg, testAction);
hashTree.add(ctg, afterSampler);
hashTree.add(ctg, listener);
TestCompiler compiler = new TestCompiler(hashTree);
hashTree.traverse(compiler);
ListenerNotifier notifier = new ListenerNotifier();
ctg.start(1, notifier, hashTree, new StandardJMeterEngine());
ctg.waitThreadsStopped();
}
use of org.apache.jmeter.threads.ListenerNotifier in project jmeter-plugins by undera.
the class AbstractSimpleThreadGroupTest method testStart.
/**
* Test of start method, of class AbstractSimpleThreadGroup.
*/
@Test
public void testStart() {
System.out.println("start");
int groupCount = 0;
ListenerNotifier notifier = null;
ListedHashTree threadGroupTree = null;
StandardJMeterEngine engine = null;
AbstractSimpleThreadGroup instance = new AbstractSimpleThreadGroupImpl();
instance.start(groupCount, notifier, threadGroupTree, engine);
}
Aggregations