sebb 2004/10/09 09:54:32
Modified: src/components/org/apache/jmeter/control Tag: rel-2_0
ForeachController.java
xdocs/usermanual Tag: rel-2_0 component_reference.xml
Added: xdocs/images/screenshots/logic-controller Tag: rel-2_0
foreach-example2.png
xdocs/demos Tag: rel-2_0 ForEachTest2.jmx
Log:
Fix ForEach Controller so it does not run if there are no matches
Add extra demo showing this behaviour
Revision Changes Path
No revision
No revision
1.1.2.1 +32 -0
jakarta-jmeter/xdocs/images/screenshots/logic-controller/Attic/foreach-example2.png
<<Binary file>>
No revision
No revision
1.1.2.1 +339 -0 jakarta-jmeter/xdocs/demos/Attic/ForEachTest2.jmx
No revision
No revision
1.3.2.1 +33 -3
jakarta-jmeter/src/components/org/apache/jmeter/control/ForeachController.java
Index: ForeachController.java
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/components/org/apache/jmeter/control/ForeachController.java,v
retrieving revision 1.3
retrieving revision 1.3.2.1
diff -u -r1.3 -r1.3.2.1
--- ForeachController.java 22 Feb 2004 19:16:12 -0000 1.3
+++ ForeachController.java 9 Oct 2004 16:54:32 -0000 1.3.2.1
@@ -97,7 +97,37 @@
}
}
- /* (non-Javadoc)
+ // Prevent entry if nothing to do
+ public Sampler next()
+ {
+ if(emptyList())
+ {
+ reInitialize();
+ return null;
+ }
+ return super.next();
+ }
+
+ /**
+ * Check if there are any matching entries
+ *
+ * @return whethere any entries in the list
+ */
+ private boolean emptyList() {
+ JMeterContext context = getThreadContext();
+ String inputVariable=getInputValString()+"_1";
+ if (context.getVariables().get(inputVariable) != null)
+ {
+ return false;
+ }
+ else
+ {
+ log.debug("No entries found - null first entry: "+inputVariable);
+ return true;
+ }
+ }
+
+ /* (non-Javadoc)
* @see org.apache.jmeter.control.GenericController#nextIsNull()
*/
protected Sampler nextIsNull() throws NextIsNullException
No revision
No revision
1.87.2.12 +24 -9 jakarta-jmeter/xdocs/usermanual/component_reference.xml
Index: component_reference.xml
===================================================================
RCS file: /home/cvs/jakarta-jmeter/xdocs/usermanual/component_reference.xml,v
retrieving revision 1.87.2.11
retrieving revision 1.87.2.12
diff -u -r1.87.2.11 -r1.87.2.12
--- component_reference.xml 8 Oct 2004 23:07:06 -0000 1.87.2.11
+++ component_reference.xml 9 Oct 2004 16:54:32 -0000 1.87.2.12
@@ -764,11 +764,8 @@
It is especially suited for running with the regular expression post-processor.
This can "create" the necessary input variables out of the result data of a
previous request.
</p>
-<p>Known bugs/problems</p>
-<ul>
-<li>When the inputVar_1 does not exist, the loop will start anyway, which is not
the correct behaviour.</li>
-<li>It will stop the foreach loop as soon as it encounters a null reference, so any
empty variable in the list is not allowed.</li>
-</ul>
+<note>The ForEach Controller does not run any samples if inputVar_1 is null.
+This would be the case if the Regular Expression returned no matches.</note>
</description>
<properties>
@@ -793,7 +790,25 @@
out of the return page and puts them in the inputVar variable</p>
<p>In the ForEach loop, a HTTP sampler is added which requests all the links that
were extracted from the first returned HTML page.
</p></example>
-
+<example title="ForEach Example" anchor="foreach_example2">
+<p>Here is <a href="../demos/ForEachTest2.jmx">another example</a> you can
download.
+This has two Regular Expressions and ForEach Controllers.
+The first RE matches, but the second does not match,
+so no samples are run by the second ForEach Controller</p>
+<figure image="logic-controller/foreach-example2.png">Figure 11 - ForEach
Controller Example 2</figure>
+<p>The Thread Group has a single thread and a loop count of two.
+</p><p>
+Sample 1 uses the JavaTest Sampler to return the string "a b c d".
+</p><p>The Regex Extractor uses the expression <b>(\w)\s</b> which matches a letter
followed by a space,
+and returns the letter (not the space). Any matches are prefixed with the string
"inputVar".
+</p><p>The ForEach Controller extracts all variables with the prefix "inputVar_",
and executes its
+sample, passing the value in the variable "returnVar". In this case it will set the
variable to the values "a" "b" and "c" in turn.
+</p><p>The For 1 Sampler is another Java Sampler which uses the return variable
"returnVar" as part of the sample Label
+and as the sampler Data.
+</p><p>Sample 2, Regex 2 and For 2 are almost identical, except that the Regex has
been changed to "(\w)\sx",
+which clearly won't match. Thus the For 2 Sampler will not be run.
+</p>
+</example>
</component>
<component name="Transaction Controller" index="15.2.12" screenshot="">
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]