public static void start(Config conf, String[] args) { // this is redundant to jpf.report.<publisher>.start=..config.. // but nobody can remember this (it's only used to produce complete reports) if (logger == null) { logger = initLogging(conf); } if (!checkArgs(args)) { return; } setNativeClassPath(conf); // in case we have to find a shell // check if there is a shell class specification, in which case we just delegate JPFShell shell = conf.getInstance("shell", JPFShell.class); if (shell != null) { shell.start(args); // responsible for exception handling itself } else { // no shell, we start JPF directly LogManager.printStatus(logger); conf.printStatus(logger); // this has to be done after we checked&consumed all "-.." arguments // this is NOT about checking properties! checkUnknownArgs(args); try { JPF jpf = new JPF(conf); jpf.run(); } catch (ExitException x) { logger.severe("JPF terminated"); // this is how we get most runtime config exceptions if (x.shouldReport()) { x.printStackTrace(); } /** * Throwable cause = x.getCause(); if ((cause != null) && conf.getBoolean("pass_exceptions", * false)) { cause.fillInStackTrace(); throw cause; } */ } catch (JPFException jx) { logger.severe("JPF exception, terminating: " + jx.getMessage()); if (conf.getBoolean("jpf.print_exception_stack")) { Throwable cause = jx.getCause(); if (cause != null && cause != jx) { cause.printStackTrace(); } else { jx.printStackTrace(); } } // pass this on, caller has to handle throw jx; } } }
/** * Terminate the current process. Note that terminate is the *only* method that should be used to * terminate the daemon processes. * * @param status exit code * @param msg message used to create the {@code ExitException} * @throws ExitException if System.exit is disabled for test purposes */ public static void terminate(int status, String msg) throws ExitException { /* LOG.info("Exiting with status "+status) */ LOG.exiting_with_status(status).info(); if (systemExitDisabled) { ExitException ee = new ExitException(status, msg); /* LOG.fatal("Terminate called",ee) */ LOG.terminate_called(ee.toString()).fatal(); if (null == firstExitException) { firstExitException = ee; } throw ee; } System.exit(status); }
private String executeTest(File test) throws Exception { String reportFileName; String reportFileFullPath; JMeter jmeterInstance = new JMeter(); try { log.info("Executing test: " + test.getCanonicalPath()); reportFileName = test.getName().substring(0, test.getName().lastIndexOf(".")) + "-" + fmt.format(new Date()) + ".jmeterResult" + ".jtl"; File reportDir = JMeterInstallationProvider.getInstance().getReportDir(); reportFileFullPath = reportDir.toString() + File.separator + reportFileName; List<String> argsTmp = Arrays.asList( "-n", "-t", test.getCanonicalPath(), "-l", reportDir.toString() + File.separator + reportFileName, "-p", jmeterProps.toString(), "-d", jmeterHome.getCanonicalPath(), "-L", "jorphan=" + jmeterLogLevel, "-L", "jmeter.util=" + jmeterLogLevel); List<String> args = new ArrayList<String>(); args.addAll(argsTmp); SecurityManager oldManager = System.getSecurityManager(); UncaughtExceptionHandler oldHandler = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler( new UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { if (e instanceof ExitException && ((ExitException) e).getCode() == 0) { return; // Ignore } log.error("Error in thread " + t.getName()); } }); try { logParamsAndProps(args); jmeterInstance.start(args.toArray(new String[] {})); BufferedReader in = new BufferedReader(new FileReader(jmeterLogFile)); while (!checkForEndOfTest(in)) { try { Thread.sleep(1000); } catch (InterruptedException e) { break; } } } catch (ExitException e) { if (e.getCode() != 0) { throw new Exception("Test failed", e); } } catch (Exception e) { log.error(e); } finally { System.setSecurityManager(oldManager); Thread.setDefaultUncaughtExceptionHandler(oldHandler); } } catch (IOException e) { throw new Exception("Can't execute test", e); } return reportFileFullPath; }