After seeing your controller, the next thing I'd want to look at is your
gui code that creates and modifies the controller.
-Mike
On Tue, 2005-07-19 at 10:09 +0200, [EMAIL PROTECTED] wrote:
> Hi.
> I've created new controller. It work's quite well but when it finishes it
> work it stops. It can't see my next controler( the same type). It is going
> through myController but it can't see myController2.
>
> myController--
> | |
> | HTTPSampler1--
> | | |
> | | RegexExtractor
> | |
> | If Controller--//if Regex found
> | | |
> | | Counter//suma++
> | | |
> | | Setter //flag=true
> | |
> | If Controller--//if Regex didin't find
> | |
> | Setter //flag=false
> |
> myController2...
> .
> .
> .
> Varibles:
> -flaga //it tells controller if the process was found
> -count //it tells controller how many processes should be found
> -sum //it tels controller how many processes have been founded
> -runtime //if flag=false timer starts. If flaga=true timer stops.It tells
> controller how long it should work if flag=false
>
> Please Help!!! It is very urgent!!!
>
> Here is a code for controller ...
>
> package org.apache.jmeter.control.gui;
>
> import java.io.Serializable;
> import java.text.MessageFormat;
>
> import org.apache.jmeter.junit.JMeterTestCase;
> import org.apache.jmeter.junit.stubs.TestSampler;
> import org.apache.jmeter.samplers.Sampler;
> import org.apache.jmeter.samplers.SampleResult;
> import org.apache.jmeter.testelement.property.LongProperty;
> import org.apache.jmeter.testelement.property.StringProperty;
> import org.apache.jmeter.testelement.property.IntegerProperty;
> import org.apache.jmeter.testelement.property.BooleanProperty;
> import org.apache.jmeter.control.GenericController;
> import org.apache.jmeter.control.NextIsNullException;
> import org.apache.jmeter.assertions.Assertion;
> import org.apache.jmeter.assertions.AssertionResult;
> import org.apache.jmeter.util.JMeterUtils;
> import org.apache.jorphan.logging.LoggingManager;
> import org.apache.log.Logger;
>
> /**
> * @version $Revision: 1.4 $
> */
> public class ProcessController extends GenericController implements
> Serializable, Assertion
> {
> private static final Logger log = LoggingManager.getLoggerForClass();
> private final static String SECONDS = "ProcessController.seconds";
> private final static String COUNT = "ProcessController.count";
> private final static String SUM = "ProcessController.sum";
> private final static String FLAG = "ProcessController.flag";
> private volatile long startTime = 0;
>
>
> private int loopCount = 0; // for getIterCount
>
> public ProcessController()
> {
> }
>
> public void setRuntime(long seconds)
> {
> setProperty(new LongProperty(SECONDS, seconds));
> }
>
> public void setCount(int count)
> {
> setProperty(new IntegerProperty(COUNT, count));
> }
> public void setSum(int sum)
> {
> setProperty(new IntegerProperty(SUM, sum));
> }
> public void setFlag(boolean flag)
> {
> setProperty(new BooleanProperty(FLAG, flag));
> }
> public void setRuntime(String seconds)
> {
> setProperty(new StringProperty(SECONDS, seconds));
> }
> public void setCount(String count)
> {
> setProperty(new StringProperty(COUNT, count));
> }
> public void setSum(String sum)
> {
> setProperty(new StringProperty(SUM, sum));
> }
> public void setFlag(String flag)
> {
> setProperty(new StringProperty(FLAG, flag));
> }
>
> public long getRuntime()
> {
> try
> {
> return Long.parseLong(getPropertyAsString(SECONDS));
>
> }
> catch (NumberFormatException e)
> {
> return 0L;
> }
> }
>
> public int getCount()
> {
> try
> {
> return Integer.parseInt(getPropertyAsString(COUNT));
>
> }
> catch (NumberFormatException e)
> {
> return (int) 0L;
> }
> }
>
> public int getSum()
> {
> try
> {
> return Integer.parseInt(getPropertyAsString(SUM));
>
> }
> catch (NumberFormatException e)
> {
> return (int) 0L;
> }
> }
>
> public boolean getFlag()
> {
> try
> {
> return Boolean.parseBoolean(getPropertyAsString(FLAG));
>
> }
> catch (NumberFormatException e)
> {
> return true;
> }
> }
>
> public String getRuntimeString()
> {
> return getPropertyAsString(SECONDS);
> }
>
> public String getCountString()
> {
> return getPropertyAsString(COUNT);
> }
>
> public String getSumString()
> {
> return getPropertyAsString(SUM);
> }
>
> public String getFlagString()
> {
> return getPropertyAsString(FLAG);
> }
>
> /* (non-Javadoc)
> * @see org.apache.jmeter.control.Controller#isDone()
> */
> public boolean isDone()
> {
>
> if (getSubControllers().size() > 0)
> {
> this.removeCurrentElement();
> return super.isDone();
> }
> else
> {
> return true; // Runtime is zero - no point staying around
> }
> }
>
> private boolean endOfLoop()
> {
> if(getCount()==getSum())
> {
> return true;
> }
>
> if(getFlag()==false&&(startTime!=0)&&(System.currentTimeMillis()-startTime
> >= 1000*getRuntime()))
> {
> return true;
> }
>
> return false;
> }
>
> public Sampler next()
> {
>
> if (startTime == 0)
> {
> if(getFlag()==false)startTime=System.currentTimeMillis();
> }
> else if(getFlag()==true)startTime=0;
>
> if (endOfLoop()){
> reInitialize();// ??
> resetLoopCount();
> return null;
> }
> return super.next();
> }
> /* (non-Javadoc)
> * @see org.apache.jmeter.control.GenericController#nextIsNull()
> */
> /*protected Sampler nextIsNull() throws NextIsNullException
> {
> log.info("nextIsNull()");
> reInitialize();
> if (endOfLoop())
> {
> log.info("Powinien skonczyc");
> resetLoopCount();
> return null;
> }
> else
> {
> return next();
> }
> }
> */
> protected void incrementLoopCount()
> {
> loopCount++;
> }
> protected void resetLoopCount()
> {
> loopCount=0;
> startTime=0;
> }
> /*
> * This is needed for OnceOnly to work like other Loop Controllers
> */
> protected int getIterCount()
> {
> return loopCount + 1;
> }
> protected void reInitialize()
> {
>
> setFirst(true);
> setSum("0");
> resetCurrent();
> incrementLoopCount();
> recoverRunningVersion();
>
> }
>
>
> //////////////////////////////Start of Test Code
> ///////////////////////////
> public AssertionResult getResult(SampleResult response)
> {
> AssertionResult result = new AssertionResult();
>
> if(getFlag()==false&&(startTime!=0)&&(System.currentTimeMillis()-startTime
> >= 1000*getRuntime()))
> {
> result.setFailure(true);
> Object[] arguments =
> { new Long(getRuntime())};
> String message =
> MessageFormat.format(
> JMeterUtils.getResString("duration_assertion_failure"),
> arguments);
> result.setFailureMessage(message);
>
> }
> else
> {
> result.setFailure(false);
> }
> return result;
> }
> }
>
>
> ...and controller gui
>
> package org.apache.jmeter.control.gui;
>
> import java.awt.*;
> import java.awt.event.ActionEvent;
> import java.awt.event.ActionListener;
>
> import javax.swing.*;
>
> import org.apache.jmeter.testelement.TestElement;
> import org.apache.jmeter.util.JMeterUtils;
> import org.apache.jorphan.gui.layout.VerticalLayout;
> import org.apache.jorphan.gui.JLabeledTextField;
> import org.apache.jorphan.logging.LoggingManager;
> import org.apache.log.Logger;
>
> /**
> * The user interface for a controller which specifies that its
> subcomponents
> * should be executed some number of seconds in a loop. This component
> can be
> * used standalone or embedded into some other component.
> *
> * @version $Revision: 1.1.2.1 $ on $Date: 2004/06/03 00:08:36 $
> */
>
> public class ProcessControllerGui
> extends AbstractControllerGui
> implements ActionListener
> {
> /**
> * A field allowing the user to specify the number of seconds the
> controller
> * should loop.
> */
> private static final Logger log = LoggingManager.getLoggerForClass();
> private JLabeledTextField seconds;
> private JLabeledTextField count;
> private JLabeledTextField sum;
> private JLabeledTextField flag;
>
>
> /**
> * Boolean indicating whether or not this component should display its
> * name. If true, this is a standalone component. If false, this
> component
> * is intended to be used as a subpanel for another component.
> */
> private boolean displayName = true;
>
> /** The name of the seconds field component. */
> // private static final String SECONDS = "Seconds Field";
> // private final static String COUNT = "Count Field";
> //private final static String SUM = "Sum Field";
> //private final static String FLAG = "Flag Field";
>
> /**
> * Create a new LoopControlPanel as a standalone component.
> */
> public ProcessControllerGui()
> {
> this(true);
> }
>
> /**
> * Create a new LoopControlPanel as either a standalone or an embedded
> * component.
> *
> * @param displayName indicates whether or not this component should
> * display its name. If true, this is a
> standalone
> * component. If false, this component is
> intended
> * to be used as a subpanel for another component.
> */
> public ProcessControllerGui(boolean displayName)
> {
> this.displayName = displayName;
> init();
> log.info("Ustawianie danych");
> setState(1,1,1,true);
>
> }
>
> /**
> * A newly created component can be initialized with the contents of
> * a Test Element object by calling this method. The component is
> * responsible for querying the Test Element object for the
> * relevant information to display in its GUI.
> *
> * @param element the TestElement to configure
> */
> public void configure(TestElement element)
> {
> super.configure(element);
> if (element instanceof ProcessController)
> {
> log.info("Ustawianie danych do gui:"+((ProcessController)
> element).getFlagString());
> setState(((ProcessController)
> element).getRuntimeString(),((ProcessController)
> element).getCountString(),((ProcessController)
> element).getSumString(),((ProcessController) element).getFlagString());
>
> }
> else
> {
> log.info("Ustawianie danych2");
> setState(1,1,1,true);
> }
> }
>
> /* Implements JMeterGUIComponent.createTestElement() */
> public TestElement createTestElement()
> {
> log.info("Tworzenie ProcesController");
> ProcessController lc = new ProcessController();
> modifyTestElement(lc);
> return lc;
> }
>
> /* Implements JMeterGUIComponent.modifyTestElement(TestElement) */
> public void modifyTestElement(TestElement lc)
> {
> log.info("Modyfikacja Test Element");
> configureTestElement(lc);
> if (lc instanceof ProcessController)
> {
> if (seconds.getText().length() > 0)
> {
> ((ProcessController) lc).setRuntime(seconds.getText());
> }
> else
> {
> ((ProcessController) lc).setRuntime(0);
> }
> if (count.getText().length() > 0)
> {
> ((ProcessController) lc).setCount(count.getText());
> }
> else
> {
> ((ProcessController) lc).setCount(0);
> }
> if (sum.getText().length() > 0)
> {
> ((ProcessController) lc).setSum(sum.getText());
> }
> else
> {
> ((ProcessController) lc).setSum(0);
> }
> if (flag.getText().length() > 0)
> {
> log.info("Ustawianie flagi: "+flag.getText());
> ((ProcessController) lc).setFlag(flag.getText());
>
> }
> else
> {
> log.info("Ustawianie flagi2"+flag.getText());
> ((ProcessController) lc).setFlag(true);
> }
> }
> }
>
> /**
> * Invoked when an action occurs. This implementation assumes that
> the
> * target component is the infinite seconds checkbox.
> *
> * @param event the event that has occurred
> */
> public void actionPerformed(ActionEvent event)
> {
> log.info("Ustawianie danych event");
> seconds.setEnabled(true);
> }
>
> public String getLabelResource()
> {
> log.info("tytul");
> return "process_controller_title";
>
> }
>
> /**
> * Initialize the GUI components and layout for this component.
> */
> private void init()
> {
> // The Loop Controller panel can be displayed standalone or inside
> // another panel. For standalone, we want to display the TITLE,
> NAME,
> // etc. (everything). However, if we want to display it within
> another
> // panel, we just display the Loop Count fields (not the TITLE and
> // NAME).
>
> // Standalone
> log.info("inicjalizacja gui");
> if (displayName)
> {
> // setLayout(new BorderLayout(0, 5));
> // setBorder(makeBorder());
> // add(makeTitlePanel(), BorderLayout.NORTH);
> createLoopCountPanel();
> //JPanel mainPanel = new JPanel(new BorderLayout());
> //mainPanel.add(createLoopCountPanel(), BorderLayout.NORTH);
> //add(mainPanel, BorderLayout.CENTER);
> }
> else
> {
> // Embedded
> //setLayout(new BorderLayout());
> //add(createLoopCountPanel(), BorderLayout.NORTH);
> createLoopCountPanel();
> }
> }
>
> /**
> * Create a GUI panel containing the components related to the number
> of
> * seconds which should be executed.
> *
> * //@return a GUI panel containing the loop count components
> */
> private void createLoopCountPanel()
> {
>
>
> setBorder (makeBorder());
> setLayout(new VerticalLayout(5, VerticalLayout.LEFT));
>
> seconds = new
> JLabeledTextField(JMeterUtils.getResString("process_controller_seconds"));//TODO
>
> proper alignment
> count = new
> JLabeledTextField(JMeterUtils.getResString("process_controller_count"));
> sum = new
> JLabeledTextField(JMeterUtils.getResString("process_controller_sum"));
> flag = new
> JLabeledTextField(JMeterUtils.getResString("process_controller_flag"));
>
> add(makeTitlePanel());
> add(seconds);
> add(count);
> add(sum);
> add(flag);
> }
> /**
> * Set the number of seconds which should be reflected in the GUI. The
> * secsCount parameter should contain the String representation of an
> * integer. This integer will be treated as the number of seconds. If
> this
> * integer is less than 0, the number of seconds will be assumed to be
> * infinity.
> *
> * @param secsCount the String representation of the number of seconds
> */
> private void setState(String secsCount, String seCount, String seSum,
> String seFlag)
> {
> log.info("set1");
> log.info("set1:flaga: "+seFlag);
> seconds.setText(secsCount);
> seconds.setEnabled(true);
> count.setEnabled(true);
> count.setText(seCount);
> sum.setEnabled(true);
> sum.setText(seSum);
> flag.setEnabled(true);
> flag.setText(seFlag);
> }
>
> /**
> * Set the number of seconds which should be reflected in the GUI. If
> the
> * secsCount is less than 0, the number of seconds will be assumed to
> be
> * infinity.
> *
> * @param secsCount the number of seconds
> */
> private void setState(long secsCount, int seCount, int seSum, boolean
> seFlag)
> {
> log.info("set2");
> log.info("set2:flaga: "+seFlag);
> seconds.setEnabled(true);
> seconds.setText("" + secsCount);
> count.setEnabled(true);
> count.setText(""+seCount);
> sum.setEnabled(true);
> sum.setText("" + seSum);
> flag.setEnabled(true);
> flag.setText(""+seFlag);
>
> }
> }
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]