HTTPCLIENT-1384: clean up of HttpCacheInvalidator and HttpAsyncCacheInvalidator APIs

This commit is contained in:
Oleg Kalnichevski 2018-01-02 13:41:31 +01:00
parent c78032d638
commit eb1cab46e6
18 changed files with 120 additions and 131 deletions

View File

@ -46,8 +46,7 @@ import org.apache.hc.core5.http.HttpResponse;
public interface HttpAsyncCacheInvalidator {
/**
* Remove cache entries from the cache that are no longer fresh or have been
* invalidated in some way.
* Flush {@link HttpCacheEntry}s invalidated by the given request.
*
* @param host backend host
* @param request request message
@ -55,7 +54,7 @@ public interface HttpAsyncCacheInvalidator {
* @param cacheStorage internal cache storage
* @param callback result callback
*/
Cancellable flushInvalidatedCacheEntries(
Cancellable flushCacheEntriesInvalidatedByRequest(
HttpHost host,
HttpRequest request,
Resolver<URI, String> cacheKeyResolver,
@ -63,8 +62,7 @@ public interface HttpAsyncCacheInvalidator {
FutureCallback<Boolean> callback);
/**
* Flushes entries that were invalidated by the given response received for
* the given host/request pair.
* Flush {@link HttpCacheEntry}s invalidated by the given message exchange.
*
* @param host backend host
* @param request request message
@ -73,7 +71,7 @@ public interface HttpAsyncCacheInvalidator {
* @param cacheStorage internal cache storage
* @param callback result callback
*/
Cancellable flushInvalidatedCacheEntries(
Cancellable flushCacheEntriesInvalidatedByExchange(
HttpHost host,
HttpRequest request,
HttpResponse response,

View File

@ -44,8 +44,7 @@ import org.apache.hc.core5.http.HttpResponse;
public interface HttpCacheInvalidator {
/**
* Remove cache entries from the cache that are no longer fresh or have been
* invalidated in some way.
* Flush {@link HttpCacheEntry}s invalidated by the given request.
*
* @param host backend host
* @param request request message
@ -54,15 +53,14 @@ public interface HttpCacheInvalidator {
*
* @since 5.0
*/
void flushInvalidatedCacheEntries(
void flushCacheEntriesInvalidatedByRequest(
HttpHost host,
HttpRequest request,
Resolver<URI, String> cacheKeyResolver,
HttpCacheStorage cacheStorage);
/**
* Flushes entries that were invalidated by the given response received for
* the given host/request pair.
* Flush {@link HttpCacheEntry}s invalidated by the given message exchange.
*
* @param host backend host
* @param request request message
@ -72,7 +70,7 @@ public interface HttpCacheInvalidator {
*
* @since 5.0
*/
void flushInvalidatedCacheEntries(
void flushCacheEntriesInvalidatedByExchange(
HttpHost host,
HttpRequest request,
HttpResponse response,

View File

@ -212,7 +212,7 @@ public class AsyncCachingExec extends CachingExecBase implements AsyncExecChainH
if (!cacheableRequestPolicy.isServableFromCache(request)) {
log.debug("Request is not servable from cache");
future.setDependency(responseCache.flushInvalidatedCacheEntriesFor(target, request, new FutureCallback<Boolean>() {
future.setDependency(responseCache.flushCacheEntriesInvalidatedByRequest(target, request, new FutureCallback<Boolean>() {
@Override
public void completed(final Boolean result) {
@ -438,7 +438,7 @@ public class AsyncCachingExec extends CachingExecBase implements AsyncExecChainH
final HttpResponse backendResponse,
final EntityDetails entityDetails) throws HttpException, IOException {
responseCompliance.ensureProtocolCompliance(scope.originalRequest, request, backendResponse);
responseCache.flushInvalidatedCacheEntriesFor(target, request, backendResponse, new FutureCallback<Boolean>() {
responseCache.flushCacheEntriesInvalidatedByExchange(target, request, backendResponse, new FutureCallback<Boolean>() {
@Override
public void completed(final Boolean result) {

View File

@ -124,28 +124,28 @@ class BasicHttpAsyncCache implements HttpAsyncCache {
}
@Override
public Cancellable flushInvalidatedCacheEntriesFor(
public Cancellable flushCacheEntriesInvalidatedByRequest(
final HttpHost host, final HttpRequest request, final FutureCallback<Boolean> callback) {
if (log.isDebugEnabled()) {
log.debug("Flush cache entries invalidated by request: " + host + "; " + new RequestLine(request));
}
return cacheInvalidator.flushCacheEntriesInvalidatedByRequest(host, request, cacheKeyGenerator, storage, callback);
}
@Override
public Cancellable flushCacheEntriesInvalidatedByExchange(
final HttpHost host, final HttpRequest request, final HttpResponse response, final FutureCallback<Boolean> callback) {
if (log.isDebugEnabled()) {
log.debug("Flush cache entries: " + host + "; " + new RequestLine(request) + " " + new StatusLine(response));
log.debug("Flush cache entries invalidated by exchange: " + host + "; " + new RequestLine(request) + " -> " + new StatusLine(response));
}
if (!StandardMethods.isSafe(request.getMethod())) {
return cacheInvalidator.flushInvalidatedCacheEntries(host, request, response, cacheKeyGenerator, storage, callback);
return cacheInvalidator.flushCacheEntriesInvalidatedByExchange(host, request, response, cacheKeyGenerator, storage, callback);
} else {
callback.completed(Boolean.TRUE);
return Operations.nonCancellable();
}
}
@Override
public Cancellable flushInvalidatedCacheEntriesFor(
final HttpHost host, final HttpRequest request, final FutureCallback<Boolean> callback) {
if (log.isDebugEnabled()) {
log.debug("Flush invalidated cache entries: " + host + "; " + new RequestLine(request));
}
return cacheInvalidator.flushInvalidatedCacheEntries(host, request, cacheKeyGenerator, storage, callback);
}
Cancellable storeInCache(
final String cacheKey,
final HttpHost host,

View File

@ -106,21 +106,21 @@ class BasicHttpCache implements HttpCache {
}
@Override
public void flushInvalidatedCacheEntriesFor(final HttpHost host, final HttpRequest request, final HttpResponse response) {
public void flushCacheEntriesInvalidatedByRequest(final HttpHost host, final HttpRequest request) {
if (log.isDebugEnabled()) {
log.debug("Flush cache entries: " + host + "; " + new RequestLine(request) + " " + new StatusLine(response));
}
if (!StandardMethods.isSafe(request.getMethod())) {
cacheInvalidator.flushInvalidatedCacheEntries(host, request, response, cacheKeyGenerator, storage);
log.debug("Flush cache entries invalidated by request: " + host + "; " + new RequestLine(request));
}
cacheInvalidator.flushCacheEntriesInvalidatedByRequest(host, request, cacheKeyGenerator, storage);
}
@Override
public void flushInvalidatedCacheEntriesFor(final HttpHost host, final HttpRequest request) {
public void flushCacheEntriesInvalidatedByExchange(final HttpHost host, final HttpRequest request, final HttpResponse response) {
if (log.isDebugEnabled()) {
log.debug("Flush invalidated cache entries: " + host + "; " + new RequestLine(request));
log.debug("Flush cache entries invalidated by exchange: " + host + "; " + new RequestLine(request) + " -> " + new StatusLine(response));
}
if (!StandardMethods.isSafe(request.getMethod())) {
cacheInvalidator.flushCacheEntriesInvalidatedByExchange(host, request, response, cacheKeyGenerator, storage);
}
cacheInvalidator.flushInvalidatedCacheEntries(host, request, cacheKeyGenerator, storage);
}
void storeInCache(

View File

@ -66,7 +66,9 @@ class CacheableRequestPolicy {
}
if (!method.equals(HeaderConstants.GET_METHOD) && !method.equals(HeaderConstants.HEAD_METHOD)) {
if (log.isDebugEnabled()) {
log.debug(method + " request is not serveable from cache");
}
return false;
}

View File

@ -175,7 +175,7 @@ public class CachingExec extends CachingExecBase implements ExecChainHandler {
if (!cacheableRequestPolicy.isServableFromCache(request)) {
log.debug("Request is not servable from cache");
responseCache.flushInvalidatedCacheEntriesFor(target, request);
responseCache.flushCacheEntriesInvalidatedByRequest(target, request);
return callBackend(target, request, scope, chain);
}
@ -340,7 +340,7 @@ public class CachingExec extends CachingExecBase implements ExecChainHandler {
responseCompliance.ensureProtocolCompliance(scope.originalRequest, request, backendResponse);
responseCache.flushInvalidatedCacheEntriesFor(target, request, backendResponse);
responseCache.flushCacheEntriesInvalidatedByExchange(target, request, backendResponse);
final boolean cacheable = responseCachingPolicy.isResponseCacheable(request, backendResponse);
if (cacheable) {
storeRequestIfModifiedSinceFor304Response(request, backendResponse);

View File

@ -93,7 +93,7 @@ public class DefaultAsyncCacheInvalidator extends CacheInvalidatorBase implement
}
@Override
public Cancellable flushInvalidatedCacheEntries(
public Cancellable flushCacheEntriesInvalidatedByRequest(
final HttpHost host,
final HttpRequest request,
final Resolver<URI, String> cacheKeyResolver,
@ -180,7 +180,7 @@ public class DefaultAsyncCacheInvalidator extends CacheInvalidatorBase implement
}
@Override
public Cancellable flushInvalidatedCacheEntries(
public Cancellable flushCacheEntriesInvalidatedByExchange(
final HttpHost host,
final HttpRequest request,
final HttpResponse response,

View File

@ -80,7 +80,7 @@ public class DefaultCacheInvalidator extends CacheInvalidatorBase implements Htt
}
@Override
public void flushInvalidatedCacheEntries(
public void flushCacheEntriesInvalidatedByRequest(
final HttpHost host,
final HttpRequest request,
final Resolver<URI, String> cacheKeyResolver,
@ -149,7 +149,7 @@ public class DefaultCacheInvalidator extends CacheInvalidatorBase implements Htt
}
@Override
public void flushInvalidatedCacheEntries(
public void flushCacheEntriesInvalidatedByExchange(
final HttpHost host,
final HttpRequest request,
final HttpResponse response,

View File

@ -51,15 +51,15 @@ interface HttpAsyncCache {
HttpHost host, HttpRequest request, FutureCallback<Boolean> callback);
/**
* Clear invalidated matching {@link HttpCacheEntry}s
* Flush {@link HttpCacheEntry}s invalidated by the given request
*/
Cancellable flushInvalidatedCacheEntriesFor(
Cancellable flushCacheEntriesInvalidatedByRequest(
HttpHost host, HttpRequest request, FutureCallback<Boolean> callback);
/** Clear any entries that may be invalidated by the given response to
* a particular request.
/**
* Flush {@link HttpCacheEntry}s invalidated by the given message exchange.
*/
Cancellable flushInvalidatedCacheEntriesFor(
Cancellable flushCacheEntriesInvalidatedByExchange(
HttpHost host, HttpRequest request, HttpResponse response, FutureCallback<Boolean> callback);
/**

View File

@ -46,14 +46,14 @@ interface HttpCache {
void flushCacheEntriesFor(HttpHost host, HttpRequest request);
/**
* Clear invalidated matching {@link HttpCacheEntry}s
* Flush {@link HttpCacheEntry}s invalidated by the given request
*/
void flushInvalidatedCacheEntriesFor(HttpHost host, HttpRequest request);
void flushCacheEntriesInvalidatedByRequest(HttpHost host, HttpRequest request);
/** Clear any entries that may be invalidated by the given response to
* a particular request.
/**
* Flush {@link HttpCacheEntry}s invalidated by the given message exchange.
*/
void flushInvalidatedCacheEntriesFor(HttpHost host, HttpRequest request, HttpResponse response);
void flushCacheEntriesInvalidatedByExchange(HttpHost host, HttpRequest request, HttpResponse response);
/**
* Retrieve matching {@link HttpCacheEntry} from the cache if it exists.

View File

@ -161,10 +161,10 @@ public abstract class AbstractProtocolTest {
mockCache.flushCacheEntriesFor(EasyMock.isA(HttpHost.class), EasyMock.isA(HttpRequest.class));
EasyMock.expectLastCall().anyTimes();
mockCache.flushInvalidatedCacheEntriesFor(EasyMock.isA(HttpHost.class), EasyMock.isA(HttpRequest.class));
mockCache.flushCacheEntriesInvalidatedByRequest(EasyMock.isA(HttpHost.class), EasyMock.isA(HttpRequest.class));
EasyMock.expectLastCall().anyTimes();
mockCache.flushInvalidatedCacheEntriesFor(EasyMock.isA(HttpHost.class), EasyMock.isA(HttpRequest.class), EasyMock.isA(HttpResponse.class));
mockCache.flushCacheEntriesInvalidatedByExchange(EasyMock.isA(HttpHost.class), EasyMock.isA(HttpRequest.class), EasyMock.isA(HttpResponse.class));
EasyMock.expectLastCall().anyTimes();
}

View File

@ -140,7 +140,7 @@ public class TestBasicHttpCache {
backing.map.put(key, entry);
impl.flushInvalidatedCacheEntriesFor(host, req, resp);
impl.flushCacheEntriesInvalidatedByExchange(host, req, resp);
assertNull(backing.map.get(key));
}
@ -161,7 +161,7 @@ public class TestBasicHttpCache {
backing.map.put(key, entry);
impl.flushInvalidatedCacheEntriesFor(host, req, resp);
impl.flushCacheEntriesInvalidatedByExchange(host, req, resp);
assertEquals(entry, backing.map.get(key));
}

View File

@ -419,9 +419,7 @@ public class TestCachingExec extends TestCachingExecChain {
}
private void cacheInvalidatorWasCalled() throws IOException {
mockCache.flushInvalidatedCacheEntriesFor(
(HttpHost)anyObject(),
(HttpRequest)anyObject());
mockCache.flushCacheEntriesInvalidatedByRequest((HttpHost)anyObject(), (HttpRequest)anyObject());
}
private void getCurrentDateReturns(final Date date) {

View File

@ -1632,8 +1632,7 @@ public abstract class TestCachingExecChain {
}
private void cacheInvalidatorWasCalled() throws IOException {
mockCache
.flushInvalidatedCacheEntriesFor((HttpHost) anyObject(), (HttpRequest) anyObject());
mockCache.flushCacheEntriesInvalidatedByRequest((HttpHost) anyObject(), (HttpRequest) anyObject());
}
protected void cacheEntryValidatable(final boolean b) {
@ -1685,8 +1684,8 @@ public abstract class TestCachingExecChain {
}
protected void doesNotFlushCache() throws IOException {
mockCache.flushInvalidatedCacheEntriesFor(isA(HttpHost.class), isA(HttpRequest.class));
EasyMock.expectLastCall().andThrow(new AssertionError("flushInvalidatedCacheEntriesFor should not have been called")).anyTimes();
mockCache.flushCacheEntriesInvalidatedByRequest(isA(HttpHost.class), isA(HttpRequest.class));
EasyMock.expectLastCall().andThrow(new AssertionError("flushCacheEntriesInvalidByResponse should not have been called")).anyTimes();
}
}

View File

@ -106,7 +106,7 @@ public class TestDefaultAsyncCacheInvalidator {
cacheEntryHasVariantMap(variantMap);
cacheReturnsEntryForUri(key, mockEntry);
impl.flushInvalidatedCacheEntries(host, request, cacheKeyResolver, mockStorage, operationCallback);
impl.flushCacheEntriesInvalidatedByRequest(host, request, cacheKeyResolver, mockStorage, operationCallback);
verify(mockEntry).getVariantMap();
verify(mockStorage).getEntry(Mockito.eq(key), Mockito.<FutureCallback<HttpCacheEntry>>any());
@ -127,7 +127,7 @@ public class TestDefaultAsyncCacheInvalidator {
cacheReturnsEntryForUri(key, mockEntry);
impl.flushInvalidatedCacheEntries(host, request, cacheKeyResolver, mockStorage, operationCallback);
impl.flushCacheEntriesInvalidatedByRequest(host, request, cacheKeyResolver, mockStorage, operationCallback);
verify(mockEntry).getVariantMap();
verify(mockStorage).getEntry(Mockito.eq(key), Mockito.<FutureCallback<HttpCacheEntry>>any());
@ -149,7 +149,7 @@ public class TestDefaultAsyncCacheInvalidator {
cacheReturnsEntryForUri(key, mockEntry);
impl.flushInvalidatedCacheEntries(host, request, cacheKeyResolver, mockStorage, operationCallback);
impl.flushCacheEntriesInvalidatedByRequest(host, request, cacheKeyResolver, mockStorage, operationCallback);
verify(mockEntry).getVariantMap();
verify(mockStorage).getEntry(Mockito.eq(key), Mockito.<FutureCallback<HttpCacheEntry>>any());
@ -171,7 +171,7 @@ public class TestDefaultAsyncCacheInvalidator {
cacheReturnsEntryForUri(key, mockEntry);
impl.flushInvalidatedCacheEntries(host, request, cacheKeyResolver, mockStorage, operationCallback);
impl.flushCacheEntriesInvalidatedByRequest(host, request, cacheKeyResolver, mockStorage, operationCallback);
verify(mockEntry).getVariantMap();
verify(mockStorage).getEntry(Mockito.eq(key), Mockito.<FutureCallback<HttpCacheEntry>>any());
@ -193,7 +193,7 @@ public class TestDefaultAsyncCacheInvalidator {
cacheReturnsEntryForUri(key, mockEntry);
impl.flushInvalidatedCacheEntries(host, request, cacheKeyResolver, mockStorage, operationCallback);
impl.flushCacheEntriesInvalidatedByRequest(host, request, cacheKeyResolver, mockStorage, operationCallback);
verify(mockEntry).getVariantMap();
verify(mockStorage).getEntry(Mockito.eq(key), Mockito.<FutureCallback<HttpCacheEntry>>any());
@ -203,7 +203,7 @@ public class TestDefaultAsyncCacheInvalidator {
@Test
public void testDoesNotInvalidateGETRequest() throws Exception {
final HttpRequest request = new BasicHttpRequest("GET","/");
impl.flushInvalidatedCacheEntries(host, request, cacheKeyResolver, mockStorage, operationCallback);
impl.flushCacheEntriesInvalidatedByRequest(host, request, cacheKeyResolver, mockStorage, operationCallback);
verify(mockStorage).getEntry(Mockito.eq("http://foo.example.com:80/"), Mockito.<FutureCallback<HttpCacheEntry>>any());
verifyNoMoreInteractions(mockStorage);
@ -212,7 +212,7 @@ public class TestDefaultAsyncCacheInvalidator {
@Test
public void testDoesNotInvalidateHEADRequest() throws Exception {
final HttpRequest request = new BasicHttpRequest("HEAD","/");
impl.flushInvalidatedCacheEntries(host, request, cacheKeyResolver, mockStorage, operationCallback);
impl.flushCacheEntriesInvalidatedByRequest(host, request, cacheKeyResolver, mockStorage, operationCallback);
verify(mockStorage).getEntry(Mockito.eq("http://foo.example.com:80/"), Mockito.<FutureCallback<HttpCacheEntry>>any());
verifyNoMoreInteractions(mockStorage);
@ -228,7 +228,7 @@ public class TestDefaultAsyncCacheInvalidator {
cacheEntryHasVariantMap(new HashMap<String, String>());
cacheReturnsEntryForUri(key, mockEntry);
impl.flushInvalidatedCacheEntries(host, request, cacheKeyResolver, mockStorage, operationCallback);
impl.flushCacheEntriesInvalidatedByRequest(host, request, cacheKeyResolver, mockStorage, operationCallback);
verify(mockEntry).getRequestMethod();
verify(mockEntry).getVariantMap();
@ -249,7 +249,7 @@ public class TestDefaultAsyncCacheInvalidator {
cacheEntryHasVariantMap(variants);
cacheReturnsEntryForUri(key, mockEntry);
impl.flushInvalidatedCacheEntries(host, request, cacheKeyResolver, mockStorage, operationCallback);
impl.flushCacheEntriesInvalidatedByRequest(host, request, cacheKeyResolver, mockStorage, operationCallback);
verify(mockEntry).getRequestMethod();
verify(mockEntry).getVariantMap();
@ -266,7 +266,7 @@ public class TestDefaultAsyncCacheInvalidator {
cacheReturnsEntryForUri(key, mockEntry);
impl.flushInvalidatedCacheEntries(host, request, cacheKeyResolver, mockStorage, operationCallback);
impl.flushCacheEntriesInvalidatedByRequest(host, request, cacheKeyResolver, mockStorage, operationCallback);
verify(mockStorage).getEntry(Mockito.eq(key), Mockito.<FutureCallback<HttpCacheEntry>>any());
verifyNoMoreInteractions(mockStorage);
@ -280,7 +280,7 @@ public class TestDefaultAsyncCacheInvalidator {
cacheReturnsEntryForUri(key, mockEntry);
impl.flushInvalidatedCacheEntries(host, request, cacheKeyResolver, mockStorage, operationCallback);
impl.flushCacheEntriesInvalidatedByRequest(host, request, cacheKeyResolver, mockStorage, operationCallback);
verify(mockStorage).getEntry(Mockito.eq(key), Mockito.<FutureCallback<HttpCacheEntry>>any());
verifyNoMoreInteractions(mockStorage);
@ -295,7 +295,7 @@ public class TestDefaultAsyncCacheInvalidator {
cacheEntryisForMethod("GET");
cacheReturnsEntryForUri(key, mockEntry);
impl.flushInvalidatedCacheEntries(host, request, cacheKeyResolver, mockStorage, operationCallback);
impl.flushCacheEntriesInvalidatedByRequest(host, request, cacheKeyResolver, mockStorage, operationCallback);
verify(mockEntry).getRequestMethod();
verify(mockStorage).getEntry(Mockito.eq(key), Mockito.<FutureCallback<HttpCacheEntry>>any());
@ -307,7 +307,7 @@ public class TestDefaultAsyncCacheInvalidator {
final HttpRequest request = new BasicHttpRequest("GET","/");
request.setHeader("Cache-Control","no-cache");
impl.flushInvalidatedCacheEntries(host, request, cacheKeyResolver, mockStorage, operationCallback);
impl.flushCacheEntriesInvalidatedByRequest(host, request, cacheKeyResolver, mockStorage, operationCallback);
verify(mockStorage).getEntry(Mockito.eq("http://foo.example.com:80/"), Mockito.<FutureCallback<HttpCacheEntry>>any());
verifyNoMoreInteractions(mockStorage);
@ -318,7 +318,7 @@ public class TestDefaultAsyncCacheInvalidator {
final HttpRequest request = new BasicHttpRequest("GET","/");
request.setHeader("Pragma","no-cache");
impl.flushInvalidatedCacheEntries(host, request, cacheKeyResolver, mockStorage, operationCallback);
impl.flushCacheEntriesInvalidatedByRequest(host, request, cacheKeyResolver, mockStorage, operationCallback);
verify(mockStorage).getEntry(Mockito.eq("http://foo.example.com:80/"), Mockito.<FutureCallback<HttpCacheEntry>>any());
verifyNoMoreInteractions(mockStorage);
@ -335,7 +335,7 @@ public class TestDefaultAsyncCacheInvalidator {
cacheReturnsEntryForUri(key, mockEntry);
cacheEntryHasVariantMap(mapOfURIs);
impl.flushInvalidatedCacheEntries(host, request, cacheKeyResolver, mockStorage, operationCallback);
impl.flushCacheEntriesInvalidatedByRequest(host, request, cacheKeyResolver, mockStorage, operationCallback);
verify(mockStorage).getEntry(Mockito.eq(key), Mockito.<FutureCallback<HttpCacheEntry>>any());
verify(mockEntry).getVariantMap();
@ -347,7 +347,7 @@ public class TestDefaultAsyncCacheInvalidator {
public void doesNotFlushForResponsesWithoutContentLocation() throws Exception {
final HttpRequest request = new BasicHttpRequest("POST","/");
final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_OK);
impl.flushInvalidatedCacheEntries(host, request, response, cacheKeyResolver, mockStorage, operationCallback);
impl.flushCacheEntriesInvalidatedByExchange(host, request, response, cacheKeyResolver, mockStorage, operationCallback);
verifyNoMoreInteractions(mockStorage);
}
@ -368,7 +368,7 @@ public class TestDefaultAsyncCacheInvalidator {
cacheReturnsEntryForUri(key, entry);
impl.flushInvalidatedCacheEntries(host, request, response, cacheKeyResolver, mockStorage, operationCallback);
impl.flushCacheEntriesInvalidatedByExchange(host, request, response, cacheKeyResolver, mockStorage, operationCallback);
verify(mockStorage).getEntry(Mockito.eq(key), Mockito.<FutureCallback<HttpCacheEntry>>any());
verify(mockStorage).removeEntry(Mockito.eq(key), Mockito.<FutureCallback<Boolean>>any());
@ -390,7 +390,7 @@ public class TestDefaultAsyncCacheInvalidator {
cacheReturnsEntryForUri(key, entry);
impl.flushInvalidatedCacheEntries(host, request, response, cacheKeyResolver, mockStorage, operationCallback);
impl.flushCacheEntriesInvalidatedByExchange(host, request, response, cacheKeyResolver, mockStorage, operationCallback);
verify(mockStorage).getEntry(Mockito.eq(key), Mockito.<FutureCallback<HttpCacheEntry>>any());
verify(mockStorage).removeEntry(Mockito.eq(key), Mockito.<FutureCallback<Boolean>>any());
@ -405,7 +405,7 @@ public class TestDefaultAsyncCacheInvalidator {
final String key = "http://foo.example.com:80/bar";
response.setHeader("Content-Location", key);
impl.flushInvalidatedCacheEntries(host, request, response, cacheKeyResolver, mockStorage, operationCallback);
impl.flushCacheEntriesInvalidatedByExchange(host, request, response, cacheKeyResolver, mockStorage, operationCallback);
verifyNoMoreInteractions(mockStorage);
}
@ -426,7 +426,7 @@ public class TestDefaultAsyncCacheInvalidator {
cacheReturnsEntryForUri(key, entry);
impl.flushInvalidatedCacheEntries(host, request, response, cacheKeyResolver, mockStorage, operationCallback);
impl.flushCacheEntriesInvalidatedByExchange(host, request, response, cacheKeyResolver, mockStorage, operationCallback);
verify(mockStorage).getEntry(Mockito.eq(key), Mockito.<FutureCallback<HttpCacheEntry>>any());
verify(mockStorage).removeEntry(Mockito.eq(key), Mockito.<FutureCallback<Boolean>>any());
@ -448,7 +448,7 @@ public class TestDefaultAsyncCacheInvalidator {
cacheReturnsEntryForUri(key, entry);
impl.flushInvalidatedCacheEntries(host, request, response, cacheKeyResolver, mockStorage, operationCallback);
impl.flushCacheEntriesInvalidatedByExchange(host, request, response, cacheKeyResolver, mockStorage, operationCallback);
verify(mockStorage).getEntry(Mockito.eq(key), Mockito.<FutureCallback<HttpCacheEntry>>any());
verify(mockStorage).removeEntry(Mockito.eq(key), Mockito.<FutureCallback<Boolean>>any());
@ -470,7 +470,7 @@ public class TestDefaultAsyncCacheInvalidator {
cacheReturnsEntryForUri(key, entry);
impl.flushInvalidatedCacheEntries(host, request, response, cacheKeyResolver, mockStorage, operationCallback);
impl.flushCacheEntriesInvalidatedByExchange(host, request, response, cacheKeyResolver, mockStorage, operationCallback);
verifyNoMoreInteractions(mockStorage);
}
@ -490,7 +490,7 @@ public class TestDefaultAsyncCacheInvalidator {
});
cacheReturnsEntryForUri(key, entry);
impl.flushInvalidatedCacheEntries(host, request, response, cacheKeyResolver, mockStorage, operationCallback);
impl.flushCacheEntriesInvalidatedByExchange(host, request, response, cacheKeyResolver, mockStorage, operationCallback);
verify(mockStorage).getEntry(Mockito.eq(key), Mockito.<FutureCallback<HttpCacheEntry>>any());
verifyNoMoreInteractions(mockStorage);
@ -512,7 +512,7 @@ public class TestDefaultAsyncCacheInvalidator {
cacheReturnsEntryForUri(key, entry);
impl.flushInvalidatedCacheEntries(host, request, response, cacheKeyResolver, mockStorage, operationCallback);
impl.flushCacheEntriesInvalidatedByExchange(host, request, response, cacheKeyResolver, mockStorage, operationCallback);
verify(mockStorage).getEntry(Mockito.eq(key), Mockito.<FutureCallback<HttpCacheEntry>>any());
verifyNoMoreInteractions(mockStorage);
@ -529,7 +529,7 @@ public class TestDefaultAsyncCacheInvalidator {
cacheReturnsEntryForUri(key, null);
impl.flushInvalidatedCacheEntries(host, request, response, cacheKeyResolver, mockStorage, operationCallback);
impl.flushCacheEntriesInvalidatedByExchange(host, request, response, cacheKeyResolver, mockStorage, operationCallback);
verify(mockStorage).getEntry(Mockito.eq(key), Mockito.<FutureCallback<HttpCacheEntry>>any());
verifyNoMoreInteractions(mockStorage);
@ -551,7 +551,7 @@ public class TestDefaultAsyncCacheInvalidator {
cacheReturnsEntryForUri(key, entry);
impl.flushInvalidatedCacheEntries(host, request, response, cacheKeyResolver, mockStorage, operationCallback);
impl.flushCacheEntriesInvalidatedByExchange(host, request, response, cacheKeyResolver, mockStorage, operationCallback);
verify(mockStorage).getEntry(Mockito.eq(key), Mockito.<FutureCallback<HttpCacheEntry>>any());
verifyNoMoreInteractions(mockStorage);
@ -572,7 +572,7 @@ public class TestDefaultAsyncCacheInvalidator {
cacheReturnsEntryForUri(key, entry);
impl.flushInvalidatedCacheEntries(host, request, response, cacheKeyResolver, mockStorage, operationCallback);
impl.flushCacheEntriesInvalidatedByExchange(host, request, response, cacheKeyResolver, mockStorage, operationCallback);
verify(mockStorage).getEntry(Mockito.eq(key), Mockito.<FutureCallback<HttpCacheEntry>>any());
verifyNoMoreInteractions(mockStorage);
@ -594,7 +594,7 @@ public class TestDefaultAsyncCacheInvalidator {
cacheReturnsEntryForUri(key, entry);
impl.flushInvalidatedCacheEntries(host, request, response, cacheKeyResolver, mockStorage, operationCallback);
impl.flushCacheEntriesInvalidatedByExchange(host, request, response, cacheKeyResolver, mockStorage, operationCallback);
verify(mockStorage).getEntry(Mockito.eq(key), Mockito.<FutureCallback<HttpCacheEntry>>any());
verify(mockStorage).removeEntry(Mockito.eq(key), Mockito.<FutureCallback<Boolean>>any());
@ -616,7 +616,7 @@ public class TestDefaultAsyncCacheInvalidator {
cacheReturnsEntryForUri(key, entry);
impl.flushInvalidatedCacheEntries(host, request, response, cacheKeyResolver, mockStorage, operationCallback);
impl.flushCacheEntriesInvalidatedByExchange(host, request, response, cacheKeyResolver, mockStorage, operationCallback);
verify(mockStorage).getEntry(Mockito.eq(key), Mockito.<FutureCallback<HttpCacheEntry>>any());
verify(mockStorage).removeEntry(Mockito.eq(key), Mockito.<FutureCallback<Boolean>>any());
@ -639,7 +639,7 @@ public class TestDefaultAsyncCacheInvalidator {
cacheReturnsEntryForUri(key, entry);
impl.flushInvalidatedCacheEntries(host, request, response, cacheKeyResolver, mockStorage, operationCallback);
impl.flushCacheEntriesInvalidatedByExchange(host, request, response, cacheKeyResolver, mockStorage, operationCallback);
verify(mockStorage).getEntry(Mockito.eq(key), Mockito.<FutureCallback<HttpCacheEntry>>any());
verify(mockStorage).removeEntry(Mockito.eq(key), Mockito.<FutureCallback<Boolean>>any());
@ -662,7 +662,7 @@ public class TestDefaultAsyncCacheInvalidator {
cacheReturnsEntryForUri(key, entry);
impl.flushInvalidatedCacheEntries(host, request, response, cacheKeyResolver, mockStorage, operationCallback);
impl.flushCacheEntriesInvalidatedByExchange(host, request, response, cacheKeyResolver, mockStorage, operationCallback);
verify(mockStorage).getEntry(Mockito.eq(key), Mockito.<FutureCallback<HttpCacheEntry>>any());
verify(mockStorage).removeEntry(Mockito.eq(key), Mockito.<FutureCallback<Boolean>>any());

View File

@ -38,7 +38,6 @@ import java.util.Map;
import org.apache.hc.client5.http.cache.HttpCacheEntry;
import org.apache.hc.client5.http.cache.HttpCacheStorage;
import org.apache.hc.client5.http.cache.ResourceIOException;
import org.apache.hc.client5.http.utils.DateUtils;
import org.apache.hc.core5.function.Resolver;
import org.apache.hc.core5.http.Header;
@ -102,7 +101,7 @@ public class TestDefaultCacheInvalidator {
cacheReturnsEntryForUri(key);
impl.flushInvalidatedCacheEntries(host, request, cacheKeyResolver, mockStorage);
impl.flushCacheEntriesInvalidatedByRequest(host, request, cacheKeyResolver, mockStorage);
verify(mockEntry).getVariantMap();
verify(mockStorage).getEntry(key);
@ -123,7 +122,7 @@ public class TestDefaultCacheInvalidator {
cacheReturnsEntryForUri(key);
impl.flushInvalidatedCacheEntries(host, request, cacheKeyResolver, mockStorage);
impl.flushCacheEntriesInvalidatedByRequest(host, request, cacheKeyResolver, mockStorage);
verify(mockEntry).getVariantMap();
verify(mockStorage).getEntry(key);
@ -145,7 +144,7 @@ public class TestDefaultCacheInvalidator {
cacheReturnsEntryForUri(key);
impl.flushInvalidatedCacheEntries(host, request, cacheKeyResolver, mockStorage);
impl.flushCacheEntriesInvalidatedByRequest(host, request, cacheKeyResolver, mockStorage);
verify(mockEntry).getVariantMap();
verify(mockStorage).getEntry(key);
@ -167,7 +166,7 @@ public class TestDefaultCacheInvalidator {
cacheReturnsEntryForUri(key);
impl.flushInvalidatedCacheEntries(host, request, cacheKeyResolver, mockStorage);
impl.flushCacheEntriesInvalidatedByRequest(host, request, cacheKeyResolver, mockStorage);
verify(mockEntry).getVariantMap();
verify(mockStorage).getEntry(key);
@ -189,7 +188,7 @@ public class TestDefaultCacheInvalidator {
cacheReturnsEntryForUri(key);
impl.flushInvalidatedCacheEntries(host, request, cacheKeyResolver, mockStorage);
impl.flushCacheEntriesInvalidatedByRequest(host, request, cacheKeyResolver, mockStorage);
verify(mockEntry).getVariantMap();
verify(mockStorage).getEntry(key);
@ -199,7 +198,7 @@ public class TestDefaultCacheInvalidator {
@Test
public void testDoesNotInvalidateGETRequest() throws Exception {
final HttpRequest request = new BasicHttpRequest("GET","/");
impl.flushInvalidatedCacheEntries(host, request, cacheKeyResolver, mockStorage);
impl.flushCacheEntriesInvalidatedByRequest(host, request, cacheKeyResolver, mockStorage);
verify(mockStorage).getEntry("http://foo.example.com:80/");
verifyNoMoreInteractions(mockStorage);
@ -208,7 +207,7 @@ public class TestDefaultCacheInvalidator {
@Test
public void testDoesNotInvalidateHEADRequest() throws Exception {
final HttpRequest request = new BasicHttpRequest("HEAD","/");
impl.flushInvalidatedCacheEntries(host, request, cacheKeyResolver, mockStorage);
impl.flushCacheEntriesInvalidatedByRequest(host, request, cacheKeyResolver, mockStorage);
verify(mockStorage).getEntry("http://foo.example.com:80/");
verifyNoMoreInteractions(mockStorage);
@ -224,7 +223,7 @@ public class TestDefaultCacheInvalidator {
cacheEntryHasVariantMap(new HashMap<String, String>());
cacheReturnsEntryForUri(key);
impl.flushInvalidatedCacheEntries(host, request, cacheKeyResolver, mockStorage);
impl.flushCacheEntriesInvalidatedByRequest(host, request, cacheKeyResolver, mockStorage);
verify(mockEntry).getRequestMethod();
verify(mockEntry).getVariantMap();
@ -245,7 +244,7 @@ public class TestDefaultCacheInvalidator {
cacheEntryHasVariantMap(variants);
cacheReturnsEntryForUri(key);
impl.flushInvalidatedCacheEntries(host, request, cacheKeyResolver, mockStorage);
impl.flushCacheEntriesInvalidatedByRequest(host, request, cacheKeyResolver, mockStorage);
verify(mockEntry).getRequestMethod();
verify(mockEntry).getVariantMap();
@ -262,7 +261,7 @@ public class TestDefaultCacheInvalidator {
cacheReturnsEntryForUri(key);
impl.flushInvalidatedCacheEntries(host, request, cacheKeyResolver, mockStorage);
impl.flushCacheEntriesInvalidatedByRequest(host, request, cacheKeyResolver, mockStorage);
verify(mockStorage).getEntry(key);
verifyNoMoreInteractions(mockStorage);
@ -276,7 +275,7 @@ public class TestDefaultCacheInvalidator {
cacheReturnsEntryForUri(key);
impl.flushInvalidatedCacheEntries(host, request, cacheKeyResolver, mockStorage);
impl.flushCacheEntriesInvalidatedByRequest(host, request, cacheKeyResolver, mockStorage);
verify(mockStorage).getEntry(key);
verifyNoMoreInteractions(mockStorage);
@ -291,7 +290,7 @@ public class TestDefaultCacheInvalidator {
cacheEntryisForMethod("GET");
cacheReturnsEntryForUri(key);
impl.flushInvalidatedCacheEntries(host, request, cacheKeyResolver, mockStorage);
impl.flushCacheEntriesInvalidatedByRequest(host, request, cacheKeyResolver, mockStorage);
verify(mockEntry).getRequestMethod();
verify(mockStorage).getEntry(key);
@ -303,7 +302,7 @@ public class TestDefaultCacheInvalidator {
final HttpRequest request = new BasicHttpRequest("GET","/");
request.setHeader("Cache-Control","no-cache");
impl.flushInvalidatedCacheEntries(host, request, cacheKeyResolver, mockStorage);
impl.flushCacheEntriesInvalidatedByRequest(host, request, cacheKeyResolver, mockStorage);
verify(mockStorage).getEntry("http://foo.example.com:80/");
verifyNoMoreInteractions(mockStorage);
@ -314,7 +313,7 @@ public class TestDefaultCacheInvalidator {
final HttpRequest request = new BasicHttpRequest("GET","/");
request.setHeader("Pragma","no-cache");
impl.flushInvalidatedCacheEntries(host, request, cacheKeyResolver, mockStorage);
impl.flushCacheEntriesInvalidatedByRequest(host, request, cacheKeyResolver, mockStorage);
verify(mockStorage).getEntry("http://foo.example.com:80/");
verifyNoMoreInteractions(mockStorage);
@ -331,7 +330,7 @@ public class TestDefaultCacheInvalidator {
cacheReturnsEntryForUri(key);
cacheEntryHasVariantMap(mapOfURIs);
impl.flushInvalidatedCacheEntries(host, request, cacheKeyResolver, mockStorage);
impl.flushCacheEntriesInvalidatedByRequest(host, request, cacheKeyResolver, mockStorage);
verify(mockStorage).getEntry(key);
verify(mockEntry).getVariantMap();
@ -343,7 +342,7 @@ public class TestDefaultCacheInvalidator {
public void doesNotFlushForResponsesWithoutContentLocation() throws Exception {
final HttpRequest request = new BasicHttpRequest("POST","/");
final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_OK);
impl.flushInvalidatedCacheEntries(host, request, response, cacheKeyResolver, mockStorage);
impl.flushCacheEntriesInvalidatedByExchange(host, request, response, cacheKeyResolver, mockStorage);
verifyNoMoreInteractions(mockStorage);
}
@ -364,7 +363,7 @@ public class TestDefaultCacheInvalidator {
when(mockStorage.getEntry(key)).thenReturn(entry);
impl.flushInvalidatedCacheEntries(host, request, response, cacheKeyResolver, mockStorage);
impl.flushCacheEntriesInvalidatedByExchange(host, request, response, cacheKeyResolver, mockStorage);
verify(mockStorage).getEntry(key);
verify(mockStorage).removeEntry(key);
@ -386,7 +385,7 @@ public class TestDefaultCacheInvalidator {
when(mockStorage.getEntry(key)).thenReturn(entry);
impl.flushInvalidatedCacheEntries(host, request, response, cacheKeyResolver, mockStorage);
impl.flushCacheEntriesInvalidatedByExchange(host, request, response, cacheKeyResolver, mockStorage);
verify(mockStorage).getEntry(key);
verify(mockStorage).removeEntry(key);
@ -401,7 +400,7 @@ public class TestDefaultCacheInvalidator {
final String key = "http://foo.example.com:80/bar";
response.setHeader("Content-Location", key);
impl.flushInvalidatedCacheEntries(host, request, response, cacheKeyResolver, mockStorage);
impl.flushCacheEntriesInvalidatedByExchange(host, request, response, cacheKeyResolver, mockStorage);
verifyNoMoreInteractions(mockStorage);
}
@ -422,7 +421,7 @@ public class TestDefaultCacheInvalidator {
when(mockStorage.getEntry(cacheKey)).thenReturn(entry);
impl.flushInvalidatedCacheEntries(host, request, response, cacheKeyResolver, mockStorage);
impl.flushCacheEntriesInvalidatedByExchange(host, request, response, cacheKeyResolver, mockStorage);
verify(mockStorage).getEntry(cacheKey);
verify(mockStorage).removeEntry(cacheKey);
@ -444,7 +443,7 @@ public class TestDefaultCacheInvalidator {
when(mockStorage.getEntry(cacheKey)).thenReturn(entry);
impl.flushInvalidatedCacheEntries(host, request, response, cacheKeyResolver, mockStorage);
impl.flushCacheEntriesInvalidatedByExchange(host, request, response, cacheKeyResolver, mockStorage);
verify(mockStorage).getEntry(cacheKey);
verify(mockStorage).removeEntry(cacheKey);
@ -459,7 +458,7 @@ public class TestDefaultCacheInvalidator {
final String cacheKey = "http://baz.example.com:80/bar";
response.setHeader("Content-Location", cacheKey);
impl.flushInvalidatedCacheEntries(host, request, response, cacheKeyResolver, mockStorage);
impl.flushCacheEntriesInvalidatedByExchange(host, request, response, cacheKeyResolver, mockStorage);
verifyNoMoreInteractions(mockStorage);
}
@ -479,7 +478,7 @@ public class TestDefaultCacheInvalidator {
});
when(mockStorage.getEntry(key)).thenReturn(entry);
impl.flushInvalidatedCacheEntries(host, request, response, cacheKeyResolver, mockStorage);
impl.flushCacheEntriesInvalidatedByExchange(host, request, response, cacheKeyResolver, mockStorage);
verify(mockStorage).getEntry(key);
verifyNoMoreInteractions(mockStorage);
@ -501,7 +500,7 @@ public class TestDefaultCacheInvalidator {
when(mockStorage.getEntry(key)).thenReturn(entry);
impl.flushInvalidatedCacheEntries(host, request, response, cacheKeyResolver, mockStorage);
impl.flushCacheEntriesInvalidatedByExchange(host, request, response, cacheKeyResolver, mockStorage);
verify(mockStorage).getEntry(key);
verifyNoMoreInteractions(mockStorage);
@ -518,7 +517,7 @@ public class TestDefaultCacheInvalidator {
when(mockStorage.getEntry(key)).thenReturn(null);
impl.flushInvalidatedCacheEntries(host, request, response, cacheKeyResolver, mockStorage);
impl.flushCacheEntriesInvalidatedByExchange(host, request, response, cacheKeyResolver, mockStorage);
verify(mockStorage).getEntry(key);
verifyNoMoreInteractions(mockStorage);
@ -540,7 +539,7 @@ public class TestDefaultCacheInvalidator {
when(mockStorage.getEntry(key)).thenReturn(entry);
impl.flushInvalidatedCacheEntries(host, request, response, cacheKeyResolver, mockStorage);
impl.flushCacheEntriesInvalidatedByExchange(host, request, response, cacheKeyResolver, mockStorage);
verify(mockStorage).getEntry(key);
verifyNoMoreInteractions(mockStorage);
@ -561,7 +560,7 @@ public class TestDefaultCacheInvalidator {
when(mockStorage.getEntry(key)).thenReturn(entry);
impl.flushInvalidatedCacheEntries(host, request, response, cacheKeyResolver, mockStorage);
impl.flushCacheEntriesInvalidatedByExchange(host, request, response, cacheKeyResolver, mockStorage);
verify(mockStorage).getEntry(key);
verifyNoMoreInteractions(mockStorage);
@ -583,7 +582,7 @@ public class TestDefaultCacheInvalidator {
when(mockStorage.getEntry(key)).thenReturn(entry);
impl.flushInvalidatedCacheEntries(host, request, response, cacheKeyResolver, mockStorage);
impl.flushCacheEntriesInvalidatedByExchange(host, request, response, cacheKeyResolver, mockStorage);
verify(mockStorage).getEntry(key);
verify(mockStorage).removeEntry(key);
@ -605,7 +604,7 @@ public class TestDefaultCacheInvalidator {
when(mockStorage.getEntry(key)).thenReturn(entry);
impl.flushInvalidatedCacheEntries(host, request, response, cacheKeyResolver, mockStorage);
impl.flushCacheEntriesInvalidatedByExchange(host, request, response, cacheKeyResolver, mockStorage);
verify(mockStorage).getEntry(key);
verify(mockStorage).removeEntry(key);
@ -628,7 +627,7 @@ public class TestDefaultCacheInvalidator {
when(mockStorage.getEntry(key)).thenReturn(entry);
impl.flushInvalidatedCacheEntries(host, request, response, cacheKeyResolver, mockStorage);
impl.flushCacheEntriesInvalidatedByExchange(host, request, response, cacheKeyResolver, mockStorage);
verify(mockStorage).getEntry(key);
verify(mockStorage).removeEntry(key);
@ -651,7 +650,7 @@ public class TestDefaultCacheInvalidator {
when(mockStorage.getEntry(key)).thenReturn(entry);
impl.flushInvalidatedCacheEntries(host, request, response, cacheKeyResolver, mockStorage);
impl.flushCacheEntriesInvalidatedByExchange(host, request, response, cacheKeyResolver, mockStorage);
verify(mockStorage).getEntry(key);
verify(mockStorage).removeEntry(key);
@ -668,11 +667,6 @@ public class TestDefaultCacheInvalidator {
when(mockStorage.getEntry(key)).thenReturn(mockEntry);
}
private void cacheReturnsExceptionForUri(final String key) throws IOException {
when(mockStorage.getEntry(key)).thenThrow(
new ResourceIOException("TOTAL FAIL"));
}
private void cacheEntryisForMethod(final String httpMethod) {
when(mockEntry.getRequestMethod()).thenReturn(httpMethod);
}

View File

@ -2535,7 +2535,7 @@ public class TestProtocolRequirements extends AbstractProtocolTest {
final Capture<ClassicHttpRequest> cap = new Capture<>();
mockCache.flushInvalidatedCacheEntriesFor(
mockCache.flushCacheEntriesInvalidatedByExchange(
EasyMock.isA(HttpHost.class),
EasyMock.isA(ClassicHttpRequest.class),
EasyMock.isA(ClassicHttpResponse.class));