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();
}
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);
}
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");
}
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();
}
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());
}
}
}
Aggregations