You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by Mike Verdone <mi...@pason.com> on 2004/02/03 21:46:18 UTC

[PATCH] new controller - RandomOrderController

Hello JMeter developers,

Attached to this message is a patch that adds a new controller type to JMeter. 
RandomOrderController executes each of its child nodes at most once, but in a 
random order. I wrote this in order to simulate a users viewing pages in a 
random order, while guaranteeing the number of times each page is viewed.

The patch is based on the latest CVS trunk (as of writing). It has unit tests 
and documentation included. Please let me know if this patch is acceptable, 
as this is my first one.

Thanks,

Mike.

Re: [PATCH] new controller - RandomOrderController

Posted by ms...@apache.org.
My only question about this is did you look at the RandomController already in 
JMeter?  I understand your is slightly different, but it might make sense to make your 
additions in the RandomController and let the user select the slightly modified 
behavior, or use the current (default) behavior.  

New controllers are great for users, but a ton of them can also be bewildering - seeing 
two Random controllers in the list could be confusing.  Having one Random controller 
with a little checkbox or something in its gui might make more sense.

-Mike

On 4 Feb 2004 at 10:55, Mike Verdone wrote:

> Small correction - RandomOrderControllerGui should inherit from 
> LogicControllerGui, not AbstractControllerGui. This way the Name field will 
> show up. Thanks!
> 
> Mike.
> 
> 
> On February 3, 2004 01:46 pm, Mike Verdone wrote:
> > Hello JMeter developers,
> >
> > Attached to this message is a patch that adds a new controller type to
> > JMeter. RandomOrderController executes each of its child nodes at most
> > once, but in a random order. I wrote this in order to simulate a users
> > viewing pages in a random order, while guaranteeing the number of times
> > each page is viewed.
> >
> > The patch is based on the latest CVS trunk (as of writing). It has unit
> > tests and documentation included. Please let me know if this patch is
> > acceptable, as this is my first one.
> >
> > Thanks,
> >
> > Mike.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org
> 




--
Michael Stover
mstover1@apache.org
Yahoo IM: mstover_ya
ICQ: 152975688
AIM: mstover777

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org


Re: [PATCH] new controller - RandomOrderController

Posted by Jordi Salvat i Alabart <js...@atg.com>.
Hi Mike.

Your contribution looks useful to me, and while Mike's suggestion to 
merge it with the RandomController makes sense, I still feel it's more 
important to get the functionality there before the next release. So 
unless you or someone else volonteers to do the merging, I will add it 
as-is.

-- 
Salut,

Jordi.

Mike Verdone wrote:
> Hello JMeter developers,
> 
> Attached to this message is a patch that adds a new controller type to JMeter. 
> RandomOrderController executes each of its child nodes at most once, but in a 
> random order. I wrote this in order to simulate a users viewing pages in a 
> random order, while guaranteeing the number of times each page is viewed.
> 
> The patch is based on the latest CVS trunk (as of writing). It has unit tests 
> and documentation included. Please let me know if this patch is acceptable, 
> as this is my first one.
> 
> Thanks,
> 
> Mike.
> 
> 
> ------------------------------------------------------------------------
> 
> Index: src/core/org/apache/jmeter/resources/messages.properties
> ===================================================================
> retrieving revision 1.95
> diff -u -r1.95 messages.properties
> --- src/core/org/apache/jmeter/resources/messages.properties	23 Jan 2004 01:18:07 -0000	1.95
> +++ src/core/org/apache/jmeter/resources/messages.properties	3 Feb 2004 20:37:02 -0000
> @@ -299,6 +299,7 @@
>  proxy_usekeepalive=Set Keep-Alive
>  ramp_up=Ramp-Up Period (in seconds)\:
>  random_control_title=Random Controller
> +random_order_control_title=Random Order Controller
>  read_response_message=Read response is not checked. To see the response, please check the box in the sampler.
>  read_response_note=If read response is unchecked, the sampler will not read the response
>  read_response_note2=or set the SampleResult. This improves performance, but it means
> Index: src/core/org/apache/jmeter/util/JMeterVersion.java
> ===================================================================
> retrieving revision 1.9
> diff -u -r1.9 JMeterVersion.java
> --- src/core/org/apache/jmeter/util/JMeterVersion.java	30 Jan 2004 16:05:38 -0000	1.9
> +++ src/core/org/apache/jmeter/util/JMeterVersion.java	3 Feb 2004 20:37:02 -0000
> @@ -24,7 +24,7 @@
>  	 * pattern: VERSION = <quote>.*<quote>
>  	 * 
>  	 */
> -	static final String VERSION = "1.9.20040130";
> +	static final String VERSION = "1.9.20040203";
>  
>      private JMeterVersion() // Not instantiable
>      {
> Index: xdocs/usermanual/component_reference.xml
> ===================================================================
> retrieving revision 1.76
> diff -u -r1.76 component_reference.xml
> --- xdocs/usermanual/component_reference.xml	2 Feb 2004 14:00:25 -0000	1.76
> +++ xdocs/usermanual/component_reference.xml	3 Feb 2004 20:37:03 -0000
> @@ -757,6 +757,16 @@
>  	<property name="Condition" required="yes">Javascript code that returns "true" or "false"</property>
>  </properties>
>  </component>
> +
> +<component name="Random Order Controller" index="14.2.10" screenshot="">
> +	<description>
> +		<p>The Random Order Controller is much like a Simple Controller in that it will execute each child
> +		 element at most once, but the order of execution of the nodes will be random.</p>
> +	</description>
> +<properties>
> +	<property name="Name" required="No">Descriptive name for this controller that is shown in the tree.</property>
> +</properties>
> +</component>
>  </section>
>  
>  <section name="14.3 Listeners" anchor="listeners">
> Index: src/components/org/apache/jmeter/control/RandomOrderController.java
> ===================================================================
> RCS file: src/components/org/apache/jmeter/control/RandomOrderController.java
> diff -N src/components/org/apache/jmeter/control/RandomOrderController.java
> --- /dev/null	1 Jan 1970 00:00:00 -0000
> +++ src/components/org/apache/jmeter/control/RandomOrderController.java	1 Jan 1970 00:00:00 -0000
> @@ -0,0 +1,215 @@
> +/*
> + * ====================================================================
> + * The Apache Software License, Version 1.1
> + *
> + * Copyright (c) 2004 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
> + * <http://www.apache.org/>.
> + */
> +package org.apache.jmeter.control;
> +
> +import java.io.Serializable;
> +import java.util.ArrayList;
> +import java.util.Iterator;
> +import java.util.List;
> +
> +import junit.framework.TestSuite;
> +
> +import org.apache.jmeter.junit.JMeterTestCase;
> +import org.apache.jmeter.junit.stubs.TestSampler;
> +import org.apache.jmeter.testelement.TestElement;
> +
> +/**
> + * A controller that runs its children each at most once, but in a random order.
> + * 
> + * @author  Mike Verdone
> + * @version $Revision$
> + */
> +public class RandomOrderController
> +    extends GenericController
> +    implements Serializable
> +{
> +    /**
> +     * Create a new RandomOrderController.
> +     */
> +    public RandomOrderController()
> +    {
> +    }
> +
> +    /**
> +     * @see GenericController#initialize()
> +     */ 
> +    public void initialize()
> +    {
> +        super.initialize();
> +        this.reorder();
> +    }
> +
> +    /**
> +     * @see GenericController#reInitialize()
> +     */     
> +    public void reInitialize()
> +    {
> +        super.reInitialize();
> +        this.reorder();
> +    }
> +    
> +    /**
> +     * Replace the subControllersAndSamplers list with a reordered ArrayList.
> +     */
> +    private void reorder()
> +    {
> +        int numElements = this.subControllersAndSamplers.size();
> +        
> +        // Create a new list containing numElements null elements.
> +        List reordered = new ArrayList(this.subControllersAndSamplers.size());
> +        for (int i = 0; i < numElements; i++)
> +        {
> +            reordered.add(null);
> +        }
> +
> +        // Insert the subControllersAndSamplers into random list positions.
> +        for (Iterator i = this.subControllersAndSamplers.iterator();
> +             i.hasNext(); )
> +        {
> +            int idx = (int)Math.floor(Math.random() * reordered.size());
> +            while (true)
> +            {
> +                if (idx == numElements)
> +                {
> +                    idx = 0;
> +                }
> +                if (reordered.get(idx) == null)
> +                {
> +                    reordered.set(idx, i.next());
> +                    break;
> +                }
> +                idx++;
> +            }
> +        }
> +        
> +        // Replace subControllersAndSamplers with reordered copy.
> +        this.subControllersAndSamplers = reordered;
> +    }
> +
> +    public static class Test extends JMeterTestCase
> +    {
> +
> +        public Test(String name)
> +        {
> +            super(name);
> +        }
> +        
> +        public void testRandomOrder()
> +        {
> +            testLog.debug("Testing RandomOrderController");
> +            RandomOrderController roc = new RandomOrderController();
> +            roc.addTestElement(new TestSampler("zero"));
> +            roc.addTestElement(new TestSampler("one"));
> +            roc.addTestElement(new TestSampler("two"));
> +            roc.addTestElement(new TestSampler("three"));
> +            TestElement sampler = null;
> +            List usedSamplers = new ArrayList();
> +            roc.initialize();
> +            while ((sampler = roc.next()) != null)
> +            {
> +                String samplerName = sampler.getPropertyAsString(TestSampler.NAME);
> +                if (usedSamplers.contains(samplerName))
> +                {
> +                    assertTrue("Duplicate sampler returned from next()", false);
> +                }
> +                usedSamplers.add(samplerName);
> +            }
> +            assertTrue("All samplers were returned",
> +                usedSamplers.size() == 4);
> +        }
> +        
> +        public void testRandomOrderNoElements()
> +        {
> +            RandomOrderController roc = new RandomOrderController();
> +            TestElement sampler = null;
> +            List usedSamplers = new ArrayList();
> +            roc.initialize();
> +            assertTrue(roc.next() == null);
> +        }
> +
> +        public void testRandomOrderOneElement()
> +        {
> +            RandomOrderController roc = new RandomOrderController();
> +            roc.addTestElement(new TestSampler("zero"));
> +            TestElement sampler = null;
> +            List usedSamplers = new ArrayList();
> +            roc.initialize();
> +            while ((sampler = roc.next()) != null)
> +            {
> +                String samplerName = sampler.getPropertyAsString(TestSampler.NAME);
> +                if (usedSamplers.contains(samplerName))
> +                {
> +                    assertTrue("Duplicate sampler returned from next()", false);
> +                }
> +                usedSamplers.add(samplerName);
> +            }
> +            assertTrue("All samplers were returned",
> +                usedSamplers.size() == 1);
> +        }
> +    }
> +
> +    public static void main(String args[])
> +    {
> +        junit.textui.TestRunner.run(suite());
> +    }
> +
> +    public static TestSuite suite()
> +    {
> +        TestSuite suite = new TestSuite();
> +        suite.addTest(new Test("testRandomOrderController"));
> +        return suite;
> +    }
> +
> +}
> Index: src/components/org/apache/jmeter/control/gui/RandomOrderControllerGui.java
> ===================================================================
> RCS file: src/components/org/apache/jmeter/control/gui/RandomOrderControllerGui.java
> diff -N src/components/org/apache/jmeter/control/gui/RandomOrderControllerGui.java
> --- /dev/null	1 Jan 1970 00:00:00 -0000
> +++ src/components/org/apache/jmeter/control/gui/RandomOrderControllerGui.java	1 Jan 1970 00:00:00 -0000
> @@ -0,0 +1,96 @@
> +/*
> + * ====================================================================
> + * The Apache Software License, Version 1.1
> + *
> + * Copyright (c) 2004 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
> + * <http://www.apache.org/>.
> + */
> +package org.apache.jmeter.control.gui;
> +
> +import org.apache.jmeter.control.RandomOrderController;
> +import org.apache.jmeter.testelement.TestElement;
> +import org.apache.jmeter.util.JMeterUtils;
> +
> +/**
> + * GUI for RandomOrderController.
> + * 
> + * @author Mike Verdone
> + * @version $Revision$
> + */
> +public class RandomOrderControllerGui extends AbstractControllerGui
> +{
> +
> +    /* (non-Javadoc)
> +     * @see org.apache.jmeter.gui.JMeterGUIComponent#getStaticLabel()
> +     */
> +    public String getStaticLabel()
> +    {
> +        return JMeterUtils.getResString("random_order_control_title");
> +    }
> +
> +    /* (non-Javadoc)
> +     * @see org.apache.jmeter.gui.JMeterGUIComponent#createTestElement()
> +     */
> +    public TestElement createTestElement()
> +    {
> +        RandomOrderController ic = new RandomOrderController();
> +        modifyTestElement(ic);
> +        return ic;
> +    }
> +
> +    /* (non-Javadoc)
> +     * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(org.apache.jmeter.testelement.TestElement)
> +     */
> +    public void modifyTestElement(TestElement ic)
> +    {
> +        configureTestElement(ic);
> +    }
> +
> +}
> 
> 
> 
> ------------------------------------------------------------------------
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org


Re: [PATCH] new controller - RandomOrderController

Posted by Mike Verdone <mi...@pason.com>.
Small correction - RandomOrderControllerGui should inherit from 
LogicControllerGui, not AbstractControllerGui. This way the Name field will 
show up. Thanks!

Mike.


On February 3, 2004 01:46 pm, Mike Verdone wrote:
> Hello JMeter developers,
>
> Attached to this message is a patch that adds a new controller type to
> JMeter. RandomOrderController executes each of its child nodes at most
> once, but in a random order. I wrote this in order to simulate a users
> viewing pages in a random order, while guaranteeing the number of times
> each page is viewed.
>
> The patch is based on the latest CVS trunk (as of writing). It has unit
> tests and documentation included. Please let me know if this patch is
> acceptable, as this is my first one.
>
> Thanks,
>
> Mike.


---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org