jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1828092 - in /jmeter/trunk: src/components/org/apache/jmeter/control/ src/core/org/apache/jmeter/control/ xdocs/
Date Sat, 31 Mar 2018 10:20:07 GMT
Author: pmouawad
Date: Sat Mar 31 10:20:07 2018
New Revision: 1828092

URL: http://svn.apache.org/viewvc?rev=1828092&view=rev
Log:
Bug 62237 - While Controller : Export variable containing current index of iteration
Contributed by Ubik Load Pack
Bugzilla Id: 62237

Added:
    jmeter/trunk/src/core/org/apache/jmeter/control/IteratingController.java   (with props)
Modified:
    jmeter/trunk/src/components/org/apache/jmeter/control/ForeachController.java
    jmeter/trunk/src/core/org/apache/jmeter/control/LoopController.java
    jmeter/trunk/src/core/org/apache/jmeter/control/WhileController.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/components/org/apache/jmeter/control/ForeachController.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/control/ForeachController.java?rev=1828092&r1=1828091&r2=1828092&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/control/ForeachController.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/control/ForeachController.java Sat Mar 31
10:20:07 2018
@@ -25,9 +25,7 @@ import org.apache.jmeter.samplers.Sample
 import org.apache.jmeter.testelement.property.BooleanProperty;
 import org.apache.jmeter.testelement.property.StringProperty;
 import org.apache.jmeter.threads.JMeterContext;
-import org.apache.jmeter.threads.JMeterContextService;
 import org.apache.jmeter.threads.JMeterVariables;
-import org.apache.jmeter.util.JMeterUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -39,7 +37,7 @@ import org.slf4j.LoggerFactory;
  *
  */
 @GUIMenuSortOrder(5)
-public class ForeachController extends GenericController implements Serializable {
+public class ForeachController extends GenericController implements Serializable, IteratingController
{
 
     private static final Logger log = LoggerFactory.getLogger(ForeachController.class);
 
@@ -59,6 +57,8 @@ public class ForeachController extends G
 
     private int loopCount = 0;
 
+    private boolean breakLoop;
+
     private static final String DEFAULT_SEPARATOR = "_";// $NON-NLS-1$
 
     public ForeachController() {
@@ -208,12 +208,7 @@ public class ForeachController extends G
             }
             return super.next();
         } finally {
-            JMeterVariables variables = JMeterContextService.getContext().getVariables();
-            if(variables != null) {
-                variables.putObject(
-                    JMeterUtils.formatJMeterExportedVariableName(
-                            getName()+LoopController.INDEX_VAR_NAME_SUFFIX), loopCount);
-            }
+            updateIterationIndex(getName(), loopCount);
         }
     }
 
@@ -303,4 +298,15 @@ public class ForeachController extends G
         super.initialize();
         loopCount = getStartIndex();
     }
+    
+    @Override
+    public void startNextLoop() {
+        reInitialize();
+    }
+    
+    @Override
+    public void breakLoop() {
+        // FIXME TO BE COMPLETED
+        this.breakLoop = true;
+    }
 }

Added: jmeter/trunk/src/core/org/apache/jmeter/control/IteratingController.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/control/IteratingController.java?rev=1828092&view=auto
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/control/IteratingController.java (added)
+++ jmeter/trunk/src/core/org/apache/jmeter/control/IteratingController.java Sat Mar 31 10:20:07
2018
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.jmeter.control;
+
+import org.apache.jmeter.threads.JMeterContextService;
+import org.apache.jmeter.threads.JMeterVariables;
+import org.apache.jmeter.util.JMeterUtils;
+
+/**
+ * Identify controller that does iterations
+ * @since 4.1
+ */
+public interface IteratingController {
+    final String INDEX_VAR_NAME_SUFFIX = "__idx";
+    
+    /**
+     * Start next iteration ("continue" keyword equivalent in loops)
+     */
+    public void startNextLoop();
+
+    /**
+     * Break loop ("break" keyword equivalent)
+     */
+    public void breakLoop();
+    
+    /**
+     * @param elementName Test Element
+     * @param 
+     */
+    default void updateIterationIndex(String elementName, int iterCount) {
+        JMeterVariables variables = JMeterContextService.getContext().getVariables();
+        if(variables != null) {
+            variables.putObject(
+                    JMeterUtils.formatJMeterExportedVariableName(elementName+INDEX_VAR_NAME_SUFFIX),
iterCount);
+        }
+    }
+    
+}

Propchange: jmeter/trunk/src/core/org/apache/jmeter/control/IteratingController.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jmeter/trunk/src/core/org/apache/jmeter/control/IteratingController.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jmeter/trunk/src/core/org/apache/jmeter/control/LoopController.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/control/LoopController.java?rev=1828092&r1=1828091&r2=1828092&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/control/LoopController.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/control/LoopController.java Sat Mar 31 10:20:07
2018
@@ -25,15 +25,11 @@ import org.apache.jmeter.testelement.pro
 import org.apache.jmeter.testelement.property.IntegerProperty;
 import org.apache.jmeter.testelement.property.JMeterProperty;
 import org.apache.jmeter.testelement.property.StringProperty;
-import org.apache.jmeter.threads.JMeterContextService;
-import org.apache.jmeter.threads.JMeterVariables;
-import org.apache.jmeter.util.JMeterUtils;
 
 /**
  * Class that implements the Loop Controller, ie iterate infinitely or a configured number
of times
  */
-public class LoopController extends GenericController implements Serializable {
-    static final String INDEX_VAR_NAME_SUFFIX = "__idx";
+public class LoopController extends GenericController implements Serializable, IteratingController
{
     
     public static final int INFINITE_LOOP_COUNT = -1; // $NON-NLS-1$
     
@@ -60,6 +56,8 @@ public class LoopController extends Gene
     // Cache loop value, see Bug 54467
     private transient Integer nbLoops;
 
+    private boolean breakLoop;
+
     public LoopController() {
         setContinueForeverPrivate(true);
     }
@@ -127,11 +125,7 @@ public class LoopController extends Gene
             }
             return super.next();
         } finally {
-            JMeterVariables variables = JMeterContextService.getContext().getVariables();
-            if(variables != null) {
-                variables.putObject(
-                        JMeterUtils.formatJMeterExportedVariableName(getName()+INDEX_VAR_NAME_SUFFIX),
loopCount);
-            }
+            updateIterationIndex(getName(), loopCount);
         }
     }
     
@@ -206,4 +200,9 @@ public class LoopController extends Gene
     public void startNextLoop() {
         reInitialize();
     }
+
+    @Override
+    public void breakLoop() {
+        this.breakLoop = true;
+    }
 }

Modified: jmeter/trunk/src/core/org/apache/jmeter/control/WhileController.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/control/WhileController.java?rev=1828092&r1=1828091&r2=1828092&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/control/WhileController.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/control/WhileController.java Sat Mar 31 10:20:07
2018
@@ -31,17 +31,20 @@ import org.slf4j.LoggerFactory;
 
 // @see TestWhileController for unit tests
 
-public class WhileController extends GenericController implements Serializable {
+public class WhileController extends GenericController implements Serializable, IteratingController
{
     private static final Logger log = LoggerFactory.getLogger(WhileController.class);
 
     private static final long serialVersionUID = 233L;
 
     private static final String CONDITION = "WhileController.condition"; // $NON-NLS-1$
 
+    private boolean breakLoop;
+
     public WhileController() {
+        super();
     }
 
-    /*
+    /**
      * 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"
@@ -77,6 +80,7 @@ public class WhileController extends Gen
     protected Sampler nextIsNull() throws NextIsNullException {
         reInitialize();
         if (endOfLoop(true)){
+            resetLoopCount();
             return null;
         }
         return next();
@@ -89,6 +93,7 @@ public class WhileController extends Gen
     public void triggerEndOfLoop() {
         super.triggerEndOfLoop();
         endOfLoop(true);
+        resetLoopCount();
     }
 
     /**
@@ -98,12 +103,21 @@ public class WhileController extends Gen
      */
     @Override
     public Sampler next(){
-        if (isFirst() && endOfLoop(false)) {
-            return null;
+        try {
+            if ( isFirst() && endOfLoop(false)) {
+                resetLoopCount();
+                return null;
+            }
+            return super.next();
+        } finally {
+            updateIterationIndex(getName(), getIterCount());
         }
-        return super.next();
     }
 
+    protected void resetLoopCount() {
+        resetIterCount();
+    }
+    
     /**
      * @param string
      *            the condition to save
@@ -121,4 +135,14 @@ public class WhileController extends Gen
         prop.recoverRunningVersion(this);
         return prop.getStringValue();
     }
+
+    @Override
+    public void startNextLoop() {
+        reInitialize();
+    }
+
+    @Override
+    public void breakLoop() {
+        this.breakLoop = true;
+    }
 }

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1828092&r1=1828091&r2=1828092&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Sat Mar 31 10:20:07 2018
@@ -95,6 +95,7 @@ this behaviour, set <code>httpclient.res
 
 <h3>Controllers</h3>
 <ul>
+    <li><bug>62237</bug>While Controller : Export variable containing current
index of iteration. Contributed by Ubik Load Pack (support at ubikloadpack.com)</li>
 </ul>
 
 <h3>Listeners</h3>



Mime
View raw message