Search in sources :

Example 1 with StandardJMeterEngine

use of org.apache.jmeter.engine.StandardJMeterEngine in project jmeter by apache.

the class Start method startEngine.

/**
     * Start JMeter engine
     * @param ignoreTimer flag to ignore timers
     * @param isValidationShot 
     * @param threadGroupsToRun Array of AbstractThreadGroup to run
     */
private void startEngine(boolean ignoreTimer, boolean isValidationShot, AbstractThreadGroup[] threadGroupsToRun) {
    GuiPackage gui = GuiPackage.getInstance();
    HashTree testTree = gui.getTreeModel().getTestPlan();
    JMeter.convertSubTree(testTree);
    if (threadGroupsToRun != null && threadGroupsToRun.length > 0) {
        removeThreadGroupsFromHashTree(testTree, threadGroupsToRun);
    }
    testTree.add(testTree.getArray()[0], gui.getMainFrame());
    if (log.isDebugEnabled()) {
        log.debug("test plan before cloning is running version: {}", ((TestPlan) testTree.getArray()[0]).isRunningVersion());
    }
    ListedHashTree clonedTree = null;
    if (isValidationShot) {
        TreeCloner cloner = createTreeClonerForValidation();
        testTree.traverse(cloner);
        clonedTree = cloner.getClonedTree();
    } else {
        TreeCloner cloner = cloneTree(testTree, ignoreTimer);
        clonedTree = cloner.getClonedTree();
    }
    if (popupCheckExistingFileListener(testTree)) {
        engine = new StandardJMeterEngine();
        engine.configure(clonedTree);
        try {
            engine.runTest();
        } catch (JMeterEngineException e) {
            JOptionPane.showMessageDialog(gui.getMainFrame(), e.getMessage(), JMeterUtils.getResString("error_occurred"), //$NON-NLS-1$
            JOptionPane.ERROR_MESSAGE);
        }
        if (log.isDebugEnabled()) {
            log.debug("test plan after cloning and running test is running version: {}", ((TestPlan) testTree.getArray()[0]).isRunningVersion());
        }
    }
}
Also used : ListedHashTree(org.apache.jorphan.collections.ListedHashTree) HashTree(org.apache.jorphan.collections.HashTree) ListedHashTree(org.apache.jorphan.collections.ListedHashTree) StandardJMeterEngine(org.apache.jmeter.engine.StandardJMeterEngine) GuiPackage(org.apache.jmeter.gui.GuiPackage) TreeCloner(org.apache.jmeter.engine.TreeCloner) JMeterEngineException(org.apache.jmeter.engine.JMeterEngineException)

Example 2 with StandardJMeterEngine

use of org.apache.jmeter.engine.StandardJMeterEngine in project jmeter-plugins by undera.

the class ConcurrencyThreadGroupTest method testSetDoneThreadsAfterHold.

// WAP-9261
@Test(timeout = 25000)
public void testSetDoneThreadsAfterHold() throws Exception {
    JMeterContextService.getContext().setVariables(new JMeterVariables());
    TestSampleListener listener = new TestSampleListener();
    DebugSampler sampler = new DebugSampler();
    sampler.setName("Sampler");
    ConstantTimer timer = new ConstantTimer();
    timer.setDelay("2000");
    timer.setName("timer");
    LoopController loopController = new LoopController();
    loopController.setContinueForever(true);
    loopController.setLoops(-1);
    loopController.setName("loop c");
    ConcurrencyThreadGroupExt ctg = new ConcurrencyThreadGroupExt();
    ctg.setName("CTG");
    ctg.setRampUp("5");
    ctg.setTargetLevel("3");
    ctg.setSteps("1");
    // TODO: increase this value for debugging
    ctg.setHold("10");
    ctg.setIterationsLimit("");
    ctg.setUnit("S");
    ListedHashTree loopTree = new ListedHashTree();
    loopTree.add(loopController, timer);
    loopTree.add(loopController, sampler);
    loopTree.add(loopController, listener);
    ListedHashTree hashTree = new ListedHashTree();
    hashTree.add(ctg, loopTree);
    TestCompiler compiler = new TestCompiler(hashTree);
    // this hashTree can be save to *jmx
    hashTree.traverse(compiler);
    ListenerNotifier notifier = new ListenerNotifier();
    long startTime = System.currentTimeMillis();
    ctg.start(1, notifier, hashTree, new StandardJMeterEngine());
    Thread threadStarter = ctg.getThreadStarter();
    threadStarter.join();
    long endTime = System.currentTimeMillis();
    // wait when all thread stopped
    Thread.currentThread().sleep(5000);
    assertTrue((endTime - startTime) < 20000);
    // ALL threads must be stopped
    assertEquals(0, ctg.getNumberOfThreads());
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) ListedHashTree(org.apache.jorphan.collections.ListedHashTree) DebugSampler(org.apache.jmeter.sampler.DebugSampler) TestCompiler(org.apache.jmeter.threads.TestCompiler) StandardJMeterEngine(org.apache.jmeter.engine.StandardJMeterEngine) ConstantTimer(org.apache.jmeter.timers.ConstantTimer) LoopController(org.apache.jmeter.control.LoopController) ListenerNotifier(org.apache.jmeter.threads.ListenerNotifier) ArrivalsThreadGroupTest(com.blazemeter.jmeter.threads.arrivals.ArrivalsThreadGroupTest) Test(org.junit.Test)

Example 3 with StandardJMeterEngine

use of org.apache.jmeter.engine.StandardJMeterEngine in project jmeter-plugins by undera.

the class TestPlanCheckTool method loadJMX.

private HashTree loadJMX(File file) throws Exception {
    HashTree tree = SaveService.loadTree(file);
    // unfortunately core JMeter code does not throw exception, we may only guess...
    if (tree == null) {
        throw new TestPlanBrokenException("There was problems loading test plan. Please investigate error messages above.");
    }
    // Remove the disabled items
    JMeter.convertSubTree(tree);
    JMeterEngine engine = new StandardJMeterEngine();
    engine.configure(tree);
    return tree;
}
Also used : HashTree(org.apache.jorphan.collections.HashTree) StandardJMeterEngine(org.apache.jmeter.engine.StandardJMeterEngine) JMeterEngine(org.apache.jmeter.engine.JMeterEngine) StandardJMeterEngine(org.apache.jmeter.engine.StandardJMeterEngine)

Example 4 with StandardJMeterEngine

use of org.apache.jmeter.engine.StandardJMeterEngine in project qpp-conversion-tool by CMSgov.

the class ConverterLoadTest method setupClass.

@BeforeAll
static void setupClass() {
    jmeter = new StandardJMeterEngine();
    // JMeter initialization (properties, log levels, locale, etc)
    JMeterUtils.setJMeterHome("src/test/resources/");
    JMeterUtils.loadJMeterProperties("src/test/resources/jmeter.properties");
    JMeterUtils.initLocale();
}
Also used : StandardJMeterEngine(org.apache.jmeter.engine.StandardJMeterEngine) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 5 with StandardJMeterEngine

use of org.apache.jmeter.engine.StandardJMeterEngine 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)

Aggregations

StandardJMeterEngine (org.apache.jmeter.engine.StandardJMeterEngine)10 HashTree (org.apache.jorphan.collections.HashTree)6 ListedHashTree (org.apache.jorphan.collections.ListedHashTree)5 LoopController (org.apache.jmeter.control.LoopController)3 ListenerNotifier (org.apache.jmeter.threads.ListenerNotifier)3 Test (org.junit.Test)3 ArrivalsThreadGroupTest (com.blazemeter.jmeter.threads.arrivals.ArrivalsThreadGroupTest)2 JMeterEngine (org.apache.jmeter.engine.JMeterEngine)2 JMeterEngineException (org.apache.jmeter.engine.JMeterEngineException)2 GuiPackage (org.apache.jmeter.gui.GuiPackage)2 JMeterTreeModel (org.apache.jmeter.gui.tree.JMeterTreeModel)2 ResultCollector (org.apache.jmeter.reporters.ResultCollector)2 DebugSampler (org.apache.jmeter.sampler.DebugSampler)2 JMeterVariables (org.apache.jmeter.threads.JMeterVariables)2 TestCompiler (org.apache.jmeter.threads.TestCompiler)2 ThreadGroup (org.apache.jmeter.threads.ThreadGroup)2 ConversionException (com.thoughtworks.xstream.converters.ConversionException)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1