hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1172302 - in /httpcomponents/httpclient/trunk: ./ httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ httpclient-cache/src/test/java/org/apache/http/impl/client/cache/ httpclient-cache/src/test/java/org/apache/http/impl/clien...
Date Sun, 18 Sep 2011 16:32:53 GMT
Author: olegk
Date: Sun Sep 18 16:32:53 2011
New Revision: 1172302

URL: http://svn.apache.org/viewvc?rev=1172302&view=rev
Log:
HTTPCLIENT-1116: ResponseCachingPolicy uses integers for sizes
Contributed by Greg Bowyer <gbowyer at fastmail.co.uk >

Modified:
    httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheConfig.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ResponseCachingPolicy.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/AbstractProtocolTest.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/DoNotTestProtocolRequirements.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestBasicHttpCache.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolDeviations.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestSizeLimitedResponseReader.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/ehcache/TestEhcacheProtocolRequirements.java

Modified: httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt?rev=1172302&r1=1172301&r2=1172302&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/trunk/RELEASE_NOTES.txt Sun Sep 18 16:32:53 2011
@@ -1,5 +1,8 @@
 Changes since 4.1.2
 
+* [HTTPCLIENT-1116] ResponseCachingPolicy uses integers for sizes
+  Contributed by Greg Bowyer <gbowyer at fastmail.co.uk >
+
 * [HTTPCLIENT-1123] Support for pluggable DNS resolvers.  
   Contributed by Alin Vasile <alinachegalati at yahoo dot com>
 

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java?rev=1172302&r1=1172301&r2=1172302&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java
Sun Sep 18 16:32:53 2011
@@ -52,7 +52,7 @@ class BasicHttpCache implements HttpCach
 
     private final CacheKeyGenerator uriExtractor;
     private final ResourceFactory resourceFactory;
-    private final int maxObjectSizeBytes;
+    private final long maxObjectSizeBytes;
     private final CacheEntryUpdater cacheEntryUpdater;
     private final CachedHttpResponseGenerator responseGenerator;
     private final CacheInvalidator cacheInvalidator;
@@ -64,7 +64,7 @@ class BasicHttpCache implements HttpCach
         this.resourceFactory = resourceFactory;
         this.uriExtractor = new CacheKeyGenerator();
         this.cacheEntryUpdater = new CacheEntryUpdater(resourceFactory);
-        this.maxObjectSizeBytes = config.getMaxObjectSizeBytes();
+        this.maxObjectSizeBytes = config.getMaxObjectSize();
         this.responseGenerator = new CachedHttpResponseGenerator();
         this.storage = storage;
         this.cacheInvalidator = new CacheInvalidator(this.uriExtractor, this.storage);

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheConfig.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheConfig.java?rev=1172302&r1=1172301&r2=1172302&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheConfig.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheConfig.java
Sun Sep 18 16:32:53 2011
@@ -131,7 +131,7 @@ public class CacheConfig {
      */
     public static final int DEFAULT_REVALIDATION_QUEUE_SIZE = 100;
 
-    private int maxObjectSizeBytes = DEFAULT_MAX_OBJECT_SIZE_BYTES;
+    private long maxObjectSize = DEFAULT_MAX_OBJECT_SIZE_BYTES;
     private int maxCacheEntries = DEFAULT_MAX_CACHE_ENTRIES;
     private int maxUpdateRetries = DEFAULT_MAX_UPDATE_RETRIES;
     private boolean heuristicCachingEnabled = false;
@@ -146,17 +146,47 @@ public class CacheConfig {
     /**
      * Returns the current maximum response body size that will be cached.
      * @return size in bytes
+     *
+     * @deprecated use {@link #getMaxObjectSize()}
      */
+    @Deprecated
     public int getMaxObjectSizeBytes() {
-        return maxObjectSizeBytes;
+        return maxObjectSize > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) maxObjectSize;
     }
 
     /**
      * Specifies the maximum response body size that will be eligible for caching.
      * @param maxObjectSizeBytes size in bytes
+     *
+     * @deprecated use {@link #setMaxObjectSize(long)}
      */
+    @Deprecated
     public void setMaxObjectSizeBytes(int maxObjectSizeBytes) {
-        this.maxObjectSizeBytes = maxObjectSizeBytes;
+        if (maxObjectSizeBytes > Integer.MAX_VALUE) {
+            this.maxObjectSize = Integer.MAX_VALUE;
+        } else {
+            this.maxObjectSize = maxObjectSizeBytes;
+        }
+    }
+
+    /**
+     * Returns the current maximum response body size that will be cached.
+     * @return size in bytes
+     *
+     * @since 4.2
+     */
+    public long getMaxObjectSize() {
+        return maxObjectSize;
+    }
+
+    /**
+     * Specifies the maximum response body size that will be eligible for caching.
+     * @param maxObjectSize size in bytes
+     *
+     * @since 4.2
+     */
+    public void setMaxObjectSize(long maxObjectSize) {
+        this.maxObjectSize = maxObjectSize;
     }
 
     /**

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java?rev=1172302&r1=1172301&r2=1172302&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java
Sun Sep 18 16:32:53 2011
@@ -130,7 +130,7 @@ public class CachingHttpClient implement
 
     private final ConditionalRequestBuilder conditionalRequestBuilder;
 
-    private final int maxObjectSizeBytes;
+    private final long maxObjectSizeBytes;
     private final boolean sharedCache;
 
     private final ResponseProtocolCompliance responseCompliance;
@@ -154,7 +154,7 @@ public class CachingHttpClient implement
         if (config == null) {
             throw new IllegalArgumentException("CacheConfig may not be null");
         }
-        this.maxObjectSizeBytes = config.getMaxObjectSizeBytes();
+        this.maxObjectSizeBytes = config.getMaxObjectSize();
         this.sharedCache = config.isSharedCache();
         this.backend = client;
         this.responseCache = cache;
@@ -268,7 +268,7 @@ public class CachingHttpClient implement
             ResponseProtocolCompliance responseCompliance,
             RequestProtocolCompliance requestCompliance) {
         CacheConfig config = new CacheConfig();
-        this.maxObjectSizeBytes = config.getMaxObjectSizeBytes();
+        this.maxObjectSizeBytes = config.getMaxObjectSize();
         this.sharedCache = config.isSharedCache();
         this.backend = backend;
         this.validityPolicy = validityPolicy;

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ResponseCachingPolicy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ResponseCachingPolicy.java?rev=1172302&r1=1172301&r2=1172302&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ResponseCachingPolicy.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ResponseCachingPolicy.java
Sun Sep 18 16:32:53 2011
@@ -51,7 +51,7 @@ import org.apache.http.protocol.HTTP;
 @Immutable
 class ResponseCachingPolicy {
 
-    private final int maxObjectSizeBytes;
+    private final long maxObjectSizeBytes;
     private final boolean sharedCache;
     private final Log log = LogFactory.getLog(getClass());
 
@@ -63,7 +63,7 @@ class ResponseCachingPolicy {
      * @param sharedCache whether to behave as a shared cache (true) or a
      * non-shared/private cache (false)
      */
-    public ResponseCachingPolicy(int maxObjectSizeBytes, boolean sharedCache) {
+    public ResponseCachingPolicy(long maxObjectSizeBytes, boolean sharedCache) {
         this.maxObjectSizeBytes = maxObjectSizeBytes;
         this.sharedCache = sharedCache;
     }

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/AbstractProtocolTest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/AbstractProtocolTest.java?rev=1172302&r1=1172301&r2=1172302&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/AbstractProtocolTest.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/AbstractProtocolTest.java
Sun Sep 18 16:32:53 2011
@@ -71,7 +71,7 @@ public abstract class AbstractProtocolTe
 
         params = new CacheConfig();
         params.setMaxCacheEntries(MAX_ENTRIES);
-        params.setMaxObjectSizeBytes(MAX_BYTES);
+        params.setMaxObjectSize(MAX_BYTES);
         cache = new BasicHttpCache(params);
         mockBackend = EasyMock.createMock(HttpClient.class);
         mockCache = EasyMock.createMock(HttpCache.class);

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/DoNotTestProtocolRequirements.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/DoNotTestProtocolRequirements.java?rev=1172302&r1=1172301&r2=1172302&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/DoNotTestProtocolRequirements.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/DoNotTestProtocolRequirements.java
Sun Sep 18 16:32:53 2011
@@ -75,7 +75,7 @@ public class DoNotTestProtocolRequiremen
 
         originResponse = make200Response();
         CacheConfig params = new CacheConfig();
-        params.setMaxObjectSizeBytes(MAX_BYTES);
+        params.setMaxObjectSize(MAX_BYTES);
         params.setMaxCacheEntries(MAX_ENTRIES);
 
         HttpCache cache = new BasicHttpCache(params);

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestBasicHttpCache.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestBasicHttpCache.java?rev=1172302&r1=1172301&r2=1172302&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestBasicHttpCache.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestBasicHttpCache.java
Sun Sep 18 16:32:53 2011
@@ -234,7 +234,7 @@ public class TestBasicHttpCache {
         Date responseReceived = new Date(now.getTime() - 1 * 1000L);
 
         HttpResponse originResponse = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
"OK");
-        originResponse.setEntity(HttpTestUtils.makeBody(CacheConfig.DEFAULT_MAX_OBJECT_SIZE_BYTES
+ 1));
+        originResponse.setEntity(HttpTestUtils.makeBody((int) CacheConfig.DEFAULT_MAX_OBJECT_SIZE_BYTES
+ 1));
         originResponse.setHeader("Cache-Control","public, max-age=3600");
         originResponse.setHeader("Date", DateUtils.formatDate(responseGenerated));
         originResponse.setHeader("ETag", "\"etag\"");
@@ -256,7 +256,7 @@ public class TestBasicHttpCache {
         Date responseReceived = new Date(now.getTime() - 1 * 1000L);
 
         HttpResponse originResponse = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
"OK");
-        originResponse.setEntity(HttpTestUtils.makeBody(CacheConfig.DEFAULT_MAX_OBJECT_SIZE_BYTES
- 1));
+        originResponse.setEntity(HttpTestUtils.makeBody((int) CacheConfig.DEFAULT_MAX_OBJECT_SIZE_BYTES
- 1));
         originResponse.setHeader("Cache-Control","public, max-age=3600");
         originResponse.setHeader("Date", DateUtils.formatDate(responseGenerated));
         originResponse.setHeader("ETag", "\"etag\"");

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolDeviations.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolDeviations.java?rev=1172302&r1=1172301&r2=1172302&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolDeviations.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolDeviations.java
Sun Sep 18 16:32:53 2011
@@ -94,7 +94,7 @@ public class TestProtocolDeviations {
         originResponse = make200Response();
 
         CacheConfig params = new CacheConfig();
-        params.setMaxObjectSizeBytes(MAX_BYTES);
+        params.setMaxObjectSize(MAX_BYTES);
         params.setMaxCacheEntries(MAX_ENTRIES);
 
         HttpCache cache = new BasicHttpCache(params);

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestSizeLimitedResponseReader.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestSizeLimitedResponseReader.java?rev=1172302&r1=1172301&r2=1172302&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestSizeLimitedResponseReader.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestSizeLimitedResponseReader.java
Sun Sep 18 16:32:53 2011
@@ -118,7 +118,7 @@ public class TestSizeLimitedResponseRead
     @Test
     public void testTooLargeEntityHasOriginalContentTypes() throws Exception {
         HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
"OK");
-        StringEntity entity = new StringEntity("large entity content", "text/plain", "utf-8");
+        StringEntity entity = new StringEntity("large entity content");
         response.setEntity(entity);
 
         impl = new SizeLimitedResponseReader(new HeapResourceFactory(), MAX_SIZE, request,
response);

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/ehcache/TestEhcacheProtocolRequirements.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/ehcache/TestEhcacheProtocolRequirements.java?rev=1172302&r1=1172301&r2=1172302&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/ehcache/TestEhcacheProtocolRequirements.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/ehcache/TestEhcacheProtocolRequirements.java
Sun Sep 18 16:32:53 2011
@@ -64,7 +64,7 @@ public class TestEhcacheProtocolRequirem
     public void setUp() {
         super.setUp();
         params = new CacheConfig();
-        params.setMaxObjectSizeBytes(MAX_BYTES);
+        params.setMaxObjectSize(MAX_BYTES);
 
         if (CACHE_MANAGER.cacheExists(TEST_EHCACHE_NAME)){
             CACHE_MANAGER.removeCache(TEST_EHCACHE_NAME);



Mime
View raw message