For the newbies who want to make the Controller.
Here it is. This is a sample EmptyController which checks whether the a "STR" 
variable exist in the JMeterContext
----- Java Code -----
package org.apache.jmeter.control;

import java.io.Serializable;

import org.apache.jmeter.control.GenericController;
import org.apache.jmeter.control.NextIsNullException;
import org.apache.jmeter.samplers.Sampler;
import org.apache.jmeter.testelement.property.StringProperty;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;

public class EmptyController extends GenericController implements Serializable {
    private static final long serialVersionUID = 1L;
    
    private static final Logger logger = LoggingManager.getLoggerForClass();

    private final static String CONDITION = "EmptyController.condition"; 
//$NON-NLS-1$

    @SuppressWarnings("unused")
    private final static String EVALUATE_ALL = "EmptyController.evaluateAll"; 
//$NON-NLS-1$
    private String value;

    public EmptyController() {
        Thread.dumpStack();

    }

    public EmptyController(String value) {
        super();
        this.value = value;
    }


    public void setValue(String value) {
        setProperty(new StringProperty(CONDITION, value));
    }
    
    public String getValue() {
        return getPropertyAsString(CONDITION);
    }

    @Override
    public Sampler next() {
        boolean result = testEmpty(this.getValue());
        if (result) {
            return super.next();
        }
        try {
            return nextIsNull();
        } catch (NextIsNullException e1) {
            return null;
        }

    }

    private boolean testEmpty(String tmp_value) {
        String str = this.getThreadContext().getVariables().get(tmp_value);
        if(str == null){
            return false;
        }
        return true;
    }
    
    public boolean isEvaluateAll() {
        return getPropertyAsBoolean(EVALUATE_ALL,false);
    }

    public void setEvaluateAll(boolean b) {
        setProperty(EVALUATE_ALL,b);
    }
}

----- Property file Code -----
### Add following code to saveservice.properties if you want to add gui you can 
do that too. Look in the property file for implementation
EmptyController=org.apache.jmeter.control.EmptyController


----- JMX Code -----

<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="2.1">
  <hashTree>
    <TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test Plan" 
enabled="true">
      <stringProp name="TestPlan.comments"></stringProp>
      <boolProp name="TestPlan.functional_mode">false</boolProp>
      <boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
      <elementProp name="TestPlan.user_defined_variables" 
elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" 
testname="User Defined Variables" enabled="true">
        <collectionProp name="Arguments.arguments"/>
      </elementProp>
      <stringProp name="TestPlan.user_define_classpath"></stringProp>
    </TestPlan>
    <hashTree>
      <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" 
testname="Thread Group" enabled="true">
        <elementProp name="ThreadGroup.main_controller" 
elementType="LoopController" guiclass="LoopControlPanel" 
testclass="LoopController" testname="Loop Controller" enabled="true">
          <boolProp name="LoopController.continue_forever">false</boolProp>
          <stringProp name="LoopController.loops">1</stringProp>
        </elementProp>
        <stringProp name="ThreadGroup.num_threads">1</stringProp>
        <stringProp name="ThreadGroup.ramp_time">1</stringProp>
        <longProp name="ThreadGroup.start_time">1240281184000</longProp>
        <longProp name="ThreadGroup.end_time">1240281184000</longProp>
        <boolProp name="ThreadGroup.scheduler">false</boolProp>
        <stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
        <stringProp name="ThreadGroup.duration"></stringProp>
        <stringProp name="ThreadGroup.delay"></stringProp>
      </ThreadGroup>
      <hashTree>
        <TestAction guiclass="TestActionGui" testclass="TestAction" 
testname="Test Action" enabled="true">
          <intProp name="ActionProcessor.action">1</intProp>
          <intProp name="ActionProcessor.target">0</intProp>
          <stringProp name="ActionProcessor.duration"></stringProp>
        </TestAction>
        <hashTree>
          <BeanShellPreProcessor guiclass="TestBeanGUI" 
testclass="BeanShellPreProcessor" testname="BeanShell PreProcessor" 
enabled="true">
            <stringProp name="filename"></stringProp>
            <stringProp name="parameters"></stringProp>
            <boolProp name="resetInterpreter">false</boolProp>
            <stringProp name="script">vars.put(&quot;COOLER&quot;,&quot;hello 
world&quot;);</stringProp>
          </BeanShellPreProcessor>
          <hashTree/>
        </hashTree>
        <EmptyController testclass="EmptyController" testname="Empty 
Controller" enabled="true">
          <stringProp name="EmptyController.condition">STR</stringProp>
          <stringProp name="EmptyController.evaluateAll">false</stringProp>
        </EmptyController>
        <hashTree>
          <TestAction guiclass="TestActionGui" testclass="TestAction" 
testname="Test Action" enabled="true">
            <intProp name="ActionProcessor.action">1</intProp>
            <intProp name="ActionProcessor.target">0</intProp>
            <stringProp name="ActionProcessor.duration"></stringProp>
          </TestAction>
          <hashTree>
            <BeanShellPreProcessor guiclass="TestBeanGUI" 
testclass="BeanShellPreProcessor" testname="BeanShell PreProcessor" 
enabled="true">
              <boolProp name="resetInterpreter">true</boolProp>
              <stringProp name="parameters"></stringProp>
              <stringProp name="filename"></stringProp>
              <stringProp 
name="script">System.out.println(vars.get(&quot;STR&quot;));</stringProp>
            </BeanShellPreProcessor>
            <hashTree/>
          </hashTree>
        </hashTree>
      </hashTree>
    </hashTree>
  </hashTree>
</jmeterTestPlan>


I guess some people think that this mailing list is substitute for Hard Work. 
Anyway thanks for feeding my ego.
Later.........................................................................................................

-----x snip



      

Reply via email to