Search in sources :

Example 1 with ResultCollector

use of org.apache.jmeter.reporters.ResultCollector 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 ResultCollector

use of org.apache.jmeter.reporters.ResultCollector in project jmeter by apache.

the class AbstractVisualizer method modifyTestElement.

/* Implements JMeterGUIComponent.modifyTestElement(TestElement) */
@Override
public void modifyTestElement(TestElement c) {
    configureTestElement((AbstractListenerElement) c);
    if (c instanceof ResultCollector) {
        ResultCollector rc = (ResultCollector) c;
        rc.setErrorLogging(errorLogging.isSelected());
        rc.setSuccessOnlyLogging(successOnlyLogging.isSelected());
        rc.setFilename(getFile());
        collector = rc;
    }
}
Also used : ResultCollector(org.apache.jmeter.reporters.ResultCollector)

Example 3 with ResultCollector

use of org.apache.jmeter.reporters.ResultCollector in project jmeter by apache.

the class AbstractAction method popupCheckExistingFileListener.

/**
     * @param tree where check if listener has existing file
     * @return true if continue test, false otherwise
     */
protected boolean popupCheckExistingFileListener(HashTree tree) {
    SearchByClass<ResultCollector> resultListeners = new SearchByClass<>(ResultCollector.class);
    tree.traverse(resultListeners);
    Iterator<ResultCollector> irc = resultListeners.getSearchResults().iterator();
    while (irc.hasNext()) {
        ResultCollector rc = irc.next();
        File f = new File(rc.getFilename());
        if (f.exists()) {
            String[] option = new String[] { JMeterUtils.getResString("concat_result"), JMeterUtils.getResString("dont_start"), JMeterUtils.getResString("replace_file") };
            String question = MessageFormat.format(// $NON-NLS-1$
            JMeterUtils.getResString("ask_existing_file"), rc.getFilename());
            // Interactive question
            int response = JOptionPane.showOptionDialog(GuiPackage.getInstance().getMainFrame(), question, JMeterUtils.getResString("warning"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, option, option[0]);
            switch(response) {
                case JOptionPane.NO_OPTION:
                    // Exit without start the test
                    return false;
                case JOptionPane.CANCEL_OPTION:
                    // replace_file so delete the existing one
                    f.delete();
                    break;
                case JOptionPane.YES_OPTION:
                    // append is the default behaviour, so nothing to do
                    break;
                default:
                    return false;
            }
        }
    }
    return true;
}
Also used : ResultCollector(org.apache.jmeter.reporters.ResultCollector) File(java.io.File) SearchByClass(org.apache.jorphan.collections.SearchByClass)

Example 4 with ResultCollector

use of org.apache.jmeter.reporters.ResultCollector in project jmeter by apache.

the class MailerVisualizer method actionPerformed.

// ////////////////////////////////////////////////////////////
//
// Implementation of the ActionListener-Interface.
//
// ////////////////////////////////////////////////////////////
/**
     * Reacts on an ActionEvent (like pressing a button).
     *
     * @param e
     *            The ActionEvent with information about the event and its
     *            source.
     */
@Override
public void actionPerformed(ActionEvent e) {
    if (e.getSource() == testerButton) {
        ResultCollector testElement = getModel();
        modifyTestElement(testElement);
        try {
            MailerModel model = ((MailerResultCollector) testElement).getMailerModel();
            model.sendTestMail();
            //$NON-NLS-1$
            displayMessage(JMeterUtils.getResString("mail_sent"), false);
        } catch (AddressException ex) {
            log.error("Invalid mail address ", ex);
            displayMessage(//$NON-NLS-1$
            JMeterUtils.getResString("invalid_mail_address") + "\n" + ex.getMessage(), //$NON-NLS-1$
            true);
        } catch (MessagingException ex) {
            log.error("Couldn't send mail...", ex);
            displayMessage(//$NON-NLS-1$
            JMeterUtils.getResString("invalid_mail") + "\n" + ex.getMessage(), //$NON-NLS-1$
            true);
        }
    }
}
Also used : MailerResultCollector(org.apache.jmeter.reporters.MailerResultCollector) MessagingException(javax.mail.MessagingException) AddressException(javax.mail.internet.AddressException) MailerModel(org.apache.jmeter.reporters.MailerModel) MailerResultCollector(org.apache.jmeter.reporters.MailerResultCollector) ResultCollector(org.apache.jmeter.reporters.ResultCollector)

Example 5 with ResultCollector

use of org.apache.jmeter.reporters.ResultCollector in project jmeter by apache.

the class TestTreeCloner method testCloning.

@Test
public void testCloning() throws Exception {
    ListedHashTree original = new ListedHashTree();
    GenericController controller = new GenericController();
    controller.setName("controller");
    Arguments args = new Arguments();
    args.setName("args");
    TestPlan plan = new TestPlan();
    plan.addParameter("server", "jakarta");
    original.add(controller, args);
    original.add(plan);
    ResultCollector listener = new ResultCollector();
    listener.setName("Collector");
    original.add(controller, listener);
    TreeCloner cloner = new TreeCloner();
    original.traverse(cloner);
    ListedHashTree newTree = cloner.getClonedTree();
    assertTrue(original != newTree);
    assertEquals(original.size(), newTree.size());
    assertEquals(original.getTree(original.getArray()[0]).size(), newTree.getTree(newTree.getArray()[0]).size());
    assertTrue(original.getArray()[0] != newTree.getArray()[0]);
    assertEquals(((GenericController) original.getArray()[0]).getName(), ((GenericController) newTree.getArray()[0]).getName());
    assertSame(original.getTree(original.getArray()[0]).getArray()[1], newTree.getTree(newTree.getArray()[0]).getArray()[1]);
    TestPlan clonedTestPlan = (TestPlan) newTree.getArray()[1];
    clonedTestPlan.setRunningVersion(true);
    clonedTestPlan.recoverRunningVersion();
    assertTrue(!plan.getUserDefinedVariablesAsProperty().isRunningVersion());
    assertTrue(clonedTestPlan.getUserDefinedVariablesAsProperty().isRunningVersion());
    Arguments vars = (Arguments) plan.getUserDefinedVariablesAsProperty().getObjectValue();
    PropertyIterator iter = ((CollectionProperty) vars.getProperty(Arguments.ARGUMENTS)).iterator();
    while (iter.hasNext()) {
        JMeterProperty argProp = iter.next();
        assertTrue(!argProp.isRunningVersion());
        assertTrue(argProp.getObjectValue() instanceof Argument);
        Argument arg = (Argument) argProp.getObjectValue();
        arg.setValue("yahoo");
        assertEquals("yahoo", arg.getValue());
    }
    vars = (Arguments) clonedTestPlan.getUserDefinedVariablesAsProperty().getObjectValue();
    iter = vars.propertyIterator();
    while (iter.hasNext()) {
        assertTrue(iter.next().isRunningVersion());
    }
}
Also used : ListedHashTree(org.apache.jorphan.collections.ListedHashTree) CollectionProperty(org.apache.jmeter.testelement.property.CollectionProperty) JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) Argument(org.apache.jmeter.config.Argument) TestPlan(org.apache.jmeter.testelement.TestPlan) Arguments(org.apache.jmeter.config.Arguments) PropertyIterator(org.apache.jmeter.testelement.property.PropertyIterator) GenericController(org.apache.jmeter.control.GenericController) ResultCollector(org.apache.jmeter.reporters.ResultCollector) Test(org.junit.Test)

Aggregations

ResultCollector (org.apache.jmeter.reporters.ResultCollector)8 File (java.io.File)2 Arguments (org.apache.jmeter.config.Arguments)2 MailerResultCollector (org.apache.jmeter.reporters.MailerResultCollector)2 TestPlan (org.apache.jmeter.testelement.TestPlan)2 SearchByClass (org.apache.jorphan.collections.SearchByClass)2 ConversionException (com.thoughtworks.xstream.converters.ConversionException)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 SocketException (java.net.SocketException)1 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 StringTokenizer (java.util.StringTokenizer)1 MessagingException (javax.mail.MessagingException)1 AddressException (javax.mail.internet.AddressException)1 Argument (org.apache.jmeter.config.Argument)1 GenericController (org.apache.jmeter.control.GenericController)1 ReplaceableController (org.apache.jmeter.control.ReplaceableController)1 ClientJMeterEngine (org.apache.jmeter.engine.ClientJMeterEngine)1