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