use of org.apache.jorphan.collections.HashTree 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);
}
}
use of org.apache.jorphan.collections.HashTree in project jmeter by apache.
the class JMeter method startGui.
/**
* Starts up JMeter in GUI mode
*/
private void startGui(String testFile) {
//NOSONAR
System.out.println("================================================================================");
//NOSONAR
System.out.println("Don't use GUI mode for load testing, only for Test creation and Test debugging !");
//NOSONAR
System.out.println("For load testing, use NON GUI Mode:");
//NOSONAR
System.out.println(" jmeter -n -t [jmx file] -l [results file] -e -o [Path to output folder]");
//NOSONAR
System.out.println("& adapt Java Heap to your test requirements:");
//NOSONAR
System.out.println(" Modify HEAP=\"-Xms512m -Xmx512m\" in the JMeter batch file");
//NOSONAR
System.out.println("================================================================================");
SplashScreen splash = new SplashScreen();
splash.showScreen();
String jMeterLaf = LookAndFeelCommand.getJMeterLaf();
try {
UIManager.setLookAndFeel(jMeterLaf);
} catch (Exception ex) {
log.warn("Could not set LAF to: {}", jMeterLaf, ex);
}
splash.setProgress(10);
JMeterUtils.applyHiDPIOnFonts();
PluginManager.install(this, true);
JMeterTreeModel treeModel = new JMeterTreeModel();
splash.setProgress(30);
JMeterTreeListener treeLis = new JMeterTreeListener(treeModel);
final ActionRouter instance = ActionRouter.getInstance();
instance.populateCommandMap();
splash.setProgress(60);
treeLis.setActionHandler(instance);
GuiPackage.initInstance(treeLis, treeModel);
splash.setProgress(80);
MainFrame main = new MainFrame(treeModel, treeLis);
splash.setProgress(100);
ComponentUtil.centerComponentInWindow(main, 80);
main.setVisible(true);
instance.actionPerformed(new ActionEvent(main, 1, ActionNames.ADD_ALL));
if (testFile != null) {
try {
File f = new File(testFile);
log.info("Loading file: {}", f);
FileServer.getFileServer().setBaseForScript(f);
HashTree tree = SaveService.loadTree(f);
GuiPackage.getInstance().setTestPlanFile(f.getAbsolutePath());
Load.insertLoadedTree(1, tree);
} catch (ConversionException e) {
log.error("Failure loading test file", e);
JMeterUtils.reportErrorToUser(SaveService.CEtoString(e));
} catch (Exception e) {
log.error("Failure loading test file", e);
JMeterUtils.reportErrorToUser(e.toString());
}
} else {
JTree jTree = GuiPackage.getInstance().getMainFrame().getTree();
TreePath path = jTree.getPathForRow(0);
jTree.setSelectionPath(path);
FocusRequester.requestFocus(jTree);
}
splash.setProgress(100);
splash.close();
}
use of org.apache.jorphan.collections.HashTree in project jmeter by apache.
the class ModuleController method getReplacementSubTree.
/**
* {@inheritDoc}
*/
@Override
public HashTree getReplacementSubTree() {
HashTree tree = new ListedHashTree();
if (selectedNode != null) {
// Use a local variable to avoid replacing reference by modified clone (see Bug 54950)
JMeterTreeNode nodeToReplace = selectedNode;
// We clone to avoid enabling existing node
if (!nodeToReplace.isEnabled()) {
nodeToReplace = cloneTreeNode(selectedNode);
nodeToReplace.setEnabled(true);
}
HashTree subtree = tree.add(nodeToReplace);
createSubTree(subtree, nodeToReplace);
}
return tree;
}
use of org.apache.jorphan.collections.HashTree in project jmeter by apache.
the class IncludeController method loadIncludedElements.
/**
* load the included elements using SaveService
*
* @return tree with loaded elements
*/
protected HashTree loadIncludedElements() {
// only try to load the JMX test plan if there is one
final String includePath = getIncludePath();
HashTree tree = null;
if (includePath != null && includePath.length() > 0) {
String fileName = PREFIX + includePath;
try {
File file = new File(fileName.trim());
final String absolutePath = file.getAbsolutePath();
log.info("loadIncludedElements -- try to load included module: {}", absolutePath);
if (!file.exists() && !file.isAbsolute()) {
log.info("loadIncludedElements -failed for: {}", absolutePath);
file = new File(FileServer.getFileServer().getBaseDir(), includePath);
if (log.isInfoEnabled()) {
log.info("loadIncludedElements -Attempting to read it from: {}", file.getAbsolutePath());
}
if (!file.canRead() || !file.isFile()) {
log.error("Include Controller '{}' can't load '{}' - see log for details", this.getName(), fileName);
throw new IOException("loadIncludedElements -failed for: " + absolutePath + " and " + file.getAbsolutePath());
}
}
tree = SaveService.loadTree(file);
// filter the tree for a TestFragment.
tree = getProperBranch(tree);
removeDisabledItems(tree);
return tree;
} catch (// Allow for missing optional jars
NoClassDefFoundError ex) {
String msg = "Including file \"" + fileName + "\" failed for Include Controller \"" + this.getName() + "\", missing jar file";
log.warn(msg, ex);
JMeterUtils.reportErrorToUser(msg + " - see log for details");
} catch (FileNotFoundException ex) {
String msg = "File \"" + fileName + "\" not found for Include Controller \"" + this.getName() + "\"";
JMeterUtils.reportErrorToUser(msg + " - see log for details");
log.warn(msg, ex);
} catch (Exception ex) {
String msg = "Including file \"" + fileName + "\" failed for Include Controller \"" + this.getName() + "\", unexpected error";
JMeterUtils.reportErrorToUser(msg + " - see log for details");
log.warn(msg, ex);
}
}
return tree;
}
use of org.apache.jorphan.collections.HashTree 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());
}
}
}
Aggregations