Search in sources :

Example 1 with JMeterStopTestException

use of org.apache.jorphan.util.JMeterStopTestException in project jmeter by apache.

the class ThreadGroup method scheduleThread.

/**
     * This will schedule the time for the JMeterThread.
     *
     * @param thread JMeterThread
     * @param now in milliseconds
     */
private void scheduleThread(JMeterThread thread, long now) {
    // if true the Scheduler is enabled
    if (getScheduler()) {
        // set the start time for the Thread
        if (getDelay() > 0) {
            // Duration is in seconds
            thread.setStartTime(getDelay() * 1000 + now);
        } else {
            long start = getStartTime();
            if (start < now) {
                // Force a sensible start time
                start = now;
            }
            thread.setStartTime(start);
        }
        // set the endtime for the Thread
        if (getDuration() > 0) {
            // Duration is in seconds
            thread.setEndTime(getDuration() * 1000 + (thread.getStartTime()));
        } else {
            if (getEndTime() <= now) {
                SimpleDateFormat sdf = new SimpleDateFormat(DATE_FIELD_FORMAT);
                throw new JMeterStopTestException("End Time (" + sdf.format(new Date(getEndTime())) + ") of Scheduler for Thread Group " + getName() + " is in the past, fix value of End Time field");
            }
            thread.setEndTime(getEndTime());
        }
        // Enables the scheduler
        thread.setScheduled(true);
    }
}
Also used : JMeterStopTestException(org.apache.jorphan.util.JMeterStopTestException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 2 with JMeterStopTestException

use of org.apache.jorphan.util.JMeterStopTestException in project jmeter by apache.

the class StandardJMeterEngine method startThreadGroup.

private void startThreadGroup(AbstractThreadGroup group, int groupCount, SearchByClass<?> searcher, List<?> testLevelElements, ListenerNotifier notifier) {
    try {
        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 " + numThreads + " threads for group " + groupName + ".");
        if (onErrorStopTest) {
            log.info("Test will stop on error");
        } else if (onErrorStopTestNow) {
            log.info("Test will stop abruptly on error");
        } else if (onErrorStopThread) {
            log.info("Thread will stop on error");
        } else if (onErrorStartNextLoop) {
            log.info("Thread will start next loop on error");
        } else {
            log.info("Thread will continue on error");
        }
        ListedHashTree threadGroupTree = (ListedHashTree) searcher.getSubTree(group);
        threadGroupTree.add(group, testLevelElements);
        groups.add(group);
        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);
        // no point continuing
        return;
    }
}
Also used : ListedHashTree(org.apache.jorphan.collections.ListedHashTree) JMeterStopTestException(org.apache.jorphan.util.JMeterStopTestException)

Example 3 with JMeterStopTestException

use of org.apache.jorphan.util.JMeterStopTestException in project jmeter by apache.

the class JMeterThread method run.

@Override
public void run() {
    // threadContext is not thread-safe, so keep within thread
    JMeterContext threadContext = JMeterContextService.getContext();
    LoopIterationListener iterationListener = null;
    try {
        iterationListener = initRun(threadContext);
        while (running) {
            Sampler sam = threadGroupLoopController.next();
            while (running && sam != null) {
                processSampler(sam, null, threadContext);
                threadContext.cleanAfterSample();
                // - or the last sample failed AND the onErrorStartNextLoop option is enabled
                if (threadContext.isRestartNextLoop() || (onErrorStartNextLoop && !TRUE.equals(threadContext.getVariables().get(LAST_SAMPLE_OK)))) {
                    if (log.isDebugEnabled() && onErrorStartNextLoop && !threadContext.isRestartNextLoop()) {
                        log.debug("StartNextLoop option is on, Last sample failed, starting next loop");
                    }
                    triggerEndOfLoopOnParentControllers(sam, threadContext);
                    sam = null;
                    threadContext.getVariables().put(LAST_SAMPLE_OK, TRUE);
                    threadContext.setRestartNextLoop(false);
                } else {
                    sam = threadGroupLoopController.next();
                }
            }
            if (threadGroupLoopController.isDone()) {
                running = false;
                log.info("Thread is done: {}", threadName);
            }
        }
    }// Might be found by controller.next()
     catch (JMeterStopTestException e) {
        // NOSONAR
        if (log.isInfoEnabled()) {
            log.info("Stopping Test: {}", e.toString());
        }
        shutdownTest();
    } catch (JMeterStopTestNowException e) {
        // NOSONAR
        if (log.isInfoEnabled()) {
            log.info("Stopping Test Now: {}", e.toString());
        }
        stopTestNow();
    } catch (JMeterStopThreadException e) {
        // NOSONAR
        if (log.isInfoEnabled()) {
            log.info("Stop Thread seen for thread {}, reason: {}", getThreadName(), e.toString());
        }
    } catch (Exception | JMeterError e) {
        log.error("Test failed!", e);
    } catch (ThreadDeath e) {
        // Must not ignore this one
        throw e;
    } finally {
        // prevent any further interrupts
        currentSampler = null;
        try {
            // make sure current interrupt is finished, prevent another starting yet
            interruptLock.lock();
            threadContext.clear();
            log.info("Thread finished: {}", threadName);
            threadFinished(iterationListener);
            // Tell the monitor we are done
            monitor.threadFinished(this);
            // Remove the ThreadLocal entry
            JMeterContextService.removeContext();
        } finally {
            // Allow any pending interrupt to complete (OK because currentSampler == null)
            interruptLock.unlock();
        }
    }
}
Also used : JMeterStopTestNowException(org.apache.jorphan.util.JMeterStopTestNowException) JMeterStopThreadException(org.apache.jorphan.util.JMeterStopThreadException) JMeterStopTestException(org.apache.jorphan.util.JMeterStopTestException) LoopIterationListener(org.apache.jmeter.engine.event.LoopIterationListener) JMeterError(org.apache.jorphan.util.JMeterError) TransactionSampler(org.apache.jmeter.control.TransactionSampler) Sampler(org.apache.jmeter.samplers.Sampler) JMeterStopTestException(org.apache.jorphan.util.JMeterStopTestException) JMeterStopThreadException(org.apache.jorphan.util.JMeterStopThreadException) JMeterStopTestNowException(org.apache.jorphan.util.JMeterStopTestNowException)

Example 4 with JMeterStopTestException

use of org.apache.jorphan.util.JMeterStopTestException in project jmeter by apache.

the class JMeterThread method processSampler.

/**
     * Process the current sampler, handling transaction samplers.
     *
     * @param current sampler
     * @param parent sampler
     * @param threadContext
     * @return SampleResult if a transaction was processed
     */
private SampleResult processSampler(Sampler current, Sampler parent, JMeterContext threadContext) {
    SampleResult transactionResult = null;
    try {
        // Check if we are running a transaction
        TransactionSampler transactionSampler = null;
        if (current instanceof TransactionSampler) {
            transactionSampler = (TransactionSampler) current;
        }
        // Find the package for the transaction
        SamplePackage transactionPack = null;
        if (transactionSampler != null) {
            transactionPack = compiler.configureTransactionSampler(transactionSampler);
            // Check if the transaction is done
            if (transactionSampler.isTransactionDone()) {
                transactionResult = doEndTransactionSampler(transactionSampler, parent, transactionPack, threadContext);
                // Transaction is done, we do not have a sampler to sample
                current = null;
            } else {
                Sampler prev = current;
                // It is the sub sampler of the transaction that will be sampled
                current = transactionSampler.getSubSampler();
                if (current instanceof TransactionSampler) {
                    // recursive call
                    SampleResult res = processSampler(current, prev, threadContext);
                    threadContext.setCurrentSampler(prev);
                    current = null;
                    if (res != null) {
                        transactionSampler.addSubSamplerResult(res);
                    }
                }
            }
        }
        // Check if we have a sampler to sample
        if (current != null) {
            executeSamplePackage(current, transactionSampler, transactionPack, threadContext);
        }
        if (scheduler) {
            // checks the scheduler to stop the iteration
            stopSchedulerIfNeeded();
        }
    } catch (JMeterStopTestException e) {
        // NOSONAR
        if (log.isInfoEnabled()) {
            log.info("Stopping Test: {}", e.toString());
        }
        if (current != null && current instanceof TransactionSampler) {
            doEndTransactionSampler((TransactionSampler) current, parent, compiler.configureTransactionSampler((TransactionSampler) current), threadContext);
        }
        shutdownTest();
    } catch (JMeterStopTestNowException e) {
        // NOSONAR
        if (log.isInfoEnabled()) {
            log.info("Stopping Test with interruption of current samplers: {}", e.toString());
        }
        if (current != null && current instanceof TransactionSampler) {
            doEndTransactionSampler((TransactionSampler) current, parent, compiler.configureTransactionSampler((TransactionSampler) current), threadContext);
        }
        stopTestNow();
    } catch (JMeterStopThreadException e) {
        // NOSONAR
        if (log.isInfoEnabled()) {
            log.info("Stopping Thread: {}", e.toString());
        }
        if (current != null && current instanceof TransactionSampler) {
            doEndTransactionSampler((TransactionSampler) current, parent, compiler.configureTransactionSampler((TransactionSampler) current), threadContext);
        }
        stopThread();
    } catch (Exception e) {
        if (current != null) {
            log.error("Error while processing sampler: '{}'.", current.getName(), e);
        } else {
            log.error("Error while processing sampler.", e);
        }
    }
    return transactionResult;
}
Also used : JMeterStopTestNowException(org.apache.jorphan.util.JMeterStopTestNowException) JMeterStopThreadException(org.apache.jorphan.util.JMeterStopThreadException) JMeterStopTestException(org.apache.jorphan.util.JMeterStopTestException) TransactionSampler(org.apache.jmeter.control.TransactionSampler) Sampler(org.apache.jmeter.samplers.Sampler) SampleResult(org.apache.jmeter.samplers.SampleResult) TransactionSampler(org.apache.jmeter.control.TransactionSampler) JMeterStopTestException(org.apache.jorphan.util.JMeterStopTestException) JMeterStopThreadException(org.apache.jorphan.util.JMeterStopThreadException) JMeterStopTestNowException(org.apache.jorphan.util.JMeterStopTestNowException)

Aggregations

JMeterStopTestException (org.apache.jorphan.util.JMeterStopTestException)4 TransactionSampler (org.apache.jmeter.control.TransactionSampler)2 Sampler (org.apache.jmeter.samplers.Sampler)2 JMeterStopTestNowException (org.apache.jorphan.util.JMeterStopTestNowException)2 JMeterStopThreadException (org.apache.jorphan.util.JMeterStopThreadException)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 LoopIterationListener (org.apache.jmeter.engine.event.LoopIterationListener)1 SampleResult (org.apache.jmeter.samplers.SampleResult)1 ListedHashTree (org.apache.jorphan.collections.ListedHashTree)1 JMeterError (org.apache.jorphan.util.JMeterError)1