Oops, here are the files...
Kate
Thread Number Modifier
This modifier provides support for multi-threaded testing with
unique test samples per thread. If a test sample contains the
text tag "$$JMETER-THREAD$$" in one of its configuration fields,
and the configuration element supports tag modification (currently
HTTP Requests and JDBC Requests provide this), and the test sample
is processed by a Modification Controller holding this Modifier element,
then the tag will be replaced with the numeric value of the currently
executing thread. A typical use of this modifier would be in servlet
testing, where a database item is inserted by the servlet. In this
scenario, each thread would be able to create a uniquely identified
database record using an HTTP Request, and the thread would then be
able to delete the item using a JDBC Request at the end of testing.
Index: config/AbstractConfigElement.java
===================================================================
RCS file:
/home/cvspublic/jakarta-jmeter/src/org/apache/jmeter/config/AbstractConfigElement.java,v
retrieving revision 1.11
diff -u -r1.11 AbstractConfigElement.java
--- config/AbstractConfigElement.java 30 Aug 2001 17:19:01 -0000 1.11
+++ config/AbstractConfigElement.java 8 Apr 2002 23:17:51 -0000
@@ -65,7 +65,7 @@
* Title: JMeter Description: Copyright: Copyright (c) 2000 Company: Apache
*
*@author Michael Stover
- *@created $Date: 2001/08/30 17:19:01 $
+ *@created $Date: 2002/03/16 01:16:52 $
*@version 1.0
***********************************************************/
@@ -272,4 +272,19 @@
{
properties.putAll(props);
}
-}
+
+ /***********************************************************************
+ * Replace a text tag in configuration element.
+ * This provides support for Tag Modifiers.
+ * Subclasses override if they have text that is suitable for
+ * tag replacement.
+ *
+ *@param tagName name of tag to look for
+ *@param replacement text to replace tagged region with
+ *@return true if the tag is found in the string
+ **********************************************************************/
+ protected boolean modifyTag(String tag, String replacement)
+ {
+ return false;
+ }
+ }
Index: protocol/http/config/UrlConfig.java
===================================================================
RCS file:
/home/cvspublic/jakarta-jmeter/src/org/apache/jmeter/protocol/http/config/UrlConfig.java,v
retrieving revision 1.27
diff -u -r1.27 UrlConfig.java
--- protocol/http/config/UrlConfig.java 23 Feb 2002 01:21:06 -0000 1.27
+++ protocol/http/config/UrlConfig.java 8 Apr 2002 23:17:51 -0000
@@ -70,8 +70,8 @@
* the value you specify here.
*
*@author Michael Stover
- *@created $Date: 2002/02/23 01:21:06 $
- *@version $Revision: 1.27 $
+ *@created $Date: 2002/03/16 00:53:44 $
+ *@version $Revision: 1.5 $
*/
public class UrlConfig extends AbstractConfigElement implements Serializable
@@ -469,6 +469,47 @@
{
return new UrlConfig();
}
+ }
+
+ /***********************************************************************
+ * Modify parameters and path to replace a tag.
+ * Overrides null implementations in parent.
+ * Provides support for Tag Modifiers.
+ *
+ *@param tag name of text tag to replace
+ *@param replacement text to use for replacement
+ *@return true if a modification was performed
+ **********************************************************************/
+ protected boolean modifyTag(String tagName, String replacement)
+ {
+ boolean modified = false;
+
+ // look for tag in path
+ if (TagModifier.findTag(tagName, getPath()))
+ {
+ setPath(TagModifier.makeTagReplacement(
+
+tagName, replacement, getPath()));
+ modified = true;
+ }
+
+ // look for tag in parameters
+ Arguments arguments = getArguments();
+ if (arguments != null)
+ {
+ Iterator iter = arguments.iterator();
+ while (iter.hasNext())
+ {
+ Argument argument = (Argument)iter.next();
+ String text = argument.getValue().toString();
+ if (TagModifier.findTag(tagName, text))
+ {
+
+argument.setValue(TagModifier.makeTagReplacement(
+
+ tagName, replacement, text));
+ modified = true;
+ }
+ }
+ }
+ return modified;
}
}
Index: protocol/jdbc/config/SqlConfig.java
===================================================================
RCS file:
/home/cvspublic/jakarta-jmeter/src/org/apache/jmeter/protocol/jdbc/config/SqlConfig.java,v
retrieving revision 1.8
diff -u -r1.8 SqlConfig.java
--- protocol/jdbc/config/SqlConfig.java 23 Feb 2002 01:21:07 -0000 1.8
+++ protocol/jdbc/config/SqlConfig.java 8 Apr 2002 23:17:51 -0000
@@ -110,4 +110,23 @@
return (String)this.getProperty(QUERY);
}
-}
+ /***********************************************************************
+ * Modify the query to replace a tag
+ * Overrides null implementations in parent
+ *
+ *@param tag Name text name of tag to replace
+ *@param replacement text to use for replacement
+ *@return true if a modification was performed
+ **********************************************************************/
+ protected boolean modifyTag(String tagName, String replacement)
+ {
+ if (TagModifier.findTag(tagName, getQuery()))
+ {
+ setQuery(TagModifier.makeTagReplacement(
+ tagName, replacement, getQuery()));
+ return true;
+ }
+ return false;
+ }
+
+ }
Index: resources/messages.properties
===================================================================
RCS file:
/home/cvspublic/jakarta-jmeter/src/org/apache/jmeter/resources/messages.properties,v
retrieving revision 1.48
diff -u -r1.48 messages.properties
--- resources/messages.properties 18 Mar 2002 00:48:25 -0000 1.48
+++ resources/messages.properties 8 Apr 2002 23:17:51 -0000
@@ -178,6 +178,8 @@
auth_base_url=Base URL
auths_stored=Authorizations Stored in the Authorization Manager
anchor_modifier_title=HTTP HTML Link Parser
+threadnumber_modifier_title=Thread Number Modifier
+threadnumber_modifier_memo= This modifier replaces the text $$JMETER-THREAD$$ with
+the numeric ID of the currently executing thread.
jndi_config_title=JNDI Configuration
jndi_url_jndi_props=JNDI Properties
jndi_lookup_title=JNDI Lookup Configuration
/*
* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache JMeter" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache JMeter", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.jmeter.config;
import org.apache.jmeter.gui.JMeterComponentModel;
import org.apache.jmeter.samplers.Entry;
import org.apache.jmeter.protocol.http.config.UrlConfig;
import org.apache.jmeter.protocol.jdbc.config.SqlConfig;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jmeter.util.ClassFinder;
import org.apache.jmeter.config.AbstractConfigElement;
import java.io.Serializable;
import java.io.IOException;
import java.util.*;
/***************************************************************************
* A TagModifier is a Regular Modifier element that can modify a test
* sample by replacing a text tag of the form $$JMETER-<tagname>$$
* This is used, for example to generate thread-unique test samples.
* See ThreadTagModifier.
*
*@author Kate Rosenbloom
*@created $Date: 2002/03/19 22:36:29 $
*@version 1.0
**************************************************************************/
public abstract class TagModifier extends AbstractConfigElement
implements JMeterComponentModel, Modifier, Serializable
{
// text tag is composed of the prefix, tag, and suffix
public final static String TAG_PREFIX = "$$JMETER-";
public final static String TAG_SUFFIX = "$$";
/***********************************************************************
* Modify an Entry to replace a tag with a replacement string
*
*@param entry configuration item to modify
*@param tagName text name of the tag to replace
*@param replacement replacement text for the tag
*@return true if a modification was performed
**********************************************************************/
protected boolean modifyTagEntry(
Entry entry, String tagName,
String replacement)
{
boolean modified = false;
// get all possible configuration elements
try {
List classes = ClassFinder.findClassesThatExtend(new Class[]
{org.apache.jmeter.config.AbstractConfigElement.class});
Iterator iter = classes.iterator();
// extract configuration elements from this entry
while (iter.hasNext())
{
Class configClass = Class.forName((String)iter.next());
AbstractConfigElement config =
(AbstractConfigElement)entry.getConfigElement(configClass);
if (config != null)
{
// have the configuration element modify tags
as
// appropriate for the element
if (config.modifyTag(tagName, replacement))
{
modified = true;
}
}
}
return modified;
// errors
} catch (IOException ex1) {
// fall thru
} catch (ClassNotFoundException ex2) {
// fall thru
}
System.out.println("ERROR: can't find classes -- check class path");
return false;
}
/***********************************************************************
* Make a tag from the tag name, by adding prefix and suffix
*
*@param tagName name of tag to look for
*@return text of the tag
**********************************************************************/
private static String makeTagFromName(String tagName)
{
return (TAG_PREFIX + tagName + TAG_SUFFIX);
}
/***********************************************************************
* Determine if a tag exists in a string
*
*@param tagName name of tag to look for
*@param text string to examine
*@return true if the tag is found in the string
**********************************************************************/
public static boolean findTag(String tagName, String text)
{
return (text.indexOf(makeTagFromName(tagName)) != -1);
}
/***********************************************************************
* Create a string with the tag replaced with replacement text
*
*@param tagName name of the tag to replace
*@param replacement replacement text
*@param text the text to replace
*@return string with tag replaced (or the original string if the
* tag is not found
**********************************************************************/
public static String makeTagReplacement(
String tagName, String
replacement, String text)
{
String tag = makeTagFromName(tagName);
StringBuffer newText = new StringBuffer();
int index;
while ((index = text.indexOf(tag)) != -1)
{
newText.append(text.substring(0, index));
newText.append(replacement);
text = text.substring(index + tag.length());
}
return newText.toString() + text;
}
/**********************************************************************/
public TagModifier()
{
}
public void addJMeterComponent(JMeterComponentModel obj)
{
}
public void uncompile()
{
}
public Collection getAddList()
{
return null;
}
public void setName(String name)
{
}
public String getName()
{
return getClassLabel();
}
public Object clone()
{
return this;
}
public void addConfigElement(ConfigElement config)
{
}
/***********************************************************************
* Test driver
**********************************************************************/
public static void main(String[] args)
{
System.out.println(
makeTagReplacement("TAG", "12345",
"Testing replacement of tag with $$JMETER-TAG$$"));
System.out.println(
makeTagReplacement("TAG", "12345",
"Testing replacement of tag with $$JMETER-TAG$$ x
$$JMETER-TAG$$ y"));
System.out.println(
makeTagReplacement("TAG", "12345",
"Testing replacement of tag with $$JMETER-TAG$$ x
$$JMETER-TAG$$"));
}
}
/*
* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache JMeter" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache JMeter", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.jmeter.config;
import org.apache.jmeter.samplers.Entry;
import org.apache.jmeter.util.JMeterUtils;
import java.util.*;
/***************************************************************************
* A ThreadNumberModifier is a Regular Modifier element that can modify a test
* sample to include the numeric ID of the thread running the sample.
* ThreadNumberModifier modifies test samples containing the
* special text tag: $JMETER-THREAD$. This class is used in multi-thread
* tests, where each thread wants its own data to modify.
*
*@author Kate Rosenbloom
*@created $Date: 2002/03/16 00:43:00 $
*@version 1.0
**************************************************************************/
public class ThreadNumberModifier extends TagModifier
{
// text of the tag name
// NOTE: the parent class wraps this to make a valid tag
public final static String TAG_NAME = "THREAD";
// from the resource file, a title for this class (e.g. for the GUI)
public static final String TITLE = "threadnumber_modifier_title";
/***********************************************************************
* Modify an Entry to replace the tag with the numeric ID of the
* current thread.
*
*@param entry configuration item to modify
*@return true if a modification was performed
**********************************************************************/
public boolean modifyEntry(Entry entry)
{
String threadName = Thread.currentThread().getName();
return modifyTagEntry(entry, TAG_NAME,
threadName.substring(threadName.indexOf("-") + 1));
}
/**********************************************************************/
public Class getGuiClass()
{
return org.apache.jmeter.config.gui.ThreadNumberModifierGui.class;
}
public String getClassLabel()
{
return JMeterUtils.getResString(ThreadNumberModifier.TITLE);
}
public ThreadNumberModifier()
{
}
}
/*
* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache JMeter" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache JMeter", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.jmeter.config.gui;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.border.*;
import javax.swing.table.*;
import java.awt.*;
import javax.swing.text.*;
import org.apache.jmeter.gui.*;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jmeter.config.ThreadNumberModifier;
/************************************************************
* GUI representation of a ThreadNumberModifier.
* It is just a named panel.
*
*@author Kate Rosenbloom
*@created $Date: 2002/03/14 04:38:24 $
*@version 1.0
***********************************************************/
public class ThreadNumberModifierGui extends JPanel implements ModelSupported
{
ThreadNumberModifier model;
public ThreadNumberModifierGui()
{
}
public void setModel(Object model)
{
this.model = (ThreadNumberModifier)model;
init();
}
public void updateGui()
{
}
private void init()
{
this.setLayout(new VerticalLayout(5, VerticalLayout.LEFT,
VerticalLayout.TOP));
// MAIN PANEL
JPanel mainPanel = new JPanel();
Border margin = new EmptyBorder(10, 10, 5, 10);
mainPanel.setBorder(margin);
mainPanel.setLayout(new VerticalLayout(5, VerticalLayout.LEFT));
// TITLE
JLabel panelTitleLabel = new
JLabel(JMeterUtils.getResString(ThreadNumberModifier.TITLE));
Font curFont = panelTitleLabel.getFont();
int curFontSize = curFont.getSize();
curFontSize += 4;
panelTitleLabel.setFont(new Font(curFont.getFontName(),
curFont.getStyle(), curFontSize));
mainPanel.add(panelTitleLabel);
// NAME
mainPanel.add(new NamePanel(model));
this.add(mainPanel);
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>