Search in sources :

Example 6 with Controller

use of org.apache.jmeter.control.Controller in project jmeter by apache.

the class ChangeParent method doAction.

@Override
public void doAction(ActionEvent e) {
    String name = ((Component) e.getSource()).getName();
    GuiPackage guiPackage = GuiPackage.getInstance();
    JMeterTreeNode currentNode = guiPackage.getTreeListener().getCurrentNode();
    if (!(currentNode.getUserObject() instanceof Controller)) {
        Toolkit.getDefaultToolkit().beep();
        return;
    }
    try {
        guiPackage.updateCurrentNode();
        TestElement controller = guiPackage.createTestElement(name);
        changeParent(controller, guiPackage, currentNode);
    } catch (Exception err) {
        Toolkit.getDefaultToolkit().beep();
        log.error("Failed to change parent", err);
    }
}
Also used : GuiPackage(org.apache.jmeter.gui.GuiPackage) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) JMeterGUIComponent(org.apache.jmeter.gui.JMeterGUIComponent) Component(java.awt.Component) Controller(org.apache.jmeter.control.Controller) TestElement(org.apache.jmeter.testelement.TestElement)

Example 7 with Controller

use of org.apache.jmeter.control.Controller 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 8 with Controller

use of org.apache.jmeter.control.Controller in project jmeter by apache.

the class TestCompiler method subtractNode.

/** {@inheritDoc} */
@Override
public void subtractNode() {
    if (log.isDebugEnabled()) {
        log.debug("Subtracting node, stack size = {}", stack.size());
    }
    TestElement child = stack.getLast();
    trackIterationListeners(stack);
    if (child instanceof Sampler) {
        saveSamplerConfigs((Sampler) child);
    } else if (child instanceof TransactionController) {
        saveTransactionControllerConfigs((TransactionController) child);
    }
    stack.removeLast();
    if (!stack.isEmpty()) {
        TestElement parent = stack.getLast();
        boolean duplicate = false;
        // Bug 53750: this condition used to be in ObjectPair#addTestElements()
        if (parent instanceof Controller && (child instanceof Sampler || child instanceof Controller)) {
            if (parent instanceof TestCompilerHelper) {
                TestCompilerHelper te = (TestCompilerHelper) parent;
                duplicate = !te.addTestElementOnce(child);
            } else {
                // this is only possible for 3rd party controllers by default
                ObjectPair pair = new ObjectPair(child, parent);
                synchronized (PAIRING) {
                    // Called from multiple threads
                    if (!PAIRING.contains(pair)) {
                        parent.addTestElement(child);
                        PAIRING.add(pair);
                    } else {
                        duplicate = true;
                    }
                }
            }
        }
        if (duplicate) {
            if (log.isWarnEnabled()) {
                log.warn("Unexpected duplicate for {} and {}", parent.getClass(), child.getClass());
            }
        }
    }
}
Also used : TransactionSampler(org.apache.jmeter.control.TransactionSampler) Sampler(org.apache.jmeter.samplers.Sampler) TestElement(org.apache.jmeter.testelement.TestElement) ConfigTestElement(org.apache.jmeter.config.ConfigTestElement) TransactionController(org.apache.jmeter.control.TransactionController) Controller(org.apache.jmeter.control.Controller) TransactionController(org.apache.jmeter.control.TransactionController)

Example 9 with Controller

use of org.apache.jmeter.control.Controller in project jmeter by apache.

the class JMeterThread method triggerEndOfLoopOnParentControllers.

/**
     * Trigger end of loop on parent controllers up to Thread Group
     * @param sam Sampler Base sampler
     * @param threadContext 
     */
private void triggerEndOfLoopOnParentControllers(Sampler sam, JMeterContext threadContext) {
    TransactionSampler transactionSampler = null;
    if (sam instanceof TransactionSampler) {
        transactionSampler = (TransactionSampler) sam;
    }
    Sampler realSampler = findRealSampler(sam);
    if (realSampler == null) {
        throw new IllegalStateException("Got null subSampler calling findRealSampler for:" + (sam != null ? sam.getName() : "null") + ", sam:" + sam);
    }
    // Find parent controllers of current sampler
    FindTestElementsUpToRootTraverser pathToRootTraverser = new FindTestElementsUpToRootTraverser(realSampler);
    testTree.traverse(pathToRootTraverser);
    // Trigger end of loop condition on all parent controllers of current sampler
    List<Controller> controllersToReinit = pathToRootTraverser.getControllersToRoot();
    for (Controller parentController : controllersToReinit) {
        if (parentController instanceof AbstractThreadGroup) {
            AbstractThreadGroup tg = (AbstractThreadGroup) parentController;
            tg.startNextLoop();
        } else {
            parentController.triggerEndOfLoop();
        }
    }
    // then we still need to report the Transaction in error (and create the sample result)
    if (transactionSampler != null) {
        SamplePackage transactionPack = compiler.configureTransactionSampler(transactionSampler);
        doEndTransactionSampler(transactionSampler, null, transactionPack, threadContext);
    }
}
Also used : TransactionSampler(org.apache.jmeter.control.TransactionSampler) Sampler(org.apache.jmeter.samplers.Sampler) Controller(org.apache.jmeter.control.Controller) TransactionSampler(org.apache.jmeter.control.TransactionSampler)

Example 10 with Controller

use of org.apache.jmeter.control.Controller in project jmeter by apache.

the class AbstractThreadGroup method initialize.

/** {@inheritDoc} */
@Override
public void initialize() {
    Controller c = getSamplerController();
    JMeterProperty property = c.getProperty(TestElement.NAME);
    // Copy our name into that of the controller
    property.setObjectValue(getName());
    // otherwise name reverts
    property.setRunningVersion(property.isRunningVersion());
    c.initialize();
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) LoopController(org.apache.jmeter.control.LoopController) Controller(org.apache.jmeter.control.Controller)

Aggregations

Controller (org.apache.jmeter.control.Controller)13 JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)7 TestElement (org.apache.jmeter.testelement.TestElement)6 ConfigTestElement (org.apache.jmeter.config.ConfigTestElement)3 TransactionController (org.apache.jmeter.control.TransactionController)3 TransactionSampler (org.apache.jmeter.control.TransactionSampler)3 GuiPackage (org.apache.jmeter.gui.GuiPackage)3 Sampler (org.apache.jmeter.samplers.Sampler)3 LinkedList (java.util.LinkedList)2 IllegalUserActionException (org.apache.jmeter.exceptions.IllegalUserActionException)2 JMeterGUIComponent (org.apache.jmeter.gui.JMeterGUIComponent)2 TestPlan (org.apache.jmeter.testelement.TestPlan)2 Component (java.awt.Component)1 ArrayList (java.util.ArrayList)1 JTree (javax.swing.JTree)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 TreeNode (javax.swing.tree.TreeNode)1 TreePath (javax.swing.tree.TreePath)1 Assertion (org.apache.jmeter.assertions.Assertion)1 LoopController (org.apache.jmeter.control.LoopController)1