hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1793308 [4/11] - in /httpcomponents/httpclient/trunk: httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/ httpclient5-cache/src/test/java/org/apache/...
Date Mon, 01 May 2017 11:11:11 GMT
Modified: httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestHttpCacheJiraNumber1147.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestHttpCacheJiraNumber1147.java?rev=1793308&r1=1793307&r2=1793308&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestHttpCacheJiraNumber1147.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestHttpCacheJiraNumber1147.java
Mon May  1 11:11:09 2017
@@ -38,12 +38,13 @@ import java.util.Date;
 import org.apache.hc.client5.http.HttpRoute;
 import org.apache.hc.client5.http.cache.HttpCacheStorage;
 import org.apache.hc.client5.http.cache.ResourceFactory;
-import org.apache.hc.client5.http.impl.sync.ClientExecChain;
+import org.apache.hc.client5.http.sync.ExecRuntime;
 import org.apache.hc.client5.http.protocol.HttpClientContext;
-import org.apache.hc.client5.http.sync.methods.HttpExecutionAware;
+import org.apache.hc.client5.http.sync.ExecChain;
+import org.apache.hc.client5.http.sync.ExecChainHandler;
 import org.apache.hc.client5.http.sync.methods.HttpGet;
-import org.apache.hc.client5.http.impl.sync.RoutedHttpRequest;
 import org.apache.hc.client5.http.utils.DateUtils;
+import org.apache.hc.core5.http.ClassicHttpRequest;
 import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.message.BasicClassicHttpResponse;
@@ -51,7 +52,6 @@ import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
-import org.mockito.Matchers;
 
 public class TestHttpCacheJiraNumber1147 {
 
@@ -92,10 +92,11 @@ public class TestHttpCacheJiraNumber1147
         final ResourceFactory resourceFactory = new FileResourceFactory(cacheDir);
         final HttpCacheStorage httpCacheStorage = new ManagedHttpCacheStorage(cacheConfig);
 
-        final ClientExecChain backend = mock(ClientExecChain.class);
+        final ExecChain mockExecChain = mock(ExecChain.class);
+        final ExecRuntime mockEndpoint = mock(ExecRuntime.class);
         final HttpHost target = new HttpHost("somehost", 80);
         final HttpRoute route = new HttpRoute(target);
-        final RoutedHttpRequest get = RoutedHttpRequest.adapt(new HttpGet("http://somehost/"),
route);
+        final ClassicHttpRequest get = new HttpGet("http://somehost/");
         final HttpClientContext context = HttpClientContext.create();
 
         final Date now = new Date();
@@ -108,44 +109,36 @@ public class TestHttpCacheJiraNumber1147
         response.setHeader("Cache-Control", "public, max-age=3600");
         response.setHeader("Last-Modified", DateUtils.formatDate(tenSecondsAgo));
 
-        when(backend.execute(
-                isA(RoutedHttpRequest.class),
-                isA(HttpClientContext.class),
-                (HttpExecutionAware) Matchers.isNull())).thenReturn(response);
+        when(mockExecChain.proceed(
+                isA(ClassicHttpRequest.class),
+                isA(ExecChain.Scope.class))).thenReturn(response);
 
         final BasicHttpCache cache = new BasicHttpCache(resourceFactory, httpCacheStorage,
cacheConfig);
-        final ClientExecChain t = createCachingExecChain(backend, cache, cacheConfig);
+        final ExecChainHandler t = createCachingExecChain(cache, cacheConfig);
 
-        final ClassicHttpResponse response1 = t.execute(get, context, null);
+        final ExecChain.Scope scope = new ExecChain.Scope(route, get, mockEndpoint, context);
+        final ClassicHttpResponse response1 = t.execute(get, scope, mockExecChain);
         Assert.assertEquals(200, response1.getCode());
         IOUtils.consume(response1.getEntity());
 
-        verify(backend).execute(
-                isA(RoutedHttpRequest.class),
-                isA(HttpClientContext.class),
-                (HttpExecutionAware) Matchers.isNull());
+        verify(mockExecChain).proceed(isA(ClassicHttpRequest.class), isA(ExecChain.Scope.class));
 
         removeCache();
 
-        reset(backend);
-        when(backend.execute(
-                isA(RoutedHttpRequest.class),
-                isA(HttpClientContext.class),
-                (HttpExecutionAware) Matchers.isNull())).thenReturn(response);
+        reset(mockExecChain);
+        when(mockExecChain.proceed(isA(ClassicHttpRequest.class), isA(ExecChain.Scope.class))).thenReturn(response);
 
-        final ClassicHttpResponse response2 = t.execute(get, context, null);
+        final ClassicHttpResponse response2 = t.execute(get, scope, mockExecChain);
         Assert.assertEquals(200, response2.getCode());
         IOUtils.consume(response2.getEntity());
 
-        verify(backend).execute(
-                isA(RoutedHttpRequest.class),
-                isA(HttpClientContext.class),
-                (HttpExecutionAware) Matchers.isNull());
+        verify(mockExecChain).proceed(
+                isA(ClassicHttpRequest.class),
+                isA(ExecChain.Scope.class));
     }
 
-    protected ClientExecChain createCachingExecChain(final ClientExecChain backend,
-            final BasicHttpCache cache, final CacheConfig config) {
-        return new CachingExec(backend, cache, config);
+    protected ExecChainHandler createCachingExecChain(final BasicHttpCache cache, final CacheConfig
config) {
+        return new CachingExec(cache, config);
     }
 
 }

Modified: httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolAllowedBehavior.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolAllowedBehavior.java?rev=1793308&r1=1793307&r2=1793308&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolAllowedBehavior.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolAllowedBehavior.java
Mon May  1 11:11:09 2017
@@ -29,8 +29,8 @@ package org.apache.hc.client5.http.impl.
 import java.net.SocketTimeoutException;
 import java.util.Date;
 
-import org.apache.hc.client5.http.impl.sync.RoutedHttpRequest;
 import org.apache.hc.client5.http.utils.DateUtils;
+import org.apache.hc.core5.http.ClassicHttpRequest;
 import org.apache.hc.core5.http.HttpResponse;
 import org.apache.hc.core5.http.HttpStatus;
 import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
@@ -46,8 +46,7 @@ public class TestProtocolAllowedBehavior
     @Test
     public void testNonSharedCacheReturnsStaleResponseWhenRevalidationFailsForProxyRevalidate()
         throws Exception {
-        final RoutedHttpRequest req1 = RoutedHttpRequest.adapt(
-                new BasicClassicHttpRequest("GET","/"), route);
+        final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET","/");
         final Date now = new Date();
         final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
         originResponse.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
@@ -56,15 +55,14 @@ public class TestProtocolAllowedBehavior
 
         backendExpectsAnyRequest().andReturn(originResponse);
 
-        final RoutedHttpRequest req2 = RoutedHttpRequest.adapt(
-                new BasicClassicHttpRequest("GET","/"), route);
+        final ClassicHttpRequest req2 = new BasicClassicHttpRequest("GET","/");
 
         backendExpectsAnyRequest().andThrow(new SocketTimeoutException());
 
         replayMocks();
         behaveAsNonSharedCache();
-        impl.execute(req1, context, null);
-        final HttpResponse result = impl.execute(req2, context, null);
+        execute(req1);
+        final HttpResponse result = execute(req2);
         verifyMocks();
 
         Assert.assertEquals(HttpStatus.SC_OK, result.getCode());
@@ -73,19 +71,17 @@ public class TestProtocolAllowedBehavior
     @Test
     public void testNonSharedCacheMayCacheResponsesWithCacheControlPrivate()
         throws Exception {
-        final RoutedHttpRequest req1 = RoutedHttpRequest.adapt(
-                new BasicClassicHttpRequest("GET","/"), route);
+        final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET","/");
         originResponse.setHeader("Cache-Control","private,max-age=3600");
 
         backendExpectsAnyRequest().andReturn(originResponse);
 
-        final RoutedHttpRequest req2 = RoutedHttpRequest.adapt(
-                new BasicClassicHttpRequest("GET","/"), route);
+        final ClassicHttpRequest req2 = new BasicClassicHttpRequest("GET","/");
 
         replayMocks();
         behaveAsNonSharedCache();
-        impl.execute(req1, context, null);
-        final HttpResponse result = impl.execute(req2, context, null);
+        execute(req1);
+        final HttpResponse result = execute(req2);
         verifyMocks();
 
         Assert.assertEquals(HttpStatus.SC_OK, result.getCode());

Modified: httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolDeviations.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolDeviations.java?rev=1793308&r1=1793307&r2=1793308&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolDeviations.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolDeviations.java
Mon May  1 11:11:09 2017
@@ -26,20 +26,22 @@
  */
 package org.apache.hc.client5.http.impl.cache;
 
+import java.io.IOException;
 import java.util.Date;
 import java.util.Random;
 
 import org.apache.hc.client5.http.HttpRoute;
 import org.apache.hc.client5.http.cache.HttpCacheContext;
-import org.apache.hc.client5.http.impl.sync.ClientExecChain;
-import org.apache.hc.client5.http.impl.sync.RoutedHttpRequest;
+import org.apache.hc.client5.http.impl.ExecSupport;
+import org.apache.hc.client5.http.sync.ExecRuntime;
 import org.apache.hc.client5.http.protocol.ClientProtocolException;
-import org.apache.hc.client5.http.protocol.HttpClientContext;
-import org.apache.hc.client5.http.sync.methods.HttpExecutionAware;
+import org.apache.hc.client5.http.sync.ExecChain;
+import org.apache.hc.client5.http.sync.ExecChainHandler;
 import org.apache.hc.client5.http.utils.DateUtils;
 import org.apache.hc.core5.http.ClassicHttpRequest;
 import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.HttpEntity;
+import org.apache.hc.core5.http.HttpException;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.HttpRequest;
 import org.apache.hc.core5.http.HttpResponse;
@@ -82,13 +84,14 @@ public class TestProtocolDeviations {
     private HttpRoute route;
     private HttpEntity body;
     private HttpEntity mockEntity;
-    private ClientExecChain mockBackend;
+    private ExecRuntime mockEndpoint;
+    private ExecChain mockExecChain;
     private HttpCache mockCache;
     private ClassicHttpRequest request;
     private HttpCacheContext context;
     private ClassicHttpResponse originResponse;
 
-    private ClientExecChain impl;
+    private ExecChainHandler impl;
 
     @Before
     public void setUp() {
@@ -110,16 +113,20 @@ public class TestProtocolDeviations {
                 .build();
 
         final HttpCache cache = new BasicHttpCache(config);
-        mockBackend = EasyMock.createNiceMock(ClientExecChain.class);
+        mockEndpoint = EasyMock.createNiceMock(ExecRuntime.class);
+        mockExecChain = EasyMock.createNiceMock(ExecChain.class);
         mockEntity = EasyMock.createNiceMock(HttpEntity.class);
         mockCache = EasyMock.createNiceMock(HttpCache.class);
 
-        impl = createCachingExecChain(mockBackend, cache, config);
+        impl = createCachingExecChain(cache, config);
     }
 
-    protected ClientExecChain createCachingExecChain(
-            final ClientExecChain backend, final HttpCache cache, final CacheConfig config)
{
-        return new CachingExec(backend, cache, config);
+    private ClassicHttpResponse execute(final ClassicHttpRequest request) throws IOException,
HttpException {
+        return impl.execute(ExecSupport.copy(request), new ExecChain.Scope(route, request,
mockEndpoint, context), mockExecChain);
+    }
+
+    protected ExecChainHandler createCachingExecChain(final HttpCache cache, final CacheConfig
config) {
+        return new CachingExec(cache, config);
     }
 
     private ClassicHttpResponse make200Response() {
@@ -131,13 +138,13 @@ public class TestProtocolDeviations {
     }
 
     private void replayMocks() {
-        EasyMock.replay(mockBackend);
+        EasyMock.replay(mockExecChain);
         EasyMock.replay(mockCache);
         EasyMock.replay(mockEntity);
     }
 
     private void verifyMocks() {
-        EasyMock.verify(mockBackend);
+        EasyMock.verify(mockExecChain);
         EasyMock.verify(mockCache);
         EasyMock.verify(mockEntity);
     }
@@ -177,7 +184,7 @@ public class TestProtocolDeviations {
 
         replayMocks();
 
-        final HttpResponse response = impl.execute(RoutedHttpRequest.adapt(post, route),
context, null);
+        final HttpResponse response = execute(post);
 
         verifyMocks();
 
@@ -220,18 +227,17 @@ public class TestProtocolDeviations {
         org.easymock.EasyMock.expect(mockBody.getContentLength()).andReturn(-1L).anyTimes();
         post.setEntity(mockBody);
 
-        final Capture<RoutedHttpRequest> reqCap = new Capture<>();
+        final Capture<ClassicHttpRequest> reqCap = new Capture<>();
         EasyMock.expect(
-                mockBackend.execute(
+                mockExecChain.proceed(
                         EasyMock.capture(reqCap),
-                        EasyMock.isA(HttpClientContext.class),
-                        EasyMock.<HttpExecutionAware>isNull())).andReturn(
+                        EasyMock.isA(ExecChain.Scope.class))).andReturn(
                                 originResponse).times(0, 1);
 
         replayMocks();
         EasyMock.replay(mockBody);
 
-        final HttpResponse result = impl.execute(RoutedHttpRequest.adapt(post, route), context,
null);
+        final HttpResponse result = execute(post);
 
         verifyMocks();
         EasyMock.verify(mockBody);
@@ -260,15 +266,14 @@ public class TestProtocolDeviations {
         options.setEntity(body);
         options.setHeader("Content-Length", "1");
 
-        final Capture<RoutedHttpRequest> reqCap = new Capture<>();
+        final Capture<ClassicHttpRequest> reqCap = new Capture<>();
         EasyMock.expect(
-                mockBackend.execute(
+                mockExecChain.proceed(
                         EasyMock.capture(reqCap),
-                        EasyMock.isA(HttpClientContext.class),
-                        EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);
+                        EasyMock.isA(ExecChain.Scope.class))).andReturn(originResponse);
         replayMocks();
 
-        impl.execute(RoutedHttpRequest.adapt(options, route), context, null);
+        execute(options);
 
         verifyMocks();
 
@@ -298,14 +303,13 @@ public class TestProtocolDeviations {
         originResponse.setEntity(makeBody(500));
 
         EasyMock.expect(
-                mockBackend.execute(
-                        EasyMock.isA(RoutedHttpRequest.class),
-                        EasyMock.isA(HttpClientContext.class),
-                        EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);
+                mockExecChain.proceed(
+                        EasyMock.isA(ClassicHttpRequest.class),
+                        EasyMock.isA(ExecChain.Scope.class))).andReturn(originResponse);
 
         replayMocks();
         try {
-            final HttpResponse result = impl.execute(RoutedHttpRequest.adapt(request, route),
context, null);
+            final HttpResponse result = execute(request);
             Assert.assertTrue(HttpStatus.SC_PARTIAL_CONTENT != result.getCode());
         } catch (final ClientProtocolException acceptableBehavior) {
             // this is probably ok
@@ -325,12 +329,11 @@ public class TestProtocolDeviations {
         originResponse = new BasicClassicHttpResponse(401, "Unauthorized");
 
         EasyMock.expect(
-                mockBackend.execute(
-                        EasyMock.isA(RoutedHttpRequest.class),
-                        EasyMock.isA(HttpClientContext.class),
-                        EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);
+                mockExecChain.proceed(
+                        EasyMock.isA(ClassicHttpRequest.class),
+                        EasyMock.isA(ExecChain.Scope.class))).andReturn(originResponse);
         replayMocks();
-        final HttpResponse result = impl.execute(RoutedHttpRequest.adapt(request, route),
context, null);
+        final HttpResponse result = execute(request);
         verifyMocks();
         Assert.assertSame(originResponse, result);
     }
@@ -346,12 +349,11 @@ public class TestProtocolDeviations {
         originResponse = new BasicClassicHttpResponse(405, "Method Not Allowed");
 
         EasyMock.expect(
-                mockBackend.execute(
-                        EasyMock.isA(RoutedHttpRequest.class),
-                        EasyMock.isA(HttpClientContext.class),
-                        EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);
+                mockExecChain.proceed(
+                        EasyMock.isA(ClassicHttpRequest.class),
+                        EasyMock.isA(ExecChain.Scope.class))).andReturn(originResponse);
         replayMocks();
-        final HttpResponse result = impl.execute(RoutedHttpRequest.adapt(request, route),
context, null);
+        final HttpResponse result = execute(request);
         verifyMocks();
         Assert.assertSame(originResponse, result);
     }
@@ -368,12 +370,11 @@ public class TestProtocolDeviations {
         originResponse = new BasicClassicHttpResponse(407, "Proxy Authentication Required");
 
         EasyMock.expect(
-                mockBackend.execute(
-                        EasyMock.isA(RoutedHttpRequest.class),
-                        EasyMock.isA(HttpClientContext.class),
-                        EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);
+                mockExecChain.proceed(
+                        EasyMock.isA(ClassicHttpRequest.class),
+                        EasyMock.isA(ExecChain.Scope.class))).andReturn(originResponse);
         replayMocks();
-        final HttpResponse result = impl.execute(RoutedHttpRequest.adapt(request, route),
context, null);
+        final HttpResponse result = execute(request);
         verifyMocks();
         Assert.assertSame(originResponse, result);
     }



Mime
View raw message