Java Code Examples for org.apache.jmeter.util.JMeterUtils#setJMeterHome()
The following examples show how to use
org.apache.jmeter.util.JMeterUtils#setJMeterHome() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JMeterPluginsUtils.java From jmeter-plugins with Apache License 2.0 | 6 votes |
public static void prepareJMeterEnv(String homeDir) { if (JMeterUtils.getJMeterHome() != null) { log.warn("JMeter env exists. No one should see this normally."); return; } log.debug("Orig jmeter home dir: " + homeDir); File dir = new File(homeDir); while (dir.exists() && dir.getName().equals("ext") && dir.getParentFile().getName().equals("lib")) { dir = dir.getParentFile(); } if (!dir.exists()) { throw new IllegalArgumentException("CMDRunner.jar must be placed in <jmeter>/lib/ext directory"); } homeDir = dir.getParent(); if (!isJMeterHome(homeDir)) { homeDir = getJMeterHomeFromCP(System.getProperty("java.class.path")); } log.debug("Final jmeter home dir: " + homeDir); JMeterUtils.setJMeterHome(homeDir); initializeProperties(); }
Example 2
Source File: TestUtilities.java From jmeter-prometheus-plugin with Apache License 2.0 | 5 votes |
public static void createJmeterEnv() { JMeterUtils.setJMeterHome("src/test/resources"); JMeterUtils.setLocale(Locale.ENGLISH); JMeterUtils.loadJMeterProperties("src/test/resources/bin/jmeter.properties"); try { SaveService.loadProperties(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } JMeterTreeModel jMeterTreeModel = new JMeterTreeModel(); JMeterTreeListener jMeterTreeListener = new JMeterTreeListener(); jMeterTreeListener.setModel(jMeterTreeModel); JMeterContextService.getContext().setVariables(new JMeterVariables()); StandardJMeterEngine engine = new StandardJMeterEngine(); JMeterContextService.getContext().setEngine(engine); JMeterThreadMonitor monitor = new NOOPThreadMonitor(); HashTree hashtree = new HashTree(); hashtree.add(new LoopController()); JMeterThread thread = new JMeterThread(hashtree, monitor, null); thread.setThreadName("test thread"); JMeterContextService.getContext().setThread(thread); ThreadGroup tg1 = new ThreadGroup(); tg1.setName("tg1"); JMeterContextService.getContext().setThreadGroup(tg1); }
Example 3
Source File: JMeterRecorder.java From jsflight with Apache License 2.0 | 5 votes |
private static void initializeJMeter() { JMeterUtils.setJMeterHome(new File("").getAbsolutePath()); JMeterUtils.loadJMeterProperties(new File("jmeter.properties").getAbsolutePath()); JMeterUtils.setProperty("saveservice_properties", File.separator + "saveservice.properties"); JMeterUtils.setProperty("user_properties", File.separator + "user.properties"); JMeterUtils.setProperty("upgrade_properties", File.separator + "upgrade.properties"); JMeterUtils.setProperty("system_properties", File.separator + "system.properties"); JMeterUtils.setLocale(Locale.ENGLISH); JMeterUtils.setProperty("proxy.cert.directory", new File("").getAbsolutePath()); }
Example 4
Source File: BaseLNPTestCase.java From teammates with GNU General Public License v2.0 | 5 votes |
/** * Setup and load the JMeter configuration and property files to run the Jmeter test. * @throws IOException if the save service properties file cannot be loaded. */ private void setJmeterProperties() throws IOException { JMeterUtils.loadJMeterProperties(TestProperties.JMETER_PROPERTIES_PATH); JMeterUtils.setJMeterHome(TestProperties.JMETER_HOME); JMeterUtils.initLocale(); SaveService.loadProperties(); }
Example 5
Source File: TestJMeterUtils.java From jmeter-plugins with Apache License 2.0 | 5 votes |
public static void createJmeterEnv() { JMeterUtils.setJMeterHome(getTempDir()); File dst = new File(JMeterUtils.getJMeterHome() + "/ss.props"); InputStream src = DirectoryAnchor.class.getResourceAsStream("/kg/apc/jmeter/bin/saveservice.properties"); try { Files.copy(src, dst.toPath(), StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { throw new RuntimeException("Failed to copy file " + src + " to " + dst, e); } JMeterUtils.loadJMeterProperties(dst.getAbsolutePath()); JMeterUtils.setLocale(new Locale("ignoreResources")); JMeterTreeModel jMeterTreeModel = new JMeterTreeModel(); JMeterTreeListener jMeterTreeListener = new JMeterTreeListener(); jMeterTreeListener.setModel(jMeterTreeModel); JMeterContextService.getContext().setVariables(new JMeterVariables()); StandardJMeterEngine engine = new EmulatorJmeterEngine(); JMeterThreadMonitor monitor = new EmulatorThreadMonitor(); JMeterContextService.getContext().setEngine(engine); HashTree hashtree = new HashTree(); hashtree.add(new LoopController()); JMeterThread thread = new JMeterThread(hashtree, monitor, null); thread.setThreadName("test thread"); JMeterContextService.getContext().setThread(thread); ThreadGroup threadGroup = new org.apache.jmeter.threads.ThreadGroup(); threadGroup.setName("test thread group"); JMeterContextService.getContext().setThreadGroup(threadGroup); JMeterUtils.setProperty("sample_variables", "TEST1,TEST2,TEST3"); // for Flexible File Writer Test JMeterUtils.setProperty("saveservice_properties", "/ss.props"); JMeterUtils.setProperty("upgrade_properties", "/ss.props"); JMeterUtils.setProperty("sampleresult.default.encoding", "UTF-8"); // enable multibyte }
Example 6
Source File: Postman2JmxConfig.java From postman2jmx with MIT License | 4 votes |
public void setJMeterHome() throws Exception { String path = new File("").getAbsolutePath(); path = path + "/jmeter"; JMeterUtils.setJMeterHome(path); }
Example 7
Source File: WebSocketSamplerTest.java From jmeter-websocket with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { JMeterUtils.setJMeterHome("src/test/resources/"); JMeterUtils.loadJMeterProperties("src/test/resources/jmeter.properties"); JMeterUtils.setProperty("saveservice_properties", "saveservice.properties"); JMeterUtils.setProperty("search_paths", "ApacheJMeter_functions-2.9.jar"); JMeterUtils.setLocale(Locale.JAPAN); JMeterEngine engine = new StandardJMeterEngine(); HashTree config = new ListedHashTree(); TestPlan testPlan = new TestPlan("websocket test"); testPlan.setFunctionalMode(false); testPlan.setSerialized(false); testPlan.setProperty(new BooleanProperty(TestElement.ENABLED, true)); testPlan.setUserDefinedVariables(new Arguments()); ThreadGroup threadGroup = new ThreadGroup(); threadGroup.setNumThreads(300); threadGroup.setRampUp(20); threadGroup.setDelay(0); threadGroup.setDuration(0); threadGroup.setProperty(new StringProperty(ThreadGroup.ON_SAMPLE_ERROR, "continue")); threadGroup.setScheduler(false); threadGroup.setName("Group1"); threadGroup.setProperty(new BooleanProperty(TestElement.ENABLED, true)); LoopController controller = new LoopController(); controller.setLoops(10); controller.setContinueForever(false); controller.setProperty(new BooleanProperty(TestElement.ENABLED, true)); threadGroup.setProperty(new TestElementProperty(ThreadGroup.MAIN_CONTROLLER, controller)); CSVDataSet csvDataSet = new CSVDataSet(); csvDataSet.setProperty(new StringProperty("filename", "src/test/resources/users.csv")); csvDataSet.setProperty(new StringProperty("variableNames", "USER_NAME")); csvDataSet.setProperty(new StringProperty("delimiter", ",")); csvDataSet.setProperty(new StringProperty("shareMode", "shareMode.all")); csvDataSet.setProperty("quoted", false); csvDataSet.setProperty("recycle", true); csvDataSet.setProperty("stopThread", false); WebSocketSampler sampler = new WebSocketSampler(); sampler.setName("WebSocket Test"); sampler.setProperty(new BooleanProperty(TestElement.ENABLED, true)); sampler.addNonEncodedArgument("name", "${USER_NAME}", "="); sampler.setContentEncoding("UTF-8"); sampler.setProtocol("ws"); sampler.setDomain("localhost"); sampler.setPort(9090); sampler.setPath("/", "UTF-8"); sampler.setSendMessage("${__RandomString(50,ABCDEFGHIJKLMNOPQRSTUVWXYZ)}"); sampler.setRecvMessage("\"name\":\"${USER_NAME}\""); OnceOnlyController onceOnlyController = new OnceOnlyController(); Summariser summariser = new Summariser(); HashTree tpConfig = config.add(testPlan); HashTree tgConfig = tpConfig.add(threadGroup); HashTree oocConfig = tgConfig.add(onceOnlyController); oocConfig.add(csvDataSet); UniformRandomTimer randomTimer = new UniformRandomTimer(); randomTimer.setRange(3000); HashTree samplerConfig = tgConfig.add(sampler); samplerConfig.add(summariser); tgConfig.add(randomTimer); engine.configure(config); engine.runTest(); }