Converted ConstantThroughputTimer into a TestBean. Woohoo!

git-svn-id: https://svn.apache.org/repos/asf/jakarta/jmeter/trunk@324091 13f79535-47bb-0310-9956-ffa450edef68

Former-commit-id: 323453023a
This commit is contained in:
Jordi Salvat i Alabart 2004-01-16 02:31:35 +00:00
parent 4d9857f391
commit a7e4d0adaf
5 changed files with 150 additions and 223 deletions

View File

@ -1,4 +1,17 @@
# Class, property and value upgrade equivalences.
#
# Format is as follows --
# for renamed test element & GUI classes:
# old.class.Name=new.class.Name
# for renamed properties:
# old.class.Name/Old.propertyName=newPropertyName
# for renamed values:
# old.class.Name.old.propertyName/oldValue=newValue
#
org.apache.jmeter.protocol.http.config.gui.UrlConfigGui=org.apache.jmeter.protocol.http.config.gui.HttpDefaultsGui
org.apache.jmeter.assertions.Assertion=org.apache.jmeter.assertions.ResponseAssertion
org.apache.jmeter.protocol.http.sampler.HTTPSamplerFull=org.apache.jmeter.protocol.http.sampler.HTTPSampler
org.apache.jmeter.control.gui.RecordController=org.apache.jmeter.protocol.http.control.gui.RecordController
org.apache.jmeter.control.gui.RecordController=org.apache.jmeter.protocol.http.control.gui.RecordController
org.apache.jmeter.timers.gui.ConstantThroughputTimerGui=org.apache.jmeter.testbeans.gui.TestBeanGUI
org.apache.jmeter.timers.ConstantThroughputTimer/ConstantThroughputTimer.throughput=throughput

View File

@ -54,10 +54,12 @@
*/
package org.apache.jmeter.timers;
import java.io.Serializable;
import org.apache.jmeter.testelement.AbstractTestElement;
import org.apache.jmeter.engine.event.LoopIterationEvent;
import org.apache.jmeter.testbeans.TestBean;
import org.apache.jmeter.testelement.TestListener;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;
/**
* This class implements a constant throughput timer. A Constant Throughtput
@ -69,11 +71,11 @@ import org.apache.jmeter.util.JMeterUtils;
* @version $Id$
*/
public class ConstantThroughputTimer
extends AbstractTestElement
implements Timer, Serializable
extends TestBean
implements Timer, TestListener
{
public final static String THROUGHPUT= "ConstantThroughputTimer.throughput";
protected static final Logger log = LoggingManager.getLoggerForClass();
/**
* Target time for the start of the next request. The delay provided by
* the timer will be calculated so that the next request happens at this
@ -81,6 +83,11 @@ public class ConstantThroughputTimer
*/
private long targetTime= 0;
/**
* Desired throughput, in samples per minute.
*/
private double throughput;
/**
* Constructor for a non-configured ConstantThroughputTimer.
*/
@ -93,39 +100,9 @@ public class ConstantThroughputTimer
*
* @param throughput Desired sampling rate, in samples per minute.
*/
public void setThroughput(String throughput)
public void setThroughput(double throughput)
{
setProperty(THROUGHPUT,throughput);
}
/**
* Not implemented.
*/
public void setRange(double range)
{
}
/**
* Not implemented.
*/
public double getRange()
{
return (double)0;
}
/**
* Not implemented.
*/
public void setDelay(String delay)
{
}
/**
* Not implemented.
*/
public String getDelay()
{
return "";
this.throughput= throughput;
}
/**
@ -133,16 +110,11 @@ public class ConstantThroughputTimer
*
* @return the rate at which samples should occur, in samples per minute.
*/
public long getThroughput()
public double getThroughput()
{
return getPropertyAsLong(THROUGHPUT);
return throughput;
}
public String getThroughputString()
{
return getPropertyAsString(THROUGHPUT);
}
/**
* Retrieve the delay to use during test execution.
*
@ -150,9 +122,11 @@ public class ConstantThroughputTimer
*/
public synchronized long delay()
{
prepare();
long currentTime = System.currentTimeMillis();
long currentTarget = targetTime == 0 ? currentTime : targetTime;
targetTime = currentTarget + 60000 / getThroughput();
targetTime = currentTarget + (long)( 60000.0 / getThroughput() );
if (currentTime > currentTarget)
{
// We're behind schedule -- try to catch up:
@ -172,17 +146,41 @@ public class ConstantThroughputTimer
}
/**
* Creates a copy of this ConstantThroughputTimer, ready to start
* calculating delays for new samples. This is in assumption that cloning
* always happens just before a test starts running.
*
* @return a fresh copy of this ConstantThroughputTimer
* Get the timer ready to compute delays for a new test.
*
* @see org.apache.jmeter.testelement.TestListener#testStarted()
*/
public Object clone()
public void testStarted()
{
ConstantThroughputTimer result =
(ConstantThroughputTimer) super.clone();
result.targetTime = 0;
return result;
log.debug("Test started - reset throughput calculation.");
targetTime= 0;
}
}
/* (non-Javadoc)
* @see org.apache.jmeter.testelement.TestListener#testEnded()
*/
public void testEnded()
{
}
/* (non-Javadoc)
* @see org.apache.jmeter.testelement.TestListener#testStarted(java.lang.String)
*/
public void testStarted(String host)
{
}
/* (non-Javadoc)
* @see org.apache.jmeter.testelement.TestListener#testEnded(java.lang.String)
*/
public void testEnded(String host)
{
}
/* (non-Javadoc)
* @see org.apache.jmeter.testelement.TestListener#testIterationStart(org.apache.jmeter.engine.event.LoopIterationEvent)
*/
public void testIterationStart(LoopIterationEvent event)
{
}
}

View File

@ -0,0 +1,76 @@
/*
* ====================================================================
* 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/>.
*
* @author <a href="mailto:jsalvata@apache.org">Jordi Salvat i Alabart</a>
* @version $Id$
*/
package org.apache.jmeter.timers;
import java.beans.PropertyDescriptor;
import org.apache.jmeter.testbeans.gui.BeanInfoSupport;
public class ConstantThroughputTimerBeanInfo extends BeanInfoSupport
{
public ConstantThroughputTimerBeanInfo()
{
super(ConstantThroughputTimer.class);
createPropertyGroup("delay", new String[] { "throughput" });
PropertyDescriptor p= property("throughput");
p.setValue(NOT_UNDEFINED, Boolean.TRUE);
p.setValue(DEFAULT, new Double(0.0));
}
}

View File

@ -0,0 +1,4 @@
displayName=Constant Throughput Timer
delay.displayName=Delay before each affected sampler
throughput.displayName=Throughput (samples per minute)
throughput.shortDescription=Maximum number of samples per minute you want to obtain per thread from all affected samplers.

View File

@ -1,164 +0,0 @@
/*
* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002,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
* <http://www.apache.org/>.
*/
package org.apache.jmeter.timers.gui;
import javax.swing.Box;
import javax.swing.JLabel;
import javax.swing.JTextField;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.timers.ConstantThroughputTimer;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.gui.layout.VerticalLayout;
/**
* GUI for the Constant Throughput Timer.
*
* @author <a href="mailto:jsalvata@atg.com">Jordi Salvat i Alabart</a>
* @author <a href="mailto:seade@backstagetech.com.au">Scott Eade</a>
* @version $Id$
*/
public class ConstantThroughputTimerGui extends AbstractTimerGui
{
private static final String DEFAULT_THROUGHPUT = "60";
private static final String THROUGHPUT_FIELD = "Throughput Field";
private JTextField throughputField;
/**
* Constructor for an initialized but unconfigured
* ConstantThroughputTimerGui.
*/
public ConstantThroughputTimerGui()
{
init();
}
/**
* Get the title to display for this component.
*
* @see org.apache.jmeter.gui.JMeterGUIComponent#getStaticLabel()
*/
public String getStaticLabel()
{
return JMeterUtils.getResString("constant_throughput_timer_title");
}
/**
* Create the test element underlying this GUI component.
*
* @see org.apache.jmeter.gui.JMeterGUIComponent#createTestElement()
*/
public TestElement createTestElement()
{
ConstantThroughputTimer timer = new ConstantThroughputTimer();
modifyTestElement(timer);
return timer;
}
/**
* Modifies a given TestElement to mirror the data in the gui components.
* @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
*/
public void modifyTestElement(TestElement timer)
{
this.configureTestElement(timer);
((ConstantThroughputTimer) timer).setThroughput(throughputField.getText());
}
/**
* Configure this GUI component from the underlying TestElement.
*
* @see org.apache.jmeter.gui.JMeterGUIComponent#configure(TestElement)
*/
public void configure(TestElement el)
{
super.configure(el);
ConstantThroughputTimer e = (ConstantThroughputTimer) el;
throughputField.setText(e.getThroughputString());
}
/**
* Initializes this GUI component. Creates and lays out all GUI elements.
*/
private void init()
{
setLayout(new VerticalLayout(5, VerticalLayout.LEFT, VerticalLayout.TOP));
setBorder(makeBorder());
setLayout(new VerticalLayout(5, VerticalLayout.LEFT));
add(makeTitlePanel());
Box throughputPanel = Box.createHorizontalBox();
throughputPanel.add(new JLabel(JMeterUtils.getResString("constant_throughput_timer_throughput")));
throughputField = new JTextField(6);
throughputField.setText(DEFAULT_THROUGHPUT);
throughputField.setName(THROUGHPUT_FIELD);
throughputPanel.add(throughputField);
add(throughputPanel);
}
/* (non-Javadoc)
* @see org.apache.jmeter.gui.JMeterGUIComponent#clear()
*/
public void clear()
{
throughputField.setText(DEFAULT_THROUGHPUT);
super.clear();
}
}