apache / jmeter

Apache JMeter open-source load testing tool for analyzing and measuring the performance of a variety of services
https://jmeter.apache.org/
Apache License 2.0
7.98k stars 2.03k forks source link

new ForEach controller #1295

Closed asfimport closed 20 years ago

asfimport commented 20 years ago

Dolf Smits (Bug 26355): Need for a new foreach controller, wjich will step through a list of values

give it some input variable, which consists of several variables each extended with a number, eg input vaibale searchlink, you need to have defined searchlink_1, searchlink_2 etc, it will se these values successive and place them in the output variable.

Severity: normal OS: All

asfimport commented 20 years ago

Dolf Smits (migrated from Bugzilla): Created attachment ForeachController.java: source from foreach controller

ForeachController.java ````java /* * ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001,2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache JMeter" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * "Apache JMeter", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . */ package org.apache.jmeter.control; import java.io.Serializable; import org.apache.jmeter.junit.JMeterTestCase; import org.apache.jmeter.junit.stubs.TestSampler; import org.apache.jmeter.samplers.Sampler; import org.apache.jmeter.testelement.TestElement; import org.apache.jmeter.threads.JMeterContext; import org.apache.jmeter.threads.JMeterContextService; import org.apache.jmeter.testelement.property.BooleanProperty; import org.apache.jmeter.testelement.property.IntegerProperty; import org.apache.jmeter.testelement.property.StringProperty; import org.apache.log.Logger; /** * @author Dolf Smits * @author Michael Stover * @author Thad Smith * @version $Revision: 1.19 $ */ public class ForeachController extends GenericController implements Serializable { private final static String INPUTVAL = "ForeachController.inputVal"; private final static String RETURNVAL ="ForeachController.returnVal"; private int loopCount = 0; public ForeachController() { } public void initialize() { log.debug("Initilizing ForEach"); } public void setInputVal(String inputValue) { setProperty(new StringProperty(INPUTVAL, inputValue)); } public String getInputValString() { return getPropertyAsString(INPUTVAL); } public void setReturnVal(String inputValue) { setProperty(new StringProperty(RETURNVAL, inputValue)); } public String getReturnValString() { return getPropertyAsString(RETURNVAL); } /* (non-Javadoc) * @see org.apache.jmeter.control.Controller#isDone() */ public boolean isDone() { JMeterContext context = JMeterContextService.getContext(); String inputVariable=getInputValString()+"_"+(loopCount+1); if (context.getVariables().get(inputVariable) != null) { context.getVariables().put(getReturnValString(), context.getVariables().get(inputVariable)); log.debug("ForEach resultstring isDone="+context.getVariables().get(getReturnValString())); return false; } return super.isDone(); } private boolean endOfArguments() { JMeterContext context = JMeterContextService.getContext(); String inputVariable=getInputValString()+"_"+(loopCount+1); if (context.getVariables().get(inputVariable) != null) { log.debug("ForEach resultstring eofArgs= false"); return false; } else { log.debug("ForEach resultstring eofArgs= true"); return true; } } /* (non-Javadoc) * @see org.apache.jmeter.control.GenericController#nextIsNull() */ protected Sampler nextIsNull() throws NextIsNullException { reInitialize(); if (endOfArguments()) { setDone(true); return null; } else { return next(); } } protected void incrementLoopCount() { loopCount++; } protected void resetLoopCount() { loopCount = 0; } /* (non-Javadoc) * @see org.apache.jmeter.control.GenericController#getIterCount() */ protected int getIterCount() { return loopCount + 1; } /* (non-Javadoc) * @see org.apache.jmeter.control.GenericController#reInitialize() */ protected void reInitialize() { setFirst(true); resetCurrent(); incrementLoopCount(); } } ````
asfimport commented 20 years ago

Dolf Smits (migrated from Bugzilla): Created attachment ForeachControlPanel.java: gui control panel for ForEach controller

ForeachControlPanel.java ````java package org.apache.jmeter.control.gui; import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.Box; import javax.swing.JCheckBox; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import org.apache.jmeter.control.ForeachController; import org.apache.jmeter.gui.util.FocusRequester; import org.apache.jmeter.gui.util.VerticalPanel; import org.apache.jmeter.testelement.TestElement; import org.apache.jmeter.util.JMeterUtils; /** * The user interface for a foreach controller which specifies that its subcomponents * should be executed some number of times in a loop. This component can be * used standalone or embedded into some other component. * Copyright: 2000 * * @author Dolf Smits * @author Michael Stover * @version $Revision: 1.1 $ */ public class ForeachControlPanel extends AbstractControllerGui { /** * A field allowing the user to specify the input variable the controller * should loop. */ private JTextField inputVal; /** * A field allowing the user to specify output variable the controller * should return. */ private JTextField returnVal; /** * 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 infinite checkbox component. */ private static final String INPUTVAL = "Input Field"; /** The name of the loops field component. */ private static final String RETURNVAL = "Return Field"; /** * Create a new LoopControlPanel as a standalone component. */ public ForeachControlPanel() { 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 ForeachControlPanel(boolean displayName) { this.displayName = displayName; init(); } /** * 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); inputVal.setText(((ForeachController) element).getInputValString()); returnVal.setText(((ForeachController) element).getReturnValString()); } /* Implements JMeterGUIComponent.createTestElement() */ public TestElement createTestElement() { ForeachController lc = new ForeachController(); modifyTestElement(lc); return lc; } /* Implements JMeterGUIComponent.modifyTestElement(TestElement) */ public void modifyTestElement(TestElement lc) { configureTestElement(lc); if (lc instanceof ForeachController) { if (inputVal.getText().length() > 0) { ((ForeachController) lc).setInputVal(inputVal.getText()); } else { ((ForeachController) lc).setInputVal(""); } if (returnVal.getText().length() > 0) { ((ForeachController) lc).setReturnVal(returnVal.getText()); } else { ((ForeachController) lc).setReturnVal(""); } } } /* Implements JMeterGUIComponent.getStaticLabel() */ public String getStaticLabel() { return JMeterUtils.getResString("foreach_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 if (displayName) { setLayout(new BorderLayout(0, 5)); setBorder(makeBorder()); add(makeTitlePanel(), BorderLayout.NORTH); JPanel mainPanel = new JPanel(new BorderLayout()); mainPanel.add(createLoopCountPanel(), BorderLayout.NORTH); add(mainPanel, BorderLayout.CENTER); } else { // Embedded setLayout(new BorderLayout()); add(createLoopCountPanel(), BorderLayout.NORTH); } } /** * Create a GUI panel containing the components related to the number of * loops which should be executed. * * @return a GUI panel containing the loop count components */ private JPanel createLoopCountPanel() { // JPanel loopPanel = new JPanel(new BorderLayout(5, 0)); VerticalPanel loopPanel = new VerticalPanel(); // LOOP LABEL JLabel inputValLabel = new JLabel(JMeterUtils.getResString("foreach_input")); JLabel returnValLabel = new JLabel(JMeterUtils.getResString("foreach_return")); // TEXT FIELD JPanel inputValSubPanel = new JPanel(new BorderLayout(5, 0)); inputVal = new JTextField("", 5); inputVal.setName(INPUTVAL); inputValLabel.setLabelFor(inputVal); inputValSubPanel.add(inputValLabel, BorderLayout.WEST); inputValSubPanel.add(inputVal, BorderLayout.CENTER); // TEXT FIELD JPanel returnValSubPanel = new JPanel(new BorderLayout(5, 0)); returnVal = new JTextField("", 5); returnVal.setName(RETURNVAL); returnValLabel.setLabelFor(returnVal); returnValSubPanel.add(returnValLabel, BorderLayout.WEST); returnValSubPanel.add(returnVal, BorderLayout.CENTER); loopPanel.add(inputValSubPanel); loopPanel.add(returnValSubPanel); return loopPanel; } } ````
asfimport commented 20 years ago

Dolf Smits (migrated from Bugzilla): I made the patch from the level core.org.apache.jmeter.control, so the following keys need to be added to the messages.properties as well. foreach_controller_title=ForEach Controller

foreach_input=Name of input variable

foreach_return=Name of return variable

asfimport commented 20 years ago

Dolf Smits (migrated from Bugzilla): Created attachment ForeachController.java: revised version

ForeachController.java ````java /* * ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001,2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache JMeter" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * "Apache JMeter", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . */ package org.apache.jmeter.control; import java.io.Serializable; import org.apache.jmeter.junit.JMeterTestCase; import org.apache.jmeter.junit.stubs.TestSampler; import org.apache.jmeter.samplers.Sampler; import org.apache.jmeter.testelement.TestElement; import org.apache.jmeter.threads.JMeterContext; import org.apache.jmeter.threads.JMeterContextService; import org.apache.jmeter.testelement.property.BooleanProperty; import org.apache.jmeter.testelement.property.IntegerProperty; import org.apache.jmeter.testelement.property.StringProperty; import org.apache.log.Logger; /** * @author Dolf Smits * @author Michael Stover * @author Thad Smith * @version $Revision: 1.19 $ */ public class ForeachController extends GenericController implements Serializable { private final static String INPUTVAL = "ForeachController.inputVal"; private final static String RETURNVAL ="ForeachController.returnVal"; private int loopCount = 0; public ForeachController() { } public void initialize() { log.debug("Initilizing ForEach"); } public void setInputVal(String inputValue) { setProperty(new StringProperty(INPUTVAL, inputValue)); } public String getInputValString() { return getPropertyAsString(INPUTVAL); } public void setReturnVal(String inputValue) { setProperty(new StringProperty(RETURNVAL, inputValue)); } public String getReturnValString() { return getPropertyAsString(RETURNVAL); } /* (non-Javadoc) * @see org.apache.jmeter.control.Controller#isDone() */ public boolean isDone() { JMeterContext context = JMeterContextService.getContext(); String inputVariable=getInputValString()+"_"+(loopCount+1); if (context.getVariables().get(inputVariable) != null) { context.getVariables().put(getReturnValString(), context.getVariables().get(inputVariable)); log.debug("ForEach resultstring isDone="+context.getVariables().get(getReturnValString())); return false; } return super.isDone(); } private boolean endOfArguments() { JMeterContext context = JMeterContextService.getContext(); String inputVariable=getInputValString()+"_"+(loopCount+1); if (context.getVariables().get(inputVariable) != null) { log.debug("ForEach resultstring eofArgs= false"); return false; } else { log.debug("ForEach resultstring eofArgs= true"); return true; } } /* (non-Javadoc) * @see org.apache.jmeter.control.GenericController#nextIsNull() */ protected Sampler nextIsNull() throws NextIsNullException { reInitialize(); if (endOfArguments()) { // setDone(true); resetLoopCount(); return null; } else { return next(); } } protected void incrementLoopCount() { loopCount++; } protected void resetLoopCount() { loopCount = 0; } /* (non-Javadoc) * @see org.apache.jmeter.control.GenericController#getIterCount() */ protected int getIterCount() { return loopCount + 1; } /* (non-Javadoc) * @see org.apache.jmeter.control.GenericController#reInitialize() */ protected void reInitialize() { setFirst(true); resetCurrent(); incrementLoopCount(); } }````
asfimport commented 20 years ago

Sebb (migrated from Bugzilla): Added as a BETA version for now.

Some issues to resolve:

asfimport commented 20 years ago

Dolf Smits (migrated from Bugzilla): Created attachment foreach_docs.zip: xml, testplan and png's for component reference

asfimport commented 20 years ago

Sebb (migrated from Bugzilla): Component reference has been updated; closing call.