private void startThreadGroup(AbstractThreadGroup group, int groupCount, SearchByClass<?> searcher, List<?> testLevelElements, ListenerNotifier notifier) int numThreads = group.getNumThreads(); JMeterContextService.addTotalThreads(numThreads); boolean onErrorStopTest = group.getOnErrorStopTest(); boolean onErrorStopTestNow = group.getOnErrorStopTestNow(); boolean onErrorStopThread = group.getOnErrorStopThread(); boolean onErrorStartNextLoop = group.getOnErrorStartNextLoop(); String groupName = group.getName(); log.info("Starting {} threads for group {}.", numThreads, groupName); if (onErrorStopTest) { group.start(groupCount, notifier, threadGroupTree, this); } catch (JMeterStopTestException ex) { // NOSONAR Reported by log JMeterUtils.reportErrorToUser("Error occurred starting thread group :" + group.getName()+ ", error message:"+ex.getMessage() +", \r\nsee log file for more details", ex); return; // no point continuing
/** * For each current thread group, invoke: * <ul> * <li>{@link AbstractThreadGroup#stop()} - set stop flag</li> * </ul> */ private void stopAllThreadGroups() { // ConcurrentHashMap does not need synch. here for (AbstractThreadGroup threadGroup : groups) { threadGroup.stop(); } }
/** * For each thread group, invoke {@link AbstractThreadGroup#tellThreadsToStop()} */ private void tellThreadGroupsToStop() { // ConcurrentHashMap does not need protecting for (AbstractThreadGroup threadGroup : groups) { threadGroup.tellThreadsToStop(); } }
private void setSampleErrorBoxes(AbstractThreadGroup te) { if (te.getOnErrorStopTest()) { stopTestBox.setSelected(true); } else if (te.getOnErrorStopTestNow()) { stopTestNowBox.setSelected(true); } else if (te.getOnErrorStopThread()) { stopThreadBox.setSelected(true); } else if (te.getOnErrorStartNextLoop()) { startNextLoop.setSelected(true); } else { continueBox.setSelected(true); } }
protected void stopTest() { if (stopTries > 30) { throw new IllegalStateException("More than 30 retries - stopping with exception"); } if (lastStopTry == time) { return; } log.info("No further RPS schedule, asking threads to stop..."); lastStopTry = time; stopTries++; if (stopTries > 10) { log.info("Tries more than 10, stopping engine NOW!"); StandardJMeterEngine.stopEngineNow(); } else if (stopTries > 5) { log.info("Tries more than 5, shutting down engine!"); StandardJMeterEngine.stopEngine(); } else if (stopTries > 3) { AbstractThreadGroup threadGroup = JMeterContextService.getContext().getThreadGroup(); log.info("Tries more than 3, hard stopping threads of Thread Group : {}", threadGroup.getName()); threadGroup.tellThreadsToStop(); } else { AbstractThreadGroup threadGroup = JMeterContextService.getContext().getThreadGroup(); log.info("Stopping gracefuly threads of Thread Group : {}", threadGroup.getName()); threadGroup.stop(); } }
private void notifyListeners(List<SampleListener> listeners, SampleResult result) { SampleEvent event = new SampleEvent(result, threadGroup.getName(), threadVars); notifier.notifyListeners(event, listeners); }
delay = Math.round(JMeterContextService.getContext().getThreadGroup().getNumberOfThreads() * msPerRequest); break;
/** {@inheritDoc} */ @Override public void initialize() { Controller c = getSamplerController(); JMeterProperty property = c.getProperty(TestElement.NAME); property.setObjectValue(getName()); // Copy our name into that of the controller property.setRunningVersion(property.isRunningVersion());// otherwise name reverts c.initialize(); }
AbstractThreadGroup group = setupIter.next(); groupCount++; String groupName = group.getName(); log.info("Starting setUp ThreadGroup: {} : {} ", groupCount, groupName); startThreadGroup(group, groupCount, setupSearcher, testLevelElements, notifier); log.info("Waiting for setup thread group: {} to finish before starting next setup group", groupName); group.waitThreadsStopped(); 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(); 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();
@Override public void threadStarted() { if(getGroupSize() == 0) { int numThreadsInGroup = JMeterContextService.getContext().getThreadGroup().getNumThreads(); // Unique Barrier creation ensured by synchronized setup this.barrier.setup(numThreadsInGroup); } }
/** * {@inheritDoc} */ @Override public final boolean addTestElementOnce(TestElement child){ if (children.putIfAbsent(child, DUMMY) == null) { addTestElement(child); return true; } return false; }
/** * Executes a break of current loop, equivalent of "break" in algorithm. * As a consequence it ends the first loop it finds on the path to root * @param pathToRootTraverser {@link FindTestElementsUpToRootTraverser} */ private static void breakOnCurrentLoop(FindTestElementsUpToRootTraverser pathToRootTraverser) { List<Controller> controllersToReinit = pathToRootTraverser.getControllersToRoot(); for (Controller parentController : controllersToReinit) { if (parentController instanceof AbstractThreadGroup) { AbstractThreadGroup tg = (AbstractThreadGroup) parentController; tg.breakThreadLoop(); } else if (parentController instanceof IteratingController) { ((IteratingController) parentController).breakLoop(); break; } else { parentController.triggerEndOfLoop(); } } }
private void threadFinished(LoopIterationListener iterationListener) { ThreadListenerTraverser shut = new ThreadListenerTraverser(false); testTree.traverse(shut); // call ThreadListener.threadFinished() JMeterContextService.decrNumberOfThreads(); threadGroup.decrNumberOfThreads(); GuiPackage gp = GuiPackage.getInstance(); if (gp != null){// check there is a GUI gp.getMainFrame().updateCounts(); } if (iterationListener != null) { // probably not possible, but check anyway threadGroupLoopController.removeIterationListener(iterationListener); } }
@Override /** * Get current thread group using sampler's context */ public String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException { JMeterContext context; if (currentSampler != null) { context = currentSampler.getThreadContext(); } else { context = JMeterContextService.getContext(); } return context.getThreadGroup().getName(); }
private SampleResult doEndTransactionSampler( TransactionSampler transactionSampler, Sampler parent, SamplePackage transactionPack, JMeterContext threadContext) { // Get the transaction sample result SampleResult transactionResult = transactionSampler.getTransactionResult(); transactionResult.setThreadName(threadName); transactionResult.setGroupThreads(threadGroup.getNumberOfThreads()); transactionResult.setAllThreads(JMeterContextService.getNumberOfThreads()); // Check assertions for the transaction sample checkAssertions(transactionPack.getAssertions(), transactionResult, threadContext); // Notify listeners with the transaction sample result if (!(parent instanceof TransactionSampler)) { notifyListeners(transactionPack.getSampleListeners(), transactionResult); } compiler.done(transactionPack); return transactionResult; }
for (Object item : subTree.list()) { if (item instanceof AbstractThreadGroup && log.isDebugEnabled()) { log.debug("num threads = {}", ((AbstractThreadGroup) item).getNumThreads());
JMeterContextService.getContext().getThreadGroup().getName(), cntSent, rps);
threadCollector.set(JMeterContextService.getContext().getThreadGroup().getNumberOfThreads());
/** * Create additional SampleEvent in NON Parent Mode */ protected void notifyListeners() { // TODO could these be done earlier (or just once?) JMeterContext threadContext = getThreadContext(); JMeterVariables threadVars = threadContext.getVariables(); SamplePackage pack = (SamplePackage) threadVars.getObject(JMeterThread.PACKAGE_OBJECT); if (pack == null) { // If child of TransactionController is a ThroughputController and TPC does // not sample its children, then we will have this // TODO Should this be at warn level ? log.warn("Could not fetch SamplePackage"); } else { SampleEvent event = new SampleEvent(res, threadContext.getThreadGroup().getName(),threadVars, true); // We must set res to null now, before sending the event for the transaction, // so that we can ignore that event in our sampleOccured method res = null; lnf.notifyListeners(event, pack.getSampleListeners()); } }
int nbActiveThreadsInThreadGroup = threadGroup.getNumberOfThreads(); int nbTotalActiveThreads = JMeterContextService.getNumberOfThreads(); result.setGroupThreads(nbActiveThreadsInThreadGroup);