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