You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by se...@apache.org on 2014/02/26 23:47:42 UTC

svn commit: r1572319 - in /jmeter/trunk: bin/jmeter.properties src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java xdocs/changes.xml

Author: sebb
Date: Wed Feb 26 22:47:42 2014
New Revision: 1572319

URL: http://svn.apache.org/r1572319
Log:
HTTP Cache Manager should not cache PUT/POST etc.
Bugzilla Id: 56162

Modified:
    jmeter/trunk/bin/jmeter.properties
    jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/bin/jmeter.properties
URL: http://svn.apache.org/viewvc/jmeter/trunk/bin/jmeter.properties?rev=1572319&r1=1572318&r2=1572319&view=diff
==============================================================================
--- jmeter/trunk/bin/jmeter.properties (original)
+++ jmeter/trunk/bin/jmeter.properties Wed Feb 26 22:47:42 2014
@@ -386,6 +386,14 @@ log_level.jorphan=INFO
 #httpclient3.retrycount=0
 
 #---------------------------------------------------------------------------
+# HTTP Cache Manager configuration
+#---------------------------------------------------------------------------
+#
+# Space or comma separated list of methods that can be cached
+cacheable_methods=GET
+# N.B. This property is currently a temporary solution for Bug 56162
+
+#---------------------------------------------------------------------------
 # Results file configuration
 #---------------------------------------------------------------------------
 

Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java?rev=1572319&r1=1572318&r2=1572319&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java (original)
+++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java Wed Feb 26 22:47:42 2014
@@ -24,6 +24,7 @@ import java.io.Serializable;
 import java.net.HttpURLConnection;
 import java.net.URL;
 import java.net.URLConnection;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.Date;
 import java.util.Map;
@@ -38,11 +39,12 @@ import org.apache.http.HttpResponse;
 import org.apache.http.client.methods.HttpRequestBase;
 import org.apache.jmeter.config.ConfigTestElement;
 import org.apache.jmeter.engine.event.LoopIterationEvent;
+import org.apache.jmeter.protocol.http.sampler.HTTPSampleResult;
 import org.apache.jmeter.protocol.http.util.HTTPConstants;
-import org.apache.jmeter.samplers.SampleResult;
 import org.apache.jmeter.testelement.TestIterationListener;
 import org.apache.jmeter.testelement.TestStateListener;
 import org.apache.jmeter.testelement.property.BooleanProperty;
+import org.apache.jmeter.util.JMeterUtils;
 import org.apache.jorphan.logging.LoggingManager;
 import org.apache.log.Logger;
 
@@ -57,6 +59,12 @@ public class CacheManager extends Config
 
     private static final Logger log = LoggingManager.getLoggerForClass();
 
+    private static final String[] CACHEABLE_METHODS = JMeterUtils.getPropDefault("cacheable_methods", "GET").split("[ ,]");
+
+    static {
+        log.info("Will only cache the following methods: "+Arrays.toString(CACHEABLE_METHODS));
+    }
+
     //+ JMX attributes, do not change values
     public static final String CLEAR = "clearEachIteration"; // $NON-NLS-1$
     public static final String USE_EXPIRES = "useExpires"; // $NON-NLS-1$
@@ -113,7 +121,7 @@ public class CacheManager extends Config
      * @param conn connection
      * @param res result
      */
-    public void saveDetails(URLConnection conn, SampleResult res){
+    public void saveDetails(URLConnection conn, HTTPSampleResult res){
         if (isCacheable(res)){
             String lastModified = conn.getHeaderField(HTTPConstants.LAST_MODIFIED);
             String expires = conn.getHeaderField(HTTPConstants.EXPIRES);
@@ -131,7 +139,7 @@ public class CacheManager extends Config
      * @param method
      * @param res result
      */
-    public void saveDetails(HttpMethod method, SampleResult res) throws URIException{
+    public void saveDetails(HttpMethod method, HTTPSampleResult res) throws URIException{
         if (isCacheable(res)){
             String lastModified = getHeader(method ,HTTPConstants.LAST_MODIFIED);
             String expires = getHeader(method ,HTTPConstants.EXPIRES);
@@ -149,7 +157,7 @@ public class CacheManager extends Config
      * @param method
      * @param res result
      */
-    public void saveDetails(HttpResponse method, SampleResult res) {
+    public void saveDetails(HttpResponse method, HTTPSampleResult res) {
         if (isCacheable(res)){
             String lastModified = getHeader(method ,HTTPConstants.LAST_MODIFIED);
             String expires = getHeader(method ,HTTPConstants.EXPIRES);
@@ -249,12 +257,23 @@ public class CacheManager extends Config
 
     /*
      * Is the sample result OK to cache?
-     * i.e is it in the 2xx range?
+     * i.e is it in the 2xx range, and is it a cacheable method?
      */
-    private boolean isCacheable(SampleResult res){
+    private boolean isCacheable(HTTPSampleResult res){
         final String responseCode = res.getResponseCode();
-        return "200".compareTo(responseCode) <= 0  // $NON-NLS-1$
-            && "299".compareTo(responseCode) >= 0; // $NON-NLS-1$
+        return isCacheableMethod(res)
+            && "200".compareTo(responseCode) <= 0  // $NON-NLS-1$
+            && "299".compareTo(responseCode) >= 0;  // $NON-NLS-1$
+    }
+
+    private boolean isCacheableMethod(HTTPSampleResult res) {
+        final String resMethod = res.getHTTPMethod();
+        for(String method : CACHEABLE_METHODS) {
+            if (method.equalsIgnoreCase(resMethod)) {
+                return true;
+            }
+        }
+        return false;
     }
 
     /**

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1572319&r1=1572318&r2=1572319&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Wed Feb 26 22:47:42 2014
@@ -142,6 +142,7 @@ A workaround is to use a Java 7 update 4
 
 <h3>Timers, Assertions, Config, Pre- &amp; Post-Processors</h3>
 <ul>
+<li><bugzilla>56162</bugzilla> -  HTTP Cache Manager should not cache PUT/POST etc.</li>
 </ul>
 
 <h3>Functions</h3>



Re: svn commit: r1572319 - in /jmeter/trunk: bin/jmeter.properties src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java xdocs/changes.xml

Posted by sebb <se...@gmail.com>.
On 27 February 2014 17:30, Rainer Jung <ra...@kippdata.de> wrote:
> On 26.02.2014 23:47, sebb@apache.org wrote:
>> Author: sebb
>> Date: Wed Feb 26 22:47:42 2014
>> New Revision: 1572319
>>
>> URL: http://svn.apache.org/r1572319
>> Log:
>> HTTP Cache Manager should not cache PUT/POST etc.
>> Bugzilla Id: 56162
>>
>> Modified:
>>     jmeter/trunk/bin/jmeter.properties
>>     jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java
>>     jmeter/trunk/xdocs/changes.xml
>>
>> Modified: jmeter/trunk/bin/jmeter.properties
>> URL: http://svn.apache.org/viewvc/jmeter/trunk/bin/jmeter.properties?rev=1572319&r1=1572318&r2=1572319&view=diff
>> ==============================================================================
>> --- jmeter/trunk/bin/jmeter.properties (original)
>> +++ jmeter/trunk/bin/jmeter.properties Wed Feb 26 22:47:42 2014
>> @@ -386,6 +386,14 @@ log_level.jorphan=INFO
>>  #httpclient3.retrycount=0
>>
>>  #---------------------------------------------------------------------------
>> +# HTTP Cache Manager configuration
>> +#---------------------------------------------------------------------------
>> +#
>> +# Space or comma separated list of methods that can be cached
>> +cacheable_methods=GET
>> +# N.B. This property is currently a temporary solution for Bug 56162
>
> Is HEAD in this context handled like GET,

No, only methods listed are cached.

> or should we also add it to the default?

Not sure that's a good idea.

HEAD is often used to probe a connection, also the respose to a HEAD
is not very large.

AFAICT, the HC cache implementation only caches GET.

> Regards,
>
> Rainer
>

Re: svn commit: r1572319 - in /jmeter/trunk: bin/jmeter.properties src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java xdocs/changes.xml

Posted by Rainer Jung <ra...@kippdata.de>.
On 26.02.2014 23:47, sebb@apache.org wrote:
> Author: sebb
> Date: Wed Feb 26 22:47:42 2014
> New Revision: 1572319
> 
> URL: http://svn.apache.org/r1572319
> Log:
> HTTP Cache Manager should not cache PUT/POST etc.
> Bugzilla Id: 56162
> 
> Modified:
>     jmeter/trunk/bin/jmeter.properties
>     jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java
>     jmeter/trunk/xdocs/changes.xml
> 
> Modified: jmeter/trunk/bin/jmeter.properties
> URL: http://svn.apache.org/viewvc/jmeter/trunk/bin/jmeter.properties?rev=1572319&r1=1572318&r2=1572319&view=diff
> ==============================================================================
> --- jmeter/trunk/bin/jmeter.properties (original)
> +++ jmeter/trunk/bin/jmeter.properties Wed Feb 26 22:47:42 2014
> @@ -386,6 +386,14 @@ log_level.jorphan=INFO
>  #httpclient3.retrycount=0
>  
>  #---------------------------------------------------------------------------
> +# HTTP Cache Manager configuration
> +#---------------------------------------------------------------------------
> +#
> +# Space or comma separated list of methods that can be cached
> +cacheable_methods=GET
> +# N.B. This property is currently a temporary solution for Bug 56162

Is HEAD in this context handled like GET, or should we also add it to
the default?

Regards,

Rainer