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/12/04 12:46:32 UTC
svn commit: r600898 - in /jakarta/jmeter/trunk:
src/core/org/apache/jmeter/control/WhileController.java
test/src/org/apache/jmeter/control/TestWhileController.java xdocs/changes.xml
Author: sebb
Date: Tue Dec 4 03:46:24 2007
New Revision: 600898
URL: http://svn.apache.org/viewvc?rev=600898&view=rev
Log:
Bug 43427 - Simple Controller is only partly executed in While loop
Modified:
jakarta/jmeter/trunk/src/core/org/apache/jmeter/control/WhileController.java
jakarta/jmeter/trunk/test/src/org/apache/jmeter/control/TestWhileController.java
jakarta/jmeter/trunk/xdocs/changes.xml
Modified: jakarta/jmeter/trunk/src/core/org/apache/jmeter/control/WhileController.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/core/org/apache/jmeter/control/WhileController.java?rev=600898&r1=600897&r2=600898&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/core/org/apache/jmeter/control/WhileController.java (original)
+++ jakarta/jmeter/trunk/src/core/org/apache/jmeter/control/WhileController.java Tue Dec 4 03:46:24 2007
@@ -31,42 +31,26 @@
// @see TestWhileController for unit tests
-/**
- * @version $Revision$
- */
public class WhileController extends GenericController implements Serializable {
private static Logger log = LoggingManager.getLoggerForClass();
+ private static final long serialVersionUID = 2L;
+
private final static String CONDITION = "WhileController.condition"; // $NON-NLS-1$
- boolean testMode = false; // To make testing easier
-
- boolean testModeResult = false; // dummy sample result
-
public WhileController() {
}
/*
- * (non-Javadoc)
- *
- * @see org.apache.jmeter.control.Controller#isDone()
- */
- public boolean isDone() {
- if (getSubControllers().size() == 0) // Nothing left to run
- {
- return true;
- }
- return false;// Never want to remove the controller from the tree
- }
-
- /*
- * Evaluate the condition, which can be: blank or LAST = was the last
- * sampler OK? otherwise, evaluate the condition to see if it is not "false"
+ * Evaluate the condition, which can be:
+ * blank or LAST = was the last sampler OK?
+ * otherwise, evaluate the condition to see if it is not "false"
* If blank, only evaluate at the end of the loop
*
* Must only be called at start and end of loop
*
- * @param loopEnd - are we at loop end? @return true means OK to continue
+ * @param loopEnd - are we at loop end?
+ * @return true means OK to continue
*/
private boolean endOfLoop(boolean loopEnd) {
String cnd = getCondition();
@@ -74,13 +58,9 @@
boolean res;
// If blank, only check previous sample when at end of loop
if ((loopEnd && cnd.length() == 0) || "LAST".equalsIgnoreCase(cnd)) {// $NON-NLS-1$
- if (testMode) {
- res = !testModeResult;
- } else {
- JMeterVariables threadVars = JMeterContextService.getContext().getVariables();
- // Use !false rather than true, so that null is treated as true
- res = "false".equalsIgnoreCase(threadVars.get(JMeterThread.LAST_SAMPLE_OK));// $NON-NLS-1$
- }
+ JMeterVariables threadVars = JMeterContextService.getContext().getVariables();
+ // Use !false rather than true, so that null is treated as true
+ res = "false".equalsIgnoreCase(threadVars.get(JMeterThread.LAST_SAMPLE_OK));// $NON-NLS-1$
} else {
// cnd may be blank if next() called us
res = "false".equalsIgnoreCase(cnd);// $NON-NLS-1$
@@ -96,11 +76,10 @@
*/
protected Sampler nextIsNull() throws NextIsNullException {
reInitialize();
- if (!endOfLoop(true)) {
- return super.next();
+ if (endOfLoop(true)){
+ return null;
}
- setDone(true);
- return null;
+ return next();
}
/*
@@ -110,16 +89,13 @@
* distinguish this from previous failure *inside* loop
*
*/
- public Sampler next() {
- if (current != 0) { // in the middle of the loop
- return super.next();
- }
- // Must be start of loop
- if (!endOfLoop(false)) {
- return super.next(); // OK to continue
+ public Sampler next(){
+ if (isFirst()){
+ if (endOfLoop(false)){
+ return null;
+ }
}
- reInitialize(); // Don't even start the loop
- return null;
+ return super.next();
}
/**
Modified: jakarta/jmeter/trunk/test/src/org/apache/jmeter/control/TestWhileController.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/test/src/org/apache/jmeter/control/TestWhileController.java?rev=600898&r1=600897&r2=600898&view=diff
==============================================================================
--- jakarta/jmeter/trunk/test/src/org/apache/jmeter/control/TestWhileController.java (original)
+++ jakarta/jmeter/trunk/test/src/org/apache/jmeter/control/TestWhileController.java Tue Dec 4 03:46:24 2007
@@ -18,14 +18,17 @@
package org.apache.jmeter.control;
+import org.apache.jmeter.engine.util.ValueReplacer;
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.testelement.property.PropertyIterator;
+import org.apache.jmeter.threads.JMeterContext;
+import org.apache.jmeter.threads.JMeterContextService;
+import org.apache.jmeter.threads.JMeterThread;
+import org.apache.jmeter.threads.JMeterVariables;
-/**
- * @version $Revision$
- */
public class TestWhileController extends JMeterTestCase {
static {
// LoggingManager.setPriority("DEBUG","jmeter");
@@ -36,6 +39,26 @@
super(name);
}
+ private JMeterContext jmctx;
+ private JMeterVariables jmvars;
+
+ public void setUp() {
+ jmctx = JMeterContextService.getContext();
+ jmctx.setVariables(new JMeterVariables());
+ jmvars = jmctx.getVariables();
+ }
+
+ private void setLastSampleStatus(boolean status){
+ jmvars.put(JMeterThread.LAST_SAMPLE_OK,Boolean.toString(status));
+ }
+
+ private void setRunning(TestElement el){
+ PropertyIterator pi = el.propertyIterator();
+ while(pi.hasNext()){
+ pi.next().setRunningVersion(true);
+ }
+ }
+
// Get next sample and its name
private String nextName(GenericController c) {
Sampler s = c.next();
@@ -58,8 +81,7 @@
runtestPrevOK("LAST");
}
- private static final String OTHER = "X"; // Dummy for testing
- // functions
+ private static final String OTHER = "X"; // Dummy for testing functions
// While (LAST), previous sample OK - should loop until false
public void testOtherPrevOK() throws Exception {
@@ -67,11 +89,10 @@
runtestPrevOK(OTHER);
}
- public void runtestPrevOK(String type) throws Exception {
+ private void runtestPrevOK(String type) throws Exception {
GenericController controller = new GenericController();
WhileController while_cont = new WhileController();
- while_cont.testMode = true;
- while_cont.testModeResult = true;
+ setLastSampleStatus(true);
while_cont.setCondition(type);
while_cont.addTestElement(new TestSampler("one"));
while_cont.addTestElement(new TestSampler("two"));
@@ -86,25 +107,29 @@
assertEquals("two", nextName(controller));
assertEquals("three", nextName(controller));
assertEquals("one", nextName(controller));
- while_cont.testModeResult = false;// one and two fail
- if (type.equals(OTHER))
+ setLastSampleStatus(false);
+ if (type.equals(OTHER)){
while_cont.setCondition("false");
+ }
assertEquals("two", nextName(controller));
assertEquals("three", nextName(controller));
- while_cont.testModeResult = true;// but three OK, so does not exit
- if (type.equals(OTHER))
+ setLastSampleStatus(true);
+ if (type.equals(OTHER)) {
while_cont.setCondition(OTHER);
+ }
assertEquals("one", nextName(controller));
assertEquals("two", nextName(controller));
assertEquals("three", nextName(controller));
- while_cont.testModeResult = false;// three fails, so exits while
- if (type.equals(OTHER))
+ setLastSampleStatus(false);
+ if (type.equals(OTHER)) {
while_cont.setCondition("false");
+ }
assertEquals("four", nextName(controller));
assertNull(nextName(controller));
- while_cont.testModeResult = true;
- if (type.equals(OTHER))
+ setLastSampleStatus(true);
+ if (type.equals(OTHER)) {
while_cont.setCondition(OTHER);
+ }
assertEquals("one", nextName(controller));
}
@@ -112,9 +137,9 @@
public void testBlankPrevFailed() throws Exception {
// log.info("testBlankPrevFailed");
GenericController controller = new GenericController();
+ controller.setRunningVersion(true);
WhileController while_cont = new WhileController();
- while_cont.testMode = true;
- while_cont.testModeResult = false;
+ setLastSampleStatus(false);
while_cont.setCondition("");
while_cont.addTestElement(new TestSampler("one"));
while_cont.addTestElement(new TestSampler("two"));
@@ -125,12 +150,113 @@
assertEquals("two", nextName(controller));
assertEquals("three", nextName(controller));
assertNull(nextName(controller));
+ // Run entire test again
assertEquals("one", nextName(controller));
assertEquals("two", nextName(controller));
assertEquals("three", nextName(controller));
assertNull(nextName(controller));
}
+ public void testVariable1() throws Exception {
+ GenericController controller = new GenericController();
+ WhileController while_cont = new WhileController();
+ setLastSampleStatus(false);
+ while_cont.setCondition("${VAR}");
+ jmvars.put("VAR", "");
+ ValueReplacer vr = new ValueReplacer();
+ vr.replaceValues(while_cont);
+ setRunning(while_cont);
+ controller.addTestElement(new TestSampler("before"));
+ controller.addTestElement(while_cont);
+ while_cont.addTestElement(new TestSampler("one"));
+ while_cont.addTestElement(new TestSampler("two"));
+ GenericController simple = new GenericController();
+ while_cont.addTestElement(simple);
+ simple.addTestElement(new TestSampler("three"));
+ simple.addTestElement(new TestSampler("four"));
+ controller.addTestElement(new TestSampler("after"));
+ controller.initialize();
+ for (int i = 1; i <= 3; i++) {
+ assertEquals("Loop: "+i,"before", nextName(controller));
+ assertEquals("Loop: "+i,"one", nextName(controller));
+ assertEquals("Loop: "+i,"two", nextName(controller));
+ assertEquals("Loop: "+i,"three", nextName(controller));
+ assertEquals("Loop: "+i,"four", nextName(controller));
+ assertEquals("Loop: "+i,"after", nextName(controller));
+ assertNull("Loop: "+i,nextName(controller));
+ }
+ jmvars.put("VAR", "LAST"); // Should not enter the loop
+ for (int i = 1; i <= 3; i++) {
+ assertEquals("Loop: "+i,"before", nextName(controller));
+ assertEquals("Loop: "+i,"after", nextName(controller));
+ assertNull("Loop: "+i,nextName(controller));
+ }
+ jmvars.put("VAR", "");
+ for (int i = 1; i <= 3; i++) {
+ assertEquals("Loop: "+i,"before", nextName(controller));
+ if (i==1) {
+ assertEquals("Loop: "+i,"one", nextName(controller));
+ assertEquals("Loop: "+i,"two", nextName(controller));
+ assertEquals("Loop: "+i,"three", nextName(controller));
+ jmvars.put("VAR", "LAST"); // Should not enter the loop next time
+ assertEquals("Loop: "+i,"four", nextName(controller));
+ }
+ assertEquals("Loop: "+i,"after", nextName(controller));
+ assertNull("Loop: "+i,nextName(controller));
+ }
+ }
+
+ // Test with SimpleController as first item
+ public void testVariable2() throws Exception {
+ GenericController controller = new GenericController();
+ WhileController while_cont = new WhileController();
+ setLastSampleStatus(false);
+ while_cont.setCondition("${VAR}");
+ jmvars.put("VAR", "");
+ ValueReplacer vr = new ValueReplacer();
+ vr.replaceValues(while_cont);
+ setRunning(while_cont);
+ controller.addTestElement(new TestSampler("before"));
+ controller.addTestElement(while_cont);
+ GenericController simple = new GenericController();
+ while_cont.addTestElement(simple);
+ simple.addTestElement(new TestSampler("one"));
+ simple.addTestElement(new TestSampler("two"));
+ while_cont.addTestElement(new TestSampler("three"));
+ while_cont.addTestElement(new TestSampler("four"));
+ controller.addTestElement(new TestSampler("after"));
+ controller.initialize();
+ for (int i = 1; i <= 3; i++) {
+ assertEquals("Loop: "+i,"before", nextName(controller));
+ assertEquals("Loop: "+i,"one", nextName(controller));
+ assertEquals("Loop: "+i,"two", nextName(controller));
+ assertEquals("Loop: "+i,"three", nextName(controller));
+ assertEquals("Loop: "+i,"four", nextName(controller));
+ assertEquals("Loop: "+i,"after", nextName(controller));
+ assertNull("Loop: "+i,nextName(controller));
+ }
+ jmvars.put("VAR", "LAST"); // Should not enter the loop
+ for (int i = 1; i <= 3; i++) {
+ assertEquals("Loop: "+i,"before", nextName(controller));
+ assertEquals("Loop: "+i,"after", nextName(controller));
+ assertNull("Loop: "+i,nextName(controller));
+ }
+ jmvars.put("VAR", "");
+ for (int i = 1; i <= 3; i++) {
+ assertEquals("Loop: "+i,"before", nextName(controller));
+ if (i==1){
+ assertEquals("Loop: "+i,"one", nextName(controller));
+ assertEquals("Loop: "+i,"two", nextName(controller));
+ jmvars.put("VAR", "LAST"); // Should not enter the loop next time
+ // But should continue to the end of the loop
+ assertEquals("Loop: "+i,"three", nextName(controller));
+ assertEquals("Loop: "+i,"four", nextName(controller));
+ }
+ assertEquals("Loop: "+i,"after", nextName(controller));
+ assertNull("Loop: "+i,nextName(controller));
+ }
+ }
+
// While LAST, previous sample failed - should not run
public void testLASTPrevFailed() throws Exception {
// log.info("testLastPrevFailed");
@@ -143,11 +269,10 @@
runTestPrevFailed("False");
}
- public void runTestPrevFailed(String s) throws Exception {
+ private void runTestPrevFailed(String s) throws Exception {
GenericController controller = new GenericController();
WhileController while_cont = new WhileController();
- while_cont.testMode = true;
- while_cont.testModeResult = false;
+ setLastSampleStatus(false);
while_cont.setCondition(s);
while_cont.addTestElement(new TestSampler("one"));
while_cont.addTestElement(new TestSampler("two"));
@@ -160,28 +285,60 @@
assertNull(nextName(controller));
}
+ public void testLastFailedBlank() throws Exception{
+ runTestLastFailed("");
+ }
+
+ public void testLastFailedLast() throws Exception{
+ runTestLastFailed("LAST");
+ }
+
+ // Should behave the same for blank and LAST because success on input
+ private void runTestLastFailed(String s) throws Exception {
+ GenericController controller = new GenericController();
+ controller.addTestElement(new TestSampler("1"));
+ WhileController while_cont = new WhileController();
+ controller.addTestElement(while_cont);
+ while_cont.setCondition(s);
+ GenericController sub = new GenericController();
+ while_cont.addTestElement(sub);
+ sub.addTestElement(new TestSampler("2"));
+ sub.addTestElement(new TestSampler("3"));
+
+ controller.addTestElement(new TestSampler("4"));
+
+ setLastSampleStatus(true);
+ controller.initialize();
+ assertEquals("1", nextName(controller));
+ assertEquals("2", nextName(controller));
+ setLastSampleStatus(false);
+ assertEquals("3", nextName(controller));
+ assertEquals("4", nextName(controller));
+ assertNull(nextName(controller));
+ }
+
// Tests for Stack Overflow (bug 33954)
public void testAlwaysFailOK() throws Exception {
runTestAlwaysFail(true); // Should be OK
}
public void testAlwaysFailBAD() throws Exception {
- runTestAlwaysFail(false); // Currently fails
+ runTestAlwaysFail(false);
}
- public void runTestAlwaysFail(boolean other) {
+ private void runTestAlwaysFail(boolean other) {
LoopController controller = new LoopController();
controller.setContinueForever(true);
controller.setLoops(-1);
WhileController while_cont = new WhileController();
- while_cont.testMode = true;
- while_cont.testModeResult = false;
+ setLastSampleStatus(false);
while_cont.setCondition("false");
while_cont.addTestElement(new TestSampler("one"));
while_cont.addTestElement(new TestSampler("two"));
controller.addTestElement(while_cont);
- if (other)
+ if (other) {
controller.addTestElement(new TestSampler("three"));
+ }
controller.initialize();
try {
if (other) {
Modified: jakarta/jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/changes.xml?rev=600898&r1=600897&r2=600898&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/changes.xml (original)
+++ jakarta/jmeter/trunk/xdocs/changes.xml Tue Dec 4 03:46:24 2007
@@ -41,6 +41,8 @@
<li>Check that the CSV delimiter is reasonable.</li>
<li>Fix Switch Controller to work properly with functions and variables</li>
<li>Bug 44011 - application/soap+xml not treated as a text type</li>
+<li>Bug 43427 - Simple Controller is only partly executed in While loop</li>
+<li>Bug 33954 - Stack Overflow in If/While controllers (may have been fixed previously)</li>
</ul>
<h4>Improvements</h4>
@@ -50,6 +52,7 @@
<li>Bug 43382 - configure Tidy output (warnings, errors) for XPath Assertion and Post-Processor</li>
<li>Bug 43984 - trim spaces from port field</li>
<li>Add optional comment to __log() function</li>
+<li>Make Random function variable name optional</li>
</ul>
<h4>Non-functional changes</h4>
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org