private void updateClassLoader() throws MalformedURLException { updatePath("search_paths",";", true); //$NON-NLS-1$//$NON-NLS-2$ updatePath("user.classpath",File.pathSeparator, true);//$NON-NLS-1$ updatePath("plugin_dependency_paths",";", false);//$NON-NLS-1$ }
/** * Add a URL to the loader classpath only; does not update the system * classpath. * * @param url * The {@link URL} to add to the classpath */ public static void addURL(URL url) { loader.addURL(url); }
/** * Close splash */ public void close() { SwingUtilities.invokeLater(() -> { setVisible(false); dispose(); }); }
private void stopTest() { stopTries++; if (JMeter.isNonGUI()) { log.info("Stopping JMeter via UDP call"); stopTestViaUDP("StopTestNow"); } else { if (stopTries > 10) { log.info("Tries more than 10, stop it NOW!"); StandardJMeterEngine.stopEngineNow(); } else if (stopTries > 5) { log.info("Tries more than 5, stop it!"); StandardJMeterEngine.stopEngine(); } else { JMeterContextService.getContext().getEngine().askThreadsToStop(); } } }
private HashTree getTestTree() { GuiPackage gui = GuiPackage.getInstance(); HashTree testTree = gui.getTreeModel().getTestPlan(); JMeter.convertSubTree(testTree); testTree.add(testTree.getArray()[0], gui.getMainFrame()); // Used for remote notification of threads start/stop,see BUG 54152 testTree.add(testTree.getArray()[0], new RemoteThreadsListenerTestElement()); return testTree; } }
private static void startUdpDdaemon(final List<JMeterEngine> engines) { int port = JMeterUtils.getPropDefault("jmeterengine.nongui.port", UDP_PORT_DEFAULT); // $NON-NLS-1$ int maxPort = JMeterUtils.getPropDefault("jmeterengine.nongui.maxport", 4455); // $NON-NLS-1$ if (port > 1000){ final DatagramSocket socket = getSocket(port, maxPort); if (socket != null) { Thread waiter = new Thread("UDP Listener"){ @Override public void run() { waitForSignals(engines, socket); } }; waiter.setDaemon(true); waiter.start(); } else { System.out.println("Failed to create UDP port");//NOSONAR } } }
private HashTree loadJMX(InputStream reader) throws Exception { HashTree tree = SaveService.loadTree(reader); // 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."); } JMeter.convertSubTree(tree); // Remove the disabled items JMeterEngine engine = new StandardJMeterEngine(); engine.configure(tree); return tree; }
@Override public void testStarted() { if (JMeter.isNonGUI()) { out = System.out; } else { out = new JMeterLoggerOutputStream(log); } cur = 0; }
/** * The main program which actually runs JMeter. * * @param args * the command line arguments */ public static void main(String[] args) { if(!EXCEPTIONS_IN_INIT.isEmpty()) { System.err.println("Configuration error during init, see exceptions:"+exceptionsToString(EXCEPTIONS_IN_INIT)); } else { Thread.currentThread().setContextClassLoader(loader); setLoggingProperties(args); try { Class<?> initialClass = loader.loadClass("org.apache.jmeter.JMeter");// $NON-NLS-1$ Object instance = initialClass.newInstance(); Method startup = initialClass.getMethod("start", new Class[] { new String[0].getClass() });// $NON-NLS-1$ startup.invoke(instance, new Object[] { args }); } catch(Throwable e){ // NOSONAR We want to log home directory in case of exception e.printStackTrace(); // NOSONAR No logger at this step System.err.println("JMeter home directory was detected as: "+JMETER_INSTALLATION_DIRECTORY); } } }
/** * Add a URL to the loader classpath only; does not update the system classpath. * * @param path to be added. * @throws MalformedURLException when <code>path</code> points to an invalid url */ public static void addURL(String path) throws MalformedURLException { File furl = new File(path); loader.addURL(furl.toURI().toURL()); // See Java bug 4496398 File[] jars = listJars(furl); for (File jar : jars) { loader.addURL(jar.toURI().toURL()); // See Java bug 4496398 } }
/** * Show screen */ public void showScreen() { SwingUtilities.invokeLater(() -> { setVisible(true); setAlwaysOnTop(true); }); }
@Override public void testEnded() { long now = System.currentTimeMillis(); println("Tidying up ... @ "+new Date(now)+" ("+now+")"); try { generateReport(); } catch (Exception e) { System.err.println("Error generating the report: "+e);//NOSONAR log.error("Error generating the report",e); } checkForRemainingThreads(); println("... end of run"); }
private static void setLoggingProperties(String[] args) { String jmLogFile = getCommandLineArgument(args, 'j', "jmeterlogfile");// $NON-NLS-1$ $NON-NLS-2$ if (jmLogFile != null && !jmLogFile.isEmpty()) { jmLogFile = replaceDateFormatInFileName(jmLogFile); System.setProperty("jmeter.logfile", jmLogFile);// $NON-NLS-1$ } else if (System.getProperty("jmeter.logfile") == null) {// $NON-NLS-1$ System.setProperty("jmeter.logfile", "jmeter.log");// $NON-NLS-1$ $NON-NLS-2$ } String jmLogConf = getCommandLineArgument(args, 'i', "jmeterlogconf");// $NON-NLS-1$ $NON-NLS-2$ File logConfFile = null; if (jmLogConf != null && !jmLogConf.isEmpty()) { logConfFile = new File(jmLogConf); } else if (System.getProperty("log4j.configurationFile") == null) {// $NON-NLS-1$ logConfFile = new File("log4j2.xml");// $NON-NLS-1$ if (!logConfFile.isFile()) { logConfFile = new File(JMETER_INSTALLATION_DIRECTORY, "bin" + File.separator + "log4j2.xml");// $NON-NLS-1$ $NON-NLS-2$ } } if (logConfFile != null) { System.setProperty("log4j.configurationFile", logConfFile.toURI().toString());// $NON-NLS-1$ } }
/** * Return a PasswordAuthentication instance using the userName and password * specified in the constructor. * Only applies to PROXY request types. * * @return a PasswordAuthentication instance to use for authenticating with * the proxy */ @Override protected PasswordAuthentication getPasswordAuthentication() { switch (getRequestorType()){ case PROXY: return new PasswordAuthentication(userName, password); case SERVER: break; default: break; } return null; } }
private void stopTest() { stopTries++; if (JMeter.isNonGUI()) { log.info("Stopping JMeter via UDP call"); stopTestViaUDP("StopTestNow"); } else { if (stopTries > 10) { log.info("Tries more than 10, stop it NOW!"); StandardJMeterEngine.stopEngineNow(); } else if (stopTries > 5) { log.info("Tries more than 5, stop it!"); StandardJMeterEngine.stopEngine(); } else { JMeterContextService.getContext().getEngine().askThreadsToStop(); } } }
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."); } JMeter.convertSubTree(tree); // Remove the disabled items JMeterEngine engine = new StandardJMeterEngine(); engine.configure(tree); return tree; }
@Override public void testStarted() { if (JMeter.isNonGUI()) { out = System.out; } else { out = new JMeterLoggerOutputStream(log); } cur = 0; }
/** * Add a directory or jar to the loader and system classpaths. * * @param path * to add to the loader and system classpath * @throws MalformedURLException * if <code>path</code> can not be transformed to a valid * {@link URL} */ public static void addPath(String path) throws MalformedURLException { File file = new File(path); // Ensure that directory URLs end in "/" if (file.isDirectory() && !path.endsWith("/")) {// $NON-NLS-1$ file = new File(path + "/");// $NON-NLS-1$ } loader.addURL(file.toURI().toURL()); // See Java bug 4496398 StringBuilder sb = new StringBuilder(System.getProperty(JAVA_CLASS_PATH)); sb.append(CLASSPATH_SEPARATOR); sb.append(path); File[] jars = listJars(file); for (File jar : jars) { loader.addURL(jar.toURI().toURL()); // See Java bug 4496398 sb.append(CLASSPATH_SEPARATOR); sb.append(jar.getPath()); } // ClassFinder needs this System.setProperty(JAVA_CLASS_PATH,sb.toString()); }
/** * * @param urls - list of URLs to add to the thread's classloader */ public static void updateLoader(URL [] urls) { DynamicClassLoader loader = (DynamicClassLoader) Thread.currentThread().getContextClassLoader(); for(URL url : urls) { loader.addURL(url); } } }