Search in sources :

Example 1 with RemoteThreadsListenerTestElement

use of org.apache.jmeter.threads.RemoteThreadsListenerTestElement in project jmeter by apache.

the class ConvertListeners method addNode.

/**
 * {@inheritDoc}
 */
@Override
public void addNode(Object node, HashTree subTree) {
    for (Object item : subTree.list()) {
        if (item instanceof AbstractThreadGroup && log.isDebugEnabled()) {
            log.debug("num threads = {}", ((AbstractThreadGroup) item).getNumThreads());
        }
        if (item instanceof Remoteable) {
            if (item instanceof RemoteThreadsListenerTestElement) {
                // Used for remote notification of threads start/stop,see BUG 54152
                try {
                    RemoteThreadsListenerWrapper wrapper = new RemoteThreadsListenerWrapper(new RemoteThreadsListenerImpl());
                    subTree.replaceKey(item, wrapper);
                } catch (RemoteException e) {
                    log.error("Error replacing {} by wrapper: {}", RemoteThreadsListenerTestElement.class, RemoteThreadsListenerWrapper.class, e);
                }
                continue;
            }
            if (item instanceof ThreadListener) {
                // TODO Document the reason for this
                log.error("Cannot handle ThreadListener Remotable item: {}", item.getClass());
                continue;
            }
            try {
                RemoteSampleListener rtl = new RemoteSampleListenerImpl(item);
                if (item instanceof TestStateListener && item instanceof SampleListener) {
                    // TL - all
                    RemoteListenerWrapper wrap = new RemoteListenerWrapper(rtl);
                    subTree.replaceKey(item, wrap);
                } else if (item instanceof TestStateListener) {
                    RemoteTestListenerWrapper wrap = new RemoteTestListenerWrapper(rtl);
                    subTree.replaceKey(item, wrap);
                } else if (item instanceof SampleListener) {
                    RemoteSampleListenerWrapper wrap = new RemoteSampleListenerWrapper(rtl);
                    subTree.replaceKey(item, wrap);
                } else {
                    if (log.isWarnEnabled()) {
                        log.warn("Could not replace Remotable item: {}", item.getClass());
                    }
                }
            } catch (RemoteException e) {
                // $NON-NLS-1$
                log.error("RemoteException occurred while replacing Remotable item.", e);
            }
        }
    }
}
Also used : RemoteThreadsListenerWrapper(org.apache.jmeter.threads.RemoteThreadsListenerWrapper) ThreadListener(org.apache.jmeter.testelement.ThreadListener) AbstractThreadGroup(org.apache.jmeter.threads.AbstractThreadGroup) Remoteable(org.apache.jmeter.samplers.Remoteable) RemoteThreadsListenerTestElement(org.apache.jmeter.threads.RemoteThreadsListenerTestElement) TestStateListener(org.apache.jmeter.testelement.TestStateListener) RemoteTestListenerWrapper(org.apache.jmeter.samplers.RemoteTestListenerWrapper) RemoteSampleListener(org.apache.jmeter.samplers.RemoteSampleListener) RemoteSampleListenerWrapper(org.apache.jmeter.samplers.RemoteSampleListenerWrapper) SampleListener(org.apache.jmeter.samplers.SampleListener) RemoteSampleListener(org.apache.jmeter.samplers.RemoteSampleListener) RemoteListenerWrapper(org.apache.jmeter.samplers.RemoteListenerWrapper) RemoteException(java.rmi.RemoteException) RemoteSampleListenerImpl(org.apache.jmeter.samplers.RemoteSampleListenerImpl) RemoteThreadsListenerImpl(org.apache.jmeter.threads.RemoteThreadsListenerImpl)

Example 2 with RemoteThreadsListenerTestElement

use of org.apache.jmeter.threads.RemoteThreadsListenerTestElement in project jmeter by apache.

the class JMeter method runNonGui.

// run test in batch mode
@SuppressWarnings("JdkObsolete")
void runNonGui(String testFile, String logFile, boolean remoteStart, String remoteHostsString, boolean generateReportDashboard) throws ConfigurationException {
    try {
        File f = new File(testFile);
        if (!f.exists() || !f.isFile()) {
            throw new ConfigurationException("The file " + f.getAbsolutePath() + " doesn't exist or can't be opened");
        }
        FileServer.getFileServer().setBaseForScript(f);
        HashTree tree = SaveService.loadTree(f);
        // Deliberate use of deprecated ctor
        @SuppressWarnings("deprecation") JMeterTreeModel // NOSONAR 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);
        }
        // Ensure tree is interpreted (ReplaceableControllers are replaced)
        // For GUI runs this is done in Start.java
        HashTree clonedTree = convertSubTree(tree, true);
        Summariser summariser = null;
        // $NON-NLS-1$
        String summariserName = JMeterUtils.getPropDefault("summariser.name", "");
        if (summariserName.length() > 0) {
            log.info("Creating summariser <{}>", summariserName);
            println("Creating summariser <" + summariserName + ">");
            summariser = new Summariser(summariserName);
        }
        ResultCollector resultCollector = null;
        if (logFile != null) {
            resultCollector = new ResultCollector(summariser);
            resultCollector.setFilename(logFile);
            clonedTree.add(clonedTree.getArray()[0], resultCollector);
        } else {
            // only add Summariser if it can not be shared with the ResultCollector
            if (summariser != null) {
                clonedTree.add(clonedTree.getArray()[0], summariser);
            }
        }
        if (deleteResultFile) {
            SearchByClass<ResultCollector> resultListeners = new SearchByClass<>(ResultCollector.class);
            clonedTree.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()) {
                    throw new IllegalStateException("Could not delete results file " + resultFile.getAbsolutePath() + "(canRead:" + resultFile.canRead() + ", canWrite:" + resultFile.canWrite() + ")");
                }
            }
        }
        ReportGenerator reportGenerator = null;
        if (logFile != null && generateReportDashboard) {
            reportGenerator = new ReportGenerator(logFile, resultCollector);
        }
        // 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
        clonedTree.add(clonedTree.getArray()[0], new RemoteThreadsListenerTestElement());
        List<JMeterEngine> engines = new ArrayList<>();
        println("Created the tree successfully using " + testFile);
        if (!remoteStart) {
            JMeterEngine engine = new StandardJMeterEngine();
            clonedTree.add(clonedTree.getArray()[0], new ListenToTest(org.apache.jmeter.JMeter.ListenToTest.RunMode.LOCAL, false, reportGenerator));
            engine.configure(clonedTree);
            long now = System.currentTimeMillis();
            println("Starting standalone test @ " + new Date(now) + " (" + now + ")");
            engines.add(engine);
            engine.runTest();
        } else {
            // $NON-NLS-1$
            java.util.StringTokenizer st = new java.util.StringTokenizer(remoteHostsString.trim(), ",");
            List<String> hosts = new ArrayList<>();
            while (st.hasMoreElements()) {
                hosts.add(((String) st.nextElement()).trim());
            }
            ListenToTest testListener = new ListenToTest(org.apache.jmeter.JMeter.ListenToTest.RunMode.REMOTE, remoteStop, reportGenerator);
            clonedTree.add(clonedTree.getArray()[0], testListener);
            DistributedRunner distributedRunner = new DistributedRunner(this.remoteProps);
            // NOSONAR
            distributedRunner.setStdout(System.out);
            // NOSONAR
            distributedRunner.setStdErr(System.err);
            distributedRunner.init(hosts, clonedTree);
            engines.addAll(distributedRunner.getEngines());
            testListener.setStartedRemoteEngines(engines);
            distributedRunner.start();
        }
        startUdpDdaemon(engines);
    } catch (ConfigurationException e) {
        throw e;
    } catch (Exception e) {
        // NOSONAR
        System.out.println("Error in NonGUIDriver " + e.toString());
        log.error("Error in NonGUIDriver", e);
        throw new ConfigurationException("Error in NonGUIDriver " + e.getMessage(), e);
    }
}
Also used : HashTree(org.apache.jorphan.collections.HashTree) RemoteThreadsListenerTestElement(org.apache.jmeter.threads.RemoteThreadsListenerTestElement) ArrayList(java.util.ArrayList) JMeterTreeModel(org.apache.jmeter.gui.tree.JMeterTreeModel) Summariser(org.apache.jmeter.reporters.Summariser) ReportGenerator(org.apache.jmeter.report.dashboard.ReportGenerator) ConfigurationException(org.apache.jmeter.report.config.ConfigurationException) 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) Date(java.util.Date) ConfigurationException(org.apache.jmeter.report.config.ConfigurationException) ScriptException(javax.script.ScriptException) JMeterException(org.apache.jorphan.util.JMeterException) ConversionException(com.thoughtworks.xstream.converters.ConversionException) SocketException(java.net.SocketException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) MalformedURLException(java.net.MalformedURLException) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException) StringTokenizer(java.util.StringTokenizer) JMeterEngine(org.apache.jmeter.engine.JMeterEngine) ClientJMeterEngine(org.apache.jmeter.engine.ClientJMeterEngine) StandardJMeterEngine(org.apache.jmeter.engine.StandardJMeterEngine) DistributedRunner(org.apache.jmeter.engine.DistributedRunner) File(java.io.File)

Example 3 with RemoteThreadsListenerTestElement

use of org.apache.jmeter.threads.RemoteThreadsListenerTestElement in project jmeter by apache.

the class RemoteStart method getTestTree.

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

Aggregations

RemoteThreadsListenerTestElement (org.apache.jmeter.threads.RemoteThreadsListenerTestElement)3 HashTree (org.apache.jorphan.collections.HashTree)2 ConversionException (com.thoughtworks.xstream.converters.ConversionException)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 SocketException (java.net.SocketException)1 RemoteException (java.rmi.RemoteException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 StringTokenizer (java.util.StringTokenizer)1 ScriptException (javax.script.ScriptException)1 ReplaceableController (org.apache.jmeter.control.ReplaceableController)1 ClientJMeterEngine (org.apache.jmeter.engine.ClientJMeterEngine)1 DistributedRunner (org.apache.jmeter.engine.DistributedRunner)1 JMeterEngine (org.apache.jmeter.engine.JMeterEngine)1 StandardJMeterEngine (org.apache.jmeter.engine.StandardJMeterEngine)1 IllegalUserActionException (org.apache.jmeter.exceptions.IllegalUserActionException)1 GuiPackage (org.apache.jmeter.gui.GuiPackage)1