jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1815716 - in /jmeter/trunk: bin/testfiles/JMS_TESTS.csv bin/testfiles/JMS_TESTS.jmx bin/testfiles/JMS_TESTS.xml src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java
Date Sun, 19 Nov 2017 10:00:27 GMT
Author: pmouawad
Date: Sun Nov 19 10:00:27 2017
New Revision: 1815716

URL: http://svn.apache.org/viewvc?rev=1815716&view=rev
Log:
Bug 61544 - JMS Point-to-Point Sampler: Enhance communication styles with read, browse, clear
Fix test : Increase timeout that was set to 1ms which led to random failure
Improve class code (logging, variable naming, use StringBuilder)
Bugzilla Id: 61544

Modified:
    jmeter/trunk/bin/testfiles/JMS_TESTS.csv
    jmeter/trunk/bin/testfiles/JMS_TESTS.jmx
    jmeter/trunk/bin/testfiles/JMS_TESTS.xml
    jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java

Modified: jmeter/trunk/bin/testfiles/JMS_TESTS.csv
URL: http://svn.apache.org/viewvc/jmeter/trunk/bin/testfiles/JMS_TESTS.csv?rev=1815716&r1=1815715&r2=1815716&view=diff
==============================================================================
--- jmeter/trunk/bin/testfiles/JMS_TESTS.csv (original)
+++ jmeter/trunk/bin/testfiles/JMS_TESTS.csv Sun Nov 19 10:00:27 2017
@@ -12,7 +12,7 @@ JMS-P2P-RequestOnly,200,OK,TG-JMS-P2P 1-
 JMS-P2P-Browse,200,1 messages available on the queue,TG-JMS-P2P 1-1,text,true,1,1,1,0
 JMS-P2P-Read,200,1 message(s) received successfully,TG-JMS-P2P 1-1,text,true,1,1,1,0
 JMS-P2P-RequestOnlyForClear,200,OK,TG-JMS-P2P 1-1,text,true,1,1,1,0
-JMS-P2P-Clear,200,1 message(s) removed,TG-JMS-P2P 1-1,text,true,1,1,1,0
+JMS-P2P-Clear,200,1 message(s) removed using receive timeout:100ms,TG-JMS-P2P 1-1,text,true,1,1,1,0
 JMS-P2P-BrowseAfterClear,200,0 messages available on the queue,TG-JMS-P2P 1-1,text,true,1,1,1,0
 JMS Publisher-NonDurable,200,1 messages published,TG-JMS-PS 2-1,,true,1,1,1,0
 JMS Subscriber-NonDurable,200,1 message(s) received successfully of 1 expected,TG-JMS-PS
2-1,text,true,1,1,1,0

Modified: jmeter/trunk/bin/testfiles/JMS_TESTS.jmx
URL: http://svn.apache.org/viewvc/jmeter/trunk/bin/testfiles/JMS_TESTS.jmx?rev=1815716&r1=1815715&r2=1815716&view=diff
==============================================================================
--- jmeter/trunk/bin/testfiles/JMS_TESTS.jmx (original)
+++ jmeter/trunk/bin/testfiles/JMS_TESTS.jmx Sun Nov 19 10:00:27 2017
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<jmeterTestPlan version="1.2" properties="3.4" jmeter="3.4-SNAPSHOT.20171118">
+<jmeterTestPlan version="1.2" properties="3.4" jmeter="3.4-SNAPSHOT.20171119">
   <hashTree>
     <TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test Plan" enabled="true">
       <stringProp name="TestPlan.comments"></stringProp>
@@ -508,11 +508,6 @@ finally {
           <intProp name="JMSSampler.communicationStyle">3</intProp>
         </JMSSampler>
         <hashTree>
-          <UniformRandomTimer guiclass="UniformRandomTimerGui" testclass="UniformRandomTimer"
testname="Pause" enabled="true">
-            <stringProp name="ConstantTimer.delay">1000</stringProp>
-            <stringProp name="RandomTimer.range">100</stringProp>
-          </UniformRandomTimer>
-          <hashTree/>
           <ResponseAssertion guiclass="AssertionGui" testclass="ResponseAssertion" testname="Response
Assertion" enabled="true">
             <collectionProp name="Asserion.test_strings">
               <stringProp name="-1029016402">requestQueue5 has 1 messages</stringProp>
@@ -607,7 +602,7 @@ finally {
           <stringProp name="JMSSampler.ReceiveQueue"></stringProp>
           <boolProp name="JMSSampler.isNonPersistent">false</boolProp>
           <boolProp name="JMSSampler.useReqMsgIdAsCorrelId">false</boolProp>
-          <stringProp name="JMSSampler.timeout">1</stringProp>
+          <stringProp name="JMSSampler.timeout">100</stringProp>
           <stringProp name="HTTPSamper.xml_data"></stringProp>
           <stringProp name="JMSSampler.initialContextFactory">org.apache.activemq.jndi.ActiveMQInitialContextFactory</stringProp>
           <stringProp name="JMSSampler.contextProviderUrl">tcp://localhost:61616</stringProp>

Modified: jmeter/trunk/bin/testfiles/JMS_TESTS.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/bin/testfiles/JMS_TESTS.xml?rev=1815716&r1=1815715&r2=1815716&view=diff
==============================================================================
--- jmeter/trunk/bin/testfiles/JMS_TESTS.xml (original)
+++ jmeter/trunk/bin/testfiles/JMS_TESTS.xml Sun Nov 19 10:00:27 2017
@@ -85,7 +85,7 @@
     <error>false</error>
   </assertionResult>
 </sample>
-<sample s="true" lb="JMS-P2P-Clear" rc="200" rm="1 message(s) removed" tn="TG-JMS-P2P
1-1" dt="text" sc="1" ec="0" ng="1" na="1">
+<sample s="true" lb="JMS-P2P-Clear" rc="200" rm="1 message(s) removed using receive timeout:100ms"
tn="TG-JMS-P2P 1-1" dt="text" sc="1" ec="0" ng="1" na="1">
   <assertionResult>
     <name>Response Assertion</name>
     <failure>false</failure>

Modified: jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java?rev=1815716&r1=1815715&r2=1815716&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java (original)
+++ jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java Sun
Nov 19 10:00:27 2017
@@ -18,6 +18,7 @@
 
 package org.apache.jmeter.protocol.jms.sampler;
 
+import java.nio.charset.StandardCharsets;
 import java.util.Date;
 import java.util.Enumeration;
 import java.util.Hashtable;
@@ -65,14 +66,17 @@ import org.slf4j.LoggerFactory;
  */
 public class JMSSampler extends AbstractSampler implements ThreadListener {
 
+    private static final long serialVersionUID = 233L;
+
     private static final Logger LOGGER = LoggerFactory.getLogger(JMSSampler.class);
 
-    private static final long serialVersionUID = 233L;
+    private static final String PREV_SAMPLER = "__PREV_SAMPLER__";
 
     private static final int DEFAULT_TIMEOUT = 2000;
+
     private static final String DEFAULT_TIMEOUT_STRING = Integer.toString(DEFAULT_TIMEOUT);
 
-    // ++ These are JMX names, and must not be changed
+    // These are JMX names, and must not be changed
     private static final String JNDI_INITIAL_CONTEXT_FACTORY = "JMSSampler.initialContextFactory";
// $NON-NLS-1$
 
     private static final String JNDI_CONTEXT_PROVIDER_URL = "JMSSampler.contextProviderUrl";
// $NON-NLS-1$
@@ -93,7 +97,7 @@ public class JMSSampler extends Abstract
      * @deprecated since 4.0 replaced by JMS_COMMUNICATION_STYLE
      */
     @Deprecated
-    public static final String IS_ONE_WAY = "JMSSampler.isFireAndForget"; // $NON-NLS-1$
+    public static final String IS_ONE_WAY = "JMSSampler.isFireAndForget"; // $NON-NLS-1$
// NOSONAR
     
     private static final String JMS_NUMBEROFSAMPLES = "JMSSampler.jmsNumberOfSamplesToAggregate";
// $NON-NLS-1$
 
@@ -178,7 +182,7 @@ public class JMSSampler extends Abstract
      */
     @Override
     public SampleResult sample(Entry entry) {
-        JMeterContext context = JMeterContextService.getContext();
+        JMeterContext jmeterContext = JMeterContextService.getContext();
 
         SampleResult res = new SampleResult();
         res.setSampleLabel(getName());
@@ -188,7 +192,7 @@ public class JMSSampler extends Abstract
         res.sampleStart();
 
         try {
-            LOGGER.debug("Point-to-point mode: " + getCommunicationstyle());
+            LOGGER.debug("Point-to-point mode: {}", getCommunicationstyle());
             if (isBrowse()) {
                 handleBrowse(res);
             } else if (isClearQueue()) {
@@ -196,7 +200,7 @@ public class JMSSampler extends Abstract
             } else if (isOneway()) {
                 handleOneWay(res);
             } else if (isRead()) {
-                handleRead(context, res);
+                handleRead(jmeterContext, res);
             } else {
                 handleRequestResponse(res);
             }
@@ -214,7 +218,7 @@ public class JMSSampler extends Abstract
 
     private void handleBrowse(SampleResult res) throws JMSException {
         LOGGER.debug("isBrowseOnly");
-        StringBuilder sb = new StringBuilder("");
+        StringBuilder sb = new StringBuilder(75);
         res.setSuccessful(true);
         sb.append("Browse message on Send Queue ").append(sendQueue.getQueueName())
             .append(": ")
@@ -225,7 +229,7 @@ public class JMSSampler extends Abstract
 
     private void handleClearQueue(SampleResult res) throws JMSException {
         LOGGER.debug("isClearQueue");
-        StringBuilder sb = new StringBuilder("");
+        StringBuilder sb = new StringBuilder(75);
         res.setSuccessful(true);
         sb.append("Clear messages on Send Queue ").append(sendQueue.getQueueName())
                 .append(": ")
@@ -246,12 +250,12 @@ public class JMSSampler extends Abstract
 
     private void handleRead(JMeterContext context, SampleResult res) {
         LOGGER.debug("isRead");
-        StringBuilder sb = new StringBuilder("");
+        StringBuilder sb = new StringBuilder(75);
         res.setSuccessful(true);
         Sampler sampler = context.getPreviousSampler();
         SampleResult sr = context.getPreviousResult();
         String jmsSelector = getJMSSelector();
-        if (jmsSelector.equals("_PREV_SAMPLER_")
+        if (jmsSelector.equals(JMSSampler.PREV_SAMPLER)
                 && (sampler instanceof JMSSampler)) {
             jmsSelector = sr.getResponseMessage();
         }
@@ -273,7 +277,7 @@ public class JMSSampler extends Abstract
         } while ((result != null) && (sampleTries < getNumberOfSamplesToAggregateAsInt()));
 
         res.setResponseMessage(sampleCounter + " samples messages received");
-        res.setResponseData(buffer.toString().getBytes()); // TODO - charset?
+        res.setResponseData(buffer.toString(), StandardCharsets.UTF_8.name());
         res.setResponseHeaders(propBuffer.toString());
         if (sampleCounter == 0) {
             res.setResponseCode("404");
@@ -379,24 +383,32 @@ public class JMSSampler extends Abstract
 
     private String browseQueueDetails(Queue queue, SampleResult res) {
         try {
-            String messageBodies = "\n==== Browsing Messages === \n";
+            StringBuilder messageBodies = new StringBuilder(150);
+            messageBodies.append("==== Browsing Messages ===\n");
             // get some queue details
             QueueBrowser qBrowser = session.createBrowser(queue);
             // browse the messages
             Enumeration<?> e = qBrowser.getEnumeration();
             int numMsgs = 0;
             // count number of messages
-            String corrID = "";
+            String corrID;
             while (e.hasMoreElements()) {
                 TextMessage message = (TextMessage) e.nextElement();
                 corrID = message.getJMSCorrelationID();
                 if (corrID == null) {
                     corrID = message.getJMSMessageID();
-                    messageBodies = messageBodies + numMsgs + " - MessageID: " + corrID +
": " + message.getText()
-                            + "\n";
+                    messageBodies.append(numMsgs)
+                        .append(" - MessageID: ")
+                        .append(corrID)
+                        .append(": ").append(message.getText())
+                        .append("\n");
                 } else {
-                    messageBodies = messageBodies + numMsgs + " - CorrelationID: " + corrID
+ ": " + message.getText()
-                            + "\n";
+                    messageBodies.append(numMsgs)
+                    .append(" - CorrelationID: ")
+                    .append(corrID)
+                    .append(": ")
+                    .append(message.getText())
+                    .append("\n");
                 }
                 numMsgs++;
             }
@@ -424,7 +436,8 @@ public class JMSSampler extends Abstract
                     deletedMsg.acknowledge();
                 }
             } while (deletedMsg != null);
-            retVal = deletedMsgCount + " message(s) removed";
+            retVal = deletedMsgCount + " message(s) removed using receive timeout:"+
+                    getTimeoutAsInt()+"ms";
             res.setResponseMessage(retVal);
         } catch (Exception ex) {
             res.setResponseMessage("Error clearing queue");
@@ -694,11 +707,11 @@ public class JMSSampler extends Abstract
             table.put(me.getKey(), me.getValue());
         }
 
-        Context context = new InitialContext(table);
+        Context initialContext = new InitialContext(table);
         if (LOGGER.isDebugEnabled()) {
-            printEnvironment(context);
+            printEnvironment(initialContext);
         }
-        return context;
+        return initialContext;
     }
 
     private void printEnvironment(Context context) throws NamingException {
@@ -721,12 +734,12 @@ public class JMSSampler extends Abstract
 
     private void logThreadStart() {
         if (LOGGER.isDebugEnabled()) {
-            LOGGER.debug("Thread started " + new Date());
-            LOGGER.debug("JMSSampler: [" + Thread.currentThread().getName() + "], hashCode=["
+ hashCode() + "]");
-            LOGGER.debug("QCF: [" + getQueueConnectionFactory() + "], sendQueue=[" + getSendQueue()
+ "]");
-            LOGGER.debug("Timeout             = " + getTimeout() + "]");
-            LOGGER.debug("Use temporary queue =" + useTemporyQueue() + "]");
-            LOGGER.debug("Reply queue         =" + getReceiveQueue() + "]");
+            LOGGER.debug("Thread started {}", new Date());
+            LOGGER.debug("JMSSampler: [{}], hashCode=[{}]", Thread.currentThread().getName(),
hashCode());
+            LOGGER.debug("QCF: [{}], sendQueue=[{}]", getQueueConnectionFactory(), getSendQueue());
+            LOGGER.debug("Timeout = [{}]", getTimeout());
+            LOGGER.debug("Use temporary queue =[{}]", useTemporyQueue());
+            LOGGER.debug("Reply queue         = [{}]", getReceiveQueue());
         }
     }
 



Mime
View raw message