Search in sources :

Example 1 with JMeterTreeModel

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

the class JMeter method runNonGui.

// run test in batch mode
private void runNonGui(String testFile, String logFile, boolean remoteStart, String remoteHostsString, boolean generateReportDashboard) {
    try {
        File f = new File(testFile);
        if (!f.exists() || !f.isFile()) {
            println("Could not open " + testFile);
            return;
        }
        FileServer.getFileServer().setBaseForScript(f);
        HashTree tree = SaveService.loadTree(f);
        // Deliberate use of deprecated ctor
        @SuppressWarnings("deprecation") JMeterTreeModel // Create non-GUI version to avoid headless problems
        treeModel = new JMeterTreeModel(new Object());
        JMeterTreeNode root = (JMeterTreeNode) treeModel.getRoot();
        treeModel.addSubTree(tree, root);
        // Hack to resolve ModuleControllers in non GUI mode
        SearchByClass<ReplaceableController> replaceableControllers = new SearchByClass<>(ReplaceableController.class);
        tree.traverse(replaceableControllers);
        Collection<ReplaceableController> replaceableControllersRes = replaceableControllers.getSearchResults();
        for (ReplaceableController replaceableController : replaceableControllersRes) {
            replaceableController.resolveReplacementSubTree(root);
        }
        // Remove the disabled items
        // For GUI runs this is done in Start.java
        convertSubTree(tree);
        if (deleteResultFile) {
            SearchByClass<ResultCollector> resultListeners = new SearchByClass<>(ResultCollector.class);
            tree.traverse(resultListeners);
            Iterator<ResultCollector> irc = resultListeners.getSearchResults().iterator();
            while (irc.hasNext()) {
                ResultCollector rc = irc.next();
                File resultFile = new File(rc.getFilename());
                if (resultFile.exists()) {
                    resultFile.delete();
                }
            }
        }
        Summariser summer = null;
        //$NON-NLS-1$
        String summariserName = JMeterUtils.getPropDefault("summariser.name", "");
        if (summariserName.length() > 0) {
            log.info("Creating summariser <{}>", summariserName);
            println("Creating summariser <" + summariserName + ">");
            summer = new Summariser(summariserName);
        }
        ReportGenerator reportGenerator = null;
        if (logFile != null) {
            ResultCollector logger = new ResultCollector(summer);
            logger.setFilename(logFile);
            tree.add(tree.getArray()[0], logger);
            if (generateReportDashboard) {
                reportGenerator = new ReportGenerator(logFile, logger);
            }
        } else {
            // only add Summariser if it can not be shared with the ResultCollector
            if (summer != null) {
                tree.add(tree.getArray()[0], summer);
            }
        }
        // Used for remote notification of threads start/stop,see BUG 54152
        // Summariser uses this feature to compute correctly number of threads 
        // when NON GUI mode is used
        tree.add(tree.getArray()[0], new RemoteThreadsListenerTestElement());
        List<JMeterEngine> engines = new LinkedList<>();
        tree.add(tree.getArray()[0], new ListenToTest(remoteStart && remoteStop ? engines : null, reportGenerator));
        println("Created the tree successfully using " + testFile);
        if (!remoteStart) {
            JMeterEngine engine = new StandardJMeterEngine();
            engine.configure(tree);
            long now = System.currentTimeMillis();
            println("Starting the test @ " + new Date(now) + " (" + now + ")");
            engine.runTest();
            engines.add(engine);
        } else {
            //$NON-NLS-1$
            java.util.StringTokenizer st = new java.util.StringTokenizer(remoteHostsString, ",");
            List<String> hosts = new LinkedList<>();
            while (st.hasMoreElements()) {
                hosts.add((String) st.nextElement());
            }
            DistributedRunner distributedRunner = new DistributedRunner(this.remoteProps);
            // NOSONAR
            distributedRunner.setStdout(System.out);
            // NOSONAR
            distributedRunner.setStdErr(System.err);
            distributedRunner.init(hosts, tree);
            engines.addAll(distributedRunner.getEngines());
            distributedRunner.start();
        }
        startUdpDdaemon(engines);
    } catch (Exception e) {
        //NOSONAR
        System.out.println("Error in NonGUIDriver " + e.toString());
        log.error("Error in NonGUIDriver", e);
    }
}
Also used : HashTree(org.apache.jorphan.collections.HashTree) RemoteThreadsListenerTestElement(org.apache.jmeter.threads.RemoteThreadsListenerTestElement) JMeterTreeModel(org.apache.jmeter.gui.tree.JMeterTreeModel) Summariser(org.apache.jmeter.reporters.Summariser) ReportGenerator(org.apache.jmeter.report.dashboard.ReportGenerator) StringTokenizer(java.util.StringTokenizer) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) ReplaceableController(org.apache.jmeter.control.ReplaceableController) ResultCollector(org.apache.jmeter.reporters.ResultCollector) StandardJMeterEngine(org.apache.jmeter.engine.StandardJMeterEngine) SearchByClass(org.apache.jorphan.collections.SearchByClass) LinkedList(java.util.LinkedList) Date(java.util.Date) ConfigurationException(org.apache.jmeter.report.config.ConfigurationException) JMeterException(org.apache.jorphan.util.JMeterException) FileNotFoundException(java.io.FileNotFoundException) ConversionException(com.thoughtworks.xstream.converters.ConversionException) SocketException(java.net.SocketException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException) GenerationException(org.apache.jmeter.report.dashboard.GenerationException) StringTokenizer(java.util.StringTokenizer) ClientJMeterEngine(org.apache.jmeter.engine.ClientJMeterEngine) JMeterEngine(org.apache.jmeter.engine.JMeterEngine) StandardJMeterEngine(org.apache.jmeter.engine.StandardJMeterEngine) DistributedRunner(org.apache.jmeter.engine.DistributedRunner) File(java.io.File)

Example 2 with JMeterTreeModel

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

the class JMeter method startGui.

/**
     * Starts up JMeter in GUI mode
     */
private void startGui(String testFile) {
    //NOSONAR
    System.out.println("================================================================================");
    //NOSONAR
    System.out.println("Don't use GUI mode for load testing, only for Test creation and Test debugging !");
    //NOSONAR
    System.out.println("For load testing, use NON GUI Mode:");
    //NOSONAR
    System.out.println("   jmeter -n -t [jmx file] -l [results file] -e -o [Path to output folder]");
    //NOSONAR
    System.out.println("& adapt Java Heap to your test requirements:");
    //NOSONAR
    System.out.println("   Modify HEAP=\"-Xms512m -Xmx512m\" in the JMeter batch file");
    //NOSONAR
    System.out.println("================================================================================");
    SplashScreen splash = new SplashScreen();
    splash.showScreen();
    String jMeterLaf = LookAndFeelCommand.getJMeterLaf();
    try {
        UIManager.setLookAndFeel(jMeterLaf);
    } catch (Exception ex) {
        log.warn("Could not set LAF to: {}", jMeterLaf, ex);
    }
    splash.setProgress(10);
    JMeterUtils.applyHiDPIOnFonts();
    PluginManager.install(this, true);
    JMeterTreeModel treeModel = new JMeterTreeModel();
    splash.setProgress(30);
    JMeterTreeListener treeLis = new JMeterTreeListener(treeModel);
    final ActionRouter instance = ActionRouter.getInstance();
    instance.populateCommandMap();
    splash.setProgress(60);
    treeLis.setActionHandler(instance);
    GuiPackage.initInstance(treeLis, treeModel);
    splash.setProgress(80);
    MainFrame main = new MainFrame(treeModel, treeLis);
    splash.setProgress(100);
    ComponentUtil.centerComponentInWindow(main, 80);
    main.setVisible(true);
    instance.actionPerformed(new ActionEvent(main, 1, ActionNames.ADD_ALL));
    if (testFile != null) {
        try {
            File f = new File(testFile);
            log.info("Loading file: {}", f);
            FileServer.getFileServer().setBaseForScript(f);
            HashTree tree = SaveService.loadTree(f);
            GuiPackage.getInstance().setTestPlanFile(f.getAbsolutePath());
            Load.insertLoadedTree(1, tree);
        } catch (ConversionException e) {
            log.error("Failure loading test file", e);
            JMeterUtils.reportErrorToUser(SaveService.CEtoString(e));
        } catch (Exception e) {
            log.error("Failure loading test file", e);
            JMeterUtils.reportErrorToUser(e.toString());
        }
    } else {
        JTree jTree = GuiPackage.getInstance().getMainFrame().getTree();
        TreePath path = jTree.getPathForRow(0);
        jTree.setSelectionPath(path);
        FocusRequester.requestFocus(jTree);
    }
    splash.setProgress(100);
    splash.close();
}
Also used : ConversionException(com.thoughtworks.xstream.converters.ConversionException) HashTree(org.apache.jorphan.collections.HashTree) ActionEvent(java.awt.event.ActionEvent) ActionRouter(org.apache.jmeter.gui.action.ActionRouter) ConfigurationException(org.apache.jmeter.report.config.ConfigurationException) JMeterException(org.apache.jorphan.util.JMeterException) FileNotFoundException(java.io.FileNotFoundException) ConversionException(com.thoughtworks.xstream.converters.ConversionException) SocketException(java.net.SocketException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException) GenerationException(org.apache.jmeter.report.dashboard.GenerationException) MainFrame(org.apache.jmeter.gui.MainFrame) JMeterTreeModel(org.apache.jmeter.gui.tree.JMeterTreeModel) JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) JMeterTreeListener(org.apache.jmeter.gui.tree.JMeterTreeListener) File(java.io.File)

Example 3 with JMeterTreeModel

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

the class SearchTreeDialog method doSearch.

/**
     * @param e {@link ActionEvent}
     */
private void doSearch(ActionEvent e) {
    boolean expand = e.getSource() == searchAndExpandButton;
    String wordToSearch = searchTF.getText();
    if (StringUtils.isEmpty(wordToSearch)) {
        return;
    } else {
        this.lastSearch = wordToSearch;
    }
    // reset previous result
    ActionRouter.getInstance().doActionNow(new ActionEvent(e.getSource(), e.getID(), ActionNames.SEARCH_RESET));
    // do search
    Searcher searcher = null;
    if (isRegexpCB.isSelected()) {
        searcher = new RegexpSearcher(isCaseSensitiveCB.isSelected(), searchTF.getText());
    } else {
        searcher = new RawTextSearcher(isCaseSensitiveCB.isSelected(), searchTF.getText());
    }
    GuiPackage guiPackage = GuiPackage.getInstance();
    JMeterTreeModel jMeterTreeModel = guiPackage.getTreeModel();
    Set<JMeterTreeNode> nodes = new HashSet<>();
    int numberOfMatches = 0;
    for (JMeterTreeNode jMeterTreeNode : jMeterTreeModel.getNodesOfType(Searchable.class)) {
        try {
            Searchable searchable = (Searchable) jMeterTreeNode.getUserObject();
            List<JMeterTreeNode> matchingNodes = jMeterTreeNode.getPathToThreadGroup();
            List<String> searchableTokens = searchable.getSearchableTokens();
            boolean result = searcher.search(searchableTokens);
            if (result) {
                numberOfMatches++;
                nodes.addAll(matchingNodes);
            }
        } catch (Exception ex) {
            logger.error("Error occurred searching for word:" + wordToSearch + " in node:" + jMeterTreeNode.getName(), ex);
        }
    }
    GuiPackage guiInstance = GuiPackage.getInstance();
    JTree jTree = guiInstance.getMainFrame().getTree();
    for (JMeterTreeNode jMeterTreeNode : nodes) {
        jMeterTreeNode.setMarkedBySearch(true);
        if (expand) {
            jTree.expandPath(new TreePath(jMeterTreeNode.getPath()));
        }
    }
    GuiPackage.getInstance().getMainFrame().repaint();
    searchTF.requestFocusInWindow();
    statusLabel.setText(MessageFormat.format(JMeterUtils.getResString("search_tree_matches"), new Object[] { numberOfMatches }));
}
Also used : ActionEvent(java.awt.event.ActionEvent) JMeterTreeModel(org.apache.jmeter.gui.tree.JMeterTreeModel) JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) GuiPackage(org.apache.jmeter.gui.GuiPackage) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) Searchable(org.apache.jmeter.gui.Searchable) HashSet(java.util.HashSet)

Example 4 with JMeterTreeModel

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

the class ResetSearchCommand method doAction.

/**
     * @see Command#doAction(ActionEvent)
     */
@Override
public void doAction(ActionEvent e) {
    GuiPackage guiPackage = GuiPackage.getInstance();
    JMeterTreeModel jMeterTreeModel = guiPackage.getTreeModel();
    for (JMeterTreeNode jMeterTreeNode : jMeterTreeModel.getNodesOfType(Searchable.class)) {
        if (jMeterTreeNode.getUserObject() instanceof Searchable) {
            List<JMeterTreeNode> matchingNodes = jMeterTreeNode.getPathToThreadGroup();
            for (JMeterTreeNode jMeterTreeNode2 : matchingNodes) {
                jMeterTreeNode2.setMarkedBySearch(false);
            }
        }
    }
    GuiPackage.getInstance().getMainFrame().repaint();
}
Also used : JMeterTreeModel(org.apache.jmeter.gui.tree.JMeterTreeModel) GuiPackage(org.apache.jmeter.gui.GuiPackage) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) Searchable(org.apache.jmeter.gui.Searchable)

Example 5 with JMeterTreeModel

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

the class UndoHistory method treeNodesInserted.

/**
     * Record adding nodes as the undo step
     *
     * @param tme {@link TreeModelEvent} with event details
     */
@Override
public void treeNodesInserted(TreeModelEvent tme) {
    String name = ((JMeterTreeNode) tme.getTreePath().getLastPathComponent()).getName();
    log.debug("Nodes inserted {}", name);
    final JMeterTreeModel sender = (JMeterTreeModel) tme.getSource();
    add(sender, "Add " + name);
}
Also used : JMeterTreeModel(org.apache.jmeter.gui.tree.JMeterTreeModel) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode)

Aggregations

JMeterTreeModel (org.apache.jmeter.gui.tree.JMeterTreeModel)19 JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)18 GuiPackage (org.apache.jmeter.gui.GuiPackage)6 TestElement (org.apache.jmeter.testelement.TestElement)6 ConfigTestElement (org.apache.jmeter.config.ConfigTestElement)5 IllegalUserActionException (org.apache.jmeter.exceptions.IllegalUserActionException)5 IOException (java.io.IOException)4 JTree (javax.swing.JTree)4 TreePath (javax.swing.tree.TreePath)4 ActionEvent (java.awt.event.ActionEvent)3 MalformedURLException (java.net.MalformedURLException)3 Searchable (org.apache.jmeter.gui.Searchable)3 ConversionException (com.thoughtworks.xstream.converters.ConversionException)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 SocketException (java.net.SocketException)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 JMeterTreeListener (org.apache.jmeter.gui.tree.JMeterTreeListener)2 ConfigurationException (org.apache.jmeter.report.config.ConfigurationException)2