Search in sources :

Example 6 with StandardJMeterEngine

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

the class ConcurrencyThreadGroupTest method testStartNextLoop.

@Test
public void testStartNextLoop() throws Exception {
    JMeterContextService.getContext().setVariables(new JMeterVariables());
    TestSampleListener listener = new TestSampleListener();
    DebugSampler beforeSampler = new DebugSamplerExt();
    beforeSampler.setName("Before Test Action sampler");
    TestAction testAction = new TestAction();
    testAction.setAction(TestAction.RESTART_NEXT_LOOP);
    DebugSampler afterSampler = new DebugSamplerExt();
    afterSampler.setName("After Test Action sampler");
    ConcurrencyThreadGroup ctg = new ConcurrencyThreadGroup();
    ctg.setProperty(new StringProperty(AbstractThreadGroup.ON_SAMPLE_ERROR, AbstractThreadGroup.ON_SAMPLE_ERROR_CONTINUE));
    ctg.setRampUp("0");
    ctg.setTargetLevel("1");
    ctg.setSteps("0");
    // TODO: increase this value for debugging
    ctg.setHold("5");
    ctg.setIterationsLimit("10");
    ctg.setUnit("S");
    ListedHashTree hashTree = new ListedHashTree();
    hashTree.add(ctg);
    hashTree.add(ctg, beforeSampler);
    hashTree.add(ctg, testAction);
    hashTree.add(ctg, afterSampler);
    hashTree.add(ctg, listener);
    TestCompiler compiler = new TestCompiler(hashTree);
    hashTree.traverse(compiler);
    ListenerNotifier notifier = new ListenerNotifier();
    ctg.start(1, notifier, hashTree, new StandardJMeterEngine());
    ctg.waitThreadsStopped();
}
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) StringProperty(org.apache.jmeter.testelement.property.StringProperty) ListenerNotifier(org.apache.jmeter.threads.ListenerNotifier) TestAction(org.apache.jmeter.sampler.TestAction) ArrivalsThreadGroupTest(com.blazemeter.jmeter.threads.arrivals.ArrivalsThreadGroupTest) Test(org.junit.Test)

Example 7 with StandardJMeterEngine

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

the class AbstractSimpleThreadGroupTest method testStart.

/**
 * Test of start method, of class AbstractSimpleThreadGroup.
 */
@Test
public void testStart() {
    System.out.println("start");
    int groupCount = 0;
    ListenerNotifier notifier = null;
    ListedHashTree threadGroupTree = null;
    StandardJMeterEngine engine = null;
    AbstractSimpleThreadGroup instance = new AbstractSimpleThreadGroupImpl();
    instance.start(groupCount, notifier, threadGroupTree, engine);
}
Also used : ListedHashTree(org.apache.jorphan.collections.ListedHashTree) StandardJMeterEngine(org.apache.jmeter.engine.StandardJMeterEngine) ListenerNotifier(org.apache.jmeter.threads.ListenerNotifier) Test(org.junit.Test)

Example 8 with StandardJMeterEngine

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

the class TestJMeterUtils method createJmeterEnv.

public static void createJmeterEnv() {
    JMeterUtils.setJMeterHome(getTempDir());
    File dst = new File(JMeterUtils.getJMeterHome() + "/ss.props");
    InputStream src = DirectoryAnchor.class.getResourceAsStream("/kg/apc/jmeter/bin/saveservice.properties");
    try {
        Files.copy(src, dst.toPath(), StandardCopyOption.REPLACE_EXISTING);
    } catch (IOException e) {
        throw new RuntimeException("Failed to copy file " + src + " to " + dst, e);
    }
    JMeterUtils.loadJMeterProperties(dst.getAbsolutePath());
    JMeterUtils.setLocale(new Locale("ignoreResources"));
    JMeterTreeModel jMeterTreeModel = new JMeterTreeModel();
    JMeterTreeListener jMeterTreeListener = new JMeterTreeListener();
    jMeterTreeListener.setModel(jMeterTreeModel);
    JMeterContextService.getContext().setVariables(new JMeterVariables());
    StandardJMeterEngine engine = new EmulatorJmeterEngine();
    JMeterThreadMonitor monitor = new EmulatorThreadMonitor();
    JMeterContextService.getContext().setEngine(engine);
    HashTree hashtree = new HashTree();
    hashtree.add(new LoopController());
    JMeterThread thread = new JMeterThread(hashtree, monitor, null);
    thread.setThreadName("test thread");
    JMeterContextService.getContext().setThread(thread);
    ThreadGroup threadGroup = new org.apache.jmeter.threads.ThreadGroup();
    threadGroup.setName("test thread group");
    JMeterContextService.getContext().setThreadGroup(threadGroup);
    // for Flexible File Writer Test
    JMeterUtils.setProperty("sample_variables", "TEST1,TEST2,TEST3");
    JMeterUtils.setProperty("saveservice_properties", "/ss.props");
    JMeterUtils.setProperty("upgrade_properties", "/ss.props");
    // enable multibyte
    JMeterUtils.setProperty("sampleresult.default.encoding", "UTF-8");
}
Also used : Locale(java.util.Locale) HashTree(org.apache.jorphan.collections.HashTree) StandardJMeterEngine(org.apache.jmeter.engine.StandardJMeterEngine) LoopController(org.apache.jmeter.control.LoopController) JMeterTreeModel(org.apache.jmeter.gui.tree.JMeterTreeModel) JMeterTreeListener(org.apache.jmeter.gui.tree.JMeterTreeListener) ThreadGroup(org.apache.jmeter.threads.ThreadGroup)

Example 9 with StandardJMeterEngine

use of org.apache.jmeter.engine.StandardJMeterEngine in project xwiki-platform by xwiki.

the class HTTPPerformanceTest method execute.

public void execute(List<HTTPSampler> samplers, String user, String password) {
    // jmeter.properties
    JMeterUtils.loadJMeterProperties("target/jmeter/home/bin/saveservice.properties");
    JMeterUtils.setLocale(Locale.ENGLISH);
    JMeterUtils.setJMeterHome("target/jmeter/home");
    // Result collector
    ResultCollector resultCollector = new ResultCollector();
    resultCollector.setFilename("target/jmeter/report.jtl");
    SampleSaveConfiguration saveConfiguration = new SampleSaveConfiguration();
    saveConfiguration.setAsXml(true);
    saveConfiguration.setCode(true);
    saveConfiguration.setLatency(true);
    saveConfiguration.setTime(true);
    saveConfiguration.setTimestamp(true);
    resultCollector.setSaveConfig(saveConfiguration);
    // Thread Group
    ThreadGroup threadGroup = new ThreadGroup();
    threadGroup.setName("xwiki");
    threadGroup.setNumThreads(1);
    threadGroup.setRampUp(1);
    LoopController loopCtrl = new LoopController();
    loopCtrl.setLoops(5);
    loopCtrl.setFirst(true);
    threadGroup.setSamplerController(loopCtrl);
    HashTree threadGroupTree = new HashTree();
    threadGroupTree.add(samplers);
    // Test plan
    TestPlan testPlan = new TestPlan("ping");
    HashTree testPlanTree = new HashTree();
    testPlanTree.add(threadGroup, threadGroupTree);
    testPlanTree.add(resultCollector);
    HashTree hashTree = new HashTree();
    hashTree.add(testPlan, testPlanTree);
    // Engine
    StandardJMeterEngine jm = new StandardJMeterEngine("localhost");
    jm.configure(hashTree);
    jm.run();
}
Also used : SampleSaveConfiguration(org.apache.jmeter.samplers.SampleSaveConfiguration) HashTree(org.apache.jorphan.collections.HashTree) StandardJMeterEngine(org.apache.jmeter.engine.StandardJMeterEngine) TestPlan(org.apache.jmeter.testelement.TestPlan) ThreadGroup(org.apache.jmeter.threads.ThreadGroup) LoopController(org.apache.jmeter.control.LoopController) ResultCollector(org.apache.jmeter.reporters.ResultCollector)

Example 10 with StandardJMeterEngine

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

the class Start method startEngine.

/**
 * Start JMeter engine
 * @param threadGroupsToRun Array of AbstractThreadGroup to run
 * @param runMode {@link RunMode} How to run engine
 */
private void startEngine(AbstractThreadGroup[] threadGroupsToRun, RunMode runMode) {
    GuiPackage gui = GuiPackage.getInstance();
    HashTree testTree = gui.getTreeModel().getTestPlan();
    // We need to make this conversion before removing any Thread Group as 1 thread Group running may
    // reference another one (not running) using ModuleController
    // We don't clone as we'll be doing it later AND we cannot clone before we have removed the unselected ThreadGroups
    HashTree treeToUse = JMeter.convertSubTree(testTree, false);
    if (threadGroupsToRun != null && threadGroupsToRun.length > 0) {
        keepOnlySelectedThreadGroupsInHashTree(treeToUse, threadGroupsToRun);
    }
    treeToUse.add(treeToUse.getArray()[0], gui.getMainFrame());
    if (log.isDebugEnabled()) {
        log.debug("test plan before cloning is running version: {}", ((TestPlan) treeToUse.getArray()[0]).isRunningVersion());
    }
    ListedHashTree clonedTree = cloneTree(treeToUse, runMode);
    if (popupCheckExistingFileListener(clonedTree)) {
        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) treeToUse.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) JMeterEngineException(org.apache.jmeter.engine.JMeterEngineException)

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