HTTPCLIENT-1324: CachingHttpClientBuilder.build() fails when asynchronousWorkersMax=0
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1447763 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
584309b3e8
commit
a54e7031b1
|
@ -143,7 +143,7 @@ public class CachingExec implements ClientExecChain {
|
|||
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 ClientExecChain {
|
|||
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 ClientExecChain {
|
|||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -103,9 +103,12 @@ public class CachingHttpClientBuilder extends HttpClientBuilder {
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
41
httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingHttpClientBuilder.java
vendored
Executable file
41
httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingHttpClientBuilder.java
vendored
Executable file
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -307,7 +307,7 @@ public class TestRFC5861Compliance extends AbstractProtocolTest {
|
|||
.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 extends AbstractProtocolTest {
|
|||
.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));
|
||||
|
|
Loading…
Reference in New Issue