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 se...@apache.org on 2007/10/03 01:48:10 UTC

svn commit: r581434 - in /jakarta/jmeter/trunk: src/components/org/apache/jmeter/control/ThroughputController.java xdocs/changes.xml

Author: sebb
Date: Tue Oct  2 16:48:10 2007
New Revision: 581434

URL: http://svn.apache.org/viewvc?rev=581434&view=rev
Log:
Throughput Controller was not working for "all thread" counts

Modified:
    jakarta/jmeter/trunk/src/components/org/apache/jmeter/control/ThroughputController.java
    jakarta/jmeter/trunk/xdocs/changes.xml

Modified: jakarta/jmeter/trunk/src/components/org/apache/jmeter/control/ThroughputController.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/components/org/apache/jmeter/control/ThroughputController.java?rev=581434&r1=581433&r2=581434&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/components/org/apache/jmeter/control/ThroughputController.java (original)
+++ jakarta/jmeter/trunk/src/components/org/apache/jmeter/control/ThroughputController.java Tue Oct  2 16:48:10 2007
@@ -18,7 +18,6 @@
 
 package org.apache.jmeter.control;
 
-import java.io.IOException;
 import java.io.Serializable;
 
 import org.apache.jmeter.engine.event.LoopIterationEvent;
@@ -32,12 +31,13 @@
 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
  * controller executed (BYNUMBER) or by the percentage of time it is called
  * (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,
 		TestListener {
@@ -54,11 +54,11 @@
 
 	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.
@@ -76,9 +76,6 @@
 	private boolean runThisTime;
 
 	public ThroughputController() {
-		globalNumExecutions = 0;
-		globalIteration = -1;
-		counterLock = new Object();
 		setStyle(BYNUMBER);
 		setPerThread(true);
 		setMaxThroughput(1);
@@ -154,42 +151,13 @@
 		return retVal;
 	}
 
-	protected void setExecutions(int executions) {
-		if (!isPerThread()) {
-			globalNumExecutions = executions;
-		}
-		this.numExecutions = executions;
-	}
-
-	protected int getExecutions() {
+	private int getExecutions() {
 		if (!isPerThread()) {
 			return globalNumExecutions;
 		}
 		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()
 	 */
@@ -203,11 +171,7 @@
 	/**
 	 * Decide whether to return any samplers on this iteration.
 	 */
-	private boolean decide() {
-		int executions, iterations;
-
-		executions = getExecutions();
-		iterations = getIteration();
+	private boolean decide(int executions, int iterations) {
 		if (getStyle() == BYNUMBER) {
 			return executions < getMaxThroughputAsInt();
 		}
@@ -232,78 +196,42 @@
 		ThroughputController clone = (ThroughputController) super.clone();
 		clone.numExecutions = numExecutions;
 		clone.iteration = iteration;
-		clone.globalNumExecutions = globalNumExecutions;
-		clone.globalIteration = globalIteration;
-		clone.counterLock = counterLock;
 		clone.runThisTime = false;
 		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) {
 		if (!isPerThread()) {
 			synchronized (counterLock) {
-				increaseIteration();
-				runThisTime = decide();
+				globalIteration++;
+				runThisTime = decide(globalNumExecutions, globalIteration);
 				if (runThisTime)
-					increaseExecutions();
+					globalNumExecutions++;
 			}
 		} else {
-			increaseIteration();
-			runThisTime = decide();
+			iteration++;
+			runThisTime = decide(numExecutions, iteration);
 			if (runThisTime)
-				increaseExecutions();
+				numExecutions++;
 		}
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.apache.jmeter.testelement.TestListener#testStarted()
-	 */
 	public void testStarted() {
-		setExecutions(0);
-		setIteration(-1);
+		globalNumExecutions = 0;
+		globalIteration = -1;
+		counterLock = new Object();
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.apache.jmeter.testelement.TestListener#testEnded()
-	 */
-	public void testEnded() {
+	public void testStarted(String host) {
+		testStarted();
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see TestListener#testStarted(String)
-	 */
-	public void testStarted(String host) {
+	public void testEnded() {
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see TestListener#testEnded(String)
-	 */
 	public void testEnded(String host) {
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see TestListener#testIterationStart(LoopIterationEvent)
-	 */
 	public void testIterationStart(LoopIterationEvent event) {
 	}
 }

Modified: jakarta/jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/changes.xml?rev=581434&r1=581433&r2=581434&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/changes.xml (original)
+++ jakarta/jmeter/trunk/xdocs/changes.xml Tue Oct  2 16:48:10 2007
@@ -32,6 +32,7 @@
 <h4>Bug fixes</h4>
 <ul>
 <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>
 
 <h4>Improvements</h4>



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