You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2017/05/24 18:23:59 UTC
[1/2] httpcomponents-client git commit: Removing unnecessary checks
for cache invalidation calls.
Repository: httpcomponents-client
Updated Branches:
refs/heads/master 4bd79fb3d -> ae2535ca3
Removing unnecessary checks for cache invalidation calls.
Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/commit/e07fd9ab
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/tree/e07fd9ab
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/diff/e07fd9ab
Branch: refs/heads/master
Commit: e07fd9abed6fd47e9356dbf258676cef1347224f
Parents: 4bd79fb
Author: Leandro Nunes <a-...@hotels.com>
Authored: Fri May 19 12:16:40 2017 +0100
Committer: Leandro Nunes <a-...@hotels.com>
Committed: Fri May 19 12:16:40 2017 +0100
----------------------------------------------------------------------
.../apache/hc/client5/http/impl/cache/TestCachingExec.java | 3 ---
.../hc/client5/http/impl/cache/TestCachingExecChain.java | 7 +------
.../hc/client5/http/impl/cache/TestProtocolRequirements.java | 6 ------
3 files changed, 1 insertion(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/e07fd9ab/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExec.java
----------------------------------------------------------------------
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExec.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExec.java
index d0df9b6..727b338 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExec.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExec.java
@@ -166,7 +166,6 @@ public class TestCachingExec extends TestCachingExecChain {
@Test
public void testCacheMissCausesBackendRequest() throws Exception {
mockImplMethods(CALL_BACKEND);
- cacheInvalidatorWasCalled();
requestPolicyAllowsCaching(true);
getCacheEntryReturns(null);
getVariantCacheEntriesReturns(new HashMap<String,Variant>());
@@ -188,7 +187,6 @@ public class TestCachingExec extends TestCachingExecChain {
@Test
public void testUnsuitableUnvalidatableCacheEntryCausesBackendRequest() throws Exception {
mockImplMethods(CALL_BACKEND);
- cacheInvalidatorWasCalled();
requestPolicyAllowsCaching(true);
requestIsFatallyNonCompliant(null);
@@ -214,7 +212,6 @@ public class TestCachingExec extends TestCachingExecChain {
@Test
public void testUnsuitableValidatableCacheEntryCausesRevalidation() throws Exception {
mockImplMethods(REVALIDATE_CACHE_ENTRY);
- cacheInvalidatorWasCalled();
requestPolicyAllowsCaching(true);
requestIsFatallyNonCompliant(null);
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/e07fd9ab/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExecChain.java
----------------------------------------------------------------------
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExecChain.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExecChain.java
index 5f5f01a..7a848cd 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExecChain.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExecChain.java
@@ -47,6 +47,7 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
+import junit.framework.AssertionFailedError;
import org.apache.hc.client5.http.HttpRoute;
import org.apache.hc.client5.http.cache.CacheResponseStatus;
import org.apache.hc.client5.http.cache.HttpCacheContext;
@@ -84,8 +85,6 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import junit.framework.AssertionFailedError;
-
@SuppressWarnings("boxing") // test code
public abstract class TestCachingExecChain {
@@ -310,7 +309,6 @@ public abstract class TestCachingExecChain {
@Test
public void testSuitableCacheEntryDoesNotCauseBackendRequest() throws Exception {
- cacheInvalidatorWasCalled();
requestPolicyAllowsCaching(true);
getCacheEntryReturns(mockCacheEntry);
cacheEntrySuitable(true);
@@ -351,7 +349,6 @@ public abstract class TestCachingExecChain {
public void testResponseIsGeneratedWhenCacheEntryIsUsable() throws Exception {
requestIsFatallyNonCompliant(null);
- cacheInvalidatorWasCalled();
requestPolicyAllowsCaching(true);
cacheEntrySuitable(true);
getCacheEntryReturns(mockCacheEntry);
@@ -1313,7 +1310,6 @@ public abstract class TestCachingExecChain {
"must-revalidate") });
requestIsFatallyNonCompliant(null);
- cacheInvalidatorWasCalled();
requestPolicyAllowsCaching(true);
getCacheEntryReturns(entry);
cacheEntrySuitable(false);
@@ -1331,7 +1327,6 @@ public abstract class TestCachingExecChain {
request.setHeader("Cache-Control", "only-if-cached");
requestIsFatallyNonCompliant(null);
- cacheInvalidatorWasCalled();
requestPolicyAllowsCaching(true);
getCacheEntryReturns(entry);
cacheEntrySuitable(true);
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/e07fd9ab/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolRequirements.java
----------------------------------------------------------------------
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolRequirements.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolRequirements.java
index aec6e42..f0325cd 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolRequirements.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolRequirements.java
@@ -2263,8 +2263,6 @@ public class TestProtocolRequirements extends AbstractProtocolTest {
notModified.setHeader("Date", DateUtils.formatDate(now));
notModified.setHeader("ETag", "\"etag\"");
- mockCache.flushInvalidatedCacheEntriesFor(EasyMock.eq(host),
- eqRequest(request));
EasyMock.expect(
mockCache.getCacheEntry(EasyMock.eq(host), eqRequest(request)))
.andReturn(entry);
@@ -2308,7 +2306,6 @@ public class TestProtocolRequirements extends AbstractProtocolTest {
impl = new CachingExec(mockCache, config);
request = new BasicClassicHttpRequest("GET", "/thing");
- mockCache.flushInvalidatedCacheEntriesFor(EasyMock.eq(host), eqRequest(request));
EasyMock.expect(mockCache.getCacheEntry(EasyMock.eq(host), eqRequest(request))).andReturn(entry);
replayMocks();
@@ -2355,7 +2352,6 @@ public class TestProtocolRequirements extends AbstractProtocolTest {
impl = new CachingExec(mockCache, config);
request = new BasicClassicHttpRequest("GET", "/thing");
- mockCache.flushInvalidatedCacheEntriesFor(EasyMock.eq(host), eqRequest(request));
EasyMock.expect(mockCache.getCacheEntry(EasyMock.eq(host), eqRequest(request))).andReturn(entry);
EasyMock.expect(
mockExecChain.proceed(
@@ -2564,7 +2560,6 @@ public class TestProtocolRequirements extends AbstractProtocolTest {
impl = new CachingExec(mockCache, config);
request = new BasicClassicHttpRequest("GET", "/thing");
- mockCache.flushInvalidatedCacheEntriesFor(EasyMock.eq(host), eqRequest(request));
EasyMock.expect(mockCache.getCacheEntry(EasyMock.eq(host), eqRequest(request))).andReturn(entry);
replayMocks();
@@ -2626,7 +2621,6 @@ public class TestProtocolRequirements extends AbstractProtocolTest {
final Capture<ClassicHttpRequest> cap = new Capture<>();
- mockCache.flushInvalidatedCacheEntriesFor(EasyMock.eq(host), eqRequest(request));
mockCache.flushInvalidatedCacheEntriesFor(
EasyMock.isA(HttpHost.class),
EasyMock.isA(ClassicHttpRequest.class),
[2/2] httpcomponents-client git commit: Avoid fetching the cached
entity twice on cache hit.
Posted by ol...@apache.org.
Avoid fetching the cached entity twice on cache hit.
Closes PR #79
Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/commit/ae2535ca
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/tree/ae2535ca
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/diff/ae2535ca
Branch: refs/heads/master
Commit: ae2535ca36661d9ed98d2986836a0002dfd9264e
Parents: e07fd9a
Author: Leandro Nunes <a-...@hotels.com>
Authored: Fri May 19 12:28:20 2017 +0100
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Wed May 24 20:23:15 2017 +0200
----------------------------------------------------------------------
.../hc/client5/http/impl/cache/CachingExec.java | 3 +--
.../http/impl/cache/TestCachingExec.java | 20 ++++++++++++++++++++
.../http/impl/cache/TestCachingExecChain.java | 5 +++++
3 files changed, 26 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/ae2535ca/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java
----------------------------------------------------------------------
diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java
index 81b80f5..0507d85 100644
--- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java
+++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java
@@ -246,10 +246,9 @@ public class CachingExec implements ExecChainHandler {
requestCompliance.makeRequestCompliant(request);
request.addHeader("Via",via);
- flushEntriesInvalidatedByRequest(target, request);
-
if (!cacheableRequestPolicy.isServableFromCache(request)) {
log.debug("Request is not servable from cache");
+ flushEntriesInvalidatedByRequest(target, request);
return callBackend(target, request, scope, chain);
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/ae2535ca/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExec.java
----------------------------------------------------------------------
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExec.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExec.java
index 727b338..281f859 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExec.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExec.java
@@ -386,6 +386,26 @@ public class TestCachingExec extends TestCachingExecChain {
verifyMocks();
}
+ @Test
+ public void testDoesNotFlushCachesOnCacheHit() throws Exception {
+ requestPolicyAllowsCaching(true);
+ requestIsFatallyNonCompliant(null);
+
+ getCacheEntryReturns(mockCacheEntry);
+ doesNotFlushCache();
+ cacheEntrySuitable(true);
+ cacheEntryValidatable(true);
+
+ expect(mockResponseGenerator.generateResponse(isA(HttpRequest.class), isA(HttpCacheEntry.class)))
+ .andReturn(mockBackendResponse);
+
+ replayMocks();
+ final HttpResponse result = impl.execute(request, scope, mockExecChain);
+ verifyMocks();
+
+ Assert.assertSame(mockBackendResponse, result);
+ }
+
private IExpectationSetters<ClassicHttpResponse> implExpectsAnyRequestAndReturn(
final ClassicHttpResponse response) throws Exception {
final ClassicHttpResponse resp = impl.callBackend(
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/ae2535ca/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExecChain.java
----------------------------------------------------------------------
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExecChain.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExecChain.java
index 7a848cd..00d3747 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExecChain.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExecChain.java
@@ -1673,4 +1673,9 @@ public abstract class TestCachingExecChain {
.andReturn(mockCachedResponse);
}
+ 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();
+ }
+
}