Author: pmouawad
Date: Tue Mar  8 20:50:34 2016
New Revision: 1734154

URL: http://svn.apache.org/viewvc?rev=1734154&view=rev
Log:
Bug 59146 - MeasuringConnectionManager is not Thread Safe (nightly before 3.0)
Bugzilla Id: 59146

Modified:
    
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
    
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/MeasuringConnectionManager.java
    jmeter/trunk/xdocs/changes.xml

Modified: 
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java?rev=1734154&r1=1734153&r2=1734154&view=diff
==============================================================================
--- 
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
 (original)
+++ 
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
 Tue Mar  8 20:50:34 2016
@@ -202,6 +202,8 @@ public class HTTPHC4Impl extends HTTPHCA
     private static final HttpParams DEFAULT_HTTP_PARAMS;
 
     private static final String USER_TOKEN = "__jmeter.USER_TOKEN__"; 
//$NON-NLS-1$
+    
+    static final String SAMPLER_RESULT_TOKEN = "__jmeter.SAMPLER_RESULT__"; 
//$NON-NLS-1$
 
     static {
         log.info("HTTP request retry count = "+RETRY_COUNT);
@@ -312,6 +314,8 @@ public class HTTPHC4Impl extends HTTPHCA
         try {
             currentRequest = httpRequest;
             handleMethod(method, res, httpRequest, localContext);
+            // store the SampleResult in LocalContext to compute connect time
+            localContext.setAttribute(SAMPLER_RESULT_TOKEN, res);
             // perform the sample
             HttpResponse httpResponse = 
                     executeRequest(httpClient, httpRequest, localContext, url);
@@ -766,9 +770,6 @@ public class HTTPHC4Impl extends HTTPHCA
             }
         }
 
-        MeasuringConnectionManager connectionManager = 
(MeasuringConnectionManager) httpClient.getConnectionManager();
-        connectionManager.setSample(res);
-
         // TODO - should this be done when the client is created?
         // If so, then the details need to be added as part of HttpClientKey
         setConnectionAuthorization(httpClient, url, getAuthManager(), key);

Modified: 
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/MeasuringConnectionManager.java
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/MeasuringConnectionManager.java?rev=1734154&r1=1734153&r2=1734154&view=diff
==============================================================================
--- 
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/MeasuringConnectionManager.java
 (original)
+++ 
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/MeasuringConnectionManager.java
 Tue Mar  8 20:50:34 2016
@@ -50,9 +50,6 @@ import org.apache.jmeter.samplers.Sample
  */
 public class MeasuringConnectionManager extends PoolingClientConnectionManager 
{
 
-    private MeasuringConnectionRequest measuredConnection;
-    private SampleResult sample;
-
     public MeasuringConnectionManager(SchemeRegistry schemeRegistry, 
DnsResolver resolver) {
         super(schemeRegistry, resolver);
     }
@@ -60,8 +57,8 @@ public class MeasuringConnectionManager
     @Override
     public ClientConnectionRequest requestConnection(final HttpRoute route, 
final Object state) {
         ClientConnectionRequest res = super.requestConnection(route, state);
-        this.measuredConnection = new MeasuringConnectionRequest(res, 
this.sample);
-        return this.measuredConnection;
+        MeasuringConnectionRequest measuredConnection = new 
MeasuringConnectionRequest(res);
+        return measuredConnection;
     }
     
     /**
@@ -75,26 +72,20 @@ public class MeasuringConnectionManager
         return new JMeterClientConnectionOperator(schreg);
     }
 
-    public void setSample(SampleResult sample) {
-        this.sample = sample;
-    }
 
     /**
      * An adapter class to pass {@link SampleResult} into {@link 
MeasuredConnection}
      */
     private static class MeasuringConnectionRequest implements 
ClientConnectionRequest {
         private final ClientConnectionRequest handler;
-        private final SampleResult sample;
-
-        public MeasuringConnectionRequest(ClientConnectionRequest res, 
SampleResult sample) {
+        public MeasuringConnectionRequest(ClientConnectionRequest res) {
             handler = res;
-            this.sample = sample;
         }
 
         @Override
         public ManagedClientConnection getConnection(long timeout, TimeUnit 
tunit) throws InterruptedException, ConnectionPoolTimeoutException {
             ManagedClientConnection res = handler.getConnection(timeout, 
tunit);
-            return new MeasuredConnection(res, this.sample);
+            return new MeasuredConnection(res);
         }
 
         @Override
@@ -109,11 +100,9 @@ public class MeasuringConnectionManager
      */
     private static class MeasuredConnection implements ManagedClientConnection 
{
         private final ManagedClientConnection handler;
-        private final SampleResult sample;
 
-        public MeasuredConnection(ManagedClientConnection res, SampleResult 
sample) {
+        public MeasuredConnection(ManagedClientConnection res) {
             handler = res;
-            this.sample = sample;
         }
 
         @Override
@@ -121,6 +110,8 @@ public class MeasuringConnectionManager
             try {
                 handler.open(route, context, params);
             } finally {
+                SampleResult sample = 
+                        
(SampleResult)context.getAttribute(HTTPHC4Impl.SAMPLER_RESULT_TOKEN);
                 if (sample != null) {
                     sample.connectEnd();
                 }

Modified: jmeter/trunk/xdocs/changes.xml
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1734154&r1=1734153&r2=1734154&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Tue Mar  8 20:50:34 2016
@@ -144,6 +144,7 @@ Summary
     <li><bug>59116</bug>Add the possibility to setup a prefix to sampler name 
recorded by proxy. Partly based on a patch by Antonio Gomes Rodrigues (ra0077 
at gmail.com)</li>
     <li><bug>59129</bug>HTTP Request : Simplify GUI with simple/advanced 
Tabs</li>
     <li><bug>59033</bug>Parallel Download : Rework Parser classes hierarchy to 
allow pluging parsers for different mime types</li>
+    <li><bug>59146</bug>MeasuringConnectionManager is not Thread Safe (nightly 
before 3.0)</li>
 </ul>
 
 <h3>Other samplers</h3>


Reply via email to