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 bu...@apache.org on 2005/07/31 20:18:26 UTC
DO NOT REPLY [Bug 35954] New: -
New Pre-Processor called Randomizer
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=35954>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=35954
Summary: New Pre-Processor called Randomizer
Product: JMeter
Version: unspecified
Platform: Other
OS/Version: other
Status: NEW
Severity: enhancement
Priority: P4
Component: Main
AssignedTo: jmeter-dev@jakarta.apache.org
ReportedBy: iletisim5@bilgidata.com
Hi everyone,
For a load tests I was writing, I had to use a randomized variable, a value that
would be different for all concurrent threads under a thread group. Based on the
CounterConfig.java code, I wrote this simple RandomizerConfig.java class, it is
working fine. I thought it could be useful for others, so I am sending a patch
file for the new feature. I hope I am adhering to protocols, it's my first
contribution!
Regards,
------------------ randomizer.patch ---------------------------------------
Index: src/core/org/apache/jmeter/resources/messages.properties
===================================================================
RCS file:
/home/cvspublic/jakarta-jmeter/src/core/org/apache/jmeter/resources/messages.properties,v
retrieving revision 1.154
diff -u -r1.154 messages.properties
--- src/core/org/apache/jmeter/resources/messages.properties 29 Jul 2005
03:54:05 -0000 1.154
+++ src/core/org/apache/jmeter/resources/messages.properties 31 Jul 2005
17:57:15 -0000
@@ -96,6 +96,7 @@
corba_sample_title=CORBA Sampler
counter_config_title=Counter
counter_per_user=Track counter independently for each user
+randomizer_config_title=Randomizer
countlim=Size limit
csvread_file_file_name=CSV file to get values from | *alias
cut=Cut
Index: src/core/org/apache/jmeter/util/JMeterVersion.java
===================================================================
RCS file:
/home/cvspublic/jakarta-jmeter/src/core/org/apache/jmeter/util/JMeterVersion.java,v
retrieving revision 1.37
diff -u -r1.37 JMeterVersion.java
--- src/core/org/apache/jmeter/util/JMeterVersion.java 12 Jul 2005 20:50:44
-0000 1.37
+++ src/core/org/apache/jmeter/util/JMeterVersion.java 31 Jul 2005 17:57:18 -0000
@@ -41,7 +41,7 @@
* JMeterUtils This ensures that JMeterUtils always gets the correct
* version, even if it is not re-compiled during the build.
*/
- private static final String VERSION = "2.1.20050630";
+ private static final String VERSION = "2.1.20050731";
static final String COPYRIGHT = "Copyright (c) 1998-2005 The Apache Software
Foundation";
--- /dev/null 2005-07-31 21:04:05.696976000 +0300
+++ ./src/components/org/apache/jmeter/modifiers/RandomizerConfig.java
2005-07-31 20:52:18.000000000 +0300
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2002-2004 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.
+ * 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.modifiers;
+
+import java.io.Serializable;
+
+import org.apache.jmeter.engine.event.LoopIterationEvent;
+import org.apache.jmeter.engine.event.LoopIterationListener;
+import org.apache.jmeter.engine.util.NoThreadClone;
+import org.apache.jmeter.testelement.AbstractTestElement;
+import org.apache.jmeter.testelement.property.BooleanProperty;
+import org.apache.jmeter.testelement.property.IntegerProperty;
+import org.apache.jmeter.threads.JMeterContextService;
+import org.apache.jmeter.threads.JMeterVariables;
+import org.apache.jorphan.logging.LoggingManager;
+import org.apache.log.Logger;
+import java.util.Random;
+
+public class RandomizerConfig extends AbstractTestElement implements
Serializable, LoopIterationListener, NoThreadClone {
+ private static Logger log = LoggingManager.getLoggerForClass();
+
+ public final static String INCREMENT = "RandomizerConfig.incr";
+
+ public final static String VAR_NAME = "RandomizerConfig.name";
+
+ private Random random = new Random();
+
+ /**
+ * @see LoopIterationListener#iterationStart(LoopIterationEvent)
+ */
+ public synchronized void iterationStart(LoopIterationEvent event) {
+ JMeterVariables variables = JMeterContextService.getContext().getVariables();
+ int increment = getIncrement();
+ int current = random.nextInt(increment);
+ variables.put(getVarName(), Integer.toString(current));
+ }
+
+ public void setIncrement(int inc) {
+ setProperty(new IntegerProperty(INCREMENT, inc));
+ }
+
+ public void setIncrement(String incr) {
+ setProperty(INCREMENT, incr);
+ }
+
+ public int getIncrement() {
+ return getPropertyAsInt(INCREMENT);
+ }
+ public void setVarName(String name) {
+ setProperty(VAR_NAME, name);
+ }
+
+ public String getVarName() {
+ return getPropertyAsString(VAR_NAME);
+ }
+}
--- /dev/null 2005-07-31 21:04:19.256473600 +0300
+++ ./src/components/org/apache/jmeter/modifiers/gui/RandomizerConfigGui.java
2005-07-31 20:52:32.000000000 +0300
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2002-2004 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.
+ * 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.modifiers.gui;
+
+import javax.swing.JCheckBox;
+
+import org.apache.jmeter.modifiers.RandomizerConfig;
+import org.apache.jmeter.processor.gui.AbstractPreProcessorGui;
+import org.apache.jmeter.testelement.TestElement;
+import org.apache.jmeter.util.JMeterUtils;
+import org.apache.jorphan.gui.JLabeledTextField;
+import org.apache.jorphan.gui.layout.VerticalLayout;
+
+public class RandomizerConfigGui extends AbstractPreProcessorGui {
+ private JLabeledTextField incrField, varNameField;
+
+ private JCheckBox perUserField;
+
+ public RandomizerConfigGui() {
+ super();
+ init();
+ }
+
+ public String getLabelResource() {
+ return "randomizer_config_title";
+ }
+
+ /**
+ * @see org.apache.jmeter.gui.JMeterGUIComponent#createTestElement()
+ */
+ public TestElement createTestElement() {
+ RandomizerConfig config = new RandomizerConfig();
+ modifyTestElement(config);
+ return config;
+ }
+
+ /**
+ * Modifies a given TestElement to mirror the data in the gui components.
+ *
+ * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
+ */
+ public void modifyTestElement(TestElement c) {
+ if (c instanceof RandomizerConfig) {
+ RandomizerConfig config = (RandomizerConfig) c;
+ config.setIncrement(incrField.getText());
+ config.setVarName(varNameField.getText());
+ }
+ super.configureTestElement(c);
+ }
+
+ public void configure(TestElement element) {
+ super.configure(element);
+ RandomizerConfig config = (RandomizerConfig) element;
+ incrField.setText(config.getPropertyAsString(RandomizerConfig.INCREMENT));
+ varNameField.setText(config.getVarName());
+ }
+
+ private void init() {
+ setBorder(makeBorder());
+ setLayout(new VerticalLayout(5, VerticalLayout.LEFT));
+ incrField = new JLabeledTextField(JMeterUtils.getResString("increment"));
+ varNameField = new JLabeledTextField(JMeterUtils.getResString("var_name"));
+
+ add(makeTitlePanel());
+ add(incrField);
+ add(varNameField);
+ }
+}
--
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org