You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@jakarta.apache.org by mi...@apache.org on 2010/11/17 20:42:21 UTC

svn commit: r1036177 - in /jakarta/jmeter/trunk: src/core/org/apache/jmeter/resources/ src/protocol/jms/org/apache/jmeter/protocol/jms/client/ src/protocol/jms/org/apache/jmeter/protocol/jms/control/gui/ src/protocol/jms/org/apache/jmeter/protocol/jms/...

Author: milamber
Date: Wed Nov 17 19:42:21 2010
New Revision: 1036177

URL: http://svn.apache.org/viewvc?rev=1036177&view=rev
Log:
Bug 50268 - Adds static and dynamic destinations to JMS Publisher

Modified:
    jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
    jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties
    jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/Publisher.java
    jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/control/gui/JMSPublisherGui.java
    jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/BaseJMSSampler.java
    jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/PublisherSampler.java
    jakarta/jmeter/trunk/xdocs/changes.xml
    jakarta/jmeter/trunk/xdocs/images/screenshots/jmspublisher.png
    jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml

Modified: jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties?rev=1036177&r1=1036176&r2=1036177&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties (original)
+++ jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties Wed Nov 17 19:42:21 2010
@@ -338,6 +338,9 @@ jms_config=Message source
 jms_config_title=JMS Configuration
 jms_connection_factory=Connection Factory
 jms_correlation_title=Use alternate fields for message correlation
+jms_dest_setup=Setup
+jms_dest_setup_dynamic=Each sample
+jms_dest_setup_static=At startup
 jms_error_msg=Object message should read from an external file. Text input is currently selected, please remember to change it.
 jms_file=File
 jms_initial_context_factory=Initial Context Factory

Modified: jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties?rev=1036177&r1=1036176&r2=1036177&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties (original)
+++ jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties Wed Nov 17 19:42:21 2010
@@ -306,6 +306,9 @@ jms_config=Source du message \:
 jms_config_title=Configuration JMS
 jms_connection_factory=Fabrique de connexion
 jms_correlation_title=Champs alternatifs pour la correspondance de message
+jms_dest_setup=Evaluer
+jms_dest_setup_dynamic=A chaque \u00E9chantillon
+jms_dest_setup_static=Au d\u00E9marrage
 jms_error_msg=L'objet du message peut \u00EAtre lu depuis un fichier externe. L'entr\u00E9e par texte est actuellement s\u00E9lectionn\u00E9e, ne pas oublier de la changer
 jms_file=Source du message \: Fichier
 jms_initial_context_factory=Fabrique de connexion initiale

Modified: jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/Publisher.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/Publisher.java?rev=1036177&r1=1036176&r2=1036177&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/Publisher.java (original)
+++ jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/Publisher.java Wed Nov 17 19:42:21 2010
@@ -23,8 +23,6 @@ import java.io.Serializable;
 import java.util.Map;
 import java.util.Map.Entry;
 
-import javax.naming.Context;
-import javax.naming.NamingException;
 import javax.jms.Connection;
 import javax.jms.Destination;
 import javax.jms.JMSException;
@@ -33,8 +31,11 @@ import javax.jms.MessageProducer;
 import javax.jms.ObjectMessage;
 import javax.jms.Session;
 import javax.jms.TextMessage;
+import javax.naming.Context;
+import javax.naming.NamingException;
 
 import org.apache.jmeter.protocol.jms.Utils;
+import org.apache.jmeter.protocol.jms.control.gui.JMSPublisherGui;
 import org.apache.jorphan.logging.LoggingManager;
 import org.apache.log.Logger;
 
@@ -47,6 +48,10 @@ public class Publisher implements Closea
     private final Session session;
 
     private final  MessageProducer producer;
+    
+    private final Context ctx;
+    
+    private final boolean staticDest;
 
     /**
      * Create a publisher using either the jndi.properties file or the provided parameters
@@ -64,33 +69,94 @@ public class Publisher implements Closea
     public Publisher(boolean useProps, String initialContextFactory, String providerUrl, 
             String connfactory, String destinationName, boolean useAuth,
             String securityPrincipal, String securityCredentials) throws JMSException, NamingException {
+        this(useProps, initialContextFactory, providerUrl, connfactory,
+                destinationName, useAuth, securityPrincipal,
+                securityCredentials, JMSPublisherGui.DEST_SETUP_STATIC);
+    }
+    
+    /**
+     * Create a publisher using either the jndi.properties file or the provided parameters
+     * @param useProps true if a jndi.properties file is to be used
+     * @param initialContextFactory the (ignored if useProps is true)
+     * @param providerUrl (ignored if useProps is true)
+     * @param connfactory
+     * @param destinationName
+     * @param useAuth (ignored if useProps is true)
+     * @param securityPrincipal (ignored if useProps is true)
+     * @param securityCredentials (ignored if useProps is true)
+     * @param destinationSetup true is the destination is not to change between loops
+     * @throws JMSException if the context could not be initialised, or there was some other error
+     * @throws NamingException 
+     */
+    public Publisher(boolean useProps, String initialContextFactory, String providerUrl, 
+            String connfactory, String destinationName, boolean useAuth,
+            String securityPrincipal, String securityCredentials,
+            String destinationSetup) throws JMSException, NamingException {
         super();
-        Context ctx = InitialContextFactory.getContext(useProps, initialContextFactory, 
+        ctx = InitialContextFactory.getContext(useProps, initialContextFactory, 
                 providerUrl, useAuth, securityPrincipal, securityCredentials);
         connection = Utils.getConnection(ctx, connfactory);
         session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        Destination dest = Utils.lookupDestination(ctx, destinationName);
-        producer = session.createProducer(dest);
+        staticDest = destinationSetup.equals(JMSPublisherGui.DEST_SETUP_STATIC) ? true : false;
+        if (staticDest) {
+            Destination dest = Utils.lookupDestination(ctx, destinationName);
+            producer = session.createProducer(dest);
+        } else {
+            producer = session.createProducer(null);
+        }
     }
 
-    public TextMessage publish(String text) throws JMSException {
+    public TextMessage publish(String text) throws JMSException,
+            NamingException {
+        return publish(text, null);
+    }
+    
+    public TextMessage publish(String text, String destinationName)
+            throws JMSException, NamingException {
         TextMessage msg = session.createTextMessage(text);
-        producer.send(msg);
+        if (staticDest || destinationName == null) {
+            producer.send(msg);
+        } else {
+            Destination dest = Utils.lookupDestination(ctx, destinationName);
+            producer.send(dest, msg);
+        }
         return msg;
     }
 
-    public ObjectMessage publish(Serializable contents) throws JMSException {
+    public ObjectMessage publish(Serializable contents) throws JMSException,
+            NamingException {
+        return publish(contents, null);
+    }
+    
+    public ObjectMessage publish(Serializable contents, String destinationName)
+            throws JMSException, NamingException {
         ObjectMessage msg = session.createObjectMessage(contents);
-        producer.send(msg);
+        if (staticDest || destinationName == null) {
+            producer.send(msg);
+        } else {
+            Destination dest = Utils.lookupDestination(ctx, destinationName);
+            producer.send(dest, msg);
+        }
         return msg;
     }
 
-    public MapMessage publish(Map<String, Object> map) throws JMSException {
+    public MapMessage publish(Map<String, Object> map) throws JMSException,
+            NamingException {
+        return publish(map, null);
+    }
+    
+    public MapMessage publish(Map<String, Object> map, String destinationName)
+            throws JMSException, NamingException {
         MapMessage msg = session.createMapMessage();
-        for (Entry<String, Object> me : map.entrySet()){
-            msg.setObject(me.getKey(), me.getValue());                
+        for (Entry<String, Object> me : map.entrySet()) {
+            msg.setObject(me.getKey(), me.getValue());
+        }
+        if (staticDest || destinationName == null) {
+            producer.send(msg);
+        } else {
+            Destination dest = Utils.lookupDestination(ctx, destinationName);
+            producer.send(dest, msg);
         }
-        producer.send(msg);
         return msg;
     }
 

Modified: jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/control/gui/JMSPublisherGui.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/control/gui/JMSPublisherGui.java?rev=1036177&r1=1036176&r2=1036177&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/control/gui/JMSPublisherGui.java (original)
+++ jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/control/gui/JMSPublisherGui.java Wed Nov 17 19:42:21 2010
@@ -21,6 +21,7 @@ package org.apache.jmeter.protocol.jms.c
 import java.awt.BorderLayout;
 import java.awt.Dimension;
 
+import javax.swing.BoxLayout;
 import javax.swing.JCheckBox;
 import javax.swing.JOptionPane;
 import javax.swing.JPanel;
@@ -96,6 +97,18 @@ public class JMSPublisherGui extends Abs
     private final JLabeledTextArea textMessage = new JLabeledTextArea(JMeterUtils.getResString("jms_text_message"));
 
     private final JLabeledRadioI18N msgChoice = new JLabeledRadioI18N("jms_message_type", MSGTYPES_ITEMS, TEXT_MSG_RSC); //$NON-NLS-1$
+    
+    //++ Do not change these strings; they are used in JMX files to record the button settings
+    public final static String DEST_SETUP_STATIC = "jms_dest_setup_static"; // $NON-NLS-1$
+
+    public final static String DEST_SETUP_DYNAMIC = "jms_dest_setup_dynamic"; // $NON-NLS-1$
+    //--
+
+    // Button group resources
+    private final static String[] DEST_SETUP_ITEMS = { DEST_SETUP_STATIC, DEST_SETUP_DYNAMIC };
+
+    private final JLabeledRadioI18N destSetup =
+        new JLabeledRadioI18N("jms_dest_setup", DEST_SETUP_ITEMS, DEST_SETUP_STATIC); // $NON-NLS-1$
 
     public JMSPublisherGui() {
         init();
@@ -153,6 +166,7 @@ public class JMSPublisherGui extends Abs
         sampler.setMessageChoice(msgChoice.getText());
         sampler.setIterations(iterations.getText());
         sampler.setUseAuth(useAuth.isSelected());
+        sampler.setDestinationSetup(destSetup.getText());
     }
 
     /**
@@ -171,13 +185,15 @@ public class JMSPublisherGui extends Abs
         mainPanel.add(jndiICF);
         mainPanel.add(urlField);
         mainPanel.add(jndiConnFac);
-        mainPanel.add(jmsDestination);
+        mainPanel.add(createDestinationPane());
         mainPanel.add(useAuth);
         mainPanel.add(jmsUser);
         mainPanel.add(jmsPwd);
         mainPanel.add(iterations);
 
+        configChoice.setLayout(new BoxLayout(configChoice, BoxLayout.X_AXIS));
         mainPanel.add(configChoice);
+        msgChoice.setLayout(new BoxLayout(msgChoice, BoxLayout.X_AXIS));
         mainPanel.add(msgChoice);
         mainPanel.add(messageFile);
         mainPanel.add(randomFile);
@@ -209,6 +225,7 @@ public class JMSPublisherGui extends Abs
         updateConfig(USE_TEXT_RSC);
         iterations.setText("1"); // $NON-NLS-1$
         useAuth.setSelected(false);
+        destSetup.setText(DEST_SETUP_STATIC);
     }
 
     /**
@@ -233,6 +250,7 @@ public class JMSPublisherGui extends Abs
         updateConfig(sampler.getConfigChoice());
         iterations.setText(sampler.getIterations());
         useAuth.setSelected(sampler.isUseAuth());
+        destSetup.setText(sampler.getDestinationSetup());
     }
 
     /**
@@ -289,4 +307,12 @@ public class JMSPublisherGui extends Abs
             }
         }
     }
+    
+    private JPanel createDestinationPane() {
+        JPanel pane = new JPanel(new BorderLayout(3, 0));
+        pane.add(jmsDestination, BorderLayout.CENTER);
+        destSetup.setLayout(new BoxLayout(destSetup, BoxLayout.X_AXIS));
+        pane.add(destSetup, BorderLayout.EAST);
+        return pane;
+    }
 }

Modified: jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/BaseJMSSampler.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/BaseJMSSampler.java?rev=1036177&r1=1036176&r2=1036177&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/BaseJMSSampler.java (original)
+++ jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/BaseJMSSampler.java Wed Nov 17 19:42:21 2010
@@ -61,6 +61,9 @@ public abstract class BaseJMSSampler ext
     private static final String READ_RESPONSE = "jms.read_response"; // $NON-NLS-1$
     //--
 
+    // Destination setup (static or dynamic)
+    private static final String DESTINATION_SETUP = "jms.destination_setup"; // $NON-NLS-1$
+
     // See BUG 45460. We need to keep the resource in order to interpret existing files
     private static final String REQUIRED = JMeterUtils.getResString("jms_auth_required"); // $NON-NLS-1$
 
@@ -288,6 +291,23 @@ public abstract class BaseJMSSampler ext
         return getPropertyAsBoolean(USE_PROPERTIES_FILE);
     }
 
+    /**
+     * if the sampler should use a static destination, call the method with true
+     *
+     * @param properties
+     */
+    public void setDestinationSetup(String properties) {
+	    setProperty(DESTINATION_SETUP, properties);
+    }
+
+    /**
+     * return whether the sampler should use a static destination.
+     *
+     * @return  whether the sampler should use a static destination.
+     */
+    public String getDestinationSetup() {
+	    return getPropertyAsString(DESTINATION_SETUP);
+    }
 
     /**
      * Returns a String with the JMS Message Header values.

Modified: jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/PublisherSampler.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/PublisherSampler.java?rev=1036177&r1=1036176&r2=1036177&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/PublisherSampler.java (original)
+++ jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/PublisherSampler.java Wed Nov 17 19:42:21 2010
@@ -116,7 +116,7 @@ public class PublisherSampler extends Ba
     private void initClient() throws JMSException, NamingException {
         publisher = new Publisher(getUseJNDIPropertiesAsBoolean(), getJNDIInitialContextFactory(), 
                 getProviderUrl(), getConnectionFactory(), getDestination(), isUseAuth(), getUsername(),
-                getPassword());
+                getPassword(), getDestinationSetup());
         ClientPool.addClient(publisher);
         log.debug("PublisherSampler.initClient called");
     }
@@ -153,12 +153,12 @@ public class PublisherSampler extends Ba
             for (int idx = 0; idx < loop; idx++) {
                 if (JMSPublisherGui.TEXT_MSG_RSC.equals(type)){
                     String tmsg = getMessageContent();
-                    Message msg = publisher.publish(tmsg);
+                    Message msg = publisher.publish(tmsg, getDestination());
                     buffer.append(tmsg);
                     Utils.messageProperties(propBuffer, msg);
                 } else if (JMSPublisherGui.MAP_MSG_RSC.equals(type)){
                     Map<String, Object> m = getMapContent();
-                    Message msg = publisher.publish(m);
+                    Message msg = publisher.publish(m, getDestination());
                     Utils.messageProperties(propBuffer, msg);
                 } else if (JMSPublisherGui.OBJECT_MSG_RSC.equals(type)){
                     throw new JMSException(type+ " is not yet supported");

Modified: jakarta/jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/changes.xml?rev=1036177&r1=1036176&r2=1036177&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/changes.xml (original)
+++ jakarta/jmeter/trunk/xdocs/changes.xml Wed Nov 17 19:42:21 2010
@@ -123,6 +123,7 @@ To override the default local language f
 <li>Bug 49603 - Allow accepting expired certificates on Mail Reader Sampler</li>
 <li>Bug 49775 - Allow sending messages without a body</li>
 <li>Bug 49862 - Improve SMTPSampler Request output.</li>
+<li>Bug 50268 - Adds static and dynamic destinations to JMS Publisher</li>
 </ul>
 
 <h3>Controllers</h3>

Modified: jakarta/jmeter/trunk/xdocs/images/screenshots/jmspublisher.png
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/images/screenshots/jmspublisher.png?rev=1036177&r1=1036176&r2=1036177&view=diff
==============================================================================
Binary files - no diff available.

Modified: jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=1036177&r1=1036176&r2=1036177&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml (original)
+++ jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml Wed Nov 17 19:42:21 2010
@@ -1135,7 +1135,7 @@ For details, see <complink name="BSF Sam
 </properties>
 </component>
 
-<component name="JMS Publisher" index="&sect-num;.1.13"  width="459" height="662" screenshot="jmspublisher.png">
+<component name="JMS Publisher" index="&sect-num;.1.13" screenshot="jmspublisher.png">
 <note>BETA CODE - the code is still subject to change</note>
 	<description>
 		<p>
@@ -1155,12 +1155,13 @@ For details, see <complink name="BSF Sam
   </property>
   <property name="JNDI Initial Context Factory" required="No">Name of the context factory</property>
   <property name="Provider URL" required="Yes, unless using jndi.properties">The URL for the jms provider</property>
-  <property name="Destination" required="Yes">the message destination (topic or queue name)</property>
+  <property name="Destination" required="Yes">The message destination (topic or queue name)</property>
+  <property name="Setup" required="Yes">The destination setup type. With At startup, the destination name is static (i.e. always same name during the test), with Each sample, the destination name is dynamic and is evaluate at each sample (i.e. the destination name may be a variable)</property>
   <property name="Authentication" required="Yes">Authentication requirement for the JMS provider</property>
   <property name="User" required="No">User Name</property>
   <property name="Password" required="No">Password</property>
-  <property name="Number of samples to aggregate" required="Yes">number of samples to aggregate</property>
-  <property name="Message source" required="Yes">where to obtain the message</property>
+  <property name="Number of samples to aggregate" required="Yes">Number of samples to aggregate</property>
+  <property name="Message source" required="Yes">Where to obtain the message</property>
   <property name="Message type" required="Yes">Text, Map or Object message</property>
 </properties>
 <p>



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@jakarta.apache.org
For additional commands, e-mail: notifications-help@jakarta.apache.org