Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void runTestWithPercentages(String format, int threadCount, String resultsFile, String firstFile,String secondFile,int firstPercent, int secondPercent,int iterations)throws IOException, FileNotFoundException
- {
- Double firstValue=new Double(firstPercent);
- Double secondValue = new Double(secondPercent);
- Double total= new Double(threadCount);
- Double threadCount1 = ((total) * (firstValue/100));
- Double threadCount2 = ((total) * (secondValue/100));
- System.out.println(threadCount1);
- System.out.println(threadCount2);
- //Create the JMeter engine to be used (similar to Android's GUI engine)
- StandardJMeterEngine jEngine = new StandardJMeterEngine();
- JMeterUtils.setJMeterHome("target/jmeter");
- //import the jmeter properties, as is provided
- JMeterUtils.loadJMeterProperties("target/jmeter/bin/jmeter.properties");
- //Set locale
- JMeterUtils.initLocale();
- //Will be used to compose the testPlan, acts as a container
- HashTree hashTree = new HashTree();
- //HTTPSampler acts as the container for the request to the site.
- Arguments newParameters = new Arguments();
- newParameters
- .addArgument("file",firstFile);
- JavaSamplerContext context = new JavaSamplerContext(newParameters);
- CDCSampler httpHandler = new CDCSampler();
- httpHandler.setName("CDCAPIRequest");
- httpHandler.setClassname("com.icims.jmeter.test.update.CDCSampler");
- httpHandler.setArguments(newParameters);
- httpHandler.setProperty(TestElement.TEST_CLASS, JavaSampler.class.getName());
- httpHandler.setProperty(TestElement.GUI_CLASS, JavaTestSamplerGui.class.getName());
- // httpHandler.runTest(context); let engine call this itself
- //Add other pieces
- //THIS IS THREAD GROUP 1
- //LoopController, handles iteration settings
- LoopController controller = new LoopController();
- controller.setLoops(iterations);
- controller.setFirst(true);
- controller.initialize();
- //Adding pieces to enable this to be exported to a .jmx file
- controller.setProperty(TestElement.TEST_CLASS, LoopController.class.getName());
- controller.setProperty(TestElement.GUI_CLASS, LoopControlPanel.class.getName());
- controller.initialize();
- //Thread groups/user count/multi threading
- SetupThreadGroup group = new SetupThreadGroup();
- group.setName("TG1");
- group.setNumThreads(threadCount1.intValue());
- group.setRampUp(1);
- group.setSamplerController(controller);
- //Adding pieces to enable this to be exported to a .jmx file
- group.setProperty(TestElement.TEST_CLASS, ThreadGroup.class.getName());
- group.setProperty(TestElement.GUI_CLASS, ThreadGroupGui.class.getName());
- //Would be Test Plan
- TestPlan testPlan = new TestPlan("CDCPerformenceTesting"+threadCount);
- //Adding pieces to enable this to be exported to a .jmx file
- testPlan.setProperty(TestElement.TEST_CLASS, TestPlan.class.getName());
- testPlan.setProperty(TestElement.GUI_CLASS, TestPlanGui.class.getName());
- testPlan.setUserDefinedVariables((Arguments) new ArgumentsPanel().createTestElement());
- hashTree.add(testPlan);
- //IMPORTANT : Although it seems like this variable is not used, if these lines aren't included, program fails.
- //This is the testplan adopting group, then group adopts HTTPHandler; So they're transitively linked
- HashTree groupTree = hashTree.add(testPlan,group);
- groupTree.add(httpHandler);
- //THIS IS THREAD GROUP 2
- //LoopController, handles iteration settings
- //The same loop controller can be used in the second thread group
- //Thread groups/user count/multi threading
- SetupThreadGroup group2 = new SetupThreadGroup();
- group.setName("TG2");
- group.setNumThreads(threadCount2.intValue());
- group.setRampUp(1);
- group.setSamplerController(controller);
- //Adding pieces to enable this to be exported to a .jmx file
- group.setProperty(TestElement.TEST_CLASS, ThreadGroup.class.getName());
- group.setProperty(TestElement.GUI_CLASS, ThreadGroupGui.class.getName());
- //Have to create another sampler with different input file
- //HTTPSampler acts as the container for the request to the site.
- Arguments newParameters2 = new Arguments();
- newParameters2
- .addArgument("file",secondFile);
- context = null;
- context = new JavaSamplerContext(newParameters2);
- CDCSampler httpHandler2 = new CDCSampler();
- httpHandler.setName("CDCAPIRequest2");
- httpHandler.setClassname("com.icims.jmeter.test.update.CDCSampler");
- httpHandler.setArguments(newParameters2);
- httpHandler.setProperty(TestElement.TEST_CLASS, JavaSampler.class.getName());
- httpHandler.setProperty(TestElement.GUI_CLASS, JavaTestSamplerGui.class.getName());
- //IMPORTANT : Although it seems like this variable is not used, if these lines aren't included, program fails.
- //This is the testplan adopting group, then group adopts HTTPHandler; So they're transitively linked
- SetupThreadGroup[] arrObject = {group,group2};
- hashTree.add(testPlan,arrObject);
- hashTree.add(httpHandler2);
- //
- //In order to get actual useful information to console, use a Summarizer
- Summariser summeriser = new Summariser("summaryOfResults");
- //Collect results
- ResultCollector logger = new ResultCollector(summeriser);
- logger.setFilename("src/pt/resources/JMetrics/"+resultsFile+".csv");
- hashTree.add(hashTree.getArray()[0],logger);
- jEngine.configure(hashTree);
- jEngine.run();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement