hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f.@apache.org
Subject svn commit: r1447763 - in /httpcomponents/httpclient/trunk/httpclient-cache/src: main/java/org/apache/http/impl/client/cache/ test/java/org/apache/http/impl/client/cache/
Date Tue, 19 Feb 2013 15:23:16 GMT
Author: fx
Date: Tue Feb 19 15:23:16 2013
New Revision: 1447763

URL: http://svn.apache.org/r1447763
Log:
HTTPCLIENT-1324: CachingHttpClientBuilder.build() fails when asynchronousWorkersMax=0

Added:
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingHttpClientBuilder.java
  (with props)
Modified:
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingExec.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClientBuilder.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingExec.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestRFC5861Compliance.java

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingExec.java?rev=1447763&r1=1447762&r2=1447763&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingExec.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingExec.java
Tue Feb 19 15:23:16 2013
@@ -143,7 +143,7 @@ public class CachingExec implements Clie
         this.responseCachingPolicy = new ResponseCachingPolicy(
                 this.cacheConfig.getMaxObjectSize(), this.cacheConfig.isSharedCache(),
                 this.cacheConfig.isNeverCacheHTTP10ResponsesWithQuery());
-        this.asynchRevalidator = asynchRevalidator != null ? asynchRevalidator : makeAsynchronousValidator(config);
+        this.asynchRevalidator = asynchRevalidator;
     }
 
     public CachingExec(
@@ -169,7 +169,8 @@ public class CachingExec implements Clie
             final ConditionalRequestBuilder conditionalRequestBuilder,
             final ResponseProtocolCompliance responseCompliance,
             final RequestProtocolCompliance requestCompliance,
-            final CacheConfig config) {
+            final CacheConfig config,
+            final AsynchronousValidator asynchRevalidator) {
         this.cacheConfig = config != null ? config : CacheConfig.DEFAULT;
         this.backend = backend;
         this.responseCache = responseCache;
@@ -181,15 +182,7 @@ public class CachingExec implements Clie
         this.conditionalRequestBuilder = conditionalRequestBuilder;
         this.responseCompliance = responseCompliance;
         this.requestCompliance = requestCompliance;
-        this.asynchRevalidator = makeAsynchronousValidator(config);
-    }
-
-    private AsynchronousValidator makeAsynchronousValidator(
-            final CacheConfig config) {
-        if (config.getAsynchronousWorkersMax() > 0) {
-            return new AsynchronousValidator(config);
-        }
-        return null;
+        this.asynchRevalidator = asynchRevalidator;
     }
 
     /**

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClientBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClientBuilder.java?rev=1447763&r1=1447762&r2=1447763&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClientBuilder.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClientBuilder.java
Tue Feb 19 15:23:16 2013
@@ -103,9 +103,12 @@ public class CachingHttpClientBuilder ex
     }
 
     private AsynchronousValidator createAsynchronousRevalidator(final CacheConfig config)
{
-        final AsynchronousValidator revalidator = new AsynchronousValidator(config);
-        addCloseable(revalidator);
-        return revalidator;
+        if (config.getAsynchronousWorkersMax() > 0) {
+            final AsynchronousValidator revalidator = new AsynchronousValidator(config);
+            addCloseable(revalidator);
+            return revalidator;
+        }
+        return null;
     }
 
 }

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingExec.java?rev=1447763&r1=1447762&r2=1447763&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingExec.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingExec.java
Tue Feb 19 15:23:16 2013
@@ -120,6 +120,7 @@ public class TestCachingExec {
     private ResponseProtocolCompliance mockResponseProtocolCompliance;
     private RequestProtocolCompliance mockRequestProtocolCompliance;
     private CacheConfig config;
+    private AsynchronousValidator asyncValidator;
 
     private Date requestDate;
     private Date responseDate;
@@ -151,6 +152,7 @@ public class TestCachingExec {
         mockRequestProtocolCompliance = createNiceMock(RequestProtocolCompliance.class);
         mockStorage = createNiceMock(HttpCacheStorage.class);
         config = CacheConfig.DEFAULT;
+        asyncValidator = new AsynchronousValidator(config);
 
         requestDate = new Date(System.currentTimeMillis() - 1000);
         responseDate = new Date();
@@ -171,7 +173,8 @@ public class TestCachingExec {
                 mockConditionalRequestBuilder,
                 mockResponseProtocolCompliance,
                 mockRequestProtocolCompliance,
-                config);
+                config,
+                asyncValidator);
     }
 
     private void replayMocks() {
@@ -1916,7 +1919,8 @@ public class TestCachingExec {
                 mockConditionalRequestBuilder,
                 mockResponseProtocolCompliance,
                 mockRequestProtocolCompliance,
-                config).addMockedMethods(methods).createNiceMock();
+                config,
+                asyncValidator).addMockedMethods(methods).createNiceMock();
     }
 
 }

Added: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingHttpClientBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingHttpClientBuilder.java?rev=1447763&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingHttpClientBuilder.java
(added)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingHttpClientBuilder.java
Tue Feb 19 15:23:16 2013
@@ -0,0 +1,41 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.http.impl.client.cache;
+
+import org.junit.Test;
+
+public class TestCachingHttpClientBuilder {
+
+    @Test
+    public void testAsynchronousWorkersMax0() throws Exception {
+        CacheConfig cacheConfig = CacheConfig.custom().setAsynchronousWorkersMax(0).build();
+        // Asynchronous validation should be disabled but we should not get an
+        // Exception
+        CachingHttpClientBuilder.create().setCacheConfig(cacheConfig).build();
+    }
+
+}

Propchange: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingHttpClientBuilder.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestRFC5861Compliance.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestRFC5861Compliance.java?rev=1447763&r1=1447762&r2=1447763&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestRFC5861Compliance.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestRFC5861Compliance.java
Tue Feb 19 15:23:16 2013
@@ -307,7 +307,7 @@ public class TestRFC5861Compliance exten
                 .setAsynchronousWorkersMax(1)
                 .build();
 
-        impl = new CachingExec(mockBackend, cache, config);
+        impl = new CachingExec(mockBackend, cache, config, new AsynchronousValidator(config));
 
         final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(
                 new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
@@ -351,7 +351,7 @@ public class TestRFC5861Compliance exten
                 .setAsynchronousWorkersMax(1)
                 .setSharedCache(false)
                 .build();
-        impl = new CachingExec(mockBackend, cache, config);
+        impl = new CachingExec(mockBackend, cache, config, new AsynchronousValidator(config));
 
         final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(
                 new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));



Mime
View raw message