jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1624849 - in /jmeter/trunk: bin/jmeter.properties src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPAbstractImpl.java xdocs/changes.xml
Date Sun, 14 Sep 2014 13:58:54 GMT
Author: pmouawad
Date: Sun Sep 14 13:58:53 2014
New Revision: 1624849

URL: http://svn.apache.org/r1624849
Log:
Bug 54778 - HTTP Sampler should not return 204 when resource is found in Cache, make it configurable
with new property cache_manager.cached_resource_mode 

Implemented as per dev mailing list discussion http://mail-archives.apache.org/mod_mbox/jmeter-dev/201409.mbox/%3CCAH9fUpZGrOhLZawoir4WrUFLiuJg3ZrRVJ4mpVxxS%2BahmcKQeQ%40mail.gmail.com%3E

Bugzilla Id: 54778

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

Modified: jmeter/trunk/bin/jmeter.properties
URL: http://svn.apache.org/viewvc/jmeter/trunk/bin/jmeter.properties?rev=1624849&r1=1624848&r2=1624849&view=diff
==============================================================================
--- jmeter/trunk/bin/jmeter.properties (original)
+++ jmeter/trunk/bin/jmeter.properties Sun Sep 14 13:58:53 2014
@@ -415,11 +415,22 @@ log_level.jorphan=INFO
 #cacheable_methods=GET
 # N.B. This property is currently a temporary solution for Bug 56162
 
-# Since 2.12, JMeter does not create anymore a Sample Result for a resource 
-# found in cache which is inline with what browser do
-# If you need to revert to previous behaviour, you can set this property
-# to true
-#cache_manager.return_204_for_cached_resource=false
+# Since 2.12, JMeter does not create anymore a Sample Result with 204 response 
+# code for a resource found in cache which is inline with what browser do.
+#cache_manager.cached_resource_mode=RETURN_NO_SAMPLE
+
+# You can choose between 3 modes:
+# RETURN_NO_SAMPLE (default)
+# RETURN_200_CACHE
+# RETURN_CUSTOM_STATUS
+
+# Those mode have the following behaviours:
+# RETURN_NO_SAMPLE : this mode returns no Sample Result, it has no additional configuration
+# RETURN_200_CACHE : this mode will return Sample Result with response code to 200 and response
message to "(ex cache)", you can modify response message by setting 
+# RETURN_200_CACHE.message=(ex cache)
+# RETURN_CUSTOM_STATUS : This mode lets you select what response code and message you want
to return, if you use this mode you need to set those properties
+# RETURN_CUSTOM_STATUS.code=
+# RETURN_CUSTOM_STATUS.message=
 
 #---------------------------------------------------------------------------
 # Results file configuration

Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPAbstractImpl.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPAbstractImpl.java?rev=1624849&r1=1624848&r2=1624849&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPAbstractImpl.java
(original)
+++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPAbstractImpl.java
Sun Sep 14 13:58:53 2014
@@ -46,12 +46,43 @@ import org.apache.jmeter.util.JMeterUtil
  * Base class for HTTP implementations used by the HTTPSamplerProxy sampler.
  */
 public abstract class HTTPAbstractImpl implements Interruptible, HTTPConstantsInterface {
+    private static enum CachedResourceMode {
+        RETURN_200_CACHE("RETURN_200_CACHE"),
+        RETURN_NO_SAMPLE("RETURN_NO_SAMPLE"),
+        RETURN_CUSTOM_STATUS("RETURN_CUSTOM_STATUS");
+        
+        private String name;
+
+        CachedResourceMode(String name) {
+            this.name = name;
+        }
+    }
 
     /**
      * If true create a SampleResult with emply content and 204 response code 
      */
-    private static final boolean RETURN_204_FOR_INCACHE_RESOURCE = 
-            JMeterUtils.getPropDefault("cache_manager.return_204_for_cached_resource", false);
+    private static final CachedResourceMode CACHED_RESOURCE_MODE = 
+            CachedResourceMode.valueOf(
+                    JMeterUtils.getPropDefault("cache_manager.cached_resource_mode", //$NON-NLS-1$
+                    CachedResourceMode.RETURN_NO_SAMPLE.toString()));
+    
+    /**
+     * SampleResult message when resource was in cache and mode is RETURN_200_CACHE
+     */
+    private static final String RETURN_200_CACHE_MESSAGE =
+            JMeterUtils.getPropDefault("RETURN_200_CACHE.message","(ex cache)");//$NON-NLS-1$
$NON-NLS-2$
+
+    /**
+     * Custom response code for cached resource
+     */
+    private static final String RETURN_CUSTOM_STATUS_CODE = 
+            JMeterUtils.getProperty("RETURN_CUSTOM_STATUS.code");//$NON-NLS-1$
+
+    /**
+     * Custom response message for cached resource
+     */
+    private static final String RETURN_CUSTOM_STATUS_MESSAGE = 
+            JMeterUtils.getProperty("RETURN_CUSTOM_STATUS.message"); //$NON-NLS-1$
 
     protected final HTTPSamplerBase testElement;
 
@@ -335,14 +366,24 @@ public abstract class HTTPAbstractImpl i
      * @return HTTPSampleResult
      */
     protected HTTPSampleResult updateSampleResultForResourceInCache(HTTPSampleResult res)
{
-        if(!RETURN_204_FOR_INCACHE_RESOURCE) {
-            // We don't want to issue a SampleResult
-            // see https://issues.apache.org/bugzilla/show_bug.cgi?id=54778
-            return null;
-        }        
-        res.sampleEnd();
-        res.setResponseNoContent();
-        res.setSuccessful(true);
-        return res;
+        switch (CACHED_RESOURCE_MODE) {
+            case RETURN_NO_SAMPLE:
+                return null;
+            case RETURN_200_CACHE:
+                res.sampleEnd();
+                res.setResponseCodeOK();
+                res.setResponseMessage(RETURN_200_CACHE_MESSAGE);
+                res.setSuccessful(true);
+                return res;
+            case RETURN_CUSTOM_STATUS:
+                res.sampleEnd();
+                res.setResponseCode(RETURN_CUSTOM_STATUS_CODE);
+                res.setResponseMessage(RETURN_CUSTOM_STATUS_MESSAGE);
+                res.setSuccessful(true);
+                return res;
+            default:
+                // Cannot happen
+                throw new IllegalStateException("Unknown CACHED_RESOURCE_MODE");
+        }
     }
 }

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1624849&r1=1624848&r2=1624849&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Sun Sep 14 13:58:53 2014
@@ -117,7 +117,7 @@ A workaround is to use a Java 7 update 4
 <ul>
 <li>Since JMeter 2.12, Mail Reader Sampler will show 1 for number of samples instead
of number of messages retrieved, see <bugzilla>56539</bugzilla></li>
 <li>Since JMeter 2.12, when using Cache Manager, if resource is found in cache no SampleResult
will be created, in previous version a SampleResult with empty content and 204 return code
was returned, see <bugzilla>54778</bugzilla>.
-To revert to old behaviour, set property "cache_manager.return_204_for_cached_resource" to
true.</li>
+You can choose between different ways to handle this case, see cache_manager.cached_resource_mode
in jmeter.properties.</li>
 <li>Since JMeter 2.12, Log Viewer will no more clear logs when closed and will have
logs available even if closed. See <bugzilla>56920</bugzilla>. Read <a href="./usermanual/hints_and_tips.html#debug_logging">Hints
and Tips &gt; Enabling Debug logging</a>
 for details on configuring this component.</li>
 </ul>
@@ -135,7 +135,7 @@ for details on configuring this componen
 <li><bugzilla>56231</bugzilla> - Move redirect location processing from
HC3/HC4 samplers to HTTPSamplerBase#followRedirects()</li>
 <li><bugzilla>56207</bugzilla> - URLs get encoded on redirects in HC3.1
&amp; HC4 samplers</li>
 <li><bugzilla>56303</bugzilla> - The width of target controller's combo
list should be set to the current panel size, not on label size of the controllers</li>
-<li><bugzilla>54778</bugzilla> - HTTP Sampler should not return 204 when
resource is found in Cache</li>
+<li><bugzilla>54778</bugzilla> - HTTP Sampler should not return 204 when
resource is found in Cache, make it configurable with new property cache_manager.cached_resource_mode</li>

 </ul>
 
 <h3>Other Samplers</h3>



Mime
View raw message