I have created a class that extends AbstractJavaSamplerClient. I
basically edited the JavaTest.class file included with the JMeter 2.3.1
source. I build the JAR file and put it in lib/ext. I'm using Java
1.6.0.03 on Ubuntu 7.10.

When I try to add a Java Sampler to a test, the first time I click on
the menu option, it does nothing. When I click a second time. I get a
sampler added. In the dropdown list, I can see my class, but no
parameters are listed (I have 2 defined in the getDefaultParameters()
method). When I select either the JavaTest or SleepTest options, they
don't show any parameters, either.

When I remove my JAR from the lib/ext directory and repeat the process,
the JavaTest and SleepTest options properly show parameters and the Java
Sampler is added on the first click.

Code is appended below.

Suggestions on where to look?

Thanks.

-Pete
-------------------------------------------
package test;

import java.io.Serializable;
import java.util.Iterator;

import org.apache.log4j.*;

import org.apache.jmeter.config.Arguments;
import
org.apache.jmeter.protocol.java.sampler.AbstractJavaSamplerClient;
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext;
import org.apache.jmeter.samplers.SampleResult;
//import org.apache.jmeter.testelement.TestElement;



public class LaunchPLC extends AbstractJavaSamplerClient implements
Serializable {
        
        private static final long serialVersionUID = 1L;

        //create our logger
        static Logger log = Logger.getLogger(LaunchPLC.class.getName());

        /** The name of the script to run. */
        private String scriptName;

        private static final String SCRIPT_NAME = "Script Name";
        
        /** The success status to be stored in the sample result. */
        private boolean status;
        
        private static final String STATUS_NAME = "Status";
        

        public LaunchPLC() {
                getLogger().debug(whoAmI() + "\tConstruct");
                
                //CONFIG LOGGING
                FileAppender fa = null;
                
                log.setLevel(Level.DEBUG);
                try {
                        fa = new FileAppender(new PatternLayout(),"log.txt");
                } catch (Exception e) {
                        e.printStackTrace();
                }
                log.addAppender(fa);
        }

        /*
         * Utility method to set up all the values
         */
        private void setupValues(JavaSamplerContext context) {

                scriptName = context.getParameter("Script Name","");

                /*
                sleepTime = context.getLongParameter(SLEEP_NAME, 
DEFAULT_SLEEP_TIME);
                sleepMask = context.getLongParameter(MASK_NAME, 
DEFAULT_SLEEP_MASK);
                
                responseMessage = context.getParameter(RESPONSE_MESSAGE_NAME,
RESPONSE_MESSAGE_DEFAULT);

                responseCode = context.getParameter(RESPONSE_CODE_NAME,
RESPONSE_CODE_DEFAULT);

                success = context.getParameter(SUCCESS_NAME,
SUCCESS_DEFAULT).equalsIgnoreCase("OK");

                label = context.getParameter(LABEL_NAME, "");
                if (label.length() == 0)
                        label = context.getParameter(TestElement.NAME); // 
default to name
                                                                                
                                        // of element

                samplerData = context.getParameter(SAMPLER_DATA_NAME,
SAMPLER_DATA_DEFAULT);

                resultData = context.getParameter(RESULT_DATA_NAME,
RESULT_DATA_DEFAULT);
                */
        }


        public void setupTest(JavaSamplerContext context) {
                getLogger().debug(whoAmI() + "\tsetupTest()");
                listParameters(context);
                
                //configure sampler
                setupValues(context);
        }


        public Arguments getDefaultParameters() {
                Arguments params = new Arguments();
                params.addArgument("Script Name","foo");
                params.addArgument("Status","OK");
                return params;
        }


        public SampleResult runTest(JavaSamplerContext context) {


                log.info("Starting runTest");

                SampleResult results = new SampleResult();


                // Record sample start time.
                results.sampleStart();
                

                
                com.pureload.tools.runner.ScenarioRunner.execute(scriptName,
Level.DEBUG_INT, com.pureload.task.runtime.BasicTaskRuntime.LOG_DEBUG,
true, log);
                
                results.setSuccessful(true);
                results.sampleEnd();

                log.info("Finished runTest");
                
                return results;
        }


        public void teardownTest(JavaSamplerContext context) {
                getLogger().debug(whoAmI() + "\tteardownTest()");
                listParameters(context);
        }


        @SuppressWarnings("unchecked")
        private void listParameters(JavaSamplerContext context) {
                if (getLogger().isDebugEnabled()) {
                        Iterator argsIt = context.getParameterNamesIterator();
                        while (argsIt.hasNext()) {
                                String name = (String) argsIt.next();
                                getLogger().debug(name + "=" + 
context.getParameter(name));
                        }
                }
        }


        private String whoAmI() {
                StringBuffer sb = new StringBuffer();
                sb.append(Thread.currentThread().toString());
                sb.append("@");
                sb.append(Integer.toHexString(hashCode()));
                return sb.toString();
        }

}





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to