jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1807719 - in /jmeter/trunk: src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/ xdocs/
Date Fri, 08 Sep 2017 11:55:41 GMT
Author: pmouawad
Date: Fri Sep  8 11:55:40 2017
New Revision: 1807719

URL: http://svn.apache.org/viewvc?rev=1807719&view=rev
Log:
Bug 60156 - TCPSampler : Latency is not measured for TCP Sampler
Contributed by UbikLoadPack
Bugzilla Id: 60156

Modified:
    jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/AbstractTCPClient.java
    jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/BinaryTCPClientImpl.java
    jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/LengthPrefixedBinaryTCPClientImpl.java
    jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPClient.java
    jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPClientImpl.java
    jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/AbstractTCPClient.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/AbstractTCPClient.java?rev=1807719&r1=1807718&r2=1807719&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/AbstractTCPClient.java
(original)
+++ jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/AbstractTCPClient.java
Fri Sep  8 11:55:40 2017
@@ -18,6 +18,10 @@
 
 package org.apache.jmeter.protocol.tcp.sampler;
 
+import java.io.InputStream;
+
+import org.apache.jmeter.samplers.SampleResult;
+
 /**
  * Basic implementation of TCPClient interface.
  */
@@ -76,4 +80,12 @@ public abstract class AbstractTCPClient
         this.charset = charset;
     }
 
+    /**
+     * Default implementation calls {@link TCPClient#read(InputStream)} for backward compatibility
+     * @see org.apache.jmeter.protocol.tcp.sampler.TCPClient#read(java.io.InputStream, org.apache.jmeter.samplers.SampleResult)
+     */
+    @Override
+    public String read(InputStream is, SampleResult sampleResult) throws ReadException {
+        return read(is);
+    }
 }

Modified: jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/BinaryTCPClientImpl.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/BinaryTCPClientImpl.java?rev=1807719&r1=1807718&r2=1807719&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/BinaryTCPClientImpl.java
(original)
+++ jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/BinaryTCPClientImpl.java
Fri Sep  8 11:55:40 2017
@@ -30,6 +30,7 @@ import java.io.InputStream;
 import java.io.OutputStream;
 
 import org.apache.commons.io.IOUtils;
+import org.apache.jmeter.samplers.SampleResult;
 import org.apache.jmeter.util.JMeterUtils;
 import org.apache.jorphan.util.JOrphanUtils;
 import org.slf4j.Logger;
@@ -53,7 +54,7 @@ public class BinaryTCPClientImpl extends
         super();
         setEolByte(EOM_INT);
         if (useEolByte) {
-            log.info("Using eomByte=" + eolByte);
+            log.info("Using eomByte={}", eolByte);
         }
     }
 
@@ -108,6 +109,12 @@ public class BinaryTCPClientImpl extends
         throw new UnsupportedOperationException(
                 "Method not supported for Length-Prefixed data.");
     }
+    
+    @Deprecated
+    public String read(InputStream is) throws ReadException {
+        log.warn("Deprecated method, use read(is, sampleResult) instead");
+        return read(is, new SampleResult());
+    }
 
     /**
      * Reads data until the defined EOM byte is reached.
@@ -118,12 +125,17 @@ public class BinaryTCPClientImpl extends
      * @throws ReadException when reading fails
      */
     @Override
-    public String read(InputStream is) throws ReadException {
+    public String read(InputStream is, SampleResult sampleResult) throws ReadException {
         ByteArrayOutputStream w = new ByteArrayOutputStream();
         try {
             byte[] buffer = new byte[4096];
             int x = 0;
+            boolean first = true;
             while ((x = is.read(buffer)) > -1) {
+                if (first) {
+                    sampleResult.latencyEnd();
+                    first = false;
+                }
                 w.write(buffer, 0, x);
                 if (useEolByte && (buffer[x - 1] == eolByte)) {
                     break;

Modified: jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/LengthPrefixedBinaryTCPClientImpl.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/LengthPrefixedBinaryTCPClientImpl.java?rev=1807719&r1=1807718&r2=1807719&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/LengthPrefixedBinaryTCPClientImpl.java
(original)
+++ jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/LengthPrefixedBinaryTCPClientImpl.java
Fri Sep  8 11:55:40 2017
@@ -32,6 +32,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 
+import org.apache.jmeter.samplers.SampleResult;
 import org.apache.jmeter.util.JMeterUtils;
 import org.apache.jorphan.util.JOrphanUtils;
 import org.slf4j.Logger;
@@ -72,21 +73,28 @@ public class LengthPrefixedBinaryTCPClie
         this.tcpClient.write(os, is);
     }
 
+    @Deprecated
+    public String read(InputStream is) throws ReadException {
+        log.warn("Deprecated method, use read(is, sampleResult) instead");
+        return read(is, new SampleResult());
+    }
+    
     /**
      * {@inheritDoc}
      */
     @Override
-    public String read(InputStream is) throws ReadException{
+    public String read(InputStream is, SampleResult sampleResult) throws ReadException{
         byte[] msg = new byte[0];
         int msgLen = 0;
         byte[] lengthBuffer = new byte[lengthPrefixLen];
         try {
             if (is.read(lengthBuffer, 0, lengthPrefixLen) == lengthPrefixLen) {
+                sampleResult.latencyEnd();
                 msgLen = byteArrayToInt(lengthBuffer);
                 msg = new byte[msgLen];
                 int bytes = JOrphanUtils.read(is, msg, 0, msgLen);
                 if (bytes < msgLen) {
-                    log.warn("Incomplete message read, expected: "+msgLen+" got: "+bytes);
+                    log.warn("Incomplete message read, expected: {} got: {}", msgLen, bytes);
                 }
             }
     

Modified: jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPClient.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPClient.java?rev=1807719&r1=1807718&r2=1807719&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPClient.java (original)
+++ jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPClient.java Fri
Sep  8 11:55:40 2017
@@ -28,18 +28,20 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 
+import org.apache.jmeter.samplers.SampleResult;
+
 /**
  * Interface required by TCPSampler for TCPClient implementations.
  */
 public interface TCPClient {
 
     /**
-     * Versions of JMeter after 2.3.2 invoke this method when the thread starts.
+     * Invoked when the thread starts.
      */
     void setupTest();
 
     /**
-     * Versions of JMeter after 2.3.2 invoke this method when the thread ends.
+     * Invoked when the thread ends
      */
     void teardownTest();
 
@@ -69,10 +71,22 @@ public interface TCPClient {
      *            InputStream for socket
      * @return String read from socket
      * @throws ReadException exception that can contain partial response (Response until
error occurred)
+     * @deprecated since 3.3, implement {@link TCPClient#read(InputStream, SampleResult)}
instead, will be removed in future version
      */
+    @Deprecated
     String read(InputStream is) throws ReadException;
 
     /**
+     * 
+     * @param is -
+     *            InputStream for socket
+     * @param sampleResult {@link SampleResult}
+     * @return String read from socket
+     * @throws ReadException
+     */
+    String read(InputStream is, SampleResult sampleResult) throws ReadException;
+
+    /**
      * Get the end-of-line/end-of-message byte.
      * @return Returns the eolByte.
      */

Modified: jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPClientImpl.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPClientImpl.java?rev=1807719&r1=1807718&r2=1807719&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPClientImpl.java
(original)
+++ jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPClientImpl.java
Fri Sep  8 11:55:40 2017
@@ -33,6 +33,7 @@ import java.io.OutputStream;
 import java.nio.charset.Charset;
 
 import org.apache.commons.lang3.StringUtils;
+import org.apache.jmeter.samplers.SampleResult;
 import org.apache.jmeter.util.JMeterUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -55,14 +56,14 @@ public class TCPClientImpl extends Abstr
         super();
         setEolByte(EOL_INT);
         if (useEolByte) {
-            log.info("Using eolByte=" + eolByte);
+            log.info("Using eolByte={}", eolByte);
         }
         setCharset(CHARSET);
         String configuredCharset = JMeterUtils.getProperty("tcp.charset");
         if(StringUtils.isEmpty(configuredCharset)) {
-            log.info("Using platform default charset:"+CHARSET);
+            log.info("Using platform default charset:{}",CHARSET);
         } else {
-            log.info("Using charset:"+configuredCharset);
+            log.info("Using charset:{}", configuredCharset);
         }
     }
 
@@ -93,18 +94,28 @@ public class TCPClientImpl extends Abstr
         }
     }
 
+    @Deprecated
+    public String read(InputStream is) throws ReadException {
+        return read(is, new SampleResult());
+    }
+    
     /**
      * Reads data until the defined EOL byte is reached.
      * If there is no EOL byte defined, then reads until
      * the end of the stream is reached.
      */
     @Override
-    public String read(InputStream is) throws ReadException{
+    public String read(InputStream is, SampleResult sampleResult) throws ReadException{
         ByteArrayOutputStream w = new ByteArrayOutputStream();
         try {
             byte[] buffer = new byte[4096];
             int x = 0;
+            boolean first = true;
             while ((x = is.read(buffer)) > -1) {
+                if (first) {
+                    sampleResult.latencyEnd();
+                    first = false;
+                }
                 w.write(buffer, 0, x);
                 if (useEolByte && (buffer[x - 1] == eolByte)) {
                     break;

Modified: jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java?rev=1807719&r1=1807718&r2=1807719&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java (original)
+++ jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java Fri
Sep  8 11:55:40 2017
@@ -400,7 +400,7 @@ public class TCPSampler extends Abstract
                 // TODO handle filenames
                 res.setSamplerData(req);
                 protocolHandler.write(os, req);
-                String in = protocolHandler.read(is);
+                String in = protocolHandler.read(is, res);
                 isSuccessful = setupSampleResult(res, in, null, protocolHandler);
             }
         } catch (ReadException ex) {

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1807719&r1=1807718&r2=1807719&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Fri Sep  8 11:55:40 2017
@@ -107,6 +107,7 @@ Incorporated feed back about unclear doc
     <li>JDBC Connection Configuration : Set "Validation Query" to <code>empty</code>
by default to use isValid method of JDBC driver</li>
     <li>JDBC Connection Configuration : Add a list for main databases validation queries
for "Validation Query" attribute</li>
     <li>JDBC Connection Configuration : Add a list for main databases JDBC driver class
name for "JDBC Driver class" attribute</li>
+    <li><bug>60156</bug> - TCPSampler : Latency is not measured for TCP
Sampler. Contributed by Ubik Load Pack (support at ubikloadpack.com)</li>
 </ul>
 
 <h3>Controllers</h3>



Mime
View raw message