You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2014/10/12 17:30:39 UTC
svn commit: r1631189 - in /jmeter/trunk: src/core/org/apache/jmeter/control/
src/core/org/apache/jmeter/threads/ test/src/org/apache/jmeter/control/
xdocs/
Author: pmouawad
Date: Sun Oct 12 15:30:39 2014
New Revision: 1631189
URL: http://svn.apache.org/r1631189
Log:
Bug 56160 - StackOverflowError when using WhileController within IfController
Bugzilla Id: 56160
Modified:
jmeter/trunk/src/core/org/apache/jmeter/control/GenericController.java
jmeter/trunk/src/core/org/apache/jmeter/control/IfController.java
jmeter/trunk/src/core/org/apache/jmeter/control/TransactionController.java
jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterContext.java
jmeter/trunk/test/src/org/apache/jmeter/control/TestIfController.java
jmeter/trunk/xdocs/changes.xml
Modified: jmeter/trunk/src/core/org/apache/jmeter/control/GenericController.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/control/GenericController.java?rev=1631189&r1=1631188&r2=1631189&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/control/GenericController.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/control/GenericController.java Sun Oct 12 15:30:39 2014
@@ -98,12 +98,18 @@ public class GenericController extends A
resetCurrent();
resetIterCount();
done = false; // TODO should this use setDone()?
- first = true; // TODO should this use setFirst()?
- TestElement elem;
- for (int i = 0; i < subControllersAndSamplers.size(); i++) {
- elem = subControllersAndSamplers.get(i);
- if (elem instanceof Controller) {
- ((Controller) elem).initialize();
+ first = true; // TODO should this use setFirst()?
+ initializeSubControllers();
+ }
+
+ /**
+ * (re)Initializes sub controllers
+ * See Bug 50032
+ */
+ protected void initializeSubControllers() {
+ for (TestElement te : subControllersAndSamplers) {
+ if(te instanceof GenericController) {
+ ((Controller) te).initialize();
}
}
}
@@ -216,15 +222,7 @@ public class GenericController extends A
* @throws NextIsNullException
*/
protected Sampler nextIsAController(Controller controller) throws NextIsNullException {
- Sampler sampler = null;
- try {
- sampler = controller.next();
- } catch (StackOverflowError soe) {
- // See bug 50618 Catches a StackOverflowError when a condition returns
- // always false (after at least one iteration with return true)
- log.warn("StackOverflowError detected"); // $NON-NLS-1$
- throw new NextIsNullException("StackOverflowError detected", soe);
- }
+ Sampler sampler = controller.next();
if (sampler == null) {
currentReturnedNull(controller);
sampler = next();
@@ -268,28 +266,10 @@ public class GenericController extends A
/**
* Called to re-initialize a index of controller's elements (Bug 50032)
- *
+ * @deprecated replaced by GeneriController#initializeSubControllers
*/
protected void reInitializeSubController() {
- boolean wasFlagSet = getThreadContext().setIsReinitializingSubControllers();
- try {
- TestElement currentElement = getCurrentElement();
- if (currentElement != null) {
- if (currentElement instanceof Sampler) {
- nextIsASampler((Sampler) currentElement);
- } else { // must be a controller
- if (nextIsAController((Controller) currentElement) != null) {
- reInitializeSubController();
- }
- }
- }
- } catch (NextIsNullException e) {
- // NOOP
- } finally {
- if (wasFlagSet) {
- getThreadContext().unsetIsReinitializingSubControllers();
- }
- }
+ initializeSubControllers();
}
/**
Modified: jmeter/trunk/src/core/org/apache/jmeter/control/IfController.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/control/IfController.java?rev=1631189&r1=1631188&r2=1631189&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/control/IfController.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/control/IfController.java Sun Oct 12 15:30:39 2014
@@ -175,7 +175,7 @@ public class IfController extends Generi
}
// If-test is false, need to re-initialize indexes
try {
- reInitializeSubController(); // Bug 50032 - reinitialize current index element for all sub controller
+ initializeSubControllers();
return nextIsNull();
} catch (NextIsNullException e1) {
return null;
@@ -187,7 +187,7 @@ public class IfController extends Generi
*/
@Override
public void triggerEndOfLoop() {
- reInitializeSubController();
+ super.initializeSubControllers();
super.triggerEndOfLoop();
}
Modified: jmeter/trunk/src/core/org/apache/jmeter/control/TransactionController.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/control/TransactionController.java?rev=1631189&r1=1631188&r2=1631189&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/control/TransactionController.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/control/TransactionController.java Sun Oct 12 15:30:39 2014
@@ -257,10 +257,7 @@ public class TransactionController exten
// We must set res to null now, before sending the event for the transaction,
// so that we can ignore that event in our sampleOccured method
res = null;
- // bug 50032
- if (!getThreadContext().isReinitializingSubControllers()) {
- lnf.notifyListeners(event, pack.getSampleListeners());
- }
+ lnf.notifyListeners(event, pack.getSampleListeners());
}
}
Modified: jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterContext.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterContext.java?rev=1631189&r1=1631188&r2=1631189&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterContext.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterContext.java Sun Oct 12 15:30:39 2014
@@ -50,8 +50,6 @@ public class JMeterContext {
private int threadNum;
- private boolean isReinitSubControllers = false;
-
private boolean restartNextLoop = false;
private ConcurrentHashMap<String, Object> samplerContext = new ConcurrentHashMap<String, Object>(5);
@@ -72,7 +70,6 @@ public class JMeterContext {
samplingStarted = false;
threadNum = 0;
thread = null;
- isReinitSubControllers = false;
samplerContext.clear();
}
@@ -167,36 +164,6 @@ public class JMeterContext {
}
/**
- * Reset flag indicating listeners should not be notified since reinit of sub
- * controllers is being done. See bug 50032
- */
- public void unsetIsReinitializingSubControllers() {
- if (isReinitSubControllers) {
- isReinitSubControllers = false;
- }
- }
-
- /**
- * Set flag indicating listeners should not be notified since reinit of sub
- * controllers is being done. See bug 50032
- * @return true if it is the first one to set
- */
- public boolean setIsReinitializingSubControllers() {
- if (!isReinitSubControllers) {
- isReinitSubControllers = true;
- return true;
- }
- return false;
- }
-
- /**
- * @return true if within reinit of Sub Controllers
- */
- public boolean isReinitializingSubControllers() {
- return isReinitSubControllers;
- }
-
- /**
* if set to true a restart of the loop will occurs
* @param restartNextLoop
*/
Modified: jmeter/trunk/test/src/org/apache/jmeter/control/TestIfController.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/control/TestIfController.java?rev=1631189&r1=1631188&r2=1631189&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/control/TestIfController.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/control/TestIfController.java Sun Oct 12 15:30:39 2014
@@ -18,14 +18,128 @@
package org.apache.jmeter.control;
+import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.junit.JMeterTestCase;
import org.apache.jmeter.junit.stubs.TestSampler;
+import org.apache.jmeter.modifiers.CounterConfig;
+import org.apache.jmeter.sampler.DebugSampler;
+import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.samplers.Sampler;
+import org.apache.jmeter.threads.JMeterContext;
+import org.apache.jmeter.threads.JMeterContextService;
+import org.apache.jmeter.threads.JMeterVariables;
public class TestIfController extends JMeterTestCase {
public TestIfController(String name) {
super(name);
}
+
+ /**
+ * See Bug 56160
+ * @throws Exception
+ */
+ public void testStackOverflow() throws Exception {
+ LoopController controller = new LoopController();
+ controller.setLoops(1);
+ controller.setContinueForever(false);
+
+ IfController ifCont = new IfController("true==false");
+ ifCont.setUseExpression(false);
+ ifCont.setEvaluateAll(false);
+ WhileController whileController = new WhileController();
+ whileController.setCondition("${__javaScript(\"true\" != \"false\")}");
+ whileController.addTestElement(new TestSampler("Sample1"));
+
+
+ controller.addTestElement(ifCont);
+ ifCont.addTestElement(whileController);
+
+ Sampler sampler = null;
+ int counter = 0;
+ controller.initialize();
+ controller.setRunningVersion(true);
+ ifCont.setRunningVersion(true);
+ whileController.setRunningVersion(true);
+
+ try {
+ while ((sampler = controller.next()) != null) {
+ sampler.sample(null);
+ counter++;
+ }
+ assertEquals(0, counter);
+ } catch(StackOverflowError e) {
+ fail("Stackoverflow occured in testStackOverflow");
+ }
+ }
+
+ /**
+ * See Bug 53768
+ * @throws Exception
+ */
+ public void testBug53768() throws Exception {
+ LoopController controller = new LoopController();
+ controller.setLoops(1);
+ controller.setContinueForever(false);
+
+ Arguments arguments = new Arguments();
+ arguments.addArgument("VAR1", "0", "=");
+
+ DebugSampler debugSampler1 = new DebugSampler();
+ debugSampler1.setName("VAR1 = ${VAR1}");
+
+ IfController ifCont = new IfController("true==false");
+ ifCont.setUseExpression(false);
+ ifCont.setEvaluateAll(false);
+
+ IfController ifCont2 = new IfController("true==true");
+ ifCont2.setUseExpression(false);
+ ifCont2.setEvaluateAll(false);
+
+ CounterConfig counterConfig = new CounterConfig();
+ counterConfig.setStart(1);
+ counterConfig.setIncrement(1);
+ counterConfig.setVarName("VAR1");
+
+ DebugSampler debugSampler2 = new DebugSampler();
+ debugSampler2.setName("VAR1 = ${VAR1}");
+
+ controller.addTestElement(arguments);
+ controller.addTestElement(debugSampler1);
+ controller.addTestElement(ifCont);
+ ifCont.addTestElement(ifCont2);
+ ifCont2.addTestElement(counterConfig);
+ controller.addTestElement(debugSampler2);
+
+
+
+ controller.initialize();
+ controller.setRunningVersion(true);
+ ifCont.setRunningVersion(true);
+ ifCont2.setRunningVersion(true);
+ counterConfig.setRunningVersion(true);
+ arguments.setRunningVersion(true);
+ debugSampler1.setRunningVersion(true);
+ debugSampler2.setRunningVersion(true);
+ ifCont2.addIterationListener(counterConfig);
+ JMeterVariables vars = new JMeterVariables();
+ JMeterContext jmctx = JMeterContextService.getContext();
+
+ jmctx.setVariables(vars);
+ vars.put("VAR1", "0");
+ try {
+
+ Sampler sampler = controller.next();
+ SampleResult sampleResult1 = sampler.sample(null);
+ assertEquals("0", vars.get("VAR1"));
+ sampler = controller.next();
+ SampleResult sampleResult2 = sampler.sample(null);
+ assertEquals("0", vars.get("VAR1"));
+
+
+ } catch(StackOverflowError e) {
+ fail("Stackoverflow occured in testStackOverflow");
+ }
+ }
public void testProcessing() throws Exception {
@@ -87,6 +201,7 @@ public class TestIfController extends JM
String[] order = new String[] { "Sample1", "Sample2", "Sample3",
"Sample1", "Sample2", "Sample3" };
int counter = 0;
+ controller.initialize();
controller.setRunningVersion(true);
ifCont.setRunningVersion(true);
@@ -120,6 +235,7 @@ public class TestIfController extends JM
String[] order = new String[] { "Sample1", "Sample2", "Sample3",
"Sample1", "Sample2", "Sample3" };
int counter = 0;
+ controller.initialize();
controller.setRunningVersion(true);
ifCont.setRunningVersion(true);
@@ -158,6 +274,7 @@ public class TestIfController extends JM
String[] order = new String[] { "Sample1", "Sample2", "Sample3",
"Sample1", "Sample2", "Sample3" };
int counter = 0;
+ controller.initialize();
controller.setRunningVersion(true);
ifCont.setRunningVersion(true);
genericCont.setRunningVersion(true);
Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1631189&r1=1631188&r2=1631189&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Sun Oct 12 15:30:39 2014
@@ -147,12 +147,6 @@ In addition, you can fetch only the mess
<li>The Once Only controller behaves correctly under a Thread Group or Loop Controller,
but otherwise its behaviour is not consistent (or clearly specified).</li>
-<li>Infinite Loop can happen within JMeter (with possible StackOverflow side effect) when a If Controller has a condition which is always false from the first iteration (see <bugzilla>52496</bugzilla>).
-A workaround is to add a sampler at the same level as (or superior to) the If Controller.
-For example a Test Action sampler with 0 wait time (which doesn't generate a sample),
-or a Debug Sampler with all fields set to False (to reduce the sample size).
-</li>
-
<li>
The numbers that appear to the left of the green box are the number of active threads / total number of threads,
the total number of threads only applies to a locally run test, otherwise it will show 0 (see <bugzilla>55510</bugzilla>).
@@ -229,6 +223,7 @@ for details on configuring this componen
<ul>
<li><bugzilla>56243</bugzilla> - Foreach works incorrectly with indexes on subsequent iterations </li>
<li><bugzilla>56276</bugzilla> - Loop controller becomes broken once loop count evaluates to zero </li>
+<li><bugzilla>56160</bugzilla> - StackOverflowError when using WhileController within IfController</li>
</ul>
<h3>Listeners</h3>