PageRenderTime 73ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/jmeter-2.5.1/src/core/org/apache/jmeter/JMeter.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 1061 lines | 858 code | 87 blank | 116 comment | 148 complexity | 1a83e4057eedce16f85a61d12e93b0cc MD5 | raw file
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. package org.apache.jmeter;
  19. import java.awt.event.ActionEvent;
  20. import java.io.File;
  21. import java.io.FileInputStream;
  22. import java.io.FileNotFoundException;
  23. import java.io.IOException;
  24. import java.lang.Thread.UncaughtExceptionHandler;
  25. import java.net.Authenticator;
  26. import java.net.DatagramPacket;
  27. import java.net.DatagramSocket;
  28. import java.net.InetAddress;
  29. import java.net.MalformedURLException;
  30. import java.net.SocketException;
  31. import java.text.SimpleDateFormat;
  32. import java.util.Collection;
  33. import java.util.Date;
  34. import java.util.Enumeration;
  35. import java.util.Iterator;
  36. import java.util.LinkedList;
  37. import java.util.List;
  38. import java.util.Locale;
  39. import java.util.Properties;
  40. import java.util.StringTokenizer;
  41. import java.util.concurrent.atomic.AtomicInteger;
  42. import org.apache.commons.cli.avalon.CLArgsParser;
  43. import org.apache.commons.cli.avalon.CLOption;
  44. import org.apache.commons.cli.avalon.CLOptionDescriptor;
  45. import org.apache.commons.cli.avalon.CLUtil;
  46. import org.apache.jmeter.control.ReplaceableController;
  47. import org.apache.jmeter.engine.ClientJMeterEngine;
  48. import org.apache.jmeter.engine.JMeterEngine;
  49. import org.apache.jmeter.engine.RemoteJMeterEngineImpl;
  50. import org.apache.jmeter.engine.StandardJMeterEngine;
  51. import org.apache.jmeter.engine.event.LoopIterationEvent;
  52. import org.apache.jmeter.exceptions.IllegalUserActionException;
  53. import org.apache.jmeter.gui.GuiPackage;
  54. import org.apache.jmeter.gui.MainFrame;
  55. import org.apache.jmeter.gui.action.ActionNames;
  56. import org.apache.jmeter.gui.action.ActionRouter;
  57. import org.apache.jmeter.gui.action.Load;
  58. import org.apache.jmeter.gui.action.LoadRecentProject;
  59. import org.apache.jmeter.gui.tree.JMeterTreeListener;
  60. import org.apache.jmeter.gui.tree.JMeterTreeModel;
  61. import org.apache.jmeter.gui.tree.JMeterTreeNode;
  62. import org.apache.jmeter.plugin.JMeterPlugin;
  63. import org.apache.jmeter.plugin.PluginManager;
  64. import org.apache.jmeter.reporters.ResultCollector;
  65. import org.apache.jmeter.reporters.Summariser;
  66. import org.apache.jmeter.samplers.Remoteable;
  67. import org.apache.jmeter.samplers.SampleEvent;
  68. import org.apache.jmeter.save.SaveService;
  69. import org.apache.jmeter.services.FileServer;
  70. import org.apache.jmeter.testelement.TestElement;
  71. import org.apache.jmeter.testelement.TestListener;
  72. import org.apache.jmeter.util.BeanShellInterpreter;
  73. import org.apache.jmeter.util.BeanShellServer;
  74. import org.apache.jmeter.util.JMeterUtils;
  75. import org.apache.jorphan.collections.HashTree;
  76. import org.apache.jorphan.collections.SearchByClass;
  77. import org.apache.jorphan.gui.ComponentUtil;
  78. import org.apache.jorphan.logging.LoggingManager;
  79. import org.apache.jorphan.reflect.ClassTools;
  80. import org.apache.jorphan.util.JMeterException;
  81. import org.apache.jorphan.util.JOrphanUtils;
  82. import org.apache.log.Logger;
  83. import com.thoughtworks.xstream.converters.ConversionException;
  84. /**
  85. * Main JMeter class; processes options and starts the GUI, non-GUI or server as appropriate.
  86. */
  87. public class JMeter implements JMeterPlugin {
  88. private static final Logger log = LoggingManager.getLoggerForClass();
  89. public static final int UDP_PORT_DEFAULT = 4445; // needed for ShutdownClient
  90. public static final String HTTP_PROXY_PASS = "http.proxyPass"; // $NON-NLS-1$
  91. public static final String HTTP_PROXY_USER = "http.proxyUser"; // $NON-NLS-1$
  92. public static final String JMETER_NON_GUI = "JMeter.NonGui"; // $NON-NLS-1$
  93. // If the -t flag is to "LAST", then the last loaded file (if any) is used
  94. private static final String USE_LAST_JMX = "LAST";
  95. // If the -j or -l flag is set to LAST or LAST.log|LAST.jtl, then the last loaded file name is used to
  96. // generate the log file name by removing .JMX and replacing it with .log|.jtl
  97. private static final int PROXY_PASSWORD = 'a';// $NON-NLS-1$
  98. private static final int JMETER_HOME_OPT = 'd';// $NON-NLS-1$
  99. private static final int HELP_OPT = 'h';// $NON-NLS-1$
  100. // jmeter.log
  101. private static final int JMLOGFILE_OPT = 'j';// $NON-NLS-1$
  102. // sample result log file
  103. private static final int LOGFILE_OPT = 'l';// $NON-NLS-1$
  104. private static final int NONGUI_OPT = 'n';// $NON-NLS-1$
  105. private static final int PROPFILE_OPT = 'p';// $NON-NLS-1$
  106. private static final int PROPFILE2_OPT = 'q';// $NON-NLS-1$
  107. private static final int REMOTE_OPT = 'r';// $NON-NLS-1$
  108. private static final int SERVER_OPT = 's';// $NON-NLS-1$
  109. private static final int TESTFILE_OPT = 't';// $NON-NLS-1$
  110. private static final int PROXY_USERNAME = 'u';// $NON-NLS-1$
  111. private static final int VERSION_OPT = 'v';// $NON-NLS-1$
  112. private static final int SYSTEM_PROPERTY = 'D';// $NON-NLS-1$
  113. private static final int JMETER_GLOBAL_PROP = 'G';// $NON-NLS-1$
  114. private static final int PROXY_HOST = 'H';// $NON-NLS-1$
  115. private static final int JMETER_PROPERTY = 'J';// $NON-NLS-1$
  116. private static final int LOGLEVEL = 'L';// $NON-NLS-1$
  117. private static final int NONPROXY_HOSTS = 'N';// $NON-NLS-1$
  118. private static final int PROXY_PORT = 'P';// $NON-NLS-1$
  119. private static final int REMOTE_OPT_PARAM = 'R';// $NON-NLS-1$
  120. private static final int SYSTEM_PROPFILE = 'S';// $NON-NLS-1$
  121. private static final int REMOTE_STOP = 'X';// $NON-NLS-1$
  122. /**
  123. * Define the understood options. Each CLOptionDescriptor contains:
  124. * <ul>
  125. * <li>The "long" version of the option. Eg, "help" means that "--help"
  126. * will be recognised.</li>
  127. * <li>The option flags, governing the option's argument(s).</li>
  128. * <li>The "short" version of the option. Eg, 'h' means that "-h" will be
  129. * recognised.</li>
  130. * <li>A description of the option.</li>
  131. * </ul>
  132. */
  133. private static final CLOptionDescriptor[] options = new CLOptionDescriptor[] {
  134. new CLOptionDescriptor("help", CLOptionDescriptor.ARGUMENT_DISALLOWED, HELP_OPT,
  135. "print usage information and exit"),
  136. new CLOptionDescriptor("version", CLOptionDescriptor.ARGUMENT_DISALLOWED, VERSION_OPT,
  137. "print the version information and exit"),
  138. new CLOptionDescriptor("propfile", CLOptionDescriptor.ARGUMENT_REQUIRED, PROPFILE_OPT,
  139. "the jmeter property file to use"),
  140. new CLOptionDescriptor("addprop", CLOptionDescriptor.ARGUMENT_REQUIRED
  141. | CLOptionDescriptor.DUPLICATES_ALLOWED, PROPFILE2_OPT,
  142. "additional JMeter property file(s)"),
  143. new CLOptionDescriptor("testfile", CLOptionDescriptor.ARGUMENT_REQUIRED, TESTFILE_OPT,
  144. "the jmeter test(.jmx) file to run"),
  145. new CLOptionDescriptor("logfile", CLOptionDescriptor.ARGUMENT_REQUIRED, LOGFILE_OPT,
  146. "the file to log samples to"),
  147. new CLOptionDescriptor("jmeterlogfile", CLOptionDescriptor.ARGUMENT_REQUIRED, JMLOGFILE_OPT,
  148. "jmeter run log file (jmeter.log)"),
  149. new CLOptionDescriptor("nongui", CLOptionDescriptor.ARGUMENT_DISALLOWED, NONGUI_OPT,
  150. "run JMeter in nongui mode"),
  151. new CLOptionDescriptor("server", CLOptionDescriptor.ARGUMENT_DISALLOWED, SERVER_OPT,
  152. "run the JMeter server"),
  153. new CLOptionDescriptor("proxyHost", CLOptionDescriptor.ARGUMENT_REQUIRED, PROXY_HOST,
  154. "Set a proxy server for JMeter to use"),
  155. new CLOptionDescriptor("proxyPort", CLOptionDescriptor.ARGUMENT_REQUIRED, PROXY_PORT,
  156. "Set proxy server port for JMeter to use"),
  157. new CLOptionDescriptor("nonProxyHosts", CLOptionDescriptor.ARGUMENT_REQUIRED, NONPROXY_HOSTS,
  158. "Set nonproxy host list (e.g. *.apache.org|localhost)"),
  159. new CLOptionDescriptor("username", CLOptionDescriptor.ARGUMENT_REQUIRED, PROXY_USERNAME,
  160. "Set username for proxy server that JMeter is to use"),
  161. new CLOptionDescriptor("password", CLOptionDescriptor.ARGUMENT_REQUIRED, PROXY_PASSWORD,
  162. "Set password for proxy server that JMeter is to use"),
  163. new CLOptionDescriptor("jmeterproperty", CLOptionDescriptor.DUPLICATES_ALLOWED
  164. | CLOptionDescriptor.ARGUMENTS_REQUIRED_2, JMETER_PROPERTY,
  165. "Define additional JMeter properties"),
  166. new CLOptionDescriptor("globalproperty", CLOptionDescriptor.DUPLICATES_ALLOWED
  167. | CLOptionDescriptor.ARGUMENTS_REQUIRED_2, JMETER_GLOBAL_PROP,
  168. "Define Global properties (sent to servers)\n\t\te.g. -Gport=123 or -Gglobal.properties"),
  169. new CLOptionDescriptor("systemproperty", CLOptionDescriptor.DUPLICATES_ALLOWED
  170. | CLOptionDescriptor.ARGUMENTS_REQUIRED_2, SYSTEM_PROPERTY,
  171. "Define additional system properties"),
  172. new CLOptionDescriptor("systemPropertyFile", CLOptionDescriptor.DUPLICATES_ALLOWED
  173. | CLOptionDescriptor.ARGUMENT_REQUIRED, SYSTEM_PROPFILE,
  174. "additional system property file(s)"),
  175. new CLOptionDescriptor("loglevel", CLOptionDescriptor.DUPLICATES_ALLOWED
  176. | CLOptionDescriptor.ARGUMENTS_REQUIRED_2, LOGLEVEL,
  177. "[category=]level e.g. jorphan=INFO or jmeter.util=DEBUG"),
  178. new CLOptionDescriptor("runremote", CLOptionDescriptor.ARGUMENT_DISALLOWED, REMOTE_OPT,
  179. "Start remote servers (as defined in remote_hosts)"),
  180. new CLOptionDescriptor("remotestart", CLOptionDescriptor.ARGUMENT_REQUIRED, REMOTE_OPT_PARAM,
  181. "Start these remote servers (overrides remote_hosts)"),
  182. new CLOptionDescriptor("homedir", CLOptionDescriptor.ARGUMENT_REQUIRED, JMETER_HOME_OPT,
  183. "the jmeter home directory to use"),
  184. new CLOptionDescriptor("remoteexit", CLOptionDescriptor.ARGUMENT_DISALLOWED, REMOTE_STOP,
  185. "Exit the remote servers at end of test (non-GUI)"),
  186. };
  187. public JMeter() {
  188. }
  189. // Hack to allow automated tests to find when test has ended
  190. //transient boolean testEnded = false;
  191. private JMeter parent;
  192. private Properties remoteProps; // Properties to be sent to remote servers
  193. private boolean remoteStop; // should remote engines be stopped at end of non-GUI test?
  194. /**
  195. * Starts up JMeter in GUI mode
  196. */
  197. private void startGui(String testFile) {
  198. PluginManager.install(this, true);
  199. JMeterTreeModel treeModel = new JMeterTreeModel();
  200. JMeterTreeListener treeLis = new JMeterTreeListener(treeModel);
  201. treeLis.setActionHandler(ActionRouter.getInstance());
  202. // NOTUSED: GuiPackage guiPack =
  203. GuiPackage.getInstance(treeLis, treeModel);
  204. MainFrame main = new MainFrame(ActionRouter.getInstance(), treeModel, treeLis);
  205. ComponentUtil.centerComponentInWindow(main, 80);
  206. main.setVisible(true);
  207. ActionRouter.getInstance().actionPerformed(new ActionEvent(main, 1, ActionNames.ADD_ALL));
  208. if (testFile != null) {
  209. FileInputStream reader = null;
  210. try {
  211. File f = new File(testFile);
  212. log.info("Loading file: " + f);
  213. reader = new FileInputStream(f);
  214. HashTree tree = SaveService.loadTree(reader);
  215. GuiPackage.getInstance().setTestPlanFile(f.getAbsolutePath());
  216. Load.insertLoadedTree(1, tree);
  217. } catch (ConversionException e) {
  218. log.error("Failure loading test file", e);
  219. JMeterUtils.reportErrorToUser(SaveService.CEtoString(e));
  220. } catch (Exception e) {
  221. log.error("Failure loading test file", e);
  222. JMeterUtils.reportErrorToUser(e.toString());
  223. } finally {
  224. JOrphanUtils.closeQuietly(reader);
  225. }
  226. }
  227. }
  228. /**
  229. * Takes the command line arguments and uses them to determine how to
  230. * startup JMeter.
  231. *
  232. * Called reflectively by {@link NewDriver#main(String[])}
  233. */
  234. public void start(String[] args) {
  235. CLArgsParser parser = new CLArgsParser(args, options);
  236. String error = parser.getErrorString();
  237. if (error == null){// Check option combinations
  238. boolean gui = parser.getArgumentById(NONGUI_OPT)==null;
  239. boolean nonGuiOnly = parser.getArgumentById(REMOTE_OPT)!=null
  240. || parser.getArgumentById(REMOTE_OPT_PARAM)!=null
  241. || parser.getArgumentById(REMOTE_STOP)!=null;
  242. if (gui && nonGuiOnly) {
  243. error = "-r and -R and -X are only valid in non-GUI mode";
  244. }
  245. }
  246. if (null != error) {
  247. System.err.println("Error: " + error);
  248. System.out.println("Usage");
  249. System.out.println(CLUtil.describeOptions(options).toString());
  250. return;
  251. }
  252. try {
  253. initializeProperties(parser); // Also initialises JMeter logging
  254. /*
  255. * The following is needed for HTTPClient.
  256. * (originally tried doing this in HTTPSampler2,
  257. * but it appears that it was done too late when running in GUI mode)
  258. * Set the commons logging default to Avalon Logkit, if not already defined
  259. */
  260. if (System.getProperty("org.apache.commons.logging.Log") == null) { // $NON-NLS-1$
  261. System.setProperty("org.apache.commons.logging.Log" // $NON-NLS-1$
  262. , "org.apache.commons.logging.impl.LogKitLogger"); // $NON-NLS-1$
  263. }
  264. Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
  265. public void uncaughtException(Thread t, Throwable e) {
  266. if (!(e instanceof ThreadDeath)) {
  267. log.error("Uncaught exception: ", e);
  268. System.err.println("Uncaught Exception " + e + ". See log file for details.");
  269. }
  270. }
  271. });
  272. log.info(JMeterUtils.getJMeterCopyright());
  273. log.info("Version " + JMeterUtils.getJMeterVersion());
  274. logProperty("java.version"); //$NON-NLS-1$
  275. logProperty("java.vm.name"); //$NON-NLS-1$
  276. logProperty("os.name"); //$NON-NLS-1$
  277. logProperty("os.arch"); //$NON-NLS-1$
  278. logProperty("os.version"); //$NON-NLS-1$
  279. logProperty("file.encoding"); // $NON-NLS-1$
  280. log.info("Default Locale=" + Locale.getDefault().getDisplayName());
  281. log.info("JMeter Locale=" + JMeterUtils.getLocale().getDisplayName());
  282. log.info("JMeterHome=" + JMeterUtils.getJMeterHome());
  283. logProperty("user.dir"," ="); //$NON-NLS-1$
  284. log.info("PWD ="+new File(".").getCanonicalPath());//$NON-NLS-1$
  285. log.info("IP: "+JMeterUtils.getLocalHostIP()
  286. +" Name: "+JMeterUtils.getLocalHostName()
  287. +" FullName: "+JMeterUtils.getLocalHostFullName());
  288. setProxy(parser);
  289. updateClassLoader();
  290. if (log.isDebugEnabled())
  291. {
  292. String jcp=System.getProperty("java.class.path");// $NON-NLS-1$
  293. String bits[] =jcp.split(File.pathSeparator);
  294. log.debug("ClassPath");
  295. for(int i = 0; i<bits.length ;i++){
  296. log.debug(bits[i]);
  297. }
  298. log.debug(jcp);
  299. }
  300. // Set some (hopefully!) useful properties
  301. long now=System.currentTimeMillis();
  302. JMeterUtils.setProperty("START.MS",Long.toString(now));// $NON-NLS-1$
  303. Date today=new Date(now); // so it agrees with above
  304. // TODO perhaps should share code with __time() function for this...
  305. JMeterUtils.setProperty("START.YMD",new SimpleDateFormat("yyyyMMdd").format(today));// $NON-NLS-1$ $NON-NLS-2$
  306. JMeterUtils.setProperty("START.HMS",new SimpleDateFormat("HHmmss").format(today));// $NON-NLS-1$ $NON-NLS-2$
  307. if (parser.getArgumentById(VERSION_OPT) != null) {
  308. System.out.println(JMeterUtils.getJMeterCopyright());
  309. System.out.println("Version " + JMeterUtils.getJMeterVersion());
  310. } else if (parser.getArgumentById(HELP_OPT) != null) {
  311. System.out.println(JMeterUtils.getResourceFileAsText("org/apache/jmeter/help.txt"));// $NON-NLS-1$
  312. } else if (parser.getArgumentById(SERVER_OPT) != null) {
  313. // Start the server
  314. try {
  315. RemoteJMeterEngineImpl.startServer(JMeterUtils.getPropDefault("server_port", 0)); // $NON-NLS-1$
  316. } catch (Exception ex) {
  317. System.err.println("Server failed to start: "+ex);
  318. log.error("Giving up, as server failed with:", ex);
  319. throw ex;
  320. }
  321. startOptionalServers();
  322. } else {
  323. String testFile=null;
  324. CLOption testFileOpt = parser.getArgumentById(TESTFILE_OPT);
  325. if (testFileOpt != null){
  326. testFile = testFileOpt.getArgument();
  327. if (USE_LAST_JMX.equals(testFile)) {
  328. testFile = LoadRecentProject.getRecentFile(0);// most recent
  329. }
  330. }
  331. if (parser.getArgumentById(NONGUI_OPT) == null) {
  332. startGui(testFile);
  333. startOptionalServers();
  334. } else {
  335. CLOption rem=parser.getArgumentById(REMOTE_OPT_PARAM);
  336. if (rem==null) { rem=parser.getArgumentById(REMOTE_OPT); }
  337. CLOption jtl = parser.getArgumentById(LOGFILE_OPT);
  338. String jtlFile = null;
  339. if (jtl != null){
  340. jtlFile=processLAST(jtl.getArgument(), ".jtl"); // $NON-NLS-1$
  341. }
  342. startNonGui(testFile, jtlFile, rem);
  343. startOptionalServers();
  344. }
  345. }
  346. } catch (IllegalUserActionException e) {
  347. System.out.println(e.getMessage());
  348. System.out.println("Incorrect Usage");
  349. System.out.println(CLUtil.describeOptions(options).toString());
  350. } catch (Throwable e) {
  351. if (log != null){
  352. log.fatalError("An error occurred: ",e);
  353. } else {
  354. e.printStackTrace();
  355. }
  356. System.out.println("An error occurred: " + e.getMessage());
  357. System.exit(1); // TODO - could this be return?
  358. }
  359. }
  360. // Update classloader if necessary
  361. private void updateClassLoader() {
  362. updatePath("search_paths",";"); //$NON-NLS-1$//$NON-NLS-2$
  363. updatePath("user.classpath",File.pathSeparator);//$NON-NLS-1$
  364. }
  365. private void updatePath(String property, String sep) {
  366. String userpath= JMeterUtils.getPropDefault(property,"");// $NON-NLS-1$
  367. if (userpath.length() <= 0) { return; }
  368. log.info(property+"="+userpath); //$NON-NLS-1$
  369. StringTokenizer tok = new StringTokenizer(userpath, sep);
  370. while(tok.hasMoreTokens()) {
  371. String path=tok.nextToken();
  372. File f=new File(path);
  373. if (!f.canRead() && !f.isDirectory()) {
  374. log.warn("Can't read "+path);
  375. } else {
  376. log.info("Adding to classpath: "+path);
  377. try {
  378. NewDriver.addPath(path);
  379. } catch (MalformedURLException e) {
  380. log.warn("Error adding: "+path+" "+e.getLocalizedMessage());
  381. }
  382. }
  383. }
  384. }
  385. /**
  386. *
  387. */
  388. private void startOptionalServers() {
  389. int bshport = JMeterUtils.getPropDefault("beanshell.server.port", 0);// $NON-NLS-1$
  390. String bshfile = JMeterUtils.getPropDefault("beanshell.server.file", "");// $NON-NLS-1$ $NON-NLS-2$
  391. if (bshport > 0) {
  392. log.info("Starting Beanshell server (" + bshport + "," + bshfile + ")");
  393. Runnable t = new BeanShellServer(bshport, bshfile);
  394. t.run();
  395. }
  396. // Should we run a beanshell script on startup?
  397. String bshinit = JMeterUtils.getProperty("beanshell.init.file");// $NON-NLS-1$
  398. if (bshinit != null){
  399. log.info("Run Beanshell on file: "+bshinit);
  400. try {
  401. BeanShellInterpreter bsi = new BeanShellInterpreter();//bshinit,log);
  402. bsi.source(bshinit);
  403. } catch (ClassNotFoundException e) {
  404. log.warn("Could not start Beanshell: "+e.getLocalizedMessage());
  405. } catch (JMeterException e) {
  406. log.warn("Could not process Beanshell file: "+e.getLocalizedMessage());
  407. }
  408. }
  409. int mirrorPort=JMeterUtils.getPropDefault("mirror.server.port", 0);// $NON-NLS-1$
  410. if (mirrorPort > 0){
  411. log.info("Starting Mirror server (" + mirrorPort + ")");
  412. try {
  413. Object instance = ClassTools.construct(
  414. "org.apache.jmeter.protocol.http.control.HttpMirrorControl",// $NON-NLS-1$
  415. mirrorPort);
  416. ClassTools.invoke(instance,"startHttpMirror");
  417. } catch (JMeterException e) {
  418. log.warn("Could not start Mirror server",e);
  419. }
  420. }
  421. }
  422. /**
  423. * Sets a proxy server for the JVM if the command line arguments are
  424. * specified.
  425. */
  426. private void setProxy(CLArgsParser parser) throws IllegalUserActionException {
  427. if (parser.getArgumentById(PROXY_USERNAME) != null) {
  428. Properties jmeterProps = JMeterUtils.getJMeterProperties();
  429. if (parser.getArgumentById(PROXY_PASSWORD) != null) {
  430. String u, p;
  431. Authenticator.setDefault(new ProxyAuthenticator(u = parser.getArgumentById(PROXY_USERNAME)
  432. .getArgument(), p = parser.getArgumentById(PROXY_PASSWORD).getArgument()));
  433. log.info("Set Proxy login: " + u + "/" + p);
  434. jmeterProps.setProperty(HTTP_PROXY_USER, u);//for Httpclient
  435. jmeterProps.setProperty(HTTP_PROXY_PASS, p);//for Httpclient
  436. } else {
  437. String u;
  438. Authenticator.setDefault(new ProxyAuthenticator(u = parser.getArgumentById(PROXY_USERNAME)
  439. .getArgument(), ""));
  440. log.info("Set Proxy login: " + u);
  441. jmeterProps.setProperty(HTTP_PROXY_USER, u);
  442. }
  443. }
  444. if (parser.getArgumentById(PROXY_HOST) != null && parser.getArgumentById(PROXY_PORT) != null) {
  445. String h = parser.getArgumentById(PROXY_HOST).getArgument();
  446. String p = parser.getArgumentById(PROXY_PORT).getArgument();
  447. System.setProperty("http.proxyHost", h );// $NON-NLS-1$
  448. System.setProperty("https.proxyHost", h);// $NON-NLS-1$
  449. System.setProperty("http.proxyPort", p);// $NON-NLS-1$
  450. System.setProperty("https.proxyPort", p);// $NON-NLS-1$
  451. log.info("Set http[s].proxyHost: " + h + " Port: " + p);
  452. } else if (parser.getArgumentById(PROXY_HOST) != null || parser.getArgumentById(PROXY_PORT) != null) {
  453. throw new IllegalUserActionException(JMeterUtils.getResString("proxy_cl_error"));// $NON-NLS-1$
  454. }
  455. if (parser.getArgumentById(NONPROXY_HOSTS) != null) {
  456. String n = parser.getArgumentById(NONPROXY_HOSTS).getArgument();
  457. System.setProperty("http.nonProxyHosts", n );// $NON-NLS-1$
  458. System.setProperty("https.nonProxyHosts", n );// $NON-NLS-1$
  459. log.info("Set http[s].nonProxyHosts: "+n);
  460. }
  461. }
  462. private void initializeProperties(CLArgsParser parser) {
  463. if (parser.getArgumentById(PROPFILE_OPT) != null) {
  464. JMeterUtils.loadJMeterProperties(parser.getArgumentById(PROPFILE_OPT).getArgument());
  465. } else {
  466. JMeterUtils.loadJMeterProperties(NewDriver.getJMeterDir() + File.separator
  467. + "bin" + File.separator // $NON-NLS-1$
  468. + "jmeter.properties");// $NON-NLS-1$
  469. }
  470. if (parser.getArgumentById(JMLOGFILE_OPT) != null){
  471. String jmlogfile=parser.getArgumentById(JMLOGFILE_OPT).getArgument();
  472. jmlogfile = processLAST(jmlogfile, ".log");// $NON-NLS-1$
  473. JMeterUtils.setProperty(LoggingManager.LOG_FILE,jmlogfile);
  474. }
  475. JMeterUtils.initLogging();
  476. JMeterUtils.initLocale();
  477. // Bug 33845 - allow direct override of Home dir
  478. if (parser.getArgumentById(JMETER_HOME_OPT) == null) {
  479. JMeterUtils.setJMeterHome(NewDriver.getJMeterDir());
  480. } else {
  481. JMeterUtils.setJMeterHome(parser.getArgumentById(JMETER_HOME_OPT).getArgument());
  482. }
  483. Properties jmeterProps = JMeterUtils.getJMeterProperties();
  484. remoteProps = new Properties();
  485. // Add local JMeter properties, if the file is found
  486. String userProp = JMeterUtils.getPropDefault("user.properties",""); //$NON-NLS-1$
  487. if (userProp.length() > 0){ //$NON-NLS-1$
  488. FileInputStream fis=null;
  489. try {
  490. File file = JMeterUtils.findFile(userProp);
  491. if (file.canRead()){
  492. log.info("Loading user properties from: "+file.getCanonicalPath());
  493. fis = new FileInputStream(file);
  494. Properties tmp = new Properties();
  495. tmp.load(fis);
  496. jmeterProps.putAll(tmp);
  497. LoggingManager.setLoggingLevels(tmp);//Do what would be done earlier
  498. }
  499. } catch (IOException e) {
  500. log.warn("Error loading user property file: " + userProp, e);
  501. } finally {
  502. JOrphanUtils.closeQuietly(fis);
  503. }
  504. }
  505. // Add local system properties, if the file is found
  506. String sysProp = JMeterUtils.getPropDefault("system.properties",""); //$NON-NLS-1$
  507. if (sysProp.length() > 0){
  508. FileInputStream fis=null;
  509. try {
  510. File file = JMeterUtils.findFile(sysProp);
  511. if (file.canRead()){
  512. log.info("Loading system properties from: "+file.getCanonicalPath());
  513. fis = new FileInputStream(file);
  514. System.getProperties().load(fis);
  515. }
  516. } catch (IOException e) {
  517. log.warn("Error loading system property file: " + sysProp, e);
  518. } finally {
  519. JOrphanUtils.closeQuietly(fis);
  520. }
  521. }
  522. // Process command line property definitions
  523. // These can potentially occur multiple times
  524. List<CLOption> clOptions = parser.getArguments();
  525. int size = clOptions.size();
  526. for (int i = 0; i < size; i++) {
  527. CLOption option = clOptions.get(i);
  528. String name = option.getArgument(0);
  529. String value = option.getArgument(1);
  530. FileInputStream fis = null;
  531. switch (option.getDescriptor().getId()) {
  532. // Should not have any text arguments
  533. case CLOption.TEXT_ARGUMENT:
  534. throw new IllegalArgumentException("Unknown arg: "+option.getArgument());
  535. case PROPFILE2_OPT: // Bug 33920 - allow multiple props
  536. try {
  537. fis = new FileInputStream(new File(name));
  538. Properties tmp = new Properties();
  539. tmp.load(fis);
  540. jmeterProps.putAll(tmp);
  541. LoggingManager.setLoggingLevels(tmp);//Do what would be done earlier
  542. } catch (FileNotFoundException e) {
  543. log.warn("Can't find additional property file: " + name, e);
  544. } catch (IOException e) {
  545. log.warn("Error loading additional property file: " + name, e);
  546. } finally {
  547. JOrphanUtils.closeQuietly(fis);
  548. }
  549. break;
  550. case SYSTEM_PROPFILE:
  551. log.info("Setting System properties from file: " + name);
  552. try {
  553. fis = new FileInputStream(new File(name));
  554. System.getProperties().load(fis);
  555. } catch (IOException e) {
  556. log.warn("Cannot find system property file "+e.getLocalizedMessage());
  557. } finally {
  558. JOrphanUtils.closeQuietly(fis);
  559. }
  560. break;
  561. case SYSTEM_PROPERTY:
  562. if (value.length() > 0) { // Set it
  563. log.info("Setting System property: " + name + "=" + value);
  564. System.getProperties().setProperty(name, value);
  565. } else { // Reset it
  566. log.warn("Removing System property: " + name);
  567. System.getProperties().remove(name);
  568. }
  569. break;
  570. case JMETER_PROPERTY:
  571. if (value.length() > 0) { // Set it
  572. log.info("Setting JMeter property: " + name + "=" + value);
  573. jmeterProps.setProperty(name, value);
  574. } else { // Reset it
  575. log.warn("Removing JMeter property: " + name);
  576. jmeterProps.remove(name);
  577. }
  578. break;
  579. case JMETER_GLOBAL_PROP:
  580. if (value.length() > 0) { // Set it
  581. log.info("Setting Global property: " + name + "=" + value);
  582. remoteProps.setProperty(name, value);
  583. } else {
  584. File propFile = new File(name);
  585. if (propFile.canRead()) {
  586. log.info("Setting Global properties from the file "+name);
  587. try {
  588. fis = new FileInputStream(propFile);
  589. remoteProps.load(fis);
  590. } catch (FileNotFoundException e) {
  591. log.warn("Could not find properties file: "+e.getLocalizedMessage());
  592. } catch (IOException e) {
  593. log.warn("Could not load properties file: "+e.getLocalizedMessage());
  594. } finally {
  595. JOrphanUtils.closeQuietly(fis);
  596. }
  597. }
  598. }
  599. break;
  600. case LOGLEVEL:
  601. if (value.length() > 0) { // Set category
  602. log.info("LogLevel: " + name + "=" + value);
  603. LoggingManager.setPriority(value, name);
  604. } else { // Set root level
  605. log.warn("LogLevel: " + name);
  606. LoggingManager.setPriority(name);
  607. }
  608. break;
  609. case REMOTE_STOP:
  610. remoteStop = true;
  611. break;
  612. }
  613. }
  614. String sample_variables = (String) jmeterProps.get(SampleEvent.SAMPLE_VARIABLES);
  615. if (sample_variables != null){
  616. remoteProps.put(SampleEvent.SAMPLE_VARIABLES, sample_variables);
  617. }
  618. }
  619. /*
  620. * Checks for LAST or LASTsuffix.
  621. * Returns the LAST name with .JMX replaced by suffix.
  622. */
  623. private String processLAST(String jmlogfile, String suffix) {
  624. if (USE_LAST_JMX.equals(jmlogfile) || USE_LAST_JMX.concat(suffix).equals(jmlogfile)){
  625. String last = LoadRecentProject.getRecentFile(0);// most recent
  626. final String JMX_SUFFIX = ".JMX"; // $NON-NLS-1$
  627. if (last.toUpperCase(Locale.ENGLISH).endsWith(JMX_SUFFIX)){
  628. jmlogfile=last.substring(0, last.length() - JMX_SUFFIX.length()).concat(suffix);
  629. }
  630. }
  631. return jmlogfile;
  632. }
  633. private void startNonGui(String testFile, String logFile, CLOption remoteStart)
  634. throws IllegalUserActionException {
  635. // add a system property so samplers can check to see if JMeter
  636. // is running in NonGui mode
  637. System.setProperty(JMETER_NON_GUI, "true");// $NON-NLS-1$
  638. JMeter driver = new JMeter();// TODO - why does it create a new instance?
  639. driver.remoteProps = this.remoteProps;
  640. driver.remoteStop = this.remoteStop;
  641. driver.parent = this;
  642. PluginManager.install(this, false);
  643. String remote_hosts_string = null;
  644. if (remoteStart != null) {
  645. remote_hosts_string = remoteStart.getArgument();
  646. if (remote_hosts_string == null) {
  647. remote_hosts_string = JMeterUtils.getPropDefault(
  648. "remote_hosts", //$NON-NLS-1$
  649. "127.0.0.1");//$NON-NLS-1$
  650. }
  651. }
  652. if (testFile == null) {
  653. throw new IllegalUserActionException("Non-GUI runs require a test plan");
  654. }
  655. driver.runNonGui(testFile, logFile, remoteStart != null, remote_hosts_string);
  656. }
  657. // run test in batch mode
  658. private void runNonGui(String testFile, String logFile, boolean remoteStart, String remote_hosts_string) {
  659. FileInputStream reader = null;
  660. try {
  661. File f = new File(testFile);
  662. if (!f.exists() || !f.isFile()) {
  663. println("Could not open " + testFile);
  664. return;
  665. }
  666. FileServer.getFileServer().setBaseForScript(f);
  667. reader = new FileInputStream(f);
  668. log.info("Loading file: " + f);
  669. HashTree tree = SaveService.loadTree(reader);
  670. @SuppressWarnings("deprecation") // Deliberate use of deprecated ctor
  671. JMeterTreeModel treeModel = new JMeterTreeModel(new Object());// Create non-GUI version to avoid headless problems
  672. JMeterTreeNode root = (JMeterTreeNode) treeModel.getRoot();
  673. treeModel.addSubTree(tree, root);
  674. // Hack to resolve ModuleControllers in non GUI mode
  675. SearchByClass<ReplaceableController> replaceableControllers = new SearchByClass<ReplaceableController>(ReplaceableController.class);
  676. tree.traverse(replaceableControllers);
  677. Collection<ReplaceableController> replaceableControllersRes = replaceableControllers.getSearchResults();
  678. for (Iterator<ReplaceableController> iter = replaceableControllersRes.iterator(); iter.hasNext();) {
  679. ReplaceableController replaceableController = iter.next();
  680. replaceableController.resolveReplacementSubTree(root);
  681. }
  682. // Remove the disabled items
  683. // For GUI runs this is done in Start.java
  684. convertSubTree(tree);
  685. Summariser summer = null;
  686. String summariserName = JMeterUtils.getPropDefault("summariser.name", "");//$NON-NLS-1$
  687. if (summariserName.length() > 0) {
  688. log.info("Creating summariser <" + summariserName + ">");
  689. println("Creating summariser <" + summariserName + ">");
  690. summer = new Summariser(summariserName);
  691. }
  692. if (logFile != null) {
  693. ResultCollector logger = new ResultCollector(summer);
  694. logger.setFilename(logFile);
  695. tree.add(tree.getArray()[0], logger);
  696. }
  697. else {
  698. // only add Summariser if it can not be shared with the ResultCollector
  699. if (summer != null) {
  700. tree.add(tree.getArray()[0], summer);
  701. }
  702. }
  703. List<JMeterEngine> engines = new LinkedList<JMeterEngine>();
  704. tree.add(tree.getArray()[0], new ListenToTest(parent, (remoteStart && remoteStop) ? engines : null));
  705. println("Created the tree successfully using "+testFile);
  706. JMeterEngine engine = null;
  707. if (!remoteStart) {
  708. engine = new StandardJMeterEngine();
  709. engine.configure(tree);
  710. long now=System.currentTimeMillis();
  711. println("Starting the test @ "+new Date(now)+" ("+now+")");
  712. engine.runTest();
  713. } else {
  714. java.util.StringTokenizer st = new java.util.StringTokenizer(remote_hosts_string, ",");//$NON-NLS-1$
  715. while (st.hasMoreElements()) {
  716. String el = (String) st.nextElement();
  717. println("Configuring remote engine for " + el);
  718. log.info("Configuring remote engine for " + el);
  719. JMeterEngine eng = doRemoteInit(el.trim(), tree);
  720. if (null != eng) {
  721. engines.add(eng);
  722. } else {
  723. println("Failed to configure "+el);
  724. }
  725. }
  726. if (engines.isEmpty()) {
  727. println("No remote engines were started.");
  728. return;
  729. }
  730. println("Starting remote engines");
  731. log.info("Starting remote engines");
  732. long now=System.currentTimeMillis();
  733. println("Starting the test @ "+new Date(now)+" ("+now+")");
  734. Iterator<JMeterEngine> iter = engines.iterator();
  735. while (iter.hasNext()) {
  736. engine = iter.next();
  737. engine.runTest();
  738. }
  739. println("Remote engines have been started");
  740. log.info("Remote engines have been started");
  741. }
  742. startUdpDdaemon(engine);
  743. } catch (Exception e) {
  744. System.out.println("Error in NonGUIDriver " + e.toString());
  745. log.error("Error in NonGUIDriver", e);
  746. } finally {
  747. JOrphanUtils.closeQuietly(reader);
  748. }
  749. }
  750. /**
  751. * Refactored from AbstractAction.java
  752. *
  753. * @param tree
  754. */
  755. public static void convertSubTree(HashTree tree) {
  756. Iterator<Object> iter = new LinkedList<Object>(tree.list()).iterator();
  757. while (iter.hasNext()) {
  758. Object o = iter.next();
  759. if (o instanceof TestElement) {
  760. TestElement item = (TestElement) o;
  761. if (item.isEnabled()) {
  762. if (item instanceof ReplaceableController) {
  763. ReplaceableController rc;
  764. // TODO this bit of code needs to be tidied up
  765. // Unfortunately ModuleController is in components, not core
  766. if (item.getClass().getName().equals("org.apache.jmeter.control.ModuleController")){ // Bug 47165
  767. rc = (ReplaceableController) item;
  768. } else {
  769. // HACK: force the controller to load its tree
  770. rc = (ReplaceableController) item.clone();
  771. }
  772. HashTree subTree = tree.getTree(item);
  773. if (subTree != null) {
  774. HashTree replacementTree = rc.getReplacementSubTree();
  775. if (replacementTree != null) {
  776. convertSubTree(replacementTree);
  777. tree.replace(item, rc);
  778. tree.set(rc, replacementTree);
  779. }
  780. } else { // null subTree
  781. convertSubTree(tree.getTree(item));
  782. }
  783. } else { // not Replaceable Controller
  784. convertSubTree(tree.getTree(item));
  785. }
  786. } else { // Not enabled
  787. tree.remove(item);
  788. }
  789. } else { // Not a TestElement
  790. JMeterTreeNode item = (JMeterTreeNode) o;
  791. if (item.isEnabled()) {
  792. // Replacement only needs to occur when starting the engine
  793. // @see StandardJMeterEngine.run()
  794. if (item.getUserObject() instanceof ReplaceableController) {
  795. ReplaceableController rc =
  796. (ReplaceableController) item.getTestElement();
  797. HashTree subTree = tree.getTree(item);
  798. if (subTree != null) {
  799. HashTree replacementTree = rc.getReplacementSubTree();
  800. if (replacementTree != null) {
  801. convertSubTree(replacementTree);
  802. tree.replace(item, rc);
  803. tree.set(rc, replacementTree);
  804. }
  805. }
  806. } else { // Not a ReplaceableController
  807. convertSubTree(tree.getTree(item));
  808. TestElement testElement = item.getTestElement();
  809. tree.replace(item, testElement);
  810. }
  811. } else { // Not enabled
  812. tree.remove(item);
  813. }
  814. }
  815. }
  816. }
  817. private JMeterEngine doRemoteInit(String hostName, HashTree testTree) {
  818. JMeterEngine engine = null;
  819. try {
  820. engine = new ClientJMeterEngine(hostName);
  821. } catch (Exception e) {
  822. log.fatalError("Failure connecting to remote host: "+hostName, e);
  823. System.err.println("Failure connecting to remote host: "+hostName+" "+e);
  824. return null;
  825. }
  826. engine.configure(testTree);
  827. if (!remoteProps.isEmpty()) {
  828. engine.setProperties(remoteProps);
  829. }
  830. return engine;
  831. }
  832. /*
  833. * Listen to test and handle tidyup after non-GUI test completes.
  834. * If running a remote test, then after waiting a few seconds for listeners to finish files,
  835. * it calls ClientJMeterEngine.tidyRMI() to deal with the Naming Timer Thread.
  836. */
  837. private static class ListenToTest implements TestListener, Runnable, Remoteable {
  838. private AtomicInteger started = new AtomicInteger(0); // keep track of remote tests
  839. //NOT YET USED private JMeter _parent;
  840. private final List<JMeterEngine> engines;
  841. public ListenToTest(JMeter parent, List<JMeterEngine> engines) {
  842. //_parent = parent;
  843. this.engines=engines;
  844. }
  845. public void testEnded(String host) {
  846. long now=System.currentTimeMillis();
  847. log.info("Finished remote host: " + host + " ("+now+")");
  848. if (started.decrementAndGet() <= 0) {
  849. Thread stopSoon = new Thread(this);
  850. stopSoon.start();
  851. }
  852. }
  853. public void testEnded() {
  854. long now = System.currentTimeMillis();
  855. println("Tidying up ... @ "+new Date(now)+" ("+now+")");
  856. println("... end of run");
  857. }
  858. public void testStarted(String host) {
  859. started.incrementAndGet();
  860. long now=System.currentTimeMillis();
  861. log.info("Started remote host: " + host + " ("+now+")");
  862. }
  863. public void testStarted() {
  864. long now=System.currentTimeMillis();
  865. log.info(JMeterUtils.getResString("running_test")+" ("+now+")");//$NON-NLS-1$
  866. }
  867. /**
  868. * This is a hack to allow listeners a chance to close their files. Must
  869. * implement a queue for sample responses tied to the engine, and the
  870. * engine won't deliver testEnded signal till all sample responses have
  871. * been delivered. Should also improve performance of remote JMeter
  872. * testing.
  873. */
  874. public void run() {
  875. long now = System.currentTimeMillis();
  876. println("Tidying up remote @ "+new Date(now)+" ("+now+")");
  877. if (engines!=null){ // it will be null unless remoteStop = true
  878. println("Exitting remote servers");
  879. Iterator<JMeterEngine> it = engines.iterator();
  880. while(it.hasNext()){
  881. JMeterEngine e = it.next();
  882. e.exit();
  883. }
  884. }
  885. try {
  886. Thread.sleep(5000); // Allow listeners to close files
  887. } catch (InterruptedException ignored) {
  888. }
  889. ClientJMeterEngine.tidyRMI(log);
  890. println("... end of run");
  891. }
  892. /**
  893. * @see TestListener#testIterationStart(LoopIterationEvent)
  894. */
  895. public void testIterationStart(LoopIterationEvent event) {
  896. // ignored
  897. }
  898. }
  899. private static void println(String str) {
  900. System.out.println(str);
  901. }
  902. private static final String[][] DEFAULT_ICONS = {
  903. { "org.apache.jmeter.control.gui.TestPlanGui", "org/apache/jmeter/images/beaker.gif" }, //$NON-NLS-1$ $NON-NLS-2$
  904. { "org.apache.jmeter.timers.gui.AbstractTimerGui", "org/apache/jmeter/images/timer.gif" }, //$NON-NLS-1$ $NON-NLS-2$
  905. { "org.apache.jmeter.threads.gui.ThreadGroupGui", "org/apache/jmeter/images/thread.gif" }, //$NON-NLS-1$ $NON-NLS-2$
  906. { "org.apache.jmeter.visualizers.gui.AbstractListenerGui", "org/apache/jmeter/images/meter.png" }, //$NON-NLS-1$ $NON-NLS-2$
  907. { "org.apache.jmeter.config.gui.AbstractConfigGui", "org/apache/jmeter/images/testtubes.png" }, //$NON-NLS-1$ $NON-NLS-2$
  908. { "org.apache.jmeter.processor.gui.AbstractPreProcessorGui", "org/apache/jmeter/images/leafnode.gif"}, //$NON-NLS-1$ $NON-NLS-2$
  909. { "org.apache.jmeter.processor.gui.AbstractPostProcessorGui","org/apache/jmeter/images/leafnodeflip.gif"},//$NON-NLS-1$ $NON-NLS-2$
  910. { "org.apache.jmeter.control.gui.AbstractControllerGui", "org/apache/jmeter/images/knob.gif" }, //$NON-NLS-1$ $NON-NLS-2$
  911. { "org.apache.jmeter.control.gui.WorkBenchGui", "org/apache/jmeter/images/clipboard.gif" }, //$NON-NLS-1$ $NON-NLS-2$
  912. { "org.apache.jmeter.samplers.gui.AbstractSamplerGui", "org/apache/jmeter/images/pipet.png" }, //$NON-NLS-1$ $NON-NLS-2$
  913. { "org.apache.jmeter.assertions.gui.AbstractAssertionGui", "org/apache/jmeter/images/question.gif"} //$NON-NLS-1$ $NON-NLS-2$
  914. };
  915. public String[][] getIconMappings() {
  916. final String defaultIconProp = "org/apache/jmeter/images/icon.properties"; //$NON-NLS-1$
  917. String iconProp = JMeterUtils.getPropDefault("jmeter.icons", defaultIconProp);//$NON-NLS-1$
  918. Properties p = JMeterUtils.loadProperties(iconProp);
  919. if (p == null && !iconProp.equals(defaultIconProp)) {
  920. log.info(iconProp + " not found - using " + defaultIconProp);
  921. iconProp = defaultIconProp;
  922. p = JMeterUtils.loadProperties(iconProp);
  923. }
  924. if (p == null) {
  925. log.info(iconProp + " not found - using inbuilt icon set");
  926. return DEFAULT_ICONS;
  927. }
  928. log.info("Loaded icon properties from " + iconProp);
  929. String[][] iconlist = new String[p.size()][3];
  930. Enumeration<?> pe = p.keys();
  931. int i = 0;
  932. while (pe.hasMoreElements()) {
  933. String key = (String) pe.nextElement();
  934. String icons[] = JOrphanUtils.split(p.getProperty(key), " ");//$NON-NLS-1$
  935. iconlist[i][0] = key;
  936. iconlist[i][1] = icons[0];
  937. if (icons.length > 1) {
  938. iconlist[i][2] = icons[1];
  939. }
  940. i++;
  941. }
  942. return iconlist;
  943. }
  944. public String[][] getResourceBundles() {
  945. return new String[0][];
  946. }
  947. /**
  948. * Check if JMeter is running in non-GUI mode.
  949. *
  950. * @return true if JMeter is running in non-GUI mode.
  951. */
  952. public static boolean isNonGUI(){
  953. return "true".equals(System.getProperty(JMeter.JMETER_NON_GUI)); //$NON-NLS-1$
  954. }
  955. private void logProperty(String prop){
  956. log.info(prop+"="+System.getProperty(prop));//$NON-NLS-1$
  957. }
  958. private void logProperty(String prop,String separator){
  959. log.info(prop+separator+System.getProperty(prop));//$NON-NLS-1$
  960. }
  961. private static void startUdpDdaemon(final JMeterEngine engine) {
  962. int port = JMeterUtils.getPropDefault("jmeterengine.nongui.port", UDP_PORT_DEFAULT); // $NON-NLS-1$
  963. int maxPort = JMeterUtils.getPropDefault("jmeterengine.nongui.maxport", 4455); // $NON-NLS-1$
  964. if (port > 1000){
  965. final DatagramSocket socket = getSocket(port, maxPort);
  966. if (socket != null) {
  967. Thread waiter = new Thread("UDP Listener"){
  968. @Override
  969. public void run() {
  970. waitForSignals(engine, socket);
  971. }
  972. };
  973. waiter.setDaemon(true);
  974. waiter.star