use of org.apache.jmeter.engine.DistributedRunner in project jmeter by apache.
the class JMeter method runNonGui.
// run test in batch mode
private void runNonGui(String testFile, String logFile, boolean remoteStart, String remoteHostsString, boolean generateReportDashboard) {
try {
File f = new File(testFile);
if (!f.exists() || !f.isFile()) {
println("Could not open " + testFile);
return;
}
FileServer.getFileServer().setBaseForScript(f);
HashTree tree = SaveService.loadTree(f);
// Deliberate use of deprecated ctor
@SuppressWarnings("deprecation") JMeterTreeModel // 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);
}
// Remove the disabled items
// For GUI runs this is done in Start.java
convertSubTree(tree);
if (deleteResultFile) {
SearchByClass<ResultCollector> resultListeners = new SearchByClass<>(ResultCollector.class);
tree.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();
}
}
}
Summariser summer = null;
//$NON-NLS-1$
String summariserName = JMeterUtils.getPropDefault("summariser.name", "");
if (summariserName.length() > 0) {
log.info("Creating summariser <{}>", summariserName);
println("Creating summariser <" + summariserName + ">");
summer = new Summariser(summariserName);
}
ReportGenerator reportGenerator = null;
if (logFile != null) {
ResultCollector logger = new ResultCollector(summer);
logger.setFilename(logFile);
tree.add(tree.getArray()[0], logger);
if (generateReportDashboard) {
reportGenerator = new ReportGenerator(logFile, logger);
}
} else {
// only add Summariser if it can not be shared with the ResultCollector
if (summer != null) {
tree.add(tree.getArray()[0], summer);
}
}
// 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
tree.add(tree.getArray()[0], new RemoteThreadsListenerTestElement());
List<JMeterEngine> engines = new LinkedList<>();
tree.add(tree.getArray()[0], new ListenToTest(remoteStart && remoteStop ? engines : null, reportGenerator));
println("Created the tree successfully using " + testFile);
if (!remoteStart) {
JMeterEngine engine = new StandardJMeterEngine();
engine.configure(tree);
long now = System.currentTimeMillis();
println("Starting the test @ " + new Date(now) + " (" + now + ")");
engine.runTest();
engines.add(engine);
} else {
//$NON-NLS-1$
java.util.StringTokenizer st = new java.util.StringTokenizer(remoteHostsString, ",");
List<String> hosts = new LinkedList<>();
while (st.hasMoreElements()) {
hosts.add((String) st.nextElement());
}
DistributedRunner distributedRunner = new DistributedRunner(this.remoteProps);
// NOSONAR
distributedRunner.setStdout(System.out);
// NOSONAR
distributedRunner.setStdErr(System.err);
distributedRunner.init(hosts, tree);
engines.addAll(distributedRunner.getEngines());
distributedRunner.start();
}
startUdpDdaemon(engines);
} catch (Exception e) {
//NOSONAR
System.out.println("Error in NonGUIDriver " + e.toString());
log.error("Error in NonGUIDriver", e);
}
}
Aggregations