Search in sources :

Example 21 with HashTree

use of org.apache.jorphan.collections.HashTree in project jmeter by apache.

the class RemoteStart method getTestTree.

private HashTree getTestTree() {
    GuiPackage gui = GuiPackage.getInstance();
    HashTree testTree = gui.getTreeModel().getTestPlan();
    JMeter.convertSubTree(testTree);
    testTree.add(testTree.getArray()[0], gui.getMainFrame());
    // Used for remote notification of threads start/stop,see BUG 54152
    testTree.add(testTree.getArray()[0], new RemoteThreadsListenerTestElement());
    return testTree;
}
Also used : HashTree(org.apache.jorphan.collections.HashTree) GuiPackage(org.apache.jmeter.gui.GuiPackage) RemoteThreadsListenerTestElement(org.apache.jmeter.threads.RemoteThreadsListenerTestElement)

Example 22 with HashTree

use of org.apache.jorphan.collections.HashTree in project jmeter by apache.

the class DistributedRunnerTest method testSuccess.

@Test
public void testSuccess() throws Exception {
    createJmeterEnv();
    JMeterUtils.setProperty(DistributedRunner.RETRIES_NUMBER, "1");
    JMeterUtils.setProperty(DistributedRunner.CONTINUE_ON_FAIL, "false");
    DistributedRunnerEmul obj = new DistributedRunnerEmul();
    obj.engines.add(new EmulatorEngine());
    obj.engines.add(new EmulatorEngine());
    List<String> hosts = Arrays.asList("test1", "test2");
    obj.init(hosts, new HashTree());
    obj.start();
    obj.shutdown(hosts);
    obj.stop(hosts);
    obj.exit(hosts);
}
Also used : HashTree(org.apache.jorphan.collections.HashTree) Test(org.junit.Test)

Example 23 with HashTree

use of org.apache.jorphan.collections.HashTree in project jmeter by apache.

the class ClientJMeterEngine method runTest.

@Override
public void runTest() throws JMeterEngineException {
    log.info("running clientengine run method");
    // See https://bz.apache.org/bugzilla/show_bug.cgi?id=55510
    JMeterContextService.clearTotalThreads();
    HashTree testTree = test;
    synchronized (testTree) {
        // limit the changes to client only test elements
        testTree.traverse(new PreCompiler(true));
        testTree.traverse(new TurnElementsOn());
        testTree.traverse(new ConvertListeners());
    }
    String methodName = "unknown";
    try {
        JMeterContextService.startTest();
        /*
             * Add fix for Deadlocks, see:
             * 
             * See https://bz.apache.org/bugzilla/show_bug.cgi?id=48350
            */
        File baseDirRelative = FileServer.getFileServer().getBaseDirRelative();
        String scriptName = FileServer.getFileServer().getScriptName();
        synchronized (LOCK) {
            // NOSONAR Used for tracing
            methodName = "rconfigure()";
            remote.rconfigure(testTree, host, baseDirRelative, scriptName);
        }
        // $NON-NLS-1$
        log.info("sent test to " + host + " basedir='" + baseDirRelative + "'");
        if (savep == null) {
            savep = new Properties();
        }
        log.info("Sending properties " + savep);
        try {
            // NOSONAR Used for tracing
            methodName = "rsetProperties()";
            remote.rsetProperties(savep);
        } catch (RemoteException e) {
            log.warn("Could not set properties: " + e.toString());
        }
        methodName = "rrunTest()";
        remote.rrunTest();
        log.info("sent run command to " + host);
    } catch (IllegalStateException ex) {
        // $NON-NLS-1$ $NON-NLS-2$
        log.error("Error in " + methodName + " method " + ex);
        tidyRMI(log);
        // Don't wrap this error - display it as is
        throw ex;
    } catch (Exception ex) {
        // $NON-NLS-1$ $NON-NLS-2$
        log.error("Error in " + methodName + " method " + ex);
        tidyRMI(log);
        // $NON-NLS-1$ $NON-NLS-2$
        throw new JMeterEngineException("Error in " + methodName + " method " + ex, ex);
    }
}
Also used : HashTree(org.apache.jorphan.collections.HashTree) Properties(java.util.Properties) RemoteException(java.rmi.RemoteException) File(java.io.File) MalformedURLException(java.net.MalformedURLException) RemoteException(java.rmi.RemoteException) NotBoundException(java.rmi.NotBoundException)

Example 24 with HashTree

use of org.apache.jorphan.collections.HashTree in project jmeter by apache.

the class JMeter method convertSubTree.

/**
     * Remove disabled elements
     * Replace the ReplaceableController with the target subtree
     *
     * @param tree The {@link HashTree} to convert
     */
public static void convertSubTree(HashTree tree) {
    LinkedList<Object> copyList = new LinkedList<>(tree.list());
    for (Object o : copyList) {
        if (o instanceof TestElement) {
            TestElement item = (TestElement) o;
            if (item.isEnabled()) {
                if (item instanceof ReplaceableController) {
                    ReplaceableController rc = ensureReplaceableControllerIsLoaded(item);
                    HashTree subTree = tree.getTree(item);
                    if (subTree != null) {
                        HashTree replacementTree = rc.getReplacementSubTree();
                        if (replacementTree != null) {
                            convertSubTree(replacementTree);
                            tree.replaceKey(item, rc);
                            tree.set(rc, replacementTree);
                        }
                    }
                } else {
                    // not Replaceable Controller
                    convertSubTree(tree.getTree(item));
                }
            } else {
                // Not enabled
                tree.remove(item);
            }
        } else {
            // Not a TestElement
            JMeterTreeNode item = (JMeterTreeNode) o;
            if (item.isEnabled()) {
                // @see StandardJMeterEngine.run()
                if (item.getUserObject() instanceof ReplaceableController) {
                    TestElement controllerAsItem = item.getTestElement();
                    ReplaceableController rc = ensureReplaceableControllerIsLoaded(controllerAsItem);
                    HashTree subTree = tree.getTree(item);
                    if (subTree != null) {
                        HashTree replacementTree = rc.getReplacementSubTree();
                        if (replacementTree != null) {
                            convertSubTree(replacementTree);
                            tree.replaceKey(item, rc);
                            tree.set(rc, replacementTree);
                        }
                    }
                } else {
                    // Not a ReplaceableController
                    convertSubTree(tree.getTree(item));
                    TestElement testElement = item.getTestElement();
                    tree.replaceKey(item, testElement);
                }
            } else {
                // Not enabled
                tree.remove(item);
            }
        }
    }
}
Also used : HashTree(org.apache.jorphan.collections.HashTree) ReplaceableController(org.apache.jmeter.control.ReplaceableController) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) TestElement(org.apache.jmeter.testelement.TestElement) RemoteThreadsListenerTestElement(org.apache.jmeter.threads.RemoteThreadsListenerTestElement) LinkedList(java.util.LinkedList)

Aggregations

HashTree (org.apache.jorphan.collections.HashTree)24 File (java.io.File)7 JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)7 IOException (java.io.IOException)5 IllegalUserActionException (org.apache.jmeter.exceptions.IllegalUserActionException)5 GuiPackage (org.apache.jmeter.gui.GuiPackage)5 ListedHashTree (org.apache.jorphan.collections.ListedHashTree)5 ActionEvent (java.awt.event.ActionEvent)4 ConversionException (com.thoughtworks.xstream.converters.ConversionException)3 FileNotFoundException (java.io.FileNotFoundException)3 MalformedURLException (java.net.MalformedURLException)3 TestElement (org.apache.jmeter.testelement.TestElement)3 Test (org.junit.Test)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileOutputStream (java.io.FileOutputStream)2 SocketException (java.net.SocketException)2 LinkedList (java.util.LinkedList)2 JTree (javax.swing.JTree)2 TreePath (javax.swing.tree.TreePath)2 ReplaceableController (org.apache.jmeter.control.ReplaceableController)2