Search in sources :

Example 71 with JMeterTreeNode

use of org.apache.jmeter.gui.tree.JMeterTreeNode in project jmeter by apache.

the class ProxyControl method putSamplesIntoModel.

private void putSamplesIntoModel(ActionEvent e) {
    // return early, as JMeterTreeModel might not been initialized yet
    if (sampleQueue.isEmpty()) {
        return;
    }
    final JMeterTreeModel treeModel = getJmeterTreeModel();
    while (!sampleQueue.isEmpty()) {
        SamplerInfo info = sampleQueue.poll();
        try {
            log.info("Add sample {} into controller {}", info.sampler.getName(), info.prefix);
            try {
                long now = info.recordedAt;
                long deltaT = now - lastTime;
                boolean firstInBatch = prepareTree(treeModel, deltaT, info);
                if (lastTime == 0) {
                    // Decent value for timers
                    deltaT = 0;
                }
                lastTime = now;
                if (info.groupingMode == GROUPING_STORE_FIRST_ONLY) {
                    if (!firstInBatch) {
                        // Huh! don't store this one!
                        return;
                    }
                    // If we're not storing subsequent samplers, we'll need the
                    // first sampler to do all the work...:
                    info.sampler.setFollowRedirects(true);
                    info.sampler.setImageParser(true);
                }
                final JMeterTreeNode targetNode = getTargetNode(info.target, info.groupingMode);
                final JMeterTreeNode newNode = treeModel.addComponent(info.sampler, targetNode);
                if (firstInBatch) {
                    if (addAssertions) {
                        addAssertion(treeModel, newNode);
                    }
                    addTimers(treeModel, newNode, deltaT);
                }
                addTestElements(treeModel, info.testElements, newNode);
            } catch (IllegalUserActionException ex) {
                log.error("Error placing sampler", ex);
                JMeterUtils.reportErrorToUser(ex.getMessage());
            }
        } catch (Exception ex) {
            log.error("Error placing sampler", ex);
            JMeterUtils.reportErrorToUser(ex.getMessage());
        }
    }
}
Also used : JMeterTreeModel(org.apache.jmeter.gui.tree.JMeterTreeModel) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException) CertificateExpiredException(java.security.cert.CertificateExpiredException) GeneralSecurityException(java.security.GeneralSecurityException) MalformedCachePatternException(org.apache.oro.text.MalformedCachePatternException) CertificateNotYetValidException(java.security.cert.CertificateNotYetValidException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) InvalidVariableException(org.apache.jmeter.functions.InvalidVariableException) IOException(java.io.IOException) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException)

Example 72 with JMeterTreeNode

use of org.apache.jmeter.gui.tree.JMeterTreeNode in project jmeter by apache.

the class ProxyControl method notifySampleListeners.

/**
 * This will notify sample listeners directly within the Proxy of the
 * sampling that just occurred -- so that we have a means to record the
 * server's responses as we go.
 *
 * @param event sampling event to be delivered
 */
@SuppressWarnings("JdkObsolete")
private void notifySampleListeners(SampleEvent event) {
    JMeterTreeModel treeModel = getJmeterTreeModel();
    JMeterTreeNode myNode = treeModel.getNodeOf(this);
    if (myNode != null) {
        Enumeration<?> kids = myNode.children();
        while (kids.hasMoreElements()) {
            JMeterTreeNode subNode = (JMeterTreeNode) kids.nextElement();
            if (subNode.isEnabled()) {
                TestElement testElement = subNode.getTestElement();
                if (testElement instanceof SampleListener) {
                    ((SampleListener) testElement).sampleOccurred(event);
                }
            }
        }
    }
}
Also used : JMeterTreeModel(org.apache.jmeter.gui.tree.JMeterTreeModel) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) TestElement(org.apache.jmeter.testelement.TestElement) ConfigTestElement(org.apache.jmeter.config.ConfigTestElement) NonTestElement(org.apache.jmeter.testelement.NonTestElement) SampleListener(org.apache.jmeter.samplers.SampleListener)

Example 73 with JMeterTreeNode

use of org.apache.jmeter.gui.tree.JMeterTreeNode in project jmeter by apache.

the class ProxyControl method prepareTree.

private boolean prepareTree(final JMeterTreeModel treeModel, long deltaT, SamplerInfo info) {
    HTTPSamplerBase sampler = info.sampler;
    JMeterTreeNode myTarget = info.target;
    int cachedGroupingMode = info.groupingMode;
    boolean prefixChanged = false;
    if (oldPrefix == null || !oldPrefix.equals(info.prefix)) {
        oldPrefix = info.prefix;
        prefixChanged = true;
    }
    if (deltaT > sampleGap || prefixChanged) {
        String controllerName = StringUtils.defaultString(getPrefixHTTPSampleName(), sampler.getName());
        if (!myTarget.isLeaf() && cachedGroupingMode == GROUPING_ADD_SEPARATORS) {
            addDivider(treeModel, myTarget);
        }
        if (cachedGroupingMode == GROUPING_IN_SIMPLE_CONTROLLERS) {
            addSimpleController(treeModel, myTarget, controllerName);
        }
        if (cachedGroupingMode == GROUPING_IN_TRANSACTION_CONTROLLERS) {
            addTransactionController(treeModel, myTarget, controllerName);
        }
        // Remember this was first in its batch
        return true;
    }
    return false;
}
Also used : JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) HTTPSamplerBase(org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)

Example 74 with JMeterTreeNode

use of org.apache.jmeter.gui.tree.JMeterTreeNode in project jmeter by apache.

the class ApplyNamingConvention method applyNamingPolicyToCurrentNode.

/**
 * Apply the naming policy of currentNode children
 * @param guiPackage {@link GuiPackage}
 * @param currentNode Parent node of elements on which we apply naming policy
 */
@SuppressWarnings("JdkObsolete")
private void applyNamingPolicyToCurrentNode(GuiPackage guiPackage, JMeterTreeNode currentNode) {
    TreeNodeNamingPolicy namingPolicy = guiPackage.getNamingPolicy();
    guiPackage.updateCurrentNode();
    Enumeration<?> enumeration = currentNode.children();
    int index = 0;
    namingPolicy.resetState(currentNode);
    while (enumeration.hasMoreElements()) {
        JMeterTreeNode childNode = (JMeterTreeNode) enumeration.nextElement();
        namingPolicy.rename(currentNode, childNode, index);
        index++;
    }
}
Also used : JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode)

Example 75 with JMeterTreeNode

use of org.apache.jmeter.gui.tree.JMeterTreeNode in project jmeter by apache.

the class Clear method doAction.

@Override
public void doAction(ActionEvent e) {
    GuiPackage guiPackage = GuiPackage.getInstance();
    final String actionCommand = e.getActionCommand();
    if (actionCommand.equals(ActionNames.CLEAR)) {
        JMeterGUIComponent guiComp = guiPackage.getCurrentGui();
        if (guiComp instanceof Clearable) {
            ((Clearable) guiComp).clearData();
        }
    } else {
        guiPackage.getMainFrame().clearData();
        for (JMeterTreeNode node : guiPackage.getTreeModel().getNodesOfType(Clearable.class)) {
            JMeterGUIComponent guiComp = guiPackage.getGui(node.getTestElement());
            if (guiComp instanceof Clearable) {
                Clearable item = (Clearable) guiComp;
                try {
                    item.clearData();
                } catch (Exception ex) {
                    log.error("Can't clear: {} {}", node, guiComp, ex);
                }
            }
        }
    }
}
Also used : Clearable(org.apache.jmeter.samplers.Clearable) GuiPackage(org.apache.jmeter.gui.GuiPackage) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) JMeterGUIComponent(org.apache.jmeter.gui.JMeterGUIComponent)

Aggregations

JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)81 GuiPackage (org.apache.jmeter.gui.GuiPackage)26 JMeterTreeModel (org.apache.jmeter.gui.tree.JMeterTreeModel)21 TestElement (org.apache.jmeter.testelement.TestElement)18 IllegalUserActionException (org.apache.jmeter.exceptions.IllegalUserActionException)13 TreePath (javax.swing.tree.TreePath)10 HashTree (org.apache.jorphan.collections.HashTree)10 Controller (org.apache.jmeter.control.Controller)9 TestPlan (org.apache.jmeter.testelement.TestPlan)9 IOException (java.io.IOException)8 ActionEvent (java.awt.event.ActionEvent)7 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)7 ConfigTestElement (org.apache.jmeter.config.ConfigTestElement)7 ArrayList (java.util.ArrayList)6 JMeterTreeListener (org.apache.jmeter.gui.tree.JMeterTreeListener)6 NonTestElement (org.apache.jmeter.testelement.NonTestElement)6 TreeNode (javax.swing.tree.TreeNode)5 JMeterGUIComponent (org.apache.jmeter.gui.JMeterGUIComponent)5 ListedHashTree (org.apache.jorphan.collections.ListedHashTree)5 JTree (javax.swing.JTree)4