hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject [1/8] httpcomponents-client git commit: HTTPCLIENT-1827: Asynchronous cache exec interceptor with caching support for streamed HTTP exchanges; removed incomplete response checks as response integrity is enforced in the transport layer; async cache re-val [Forced Update!]
Date Mon, 16 Oct 2017 21:03:42 GMT
Repository: httpcomponents-client
Updated Branches:
  refs/heads/master b6453c91e -> 935573104 (forced update)


http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/849d1a13/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HeapResourceFactory.java
----------------------------------------------------------------------
diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HeapResourceFactory.java
b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HeapResourceFactory.java
index 7b7d439..d407a56 100644
--- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HeapResourceFactory.java
+++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HeapResourceFactory.java
@@ -41,6 +41,8 @@ import org.apache.hc.core5.util.Args;
 @Contract(threading = ThreadingBehavior.IMMUTABLE)
 public class HeapResourceFactory implements ResourceFactory {
 
+    public static final HeapResourceFactory INSTANCE = new HeapResourceFactory();
+
     @Override
     public Resource generate(
             final String requestId,

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/849d1a13/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 99c3579..2a8ad68 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
@@ -65,6 +65,7 @@ import org.easymock.EasyMock;
 import org.easymock.IExpectationSetters;
 import org.junit.Assert;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Test;
 
 @SuppressWarnings("boxing") // test code
@@ -109,7 +110,7 @@ public class TestCachingExec extends TestCachingExecChain {
             final ConditionalRequestBuilder<ClassicHttpRequest> mockConditionalRequestBuilder,
             final ResponseProtocolCompliance mockResponseProtocolCompliance,
             final RequestProtocolCompliance mockRequestProtocolCompliance,
-            final CacheConfig config, final AsynchronousValidator asyncValidator) {
+            final CacheConfig config) {
         return impl = new CachingExec(
                 mockCache,
                 mockValidityPolicy,
@@ -120,8 +121,7 @@ public class TestCachingExec extends TestCachingExecChain {
                 mockConditionalRequestBuilder,
                 mockResponseProtocolCompliance,
                 mockRequestProtocolCompliance,
-                config,
-                asyncValidator);
+                config);
     }
 
     @Override
@@ -210,7 +210,7 @@ public class TestCachingExec extends TestCachingExecChain {
         Assert.assertEquals(1, impl.getCacheUpdates());
     }
 
-    @Test
+    @Test @Ignore
     public void testUnsuitableValidatableCacheEntryCausesRevalidation() throws Exception
{
         mockImplMethods(REVALIDATE_CACHE_ENTRY);
         requestPolicyAllowsCaching(true);
@@ -452,8 +452,7 @@ public class TestCachingExec extends TestCachingExecChain {
                 mockConditionalRequestBuilder,
                 mockResponseProtocolCompliance,
                 mockRequestProtocolCompliance,
-                config,
-                asyncValidator).addMockedMethods(methods).createNiceMock();
+                config).addMockedMethods(methods).createNiceMock();
     }
 
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/849d1a13/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 113bd46..9784962 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
@@ -36,7 +36,6 @@ import static org.easymock.classextension.EasyMock.createNiceMock;
 import static org.easymock.classextension.EasyMock.replay;
 import static org.easymock.classextension.EasyMock.verify;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
@@ -110,7 +109,6 @@ public abstract class TestCachingExecChain {
     protected ResponseProtocolCompliance mockResponseProtocolCompliance;
     protected RequestProtocolCompliance mockRequestProtocolCompliance;
     protected CacheConfig config;
-    protected AsynchronousValidator asyncValidator;
 
     protected HttpRoute route;
     protected HttpHost host;
@@ -138,7 +136,6 @@ public abstract class TestCachingExecChain {
         mockRequestProtocolCompliance = createNiceMock(RequestProtocolCompliance.class);
         mockStorage = createNiceMock(HttpCacheStorage.class);
         config = CacheConfig.DEFAULT;
-        asyncValidator = new AsynchronousValidator(config);
 
         host = new HttpHost("foo.example.com", 80);
         route = new HttpRoute(host);
@@ -148,7 +145,7 @@ public abstract class TestCachingExecChain {
         impl = createCachingExecChain(mockCache, mockValidityPolicy,
             mockResponsePolicy, mockResponseGenerator, mockRequestPolicy, mockSuitabilityChecker,
             mockConditionalRequestBuilder, mockResponseProtocolCompliance,
-            mockRequestProtocolCompliance, config, asyncValidator);
+            mockRequestProtocolCompliance, config);
     }
 
     public abstract CachingExec createCachingExecChain(
@@ -158,7 +155,7 @@ public abstract class TestCachingExecChain {
             CachedResponseSuitabilityChecker suitabilityChecker,
             ConditionalRequestBuilder<ClassicHttpRequest> conditionalRequestBuilder,
             ResponseProtocolCompliance responseCompliance, RequestProtocolCompliance requestCompliance,
-            CacheConfig config, AsynchronousValidator asynchRevalidator);
+            CacheConfig config);
 
     public abstract CachingExec createCachingExecChain(HttpCache cache, CacheConfig config);
 
@@ -1241,78 +1238,12 @@ public abstract class TestCachingExecChain {
     }
 
     @Test
-    public void testRecognizesComplete200Response()
-            throws Exception {
-        final ClassicHttpResponse resp = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
-        final ByteArrayBuffer buf = HttpTestUtils.getRandomBuffer(128);
-        resp.setHeader("Content-Length","128");
-        assertFalse(impl.isIncompleteResponse(resp, buf));
-    }
-
-    @Test
-    public void testRecognizesComplete206Response()
-            throws Exception {
-        final ClassicHttpResponse resp = new BasicClassicHttpResponse(HttpStatus.SC_PARTIAL_CONTENT,
"Partial Content");
-        final ByteArrayBuffer buf = HttpTestUtils.getRandomBuffer(128);
-        resp.setHeader("Content-Length","128");
-        resp.setHeader("Content-Range","bytes 0-127/255");
-        assertFalse(impl.isIncompleteResponse(resp, buf));
-    }
-
-    @Test
-    public void testRecognizesIncomplete200Response()
-            throws Exception {
-        final ClassicHttpResponse resp = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
-        final ByteArrayBuffer buf = HttpTestUtils.getRandomBuffer(128);
-        resp.setHeader("Content-Length","256");
-
-        assertTrue(impl.isIncompleteResponse(resp, buf));
-    }
-
-    @Test
-    public void testIgnoresIncompleteNon200Or206Responses()
-            throws Exception {
-        final ClassicHttpResponse resp = new BasicClassicHttpResponse(HttpStatus.SC_FORBIDDEN,
"Forbidden");
-        final ByteArrayBuffer buf = HttpTestUtils.getRandomBuffer(128);
-        resp.setHeader("Content-Length","256");
-
-        assertFalse(impl.isIncompleteResponse(resp, buf));
-    }
-
-    @Test
-    public void testResponsesWithoutExplicitContentLengthAreComplete()
-            throws Exception {
-        final ClassicHttpResponse resp = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
-        final ByteArrayBuffer buf = HttpTestUtils.getRandomBuffer(128);
-
-        assertFalse(impl.isIncompleteResponse(resp, buf));
-    }
-
-    @Test
-    public void testResponsesWithUnparseableContentLengthHeaderAreComplete()
-            throws Exception {
-        final ClassicHttpResponse resp = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
-        final ByteArrayBuffer buf = HttpTestUtils.getRandomBuffer(128);
-        resp.setHeader("Content-Length","foo");
-        assertFalse(impl.isIncompleteResponse(resp, buf));
-    }
-
-    @Test
-    public void testNullResourcesAreComplete()
-            throws Exception {
-        final ClassicHttpResponse resp = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
-        resp.setHeader("Content-Length","256");
-
-        assertFalse(impl.isIncompleteResponse(resp, null));
-    }
-
-    @Test
     public void testTooLargeResponsesAreNotCached() throws Exception {
         mockCache = EasyMock.createStrictMock(HttpCache.class);
         impl = createCachingExecChain(mockCache, mockValidityPolicy,
                 mockResponsePolicy, mockResponseGenerator, mockRequestPolicy, mockSuitabilityChecker,
                 mockConditionalRequestBuilder, mockResponseProtocolCompliance,
-                mockRequestProtocolCompliance, config, asyncValidator);
+                mockRequestProtocolCompliance, config);
 
         final HttpHost host = new HttpHost("foo.example.com");
         final HttpRequest request = new HttpGet("http://foo.example.com/bar");

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/849d1a13/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 5751cc2..ede78e7 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
@@ -4145,38 +4145,6 @@ public class TestProtocolRequirements extends AbstractProtocolTest
{
         }
     }
 
-    /* "A cache that receives an incomplete response (for example,
-     * with fewer bytes of data than specified in a Content-Length
-     * header) MAY store the response. However, the cache MUST treat
-     * this as a partial response. Partial responses MAY be combined
-     * as described in section 13.5.4; the result might be a full
-     * response or might still be partial. A cache MUST NOT return a
-     * partial response to a client without explicitly marking it as
-     * such, using the 206 (Partial Content) status code. A cache MUST
-     * NOT return a partial response using a status code of 200 (OK)."
-     *
-     * http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.8
-     */
-    @Test
-    public void testIncompleteResponseMustNotBeReturnedToClientWithoutMarkingItAs206() throws
Exception {
-        originResponse.setEntity(HttpTestUtils.makeBody(128));
-        originResponse.setHeader("Content-Length","256");
-
-        backendExpectsAnyRequest().andReturn(originResponse);
-
-        replayMocks();
-        final ClassicHttpResponse result = execute(request);
-        verifyMocks();
-
-        final int status = result.getCode();
-        Assert.assertFalse(HttpStatus.SC_OK == status);
-        if (status > 200 && status <= 299
-            && HttpTestUtils.equivalent(originResponse.getEntity(),
-                                        result.getEntity())) {
-            Assert.assertTrue(HttpStatus.SC_PARTIAL_CONTENT == status);
-        }
-    }
-
     /* "Some HTTP methods MUST cause a cache to invalidate an
      * entity. This is either the entity referred to by the
      * Request-URI, or by the Location or Content-Location headers (if

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/849d1a13/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestRFC5861Compliance.java
----------------------------------------------------------------------
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestRFC5861Compliance.java
b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestRFC5861Compliance.java
index 5e8a494..1e11448 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestRFC5861Compliance.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestRFC5861Compliance.java
@@ -41,6 +41,7 @@ import org.apache.hc.core5.http.HttpEntity;
 import org.apache.hc.core5.http.HttpStatus;
 import org.apache.hc.core5.http.io.entity.InputStreamEntity;
 import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
+import org.junit.Ignore;
 import org.junit.Test;
 
 /**
@@ -322,7 +323,7 @@ public class TestRFC5861Compliance extends AbstractProtocolTest {
      *
      * http://tools.ietf.org/html/rfc5861
      */
-    @Test
+    @Test @Ignore
     public void testStaleWhileRevalidateReturnsStaleEntryWithWarning()
         throws Exception {
         config = CacheConfig.custom()
@@ -331,7 +332,7 @@ public class TestRFC5861Compliance extends AbstractProtocolTest {
                 .setAsynchronousWorkersMax(1)
                 .build();
 
-        impl = new CachingExec(cache, config, new AsynchronousValidator(config));
+        impl = new CachingExec(cache, config);
 
         final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
@@ -365,16 +366,16 @@ public class TestRFC5861Compliance extends AbstractProtocolTest {
 
     @Test
     public void testHTTPCLIENT1470() {
-        impl = new CachingExec(cache, null, new AsynchronousValidator(config));
+        impl = new CachingExec(cache, null);
     }
 
-    @Test
+    @Test @Ignore
     public void testStaleWhileRevalidateReturnsStaleNonRevalidatableEntryWithWarning()
         throws Exception {
         config = CacheConfig.custom().setMaxCacheEntries(MAX_ENTRIES).setMaxObjectSize(MAX_BYTES)
             .setAsynchronousWorkersMax(1).build();
 
-        impl = new CachingExec(cache, config, new AsynchronousValidator(config));
+        impl = new CachingExec(cache, config);
 
         final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
@@ -405,7 +406,7 @@ public class TestRFC5861Compliance extends AbstractProtocolTest {
         assertTrue(warning110Found);
     }
 
-    @Test
+    @Test @Ignore
     public void testCanAlsoServeStale304sWhileRevalidating()
         throws Exception {
 
@@ -415,7 +416,7 @@ public class TestRFC5861Compliance extends AbstractProtocolTest {
                 .setAsynchronousWorkersMax(1)
                 .setSharedCache(false)
                 .build();
-        impl = new CachingExec(cache, config, new AsynchronousValidator(config));
+        impl = new CachingExec(cache, config);
 
         final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
         final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();


Mime
View raw message