Search in sources :

Example 1 with Timer

use of org.apache.jmeter.timers.Timer in project jmeter by apache.

the class TestCompiler method saveTransactionControllerConfigs.

private void saveTransactionControllerConfigs(TransactionController tc) {
    List<ConfigTestElement> configs = new LinkedList<>();
    List<Controller> controllers = new LinkedList<>();
    List<SampleListener> listeners = new LinkedList<>();
    List<Timer> timers = new LinkedList<>();
    List<Assertion> assertions = new LinkedList<>();
    LinkedList<PostProcessor> posts = new LinkedList<>();
    LinkedList<PreProcessor> pres = new LinkedList<>();
    for (int i = stack.size(); i > 0; i--) {
        addDirectParentControllers(controllers, stack.get(i - 1));
        for (Object item : testTree.list(stack.subList(0, i))) {
            if (item instanceof SampleListener) {
                listeners.add((SampleListener) item);
            }
            if (item instanceof Assertion) {
                assertions.add((Assertion) item);
            }
        }
    }
    SamplePackage pack = new SamplePackage(configs, listeners, timers, assertions, posts, pres, controllers);
    pack.setSampler(new TransactionSampler(tc, tc.getName()));
    pack.setRunningVersion(true);
    transactionControllerConfigMap.put(tc, pack);
}
Also used : Assertion(org.apache.jmeter.assertions.Assertion) PreProcessor(org.apache.jmeter.processor.PreProcessor) Controller(org.apache.jmeter.control.Controller) TransactionController(org.apache.jmeter.control.TransactionController) SampleListener(org.apache.jmeter.samplers.SampleListener) LinkedList(java.util.LinkedList) Timer(org.apache.jmeter.timers.Timer) TransactionSampler(org.apache.jmeter.control.TransactionSampler) ConfigTestElement(org.apache.jmeter.config.ConfigTestElement) PostProcessor(org.apache.jmeter.processor.PostProcessor)

Example 2 with Timer

use of org.apache.jmeter.timers.Timer in project jmeter by apache.

the class JMeterThread method delay.

private void delay(List<Timer> timers) {
    long totalDelay = 0;
    for (Timer timer : timers) {
        TestBeanHelper.prepare((TestElement) timer);
        long delay = timer.delay();
        if (APPLY_TIMER_FACTOR && timer.isModifiable()) {
            if (log.isDebugEnabled()) {
                log.debug("Applying TIMER_FACTOR:{} on timer:{} for thread:{}", TIMER_FACTOR, ((TestElement) timer).getName(), getThreadName());
            }
            delay = Math.round(delay * TIMER_FACTOR);
        }
        totalDelay += delay;
    }
    if (totalDelay > 0) {
        try {
            if (scheduler) {
                // We reduce pause to ensure end of test is not delayed by a sleep ending after test scheduled end
                // See Bug 60049
                totalDelay = TIMER_SERVICE.adjustDelay(totalDelay, endTime);
            }
            TimeUnit.MILLISECONDS.sleep(totalDelay);
        } catch (InterruptedException e) {
            log.warn("The delay timer was interrupted - probably did not wait as long as intended.");
            Thread.currentThread().interrupt();
        }
    }
}
Also used : Timer(org.apache.jmeter.timers.Timer)

Example 3 with Timer

use of org.apache.jmeter.timers.Timer in project jmeter by apache.

the class ProxyControl method addTimers.

/**
     * Helper method to replicate any timers found within the Proxy Controller
     * into the provided sampler, while replacing any occurrences of string _T_
     * in the timer's configuration with the provided deltaT.
     * Called from AWT Event thread
     * @param model
     *            Test component tree model
     * @param node
     *            Sampler node in where we will add the timers
     * @param deltaT
     *            Time interval from the previous request
     */
private void addTimers(JMeterTreeModel model, JMeterTreeNode node, long deltaT) {
    TestPlan variables = new TestPlan();
    // $NON-NLS-1$
    variables.addParameter("T", Long.toString(deltaT));
    ValueReplacer replacer = new ValueReplacer(variables);
    JMeterTreeNode mySelf = model.getNodeOf(this);
    Enumeration<JMeterTreeNode> children = mySelf.children();
    while (children.hasMoreElements()) {
        JMeterTreeNode templateNode = children.nextElement();
        if (templateNode.isEnabled()) {
            TestElement template = templateNode.getTestElement();
            if (template instanceof Timer) {
                TestElement timer = (TestElement) template.clone();
                try {
                    timer.setComment("Recorded:" + Long.toString(deltaT) + "ms");
                    replacer.undoReverseReplace(timer);
                    model.addComponent(timer, node);
                } catch (InvalidVariableException | IllegalUserActionException e) {
                    // Not 100% sure, but I believe this can't happen, so
                    // I'll log and throw an error:
                    log.error("Program error", e);
                    throw new Error(e);
                }
            }
        }
    }
}
Also used : InvalidVariableException(org.apache.jmeter.functions.InvalidVariableException) Timer(org.apache.jmeter.timers.Timer) TestPlan(org.apache.jmeter.testelement.TestPlan) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException) ValueReplacer(org.apache.jmeter.engine.util.ValueReplacer) TestElement(org.apache.jmeter.testelement.TestElement) ConfigTestElement(org.apache.jmeter.config.ConfigTestElement)

Example 4 with Timer

use of org.apache.jmeter.timers.Timer in project jmeter by apache.

the class TreeClonerForValidation method addNodeToTree.

/**
     * @see org.apache.jmeter.engine.TreeCloner#addNodeToTree(java.lang.Object)
     */
@Override
protected Object addNodeToTree(Object node) {
    if ((VALIDATION_IGNORE_TIMERS && node instanceof Timer) || (VALIDATION_IGNORE_BACKENDS && node instanceof Backend)) {
        // don't add timer or backend
        return node;
    } else {
        Object clonedNode = super.addNodeToTree(node);
        if (clonedNode instanceof org.apache.jmeter.threads.ThreadGroup) {
            ThreadGroup tg = (ThreadGroup) clonedNode;
            tg.setNumThreads(VALIDATION_NUMBER_OF_THREADS);
            tg.setScheduler(false);
            tg.setProperty(ThreadGroup.DELAY, 0);
            if (((AbstractThreadGroup) clonedNode).getSamplerController() instanceof LoopController) {
                ((LoopController) ((AbstractThreadGroup) clonedNode).getSamplerController()).setLoops(VALIDATION_ITERATIONS);
            }
        }
        return clonedNode;
    }
}
Also used : Backend(org.apache.jmeter.visualizers.backend.Backend) Timer(org.apache.jmeter.timers.Timer) ThreadGroup(org.apache.jmeter.threads.ThreadGroup) AbstractThreadGroup(org.apache.jmeter.threads.AbstractThreadGroup) LoopController(org.apache.jmeter.control.LoopController)

Aggregations

Timer (org.apache.jmeter.timers.Timer)4 ConfigTestElement (org.apache.jmeter.config.ConfigTestElement)2 LinkedList (java.util.LinkedList)1 Assertion (org.apache.jmeter.assertions.Assertion)1 Controller (org.apache.jmeter.control.Controller)1 LoopController (org.apache.jmeter.control.LoopController)1 TransactionController (org.apache.jmeter.control.TransactionController)1 TransactionSampler (org.apache.jmeter.control.TransactionSampler)1 ValueReplacer (org.apache.jmeter.engine.util.ValueReplacer)1 IllegalUserActionException (org.apache.jmeter.exceptions.IllegalUserActionException)1 InvalidVariableException (org.apache.jmeter.functions.InvalidVariableException)1 JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)1 PostProcessor (org.apache.jmeter.processor.PostProcessor)1 PreProcessor (org.apache.jmeter.processor.PreProcessor)1 SampleListener (org.apache.jmeter.samplers.SampleListener)1 TestElement (org.apache.jmeter.testelement.TestElement)1 TestPlan (org.apache.jmeter.testelement.TestPlan)1 AbstractThreadGroup (org.apache.jmeter.threads.AbstractThreadGroup)1 ThreadGroup (org.apache.jmeter.threads.ThreadGroup)1 Backend (org.apache.jmeter.visualizers.backend.Backend)1