Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id D49C7200C7D for ; Mon, 1 May 2017 13:11:14 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id D313C160BC4; Mon, 1 May 2017 11:11:14 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id A3552160BAE for ; Mon, 1 May 2017 13:11:13 +0200 (CEST) Received: (qmail 29586 invoked by uid 500); 1 May 2017 11:11:12 -0000 Mailing-List: contact commits-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list commits@hc.apache.org Received: (qmail 29577 invoked by uid 99); 1 May 2017 11:11:12 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 May 2017 11:11:12 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 17EF13A3C9B for ; Mon, 1 May 2017 11:11:12 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@hc.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20170501111112.17EF13A3C9B@svn01-us-west.apache.org> archived-at: Mon, 01 May 2017 11:11:15 -0000 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 reqCap = new Capture<>(); + final Capture reqCap = new Capture<>(); EasyMock.expect( - mockBackend.execute( + mockExecChain.proceed( EasyMock.capture(reqCap), - EasyMock.isA(HttpClientContext.class), - EasyMock.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 reqCap = new Capture<>(); + final Capture reqCap = new Capture<>(); EasyMock.expect( - mockBackend.execute( + mockExecChain.proceed( EasyMock.capture(reqCap), - EasyMock.isA(HttpClientContext.class), - EasyMock.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.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.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.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.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); }