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 2006/04/29 02:18:12 UTC
svn commit: r398043 - in /jakarta/jmeter/branches/rel-2-1:
src/components/org/apache/jmeter/modifiers/
src/components/org/apache/jmeter/modifiers/gui/
src/core/org/apache/jmeter/resources/ xdocs/ xdocs/images/screenshots/
xdocs/usermanual/
Author: sebb
Date: Fri Apr 28 17:18:11 2006
New Revision: 398043
URL: http://svn.apache.org/viewcvs?rev=398043&view=rev
Log:
Allow Counter value to be formatted
Modified:
jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/modifiers/CounterConfig.java
jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/modifiers/gui/CounterConfigGui.java
jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/resources/messages.properties
jakarta/jmeter/branches/rel-2-1/xdocs/changes.xml
jakarta/jmeter/branches/rel-2-1/xdocs/images/screenshots/counter.png
jakarta/jmeter/branches/rel-2-1/xdocs/usermanual/component_reference.xml
Modified: jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/modifiers/CounterConfig.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/modifiers/CounterConfig.java?rev=398043&r1=398042&r2=398043&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/modifiers/CounterConfig.java (original)
+++ jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/modifiers/CounterConfig.java Fri Apr 28 17:18:11 2006
@@ -18,6 +18,7 @@
package org.apache.jmeter.modifiers;
import java.io.Serializable;
+import java.text.DecimalFormat;
import org.apache.jmeter.engine.event.LoopIterationEvent;
import org.apache.jmeter.engine.event.LoopIterationListener;
@@ -27,26 +28,34 @@
import org.apache.jmeter.testelement.property.LongProperty;
import org.apache.jmeter.threads.JMeterContextService;
import org.apache.jmeter.threads.JMeterVariables;
-import org.apache.jorphan.logging.LoggingManager;
-import org.apache.log.Logger;
/**
- * @version $Revision$
+ * Provides a counter per-thread/user or globally
+ * The long value can be
*/
public class CounterConfig extends AbstractTestElement implements Serializable, LoopIterationListener, NoThreadClone {
- private static Logger log = LoggingManager.getLoggerForClass();
- public final static String START = "CounterConfig.start";
+ public final static String START = "CounterConfig.start"; // $NON-NLS-1$
- public final static String END = "CounterConfig.end";
+ public final static String END = "CounterConfig.end"; // $NON-NLS-1$
- public final static String INCREMENT = "CounterConfig.incr";
+ public final static String INCREMENT = "CounterConfig.incr"; // $NON-NLS-1$
- public final static String PER_USER = "CounterConfig.per_user";
+ private final static String FORMAT = "CounterConfig.format"; // $NON-NLS-1$
- public final static String VAR_NAME = "CounterConfig.name";
+ public final static String PER_USER = "CounterConfig.per_user"; // $NON-NLS-1$
- private long globalCounter = -1;
+ public final static String VAR_NAME = "CounterConfig.name"; // $NON-NLS-1$
+
+ // This class is not cloned per thread, so this is shared
+ private long globalCounter = Long.MIN_VALUE;
+
+ // Used for per-thread/user numbers
+ private ThreadLocal perTheadNumber = new ThreadLocal() {
+ protected synchronized Object initialValue() {
+ return new Long(getStart());
+ }
+ };
/**
* @see LoopIterationListener#iterationStart(LoopIterationEvent)
@@ -56,30 +65,36 @@
JMeterVariables variables = JMeterContextService.getContext().getVariables();
long start = getStart(), end = getEnd(), increment = getIncrement();
if (!isPerUser()) {
- if (globalCounter == -1 || globalCounter > end) {
+ if (globalCounter == Long.MIN_VALUE || globalCounter > end) {
globalCounter = start;
}
- variables.put(getVarName(), Long.toString(globalCounter));
+ variables.put(getVarName(), formatNumber(globalCounter));
globalCounter += increment;
} else {
- String value = variables.get(getVarName());
- if (value == null) {
- variables.put(getVarName(), Long.toString(start));
- } else {
- try {
- long current = Long.parseLong(value);
- current += increment;
- if (current > end) {
- current = start;
- }
- variables.put(getVarName(), Long.toString(current));
- } catch (NumberFormatException e) {
- log.info("Bad number in Counter config", e);
- }
- }
+ long current = ((Long) perTheadNumber.get()).longValue();
+ variables.put(getVarName(), formatNumber(current));
+ current += increment;
+ if (current > end) {
+ current = start;
+ }
+ perTheadNumber.set(new Long(current));
}
}
+ // Use format to create number; if it fails, use the default
+ private String formatNumber(long value){
+ String format = getFormat();
+ if (format != null && format.length() > 0) {
+ try {
+ DecimalFormat myFormatter = new DecimalFormat(format);
+ return myFormatter.format(value);
+ } catch (NumberFormatException ignored) {
+ } catch (IllegalArgumentException ignored) {
+ }
+ }
+ return Long.toString(value);
+ }
+
public void setStart(long start) {
setProperty(new LongProperty(START, start));
}
@@ -131,4 +146,12 @@
public String getVarName() {
return getPropertyAsString(VAR_NAME);
}
+
+ public void setFormat(String format) {
+ setProperty(FORMAT, format);
+ }
+
+ public String getFormat() {
+ return getPropertyAsString(FORMAT);
+ }
}
Modified: jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/modifiers/gui/CounterConfigGui.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/modifiers/gui/CounterConfigGui.java?rev=398043&r1=398042&r2=398043&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/modifiers/gui/CounterConfigGui.java (original)
+++ jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/modifiers/gui/CounterConfigGui.java Fri Apr 28 17:18:11 2006
@@ -1,6 +1,5 @@
-// $Header$
/*
- * Copyright 2002-2004 The Apache Software Foundation.
+ * Copyright 2002-2004,2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,7 +30,7 @@
* @version $Revision$ on $Date$
*/
public class CounterConfigGui extends AbstractPreProcessorGui {
- private JLabeledTextField startField, incrField, endField, varNameField;
+ private JLabeledTextField startField, incrField, endField, varNameField, formatField;
private JCheckBox perUserField;
@@ -68,6 +67,7 @@
}
config.setIncrement(incrField.getText());
config.setVarName(varNameField.getText());
+ config.setFormat(formatField.getText());
config.setIsPerUser(perUserField.isSelected());
}
super.configureTestElement(c);
@@ -79,6 +79,7 @@
startField.setText(config.getPropertyAsString(CounterConfig.START));
endField.setText(config.getPropertyAsString(CounterConfig.END));
incrField.setText(config.getPropertyAsString(CounterConfig.INCREMENT));
+ formatField.setText(config.getFormat());
varNameField.setText(config.getVarName());
perUserField.setSelected(config.isPerUser());
}
@@ -93,12 +94,14 @@
incrField = new JLabeledTextField(JMeterUtils.getResString("increment"));
endField = new JLabeledTextField(JMeterUtils.getResString("max"));
varNameField = new JLabeledTextField(JMeterUtils.getResString("var_name"));
+ formatField = new JLabeledTextField(JMeterUtils.getResString("format"));
perUserField = new JCheckBox(JMeterUtils.getResString("counter_per_user"));
add(makeTitlePanel());
add(startField);
add(incrField);
add(endField);
+ add(formatField);
add(varNameField);
add(perUserField);
}
Modified: jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/resources/messages.properties
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/resources/messages.properties?rev=398043&r1=398042&r2=398043&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/resources/messages.properties (original)
+++ jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/resources/messages.properties Fri Apr 28 17:18:11 2006
@@ -188,6 +188,7 @@
foreach_input=Input variable prefix
foreach_output=Output variable name
foreach_use_separator=Add "_" before number ?
+format=Number format
fr=French
ftp_sample_title=FTP Request Defaults
ftp_testing_title=FTP Request
Modified: jakarta/jmeter/branches/rel-2-1/xdocs/changes.xml
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/xdocs/changes.xml?rev=398043&r1=398042&r2=398043&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/xdocs/changes.xml (original)
+++ jakarta/jmeter/branches/rel-2-1/xdocs/changes.xml Fri Apr 28 17:18:11 2006
@@ -84,6 +84,7 @@
<li>Bug 26136 - allow configuration of local address</li>
<li>Expand tree by default when loading a test plan - can be disabled by setting property onload.expandtree=false</li>
<li>Bug 11843 - URL Rewriter can now cache the session id</li>
+<li>Counter Pre-Processor now supports formatted numbers</li>
</ul>
<h4>Bug fixes:</h4>
Modified: jakarta/jmeter/branches/rel-2-1/xdocs/images/screenshots/counter.png
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/xdocs/images/screenshots/counter.png?rev=398043&r1=398042&r2=398043&view=diff
==============================================================================
Binary files - no diff available.
Modified: jakarta/jmeter/branches/rel-2-1/xdocs/usermanual/component_reference.xml
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/xdocs/usermanual/component_reference.xml?rev=398043&r1=398042&r2=398043&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/xdocs/usermanual/component_reference.xml (original)
+++ jakarta/jmeter/branches/rel-2-1/xdocs/usermanual/component_reference.xml Fri Apr 28 17:18:11 2006
@@ -2657,6 +2657,11 @@
<property name="Increment" required="Yes">How much to increment the counter by after each
iteration.</property>
<property name="Maximum" required="Yes">If the counter exceeds the maximum, then it is reset to the Start value.</property>
+ <property name="Format" required="No">Optional format, e.g. 000 will format as 001, 002 etc.
+ This is passed to DecimalFormat, so any valid formats can be used.
+ If there is a problem interpreting the format, then it is ignored.
+ [The default format is generated using Long.toString()]
+ </property>
<property name="Reference Name" required="Yes">This controls how you refer to this value in other elements. Syntax is
as in <a href="functions.html">user-defined values</a>: <code>$(reference_name}</code>.</property>
<property name="Track Counter Independently for each User" required="No">In other words, is this a global counter, or does each user get their
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org