jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1213053 - in /jmeter/trunk: src/components/org/apache/jmeter/modifiers/ src/components/org/apache/jmeter/modifiers/gui/ src/core/org/apache/jmeter/resources/ xdocs/ xdocs/usermanual/
Date Sun, 11 Dec 2011 20:28:08 GMT
Author: pmouawad
Date: Sun Dec 11 20:28:07 2011
New Revision: 1213053

URL: http://svn.apache.org/viewvc?rev=1213053&view=rev
Log:
Bug 52317 - Counter : Add option to reset counter on each Thread Group iteration

Modified:
    jmeter/trunk/src/components/org/apache/jmeter/modifiers/CounterConfig.java
    jmeter/trunk/src/components/org/apache/jmeter/modifiers/gui/CounterConfigGui.java
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties
    jmeter/trunk/xdocs/changes.xml
    jmeter/trunk/xdocs/usermanual/component_reference.xml

Modified: jmeter/trunk/src/components/org/apache/jmeter/modifiers/CounterConfig.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/modifiers/CounterConfig.java?rev=1213053&r1=1213052&r2=1213053&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/modifiers/CounterConfig.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/modifiers/CounterConfig.java Sun Dec 11
20:28:07 2011
@@ -50,12 +50,19 @@ public class CounterConfig extends Abstr
 
     public final static String VAR_NAME = "CounterConfig.name"; // $NON-NLS-1$
 
+    public final static String RESET_ON_THREAD_GROUP_ITERATION = "CounterConfig.reset_on_tg_iteration";
// $NON-NLS-1$
+
+	private static final boolean RESET_ON_THREAD_GROUP_ITERATION_DEFAULT = false;
+
     // This class is not cloned per thread, so this is shared
     private long globalCounter = Long.MIN_VALUE;
 
     // Used for per-thread/user numbers
     private transient ThreadLocal<Long> perTheadNumber;
 
+    // Used for per-thread/user storage of increment in Thread Group Main loop
+    private transient ThreadLocal<Long> perTheadLastIterationNumber;
+
     private void init() {
         perTheadNumber = new ThreadLocal<Long>() {
             @Override
@@ -63,6 +70,12 @@ public class CounterConfig extends Abstr
                 return Long.valueOf(getStart());
             }
         };
+        perTheadLastIterationNumber = new ThreadLocal<Long>() {
+            @Override
+            protected Long initialValue() {
+                return Long.valueOf(1);
+            }
+        };
     }
 
 
@@ -89,7 +102,16 @@ public class CounterConfig extends Abstr
             variables.put(getVarName(), formatNumber(globalCounter));
             globalCounter += increment;
         } else {
-            long current = perTheadNumber.get().longValue();
+        	long current = perTheadNumber.get().longValue();
+        	if(isResetOnThreadGroupIteration()) {
+            	int iteration = JMeterContextService.getContext().getVariables().getIteration();
+	        	Long lastIterationNumber = perTheadLastIterationNumber.get();
+	        	if(iteration != lastIterationNumber.longValue()) {
+	        		// reset 
+	        		current = getStart();
+	        	} 
+	        	perTheadLastIterationNumber.set(Long.valueOf(iteration));
+        	}
             variables.put(getVarName(), formatNumber(current));
             current += increment;
             if (current > end) {
@@ -136,6 +158,20 @@ public class CounterConfig extends Abstr
     public void setEnd(String end) {
         setProperty(END, end);
     }
+    
+    /**
+     * @param value boolean indicating if counter must be reset on Thread Group Iteration
+     */
+    public void setResetOnThreadGroupIteration(boolean value) {
+    	setProperty(RESET_ON_THREAD_GROUP_ITERATION, value, RESET_ON_THREAD_GROUP_ITERATION_DEFAULT);
+    }
+    
+    /**
+     * @return true if counter must be reset on Thread Group Iteration
+     */
+    public boolean isResetOnThreadGroupIteration() {
+    	return getPropertyAsBoolean(RESET_ON_THREAD_GROUP_ITERATION, RESET_ON_THREAD_GROUP_ITERATION_DEFAULT);
+    }
 
     /**
      *

Modified: jmeter/trunk/src/components/org/apache/jmeter/modifiers/gui/CounterConfigGui.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/modifiers/gui/CounterConfigGui.java?rev=1213053&r1=1213052&r2=1213053&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/modifiers/gui/CounterConfigGui.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/modifiers/gui/CounterConfigGui.java Sun
Dec 11 20:28:07 2011
@@ -18,6 +18,9 @@
 
 package org.apache.jmeter.modifiers.gui;
 
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
 import javax.swing.JCheckBox;
 
 import org.apache.jmeter.config.gui.AbstractConfigGui;
@@ -27,10 +30,15 @@ import org.apache.jmeter.util.JMeterUtil
 import org.apache.jorphan.gui.JLabeledTextField;
 import org.apache.jorphan.gui.layout.VerticalLayout;
 
-public class CounterConfigGui extends AbstractConfigGui {
+public class CounterConfigGui extends AbstractConfigGui implements ActionListener {
     private static final long serialVersionUID = 240L;
 
-    private JLabeledTextField startField, incrField, endField, varNameField, formatField;
+    private JLabeledTextField startField;
+    private JLabeledTextField incrField;
+    private JLabeledTextField endField;
+    private JLabeledTextField varNameField;
+    private JLabeledTextField formatField;
+    private JCheckBox resetCounterOnEachThreadGroupIteration;
 
     private JCheckBox perUserField;
 
@@ -69,6 +77,8 @@ public class CounterConfigGui extends Ab
             config.setVarName(varNameField.getText());
             config.setFormat(formatField.getText());
             config.setIsPerUser(perUserField.isSelected());
+            config.setResetOnThreadGroupIteration(resetCounterOnEachThreadGroupIteration.isEnabled()

+            		&& resetCounterOnEachThreadGroupIteration.isSelected());
         }
         super.configureTestElement(c);
     }
@@ -86,6 +96,7 @@ public class CounterConfigGui extends Ab
         varNameField.setText(""); //$NON-NLS-1$
         formatField.setText(""); //$NON-NLS-1$
         perUserField.setSelected(false);
+        resetCounterOnEachThreadGroupIteration.setEnabled(false);
     }
 
     @Override
@@ -98,6 +109,12 @@ public class CounterConfigGui extends Ab
         formatField.setText(config.getFormat());
         varNameField.setText(config.getVarName());
         perUserField.setSelected(config.isPerUser());
+        if(config.isPerUser()) {
+        	resetCounterOnEachThreadGroupIteration.setEnabled(true);
+        	resetCounterOnEachThreadGroupIteration.setSelected(config.isResetOnThreadGroupIteration());
+        } else {
+        	resetCounterOnEachThreadGroupIteration.setEnabled(false);
+        }
     }
 
     private void init() {
@@ -110,7 +127,7 @@ public class CounterConfigGui extends Ab
         varNameField = new JLabeledTextField(JMeterUtils.getResString("var_name"));//$NON-NLS-1$
         formatField = new JLabeledTextField(JMeterUtils.getResString("format"));//$NON-NLS-1$
         perUserField = new JCheckBox(JMeterUtils.getResString("counter_per_user"));//$NON-NLS-1$
-
+        resetCounterOnEachThreadGroupIteration = new JCheckBox(JMeterUtils.getResString("counter_reset_per_tg_iteration"));//$NON-NLS-1$
         add(makeTitlePanel());
         add(startField);
         add(incrField);
@@ -118,5 +135,17 @@ public class CounterConfigGui extends Ab
         add(formatField);
         add(varNameField);
         add(perUserField);
+        add(resetCounterOnEachThreadGroupIteration);
+        
+        perUserField.addActionListener(this);
     }
+
+    /**
+     * Disable/Enable resetCounterOnEachThreadGroupIteration when perUserField is disabled
/ enabled
+     */
+	public void actionPerformed(ActionEvent e) {
+		if(e.getSource() == perUserField) {
+			resetCounterOnEachThreadGroupIteration.setEnabled(perUserField.isSelected());
+		}
+	}
 }

Modified: jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties?rev=1213053&r1=1213052&r2=1213053&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties Sun Dec 11 20:28:07
2011
@@ -154,6 +154,7 @@ cookies_stored=User-Defined Cookies
 copy=Copy
 counter_config_title=Counter
 counter_per_user=Track counter independently for each user
+counter_reset_per_tg_iteration=Reset counter on each Thread Group Iteration
 countlim=Size limit
 csvread_file_file_name=CSV file to get values from | *alias
 cut=Cut

Modified: jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties?rev=1213053&r1=1213052&r2=1213053&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties Sun Dec 11 20:28:07
2011
@@ -148,6 +148,7 @@ cookies_stored=Cookies stock\u00E9s
 copy=Copier
 counter_config_title=Compteur
 counter_per_user=Suivre le compteur ind\u00E9pendamment pour chaque unit\u00E9 de test
+counter_reset_per_tg_iteration=R\u00E9initialiser le compteur \u00E0 chaque it\u00E9ration
du groupe d'unit\u00E9s
 countlim=Limiter le nombre d'\u00E9l\u00E9ments retourn\u00E9s \u00E0
 csvread_file_file_name=Fichier CSV pour obtenir les valeurs de | *alias
 cut=Couper

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1213053&r1=1213052&r2=1213053&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Sun Dec 11 20:28:07 2011
@@ -189,6 +189,7 @@ This behaviour can be changed with prope
 <ul>
 <li>Bug 52128 - Add JDBC pre- and post-processor</li>
 <li>Bug 52183 - SyncTimer could be improved (performance+reliability)</li>
+<li>Bug 52317 - Counter : Add option to reset counter on each Thread Group iteration</li>
 </ul>
 
 <h3>Functions</h3>

Modified: jmeter/trunk/xdocs/usermanual/component_reference.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=1213053&r1=1213052&r2=1213053&view=diff
==============================================================================
--- jmeter/trunk/xdocs/usermanual/component_reference.xml (original)
+++ jmeter/trunk/xdocs/usermanual/component_reference.xml Sun Dec 11 20:28:07 2011
@@ -3533,6 +3533,8 @@ with the start, continuing on like that 
         <property name="Track Counter Independently for each User" required="No">In
other words, is this a global counter, or does each user get their
         own counter?  If unchecked, the counter is global (ie, user #1 will get value "1",
and user #2 will get value "2" on
         the first iteration).  If checked, each user has an independent counter.</property>
+        <property name="Reset counter on each Thread Group Iteration" required="No">This
option is only available when counter is tracked per User, if checked, 
+        counter will be reset to Start value on each Thread Group iteration. This can be
useful when Counter is inside a Loop Controller.</property>
 </properties>
 </component>
 



Mime
View raw message