Hello all, 

What I would like to know is if there is a way to use the Java API to
generate JMX files.  Although these files are XML, we do not want to have to
re-code an application that produces 100 JMX files.  This could happen if
there are changes in the JMeter code... 

I have a Java source file that tries to do this - however there is something
unclear about his code. Specifically why does he need to SET properties
TEST_CLASS, GUI_CLASS???  Perhaps his solution is NOT the correct one?  Also
is using the Java API to produce JMX file okay (supported)? 

package com.test; 

import java.io.FileOutputStream; 

import org.apache.jmeter.control.LoopController; 
import org.apache.jmeter.control.gui.LoopControlPanel; 
import org.apache.jmeter.control.gui.TestPlanGui; 
import org.apache.jmeter.protocol.java.control.gui.JavaTestSamplerGui; 
import org.apache.jmeter.protocol.java.sampler.JavaSampler; 
import org.apache.jmeter.save.SaveService; 
import org.apache.jmeter.testelement.TestElement; 
import org.apache.jmeter.testelement.TestPlan; 
import org.apache.jmeter.threads.ThreadGroup; 
import org.apache.jmeter.threads.gui.ThreadGroupGui; 
import org.apache.jmeter.util.JMeterUtils; 
import org.apache.jorphan.collections.HashTree; 

public class JMXCreator { 
    public static void main(String[] argv) throws Exception { 
        // Initialize the configuration variables 
        String jmeterHome = "D:\\apache-jmeter-2.11"; 
        JMeterUtils.setJMeterHome(jmeterHome); 
        JMeterUtils.loadJMeterProperties(JMeterUtils.getJMeterBinDir() +
"\\jmeter.properties"); 
        JMeterUtils.initLogging(); 
        JMeterUtils.initLocale(); 

        // TestPlan 
        TestPlan testPlan = new TestPlan(); 
        testPlan.setName("Test Plan"); 
        testPlan.setEnabled(true); 
        testPlan.setProperty(TestElement.TEST_CLASS,
TestPlan.class.getName()); 
        testPlan.setProperty(TestElement.GUI_CLASS,
TestPlanGui.class.getName()); 

        // ThreadGroup controller 
        LoopController loopController = new LoopController(); 
        loopController.setEnabled(true); 
        loopController.setLoops(5); 
        loopController.setProperty(TestElement.TEST_CLASS,
LoopController.class.getName()); 
        loopController.setProperty(TestElement.GUI_CLASS,
LoopControlPanel.class.getName()); 

        // ThreadGroup 
        ThreadGroup threadGroup = new ThreadGroup(); 
        threadGroup.setName("Thread Group"); 
        threadGroup.setEnabled(true); 
        threadGroup.setSamplerController(loopController); 
        threadGroup.setNumThreads(5); 
        threadGroup.setRampUp(10); 
        threadGroup.setProperty(TestElement.TEST_CLASS,
ThreadGroup.class.getName()); 
        threadGroup.setProperty(TestElement.GUI_CLASS,
ThreadGroupGui.class.getName()); 

        // JavaSampler 
        JavaSampler javaSampler = new JavaSampler(); 
        javaSampler.setClassname("my.example.sampler"); 
        javaSampler.setEnabled(true); 
        javaSampler.setProperty(TestElement.TEST_CLASS,
JavaSampler.class.getName()); 
        javaSampler.setProperty(TestElement.GUI_CLASS,
JavaTestSamplerGui.class.getName()); 

        // Create TestPlan hash tree 
        HashTree testPlanHashTree = new HashTree(); 
        testPlanHashTree.add(testPlan); 

        // Add ThreadGroup to TestPlan hash tree 
        HashTree threadGroupHashTree = new HashTree(); 
        threadGroupHashTree = testPlanHashTree.add(testPlan, threadGroup); 

        // Add Java Sampler to ThreadGroup hash tree 
        HashTree javaSamplerHashTree = new HashTree(); 
        javaSamplerHashTree = threadGroupHashTree.add(javaSampler); 

        // Save to jmx file 
        SaveService.saveTree(testPlanHashTree, new
FileOutputStream("c:\\test.jmx")); 
    } 
} 

Anyone care to comment?

P.S.: Sorry to post this message TWICE I had a hard time subscribing to the
User mailing list and it said my old message was not yet approved...  So I
was unsure if it would EVER get approved!

Sincerely, 


Kristopher



--
View this message in context: 
http://jmeter.512774.n5.nabble.com/Using-Java-API-to-generate-JMX-files-tp5721657.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to