Throughput Controller was not working for "all thread" counts

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

Former-commit-id: e1bff9ee9b
This commit is contained in:
Sebastian Bazley 2007-10-02 23:48:10 +00:00
parent c13aaf7c94
commit e115c87a88
2 changed files with 22 additions and 93 deletions

View File

@ -18,7 +18,6 @@
package org.apache.jmeter.control; package org.apache.jmeter.control;
import java.io.IOException;
import java.io.Serializable; import java.io.Serializable;
import org.apache.jmeter.engine.event.LoopIterationEvent; import org.apache.jmeter.engine.event.LoopIterationEvent;
@ -32,12 +31,13 @@ import org.apache.jmeter.testelement.property.JMeterProperty;
import org.apache.jmeter.testelement.property.StringProperty; import org.apache.jmeter.testelement.property.StringProperty;
/** /**
* This class represents a controller that can controll the number of times that * This class represents a controller that can control the number of times that
* it is executed, either by the total number of times the user wants the * it is executed, either by the total number of times the user wants the
* controller executed (BYNUMBER) or by the percentage of time it is called * controller executed (BYNUMBER) or by the percentage of time it is called
* (BYPERCENT) * (BYPERCENT)
* *
* @author Thad Smith * The current implementation executes the first N samples (BYNUMBER)
* or the last N% of samples (BYPERCENT).
*/ */
public class ThroughputController extends GenericController implements Serializable, LoopIterationListener, public class ThroughputController extends GenericController implements Serializable, LoopIterationListener,
TestListener { TestListener {
@ -54,11 +54,11 @@ public class ThroughputController extends GenericController implements Serializa
private static final String PERCENTTHROUGHPUT = "ThroughputController.percentThroughput";// $NON-NLS-1$ private static final String PERCENTTHROUGHPUT = "ThroughputController.percentThroughput";// $NON-NLS-1$
private int globalNumExecutions; private static int globalNumExecutions;
private int globalIteration; private static int globalIteration;
private transient Object counterLock; private static Object counterLock; // ensure counts are updated correctly
/** /**
* Number of iterations on which we've chosen to deliver samplers. * Number of iterations on which we've chosen to deliver samplers.
@ -76,9 +76,6 @@ public class ThroughputController extends GenericController implements Serializa
private boolean runThisTime; private boolean runThisTime;
public ThroughputController() { public ThroughputController() {
globalNumExecutions = 0;
globalIteration = -1;
counterLock = new Object();
setStyle(BYNUMBER); setStyle(BYNUMBER);
setPerThread(true); setPerThread(true);
setMaxThroughput(1); setMaxThroughput(1);
@ -154,42 +151,13 @@ public class ThroughputController extends GenericController implements Serializa
return retVal; return retVal;
} }
protected void setExecutions(int executions) { private int getExecutions() {
if (!isPerThread()) {
globalNumExecutions = executions;
}
this.numExecutions = executions;
}
protected int getExecutions() {
if (!isPerThread()) { if (!isPerThread()) {
return globalNumExecutions; return globalNumExecutions;
} }
return numExecutions; return numExecutions;
} }
private void increaseExecutions() {
setExecutions(getExecutions() + 1);
}
protected void setIteration(int iteration) {
if (!isPerThread()) {
globalIteration = iteration;
}
this.iteration = iteration;
}
protected int getIteration() {
if (!isPerThread()) {
return globalIteration;
}
return iteration;
}
private void increaseIteration() {
setIteration(getIteration() + 1);
}
/** /**
* @see org.apache.jmeter.control.Controller#next() * @see org.apache.jmeter.control.Controller#next()
*/ */
@ -203,11 +171,7 @@ public class ThroughputController extends GenericController implements Serializa
/** /**
* Decide whether to return any samplers on this iteration. * Decide whether to return any samplers on this iteration.
*/ */
private boolean decide() { private boolean decide(int executions, int iterations) {
int executions, iterations;
executions = getExecutions();
iterations = getIteration();
if (getStyle() == BYNUMBER) { if (getStyle() == BYNUMBER) {
return executions < getMaxThroughputAsInt(); return executions < getMaxThroughputAsInt();
} }
@ -232,78 +196,42 @@ public class ThroughputController extends GenericController implements Serializa
ThroughputController clone = (ThroughputController) super.clone(); ThroughputController clone = (ThroughputController) super.clone();
clone.numExecutions = numExecutions; clone.numExecutions = numExecutions;
clone.iteration = iteration; clone.iteration = iteration;
clone.globalNumExecutions = globalNumExecutions;
clone.globalIteration = globalIteration;
clone.counterLock = counterLock;
clone.runThisTime = false; clone.runThisTime = false;
return clone; return clone;
} }
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
counterLock = new Object();
}
/*
* (non-Javadoc)
*
* @see LoopIterationListener#iterationStart(LoopIterationEvent)
*/
public void iterationStart(LoopIterationEvent iterEvent) { public void iterationStart(LoopIterationEvent iterEvent) {
if (!isPerThread()) { if (!isPerThread()) {
synchronized (counterLock) { synchronized (counterLock) {
increaseIteration(); globalIteration++;
runThisTime = decide(); runThisTime = decide(globalNumExecutions, globalIteration);
if (runThisTime) if (runThisTime)
increaseExecutions(); globalNumExecutions++;
} }
} else { } else {
increaseIteration(); iteration++;
runThisTime = decide(); runThisTime = decide(numExecutions, iteration);
if (runThisTime) if (runThisTime)
increaseExecutions(); numExecutions++;
} }
} }
/*
* (non-Javadoc)
*
* @see org.apache.jmeter.testelement.TestListener#testStarted()
*/
public void testStarted() { public void testStarted() {
setExecutions(0); globalNumExecutions = 0;
setIteration(-1); globalIteration = -1;
counterLock = new Object();
}
public void testStarted(String host) {
testStarted();
} }
/*
* (non-Javadoc)
*
* @see org.apache.jmeter.testelement.TestListener#testEnded()
*/
public void testEnded() { public void testEnded() {
} }
/*
* (non-Javadoc)
*
* @see TestListener#testStarted(String)
*/
public void testStarted(String host) {
}
/*
* (non-Javadoc)
*
* @see TestListener#testEnded(String)
*/
public void testEnded(String host) { public void testEnded(String host) {
} }
/*
* (non-Javadoc)
*
* @see TestListener#testIterationStart(LoopIterationEvent)
*/
public void testIterationStart(LoopIterationEvent event) { public void testIterationStart(LoopIterationEvent event) {
} }
} }

View File

@ -32,6 +32,7 @@
<h4>Bug fixes</h4> <h4>Bug fixes</h4>
<ul> <ul>
<li>Bug 43430 - Count of active threads is incorrect for remote samples</li> <li>Bug 43430 - Count of active threads is incorrect for remote samples</li>
<li>Throughput Controller was not working for "all thread" counts</li>
</ul> </ul>
<h4>Improvements</h4> <h4>Improvements</h4>