Author: sebb
Date: Thu Nov 17 15:40:54 2005
New Revision: 345368

URL: http://svn.apache.org/viewcvs?rev=345368&view=rev
Log:
Slow connection emulation for HttpClient

Modified:
    jakarta/jmeter/branches/rel-2-1/bin/jmeter.properties
    
jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java
    jakarta/jmeter/branches/rel-2-1/xdocs/changes.xml

Modified: jakarta/jmeter/branches/rel-2-1/bin/jmeter.properties
URL: 
http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/bin/jmeter.properties?rev=345368&r1=345367&r2=345368&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/bin/jmeter.properties (original)
+++ jakarta/jmeter/branches/rel-2-1/bin/jmeter.properties Thu Nov 17 15:40:54 
2005
@@ -174,6 +174,10 @@
 # Set the http version (defaults to 1.1)
 #httpclient.version=1.0
 
+# Define characters per second > 0 to emulate slow connections
+#httpclient.socket.http.cps=0
+#httpclient.socket.https.cps=0
+
 # Sample logging levels for HttpClient
 # Note that full category names are used, i.e. must include the org.apache.
 # Info level produces no output:

Modified: 
jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java
URL: 
http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java?rev=345368&r1=345367&r2=345368&view=diff
==============================================================================
--- 
jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java
 (original)
+++ 
jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java
 Thu Nov 17 15:40:54 2005
@@ -33,8 +33,10 @@
 import org.apache.commons.httpclient.DefaultMethodRetryHandler;
 import org.apache.commons.httpclient.HostConfiguration;
 import org.apache.commons.httpclient.HttpConnection;
+import org.apache.commons.httpclient.HttpConstants;
 import org.apache.commons.httpclient.HttpMethod;
 import org.apache.commons.httpclient.HttpMethodBase;
+import org.apache.commons.httpclient.HttpRecoverableException;
 import org.apache.commons.httpclient.HttpState;
 import org.apache.commons.httpclient.NTCredentials;
 import org.apache.commons.httpclient.methods.EntityEnclosingMethod;
@@ -48,6 +50,7 @@
 import org.apache.jmeter.protocol.http.control.CookieManager;
 import org.apache.jmeter.protocol.http.control.HeaderManager;
 import org.apache.jmeter.protocol.http.control.Cookie;
+import org.apache.jmeter.protocol.http.util.SlowHttpClientSocketFactory;
 
 import org.apache.jmeter.testelement.property.CollectionProperty;
 import org.apache.jmeter.testelement.property.PropertyIterator;
@@ -63,19 +66,42 @@
  * 
  */
 public class HTTPSampler2 extends HTTPSamplerBase {
-       transient private static Logger log = 
LoggingManager.getLoggerForClass();
+    private static final Logger log = LoggingManager.getLoggerForClass();
+
+    private static final String PROTOCOL_HTTP = "http"; // $NON-NLS-1$
 
     /*
      * Connection is re-used within the thread if possible
      */
        transient private static ThreadLocal httpClients = null;
 
+    private static boolean basicAuth 
+    = JMeterUtils.getPropDefault("httpsampler2.basicauth", false); // 
$NON-NLS-1$
+
        static {
                // Set the default to Avalon Logkit, if not already defined:
                if (System.getProperty("org.apache.commons.logging.Log") == 
null) { // $NON-NLS-1$
                        System.setProperty("org.apache.commons.logging.Log" // 
$NON-NLS-1$
                     , "org.apache.commons.logging.impl.LogKitLogger"); // 
$NON-NLS-1$
                }
+        log.info("httpsampler2.basicauth=" + basicAuth); // $NON-NLS-1$
+        
+        int cps =
+            JMeterUtils.getPropDefault("httpclient.socket.http.cps", 0); // 
$NON-NLS-1$        
+
+        if (cps > 0) {
+            log.info("Setting up HTTP SlowProtocol, cps="+cps);
+            Protocol.registerProtocol(PROTOCOL_HTTP, 
+                    new Protocol(PROTOCOL_HTTP,new 
SlowHttpClientSocketFactory(cps),DEFAULT_HTTP_PORT));
+        }
+        cps =
+            JMeterUtils.getPropDefault("httpclient.socket.https.cps", 0); // 
$NON-NLS-1$        
+
+        if (cps > 0) {
+            log.info("Setting up HTTPS SlowProtocol, cps="+cps);
+            Protocol.registerProtocol(PROTOCOL_HTTPS, 
+                    new Protocol(PROTOCOL_HTTPS,new 
SlowHttpClientSocketFactory(cps),DEFAULT_HTTPS_PORT));
+        }
        }
 
        /*
@@ -86,13 +112,6 @@
 
        private transient HttpState httpState = null;
 
-       private static boolean basicAuth 
-        = JMeterUtils.getPropDefault("httpsampler2.basicauth", false); // 
$NON-NLS-1$
-
-       static {
-               log.info("httpsampler2.basicauth=" + basicAuth); // $NON-NLS-1$
-       }
-
        /**
         * Constructor for the HTTPSampler2 object.
         */
@@ -157,14 +176,14 @@
                }
        }
 
+    // Convert \ to \\
        private String encode(String value) {
                StringBuffer newValue = new StringBuffer();
-               char[] chars = value.toCharArray();
-               for (int i = 0; i < chars.length; i++) {
-                       if (chars[i] == '\\') { // $NON-NLS-1$
+               for (int i = 0; i < value.length(); i++) {
+                       if (value.charAt(i) == '\\') { // $NON-NLS-1$
                                newValue.append("\\\\"); // $NON-NLS-1$
                        } else {
-                               newValue.append(chars[i]);
+                               newValue.append(value.charAt(i));
                        }
                }
                return newValue.toString();
@@ -195,7 +214,7 @@
 
                String schema = uri.getScheme();
                if ((schema == null) || (schema.equals(""))) { // $NON-NLS-1$
-                       schema = "http"; // $NON-NLS-1$
+                       schema = PROTOCOL_HTTP;
                }
                Protocol protocol = Protocol.getProtocol(schema);
 

Modified: jakarta/jmeter/branches/rel-2-1/xdocs/changes.xml
URL: 
http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/xdocs/changes.xml?rev=345368&r1=345367&r2=345368&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/xdocs/changes.xml (original)
+++ jakarta/jmeter/branches/rel-2-1/xdocs/changes.xml Thu Nov 17 15:40:54 2005
@@ -35,6 +35,7 @@
 <li>Simpler JMX file format (2.2)</li>
 <li>BeanshellSampler code can update ResponseData directly</li>
 <li>Bug 37490 - Allow UDV as delay in Duration Assertion</li>
+<li>Slow connection emulation for HttpClient</li>
 </ul>
 
 <h4>Bug fixes:</h4>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to