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/09/02 15:28:03 UTC
[03/17] httpcomponents-client git commit: Moved classes and renamed
packages (no functional changes)
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/test/java/org/apache/hc/client5/http/impl/protocol/TestDefaultRedirectStrategy.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/protocol/TestDefaultRedirectStrategy.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/protocol/TestDefaultRedirectStrategy.java
deleted file mode 100644
index 1f79e79..0000000
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/protocol/TestDefaultRedirectStrategy.java
+++ /dev/null
@@ -1,287 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-package org.apache.hc.client5.http.impl.protocol;
-
-import java.net.URI;
-import java.util.List;
-
-import org.apache.hc.client5.http.config.RequestConfig;
-import org.apache.hc.client5.http.protocol.HttpClientContext;
-import org.apache.hc.client5.http.sync.methods.HttpGet;
-import org.apache.hc.client5.http.sync.methods.HttpPost;
-import org.apache.hc.core5.http.HttpException;
-import org.apache.hc.core5.http.HttpHeaders;
-import org.apache.hc.core5.http.HttpResponse;
-import org.apache.hc.core5.http.HttpStatus;
-import org.apache.hc.core5.http.ProtocolException;
-import org.apache.hc.core5.http.message.BasicHttpResponse;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class TestDefaultRedirectStrategy {
-
- @Test
- public void testIsRedirectedMovedTemporary() throws Exception {
- final DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
- final HttpClientContext context = HttpClientContext.create();
- final HttpGet httpget = new HttpGet("http://localhost/");
- final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_MOVED_TEMPORARILY, "Redirect");
- Assert.assertFalse(redirectStrategy.isRedirected(httpget, response, context));
- response.setHeader(HttpHeaders.LOCATION, "http://localhost/blah");
- Assert.assertTrue(redirectStrategy.isRedirected(httpget, response, context));
- }
-
- @Test
- public void testIsRedirectedMovedTemporaryNoLocation() throws Exception {
- final DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
- final HttpClientContext context = HttpClientContext.create();
- final HttpGet httpget = new HttpGet("http://localhost/");
- final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_MOVED_TEMPORARILY, "Redirect");
- Assert.assertFalse(redirectStrategy.isRedirected(httpget, response, context));
- }
-
- @Test
- public void testIsRedirectedMovedPermanently() throws Exception {
- final DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
- final HttpClientContext context = HttpClientContext.create();
- final HttpGet httpget = new HttpGet("http://localhost/");
- final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_MOVED_PERMANENTLY, "Redirect");
- Assert.assertFalse(redirectStrategy.isRedirected(httpget, response, context));
- response.setHeader(HttpHeaders.LOCATION, "http://localhost/blah");
- Assert.assertTrue(redirectStrategy.isRedirected(httpget, response, context));
- }
-
- @Test
- public void testIsRedirectedTemporaryRedirect() throws Exception {
- final DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
- final HttpClientContext context = HttpClientContext.create();
- final HttpGet httpget = new HttpGet("http://localhost/");
- final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_TEMPORARY_REDIRECT, "Redirect");
- Assert.assertFalse(redirectStrategy.isRedirected(httpget, response, context));
- response.setHeader(HttpHeaders.LOCATION, "http://localhost/blah");
- Assert.assertTrue(redirectStrategy.isRedirected(httpget, response, context));
- }
-
- @Test
- public void testIsRedirectedSeeOther() throws Exception {
- final DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
- final HttpClientContext context = HttpClientContext.create();
- final HttpGet httpget = new HttpGet("http://localhost/");
- final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_SEE_OTHER, "Redirect");
- Assert.assertFalse(redirectStrategy.isRedirected(httpget, response, context));
- response.setHeader(HttpHeaders.LOCATION, "http://localhost/blah");
- Assert.assertTrue(redirectStrategy.isRedirected(httpget, response, context));
- }
-
- @Test
- public void testIsRedirectedUnknownStatus() throws Exception {
- final DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
- final HttpClientContext context = HttpClientContext.create();
- final HttpGet httpget = new HttpGet("http://localhost/");
- final HttpResponse response = new BasicHttpResponse(333, "Redirect");
- Assert.assertFalse(redirectStrategy.isRedirected(httpget, response, context));
- final HttpPost httppost = new HttpPost("http://localhost/");
- Assert.assertFalse(redirectStrategy.isRedirected(httppost, response, context));
- }
-
- @Test
- public void testIsRedirectedInvalidInput() throws Exception {
- final DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
- final HttpClientContext context = HttpClientContext.create();
- final HttpGet httpget = new HttpGet("http://localhost/");
- final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_SEE_OTHER, "Redirect");
- try {
- redirectStrategy.isRedirected(null, response, context);
- Assert.fail("IllegalArgumentException expected");
- } catch (final IllegalArgumentException expected) {
- }
- try {
- redirectStrategy.isRedirected(httpget, null, context);
- Assert.fail("IllegalArgumentException expected");
- } catch (final IllegalArgumentException expected) {
- }
- }
-
- @Test
- public void testGetLocationUri() throws Exception {
- final DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
- final HttpClientContext context = HttpClientContext.create();
- final HttpGet httpget = new HttpGet("http://localhost/");
- final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_MOVED_TEMPORARILY, "Redirect");
- response.addHeader("Location", "http://localhost/stuff");
- final URI uri = redirectStrategy.getLocationURI(httpget, response, context);
- Assert.assertEquals(URI.create("http://localhost/stuff"), uri);
- }
-
- @Test(expected=HttpException.class)
- public void testGetLocationUriMissingHeader() throws Exception {
- final DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
- final HttpClientContext context = HttpClientContext.create();
- final HttpGet httpget = new HttpGet("http://localhost/");
- final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_MOVED_TEMPORARILY, "Redirect");
- redirectStrategy.getLocationURI(httpget, response, context);
- }
-
- @Test(expected=ProtocolException.class)
- public void testGetLocationUriInvalidLocation() throws Exception {
- final DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
- final HttpClientContext context = HttpClientContext.create();
- final HttpGet httpget = new HttpGet("http://localhost/");
- final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_MOVED_TEMPORARILY, "Redirect");
- response.addHeader("Location", "http://localhost/not valid");
- redirectStrategy.getLocationURI(httpget, response, context);
- }
-
- @Test
- public void testGetLocationUriRelative() throws Exception {
- final DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
- final HttpClientContext context = HttpClientContext.create();
- final HttpGet httpget = new HttpGet("http://localhost/");
- final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_MOVED_TEMPORARILY, "Redirect");
- response.addHeader("Location", "/stuff");
- final URI uri = redirectStrategy.getLocationURI(httpget, response, context);
- Assert.assertEquals(URI.create("http://localhost/stuff"), uri);
- }
-
- @Test
- public void testGetLocationUriRelativeWithFragment() throws Exception {
- final DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
- final HttpClientContext context = HttpClientContext.create();
- final HttpGet httpget = new HttpGet("http://localhost/");
- final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_MOVED_TEMPORARILY, "Redirect");
- response.addHeader("Location", "/stuff#fragment");
- final URI uri = redirectStrategy.getLocationURI(httpget, response, context);
- Assert.assertEquals(URI.create("http://localhost/stuff#fragment"), uri);
- }
-
- @Test
- public void testGetLocationUriAbsoluteWithFragment() throws Exception {
- final DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
- final HttpClientContext context = HttpClientContext.create();
- final HttpGet httpget = new HttpGet("http://localhost/");
- final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_MOVED_TEMPORARILY, "Redirect");
- response.addHeader("Location", "http://localhost/stuff#fragment");
- final URI uri = redirectStrategy.getLocationURI(httpget, response, context);
- Assert.assertEquals(URI.create("http://localhost/stuff#fragment"), uri);
- }
-
- @Test
- public void testGetLocationUriNormalized() throws Exception {
- final DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
- final HttpClientContext context = HttpClientContext.create();
- final HttpGet httpget = new HttpGet("http://localhost/");
- final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_MOVED_TEMPORARILY, "Redirect");
- response.addHeader("Location", "http://localhost/././stuff/../morestuff");
- final URI uri = redirectStrategy.getLocationURI(httpget, response, context);
- Assert.assertEquals(URI.create("http://localhost/morestuff"), uri);
- }
-
- @Test
- public void testGetLocationUriAllowCircularRedirects() throws Exception {
- final DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
- final HttpClientContext context = HttpClientContext.create();
- final RequestConfig config = RequestConfig.custom().setCircularRedirectsAllowed(true).build();
- context.setRequestConfig(config);
- final URI uri1 = URI.create("http://localhost/stuff1");
- final URI uri2 = URI.create("http://localhost/stuff2");
- final URI uri3 = URI.create("http://localhost/stuff3");
- final HttpGet httpget1 = new HttpGet("http://localhost/");
- final HttpResponse response1 = new BasicHttpResponse(HttpStatus.SC_MOVED_TEMPORARILY, "Redirect");
- response1.addHeader("Location", uri1.toASCIIString());
- final HttpGet httpget2 = new HttpGet(uri1.toASCIIString());
- final HttpResponse response2 = new BasicHttpResponse(HttpStatus.SC_MOVED_TEMPORARILY, "Redirect");
- response2.addHeader("Location", uri2.toASCIIString());
- final HttpGet httpget3 = new HttpGet(uri2.toASCIIString());
- final HttpResponse response3 = new BasicHttpResponse(HttpStatus.SC_MOVED_TEMPORARILY, "Redirect");
- response3.addHeader("Location", uri3.toASCIIString());
- Assert.assertEquals(uri1, redirectStrategy.getLocationURI(httpget1, response1, context));
- Assert.assertEquals(uri2, redirectStrategy.getLocationURI(httpget2, response2, context));
- Assert.assertEquals(uri3, redirectStrategy.getLocationURI(httpget3, response3, context));
-
- final List<URI> uris = context.getRedirectLocations();
- Assert.assertNotNull(uris);
- Assert.assertTrue(uris.contains(uri1));
- Assert.assertTrue(uris.contains(uri2));
- Assert.assertTrue(uris.contains(uri3));
- Assert.assertEquals(3, uris.size());
- Assert.assertEquals(uri1, uris.get(0));
- Assert.assertEquals(uri2, uris.get(1));
- Assert.assertEquals(uri3, uris.get(2));
- }
-
- @Test(expected=ProtocolException.class)
- public void testGetLocationUriDisallowCircularRedirects() throws Exception {
- final DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
- final HttpClientContext context = HttpClientContext.create();
- final HttpGet httpget = new HttpGet("http://localhost/stuff");
- final RequestConfig config = RequestConfig.custom().setCircularRedirectsAllowed(false).build();
- context.setRequestConfig(config);
- final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_MOVED_TEMPORARILY, "Redirect");
- response.addHeader("Location", "http://localhost/stuff");
- final URI uri = URI.create("http://localhost/stuff");
- Assert.assertEquals(uri, redirectStrategy.getLocationURI(httpget, response, context));
- redirectStrategy.getLocationURI(httpget, response, context);
- }
-
- @Test
- public void testGetLocationUriInvalidInput() throws Exception {
- final DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
- final HttpClientContext context = HttpClientContext.create();
- final HttpGet httpget = new HttpGet("http://localhost/");
- final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_MOVED_TEMPORARILY, "Redirect");
- response.addHeader("Location", "http://localhost/stuff");
- try {
- redirectStrategy.getLocationURI(null, response, context);
- Assert.fail("IllegalArgumentException expected");
- } catch (final IllegalArgumentException expected) {
- }
- try {
- redirectStrategy.getLocationURI(httpget, null, context);
- Assert.fail("IllegalArgumentException expected");
- } catch (final IllegalArgumentException expected) {
- }
- try {
- redirectStrategy.getLocationURI(httpget, response, null);
- Assert.fail("IllegalArgumentException expected");
- } catch (final IllegalArgumentException expected) {
- }
- }
-
- @Test
- public void testCreateLocationURI() throws Exception {
- final DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
- Assert.assertEquals("http://blahblah/",
- redirectStrategy.createLocationURI("http://BlahBlah").toASCIIString());
- }
-
- @Test(expected=ProtocolException.class)
- public void testCreateLocationURIInvalid() throws Exception {
- final DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
- redirectStrategy.createLocationURI(":::::::");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/MockClock.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/MockClock.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/MockClock.java
deleted file mode 100644
index 4b1238c..0000000
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/MockClock.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-package org.apache.hc.client5.http.impl.sync;
-
-public class MockClock implements Clock {
-
- private long t = System.currentTimeMillis();
-
- @Override
- public long getCurrentTime() {
- return t;
- }
-
- public void setCurrentTime(final long now) {
- t = now;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/MockConnPoolControl.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/MockConnPoolControl.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/MockConnPoolControl.java
deleted file mode 100644
index f055c2c..0000000
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/MockConnPoolControl.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-package org.apache.hc.client5.http.impl.sync;
-
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.apache.hc.client5.http.HttpRoute;
-import org.apache.hc.core5.pool.ConnPoolControl;
-import org.apache.hc.core5.pool.PoolStats;
-import org.apache.hc.core5.util.TimeValue;
-
-public final class MockConnPoolControl implements ConnPoolControl<HttpRoute> {
-
- private final ConcurrentHashMap<HttpRoute, Integer> maxPerHostMap;
-
- private volatile int totalMax;
- private volatile int defaultMax;
-
- public MockConnPoolControl() {
- super();
- this.maxPerHostMap = new ConcurrentHashMap<>();
- this.totalMax = 20;
- this.defaultMax = 2;
- }
-
- @Override
- public void setMaxTotal(final int max) {
- this.totalMax = max;
- }
-
- @Override
- public int getMaxTotal() {
- return this.totalMax;
- }
-
- @Override
- public PoolStats getTotalStats() {
- return new PoolStats(-1, -1, -1, this.totalMax);
- }
-
- @Override
- public PoolStats getStats(final HttpRoute route) {
- return new PoolStats(-1, -1, -1, getMaxPerRoute(route));
- }
-
- @Override
- public int getDefaultMaxPerRoute() {
- return this.defaultMax;
- }
-
- @Override
- public void setDefaultMaxPerRoute(final int max) {
- this.defaultMax = max;
- }
-
- @Override
- public void setMaxPerRoute(final HttpRoute route, final int max) {
- this.maxPerHostMap.put(route, Integer.valueOf(max));
- }
-
- @Override
- public int getMaxPerRoute(final HttpRoute route) {
- final Integer max = this.maxPerHostMap.get(route);
- if (max != null) {
- return max.intValue();
- } else {
- return this.defaultMax;
- }
- }
-
- @Override
- public void closeIdle(final TimeValue idletime) {
- }
-
- @Override
- public void closeExpired() {
- }
-
- public void setMaxForRoutes(final Map<HttpRoute, Integer> map) {
- if (map == null) {
- return;
- }
- this.maxPerHostMap.clear();
- this.maxPerHostMap.putAll(map);
- }
-
- @Override
- public String toString() {
- return this.maxPerHostMap.toString();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestAIMDBackoffManager.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestAIMDBackoffManager.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestAIMDBackoffManager.java
deleted file mode 100644
index ff1d235..0000000
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestAIMDBackoffManager.java
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-package org.apache.hc.client5.http.impl.sync;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Random;
-
-import org.apache.hc.client5.http.HttpRoute;
-import org.apache.hc.client5.http.sync.BackoffManager;
-import org.apache.hc.core5.http.HttpHost;
-import org.junit.Before;
-import org.junit.Test;
-
-public class TestAIMDBackoffManager {
-
- private AIMDBackoffManager impl;
- private MockConnPoolControl connPerRoute;
- private HttpRoute route;
- private MockClock clock;
-
- @Before
- public void setUp() {
- connPerRoute = new MockConnPoolControl();
- route = new HttpRoute(new HttpHost("localhost", 80));
- clock = new MockClock();
- impl = new AIMDBackoffManager(connPerRoute, clock);
- impl.setPerHostConnectionCap(10);
- }
-
- @Test
- public void isABackoffManager() {
- assertTrue(impl instanceof BackoffManager);
- }
-
- @Test
- public void halvesConnectionsOnBackoff() {
- connPerRoute.setMaxPerRoute(route, 4);
- impl.backOff(route);
- assertEquals(2, connPerRoute.getMaxPerRoute(route));
- }
-
- @Test
- public void doesNotBackoffBelowOneConnection() {
- connPerRoute.setMaxPerRoute(route, 1);
- impl.backOff(route);
- assertEquals(1, connPerRoute.getMaxPerRoute(route));
- }
-
- @Test
- public void increasesByOneOnProbe() {
- connPerRoute.setMaxPerRoute(route, 2);
- impl.probe(route);
- assertEquals(3, connPerRoute.getMaxPerRoute(route));
- }
-
- @Test
- public void doesNotIncreaseBeyondPerHostMaxOnProbe() {
- connPerRoute.setDefaultMaxPerRoute(5);
- connPerRoute.setMaxPerRoute(route, 5);
- impl.setPerHostConnectionCap(5);
- impl.probe(route);
- assertEquals(5, connPerRoute.getMaxPerRoute(route));
- }
-
- @Test
- public void backoffDoesNotAdjustDuringCoolDownPeriod() {
- connPerRoute.setMaxPerRoute(route, 4);
- final long now = System.currentTimeMillis();
- clock.setCurrentTime(now);
- impl.backOff(route);
- final long max = connPerRoute.getMaxPerRoute(route);
- clock.setCurrentTime(now + 1);
- impl.backOff(route);
- assertEquals(max, connPerRoute.getMaxPerRoute(route));
- }
-
- @Test
- public void backoffStillAdjustsAfterCoolDownPeriod() {
- connPerRoute.setMaxPerRoute(route, 8);
- final long now = System.currentTimeMillis();
- clock.setCurrentTime(now);
- impl.backOff(route);
- final long max = connPerRoute.getMaxPerRoute(route);
- clock.setCurrentTime(now + 10 * 1000L);
- impl.backOff(route);
- assertTrue(max == 1 || max > connPerRoute.getMaxPerRoute(route));
- }
-
- @Test
- public void probeDoesNotAdjustDuringCooldownPeriod() {
- connPerRoute.setMaxPerRoute(route, 4);
- final long now = System.currentTimeMillis();
- clock.setCurrentTime(now);
- impl.probe(route);
- final long max = connPerRoute.getMaxPerRoute(route);
- clock.setCurrentTime(now + 1);
- impl.probe(route);
- assertEquals(max, connPerRoute.getMaxPerRoute(route));
- }
-
- @Test
- public void probeStillAdjustsAfterCoolDownPeriod() {
- connPerRoute.setMaxPerRoute(route, 8);
- final long now = System.currentTimeMillis();
- clock.setCurrentTime(now);
- impl.probe(route);
- final long max = connPerRoute.getMaxPerRoute(route);
- clock.setCurrentTime(now + 10 * 1000L);
- impl.probe(route);
- assertTrue(max < connPerRoute.getMaxPerRoute(route));
- }
-
- @Test
- public void willBackoffImmediatelyEvenAfterAProbe() {
- connPerRoute.setMaxPerRoute(route, 8);
- final long now = System.currentTimeMillis();
- clock.setCurrentTime(now);
- impl.probe(route);
- final long max = connPerRoute.getMaxPerRoute(route);
- clock.setCurrentTime(now + 1);
- impl.backOff(route);
- assertTrue(connPerRoute.getMaxPerRoute(route) < max);
- }
-
- @Test
- public void backOffFactorIsConfigurable() {
- connPerRoute.setMaxPerRoute(route, 10);
- impl.setBackoffFactor(0.9);
- impl.backOff(route);
- assertEquals(9, connPerRoute.getMaxPerRoute(route));
- }
-
- @Test
- public void coolDownPeriodIsConfigurable() {
- long cd = new Random().nextLong() / 2;
- if (cd < 0) {
- cd *= -1;
- }
- if (cd < 1) {
- cd++;
- }
- final long now = System.currentTimeMillis();
- impl.setCooldownMillis(cd);
- clock.setCurrentTime(now);
- impl.probe(route);
- final int max0 = connPerRoute.getMaxPerRoute(route);
- clock.setCurrentTime(now);
- impl.probe(route);
- assertEquals(max0, connPerRoute.getMaxPerRoute(route));
- clock.setCurrentTime(now + cd + 1);
- impl.probe(route);
- assertTrue(max0 < connPerRoute.getMaxPerRoute(route));
- }
-}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestCloseableHttpClient.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestCloseableHttpClient.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestCloseableHttpClient.java
deleted file mode 100644
index 99687d6..0000000
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestCloseableHttpClient.java
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-package org.apache.hc.client5.http.impl.sync;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-import org.apache.hc.client5.http.sync.methods.HttpGet;
-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.HttpHost;
-import org.apache.hc.core5.http.HttpResponse;
-import org.apache.hc.core5.http.io.HttpClientResponseHandler;
-import org.apache.hc.core5.http.protocol.HttpContext;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mockito;
-
-/**
- * Simple tests for {@link CloseableHttpClient}.
- */
-@SuppressWarnings({"boxing","static-access"}) // test code
-public class TestCloseableHttpClient {
-
- static abstract class NoopCloseableHttpClient extends CloseableHttpClient {
-
- @Override
- protected CloseableHttpResponse doExecute(
- final HttpHost target,
- final ClassicHttpRequest request,
- final HttpContext context) throws IOException {
- return null;
- }
-
- }
-
- private NoopCloseableHttpClient client;
- private InputStream content;
- private HttpEntity entity;
- private ClassicHttpResponse originResponse;
- private CloseableHttpResponse response;
-
- @Before
- public void setup() throws Exception {
- content = Mockito.mock(InputStream.class);
- entity = Mockito.mock(HttpEntity.class);
- originResponse = Mockito.mock(ClassicHttpResponse.class);
- response = CloseableHttpResponse.adapt(originResponse);
- Mockito.when(entity.getContent()).thenReturn(content);
- Mockito.when(entity.isStreaming()).thenReturn(Boolean.TRUE);
- Mockito.when(response.getEntity()).thenReturn(entity);
- client = Mockito.mock(NoopCloseableHttpClient.class, Mockito.CALLS_REAL_METHODS);
- }
-
- @Test
- public void testExecuteRequestAbsoluteURI() throws Exception {
- final HttpGet httpget = new HttpGet("https://somehost:444/stuff");
- client.execute(httpget);
-
- Mockito.verify(client).doExecute(
- Mockito.eq(new HttpHost("somehost", 444, "https")),
- Mockito.same(httpget),
- (HttpContext) Mockito.isNull());
- }
-
- @Test
- public void testExecuteRequestRelativeURI() throws Exception {
- final HttpGet httpget = new HttpGet("/stuff");
- client.execute(httpget);
-
- Mockito.verify(client).doExecute(
- (HttpHost) Mockito.isNull(),
- Mockito.same(httpget),
- (HttpContext) Mockito.isNull());
- }
-
- @Test
- public void testExecuteRequest() throws Exception {
- final HttpGet httpget = new HttpGet("https://somehost:444/stuff");
-
- Mockito.when(client.doExecute(
- new HttpHost("somehost", 444, "https"), httpget, null)).thenReturn(response);
-
- final CloseableHttpResponse result = client.execute(httpget);
- Assert.assertSame(response, result);
- }
-
- @Test
- @SuppressWarnings("unchecked")
- public void testExecuteRequestHandleResponse() throws Exception {
- final HttpGet httpget = new HttpGet("https://somehost:444/stuff");
-
- Mockito.when(client.doExecute(
- new HttpHost("somehost", 444, "https"), httpget, null)).thenReturn(response);
-
- final HttpClientResponseHandler<HttpResponse> handler = Mockito.mock(HttpClientResponseHandler.class);
-
- client.execute(httpget, handler);
-
- Mockito.verify(client).doExecute(
- Mockito.eq(new HttpHost("somehost", 444, "https")),
- Mockito.same(httpget),
- (HttpContext) Mockito.isNull());
- Mockito.verify(handler).handleResponse(response);
- Mockito.verify(content).close();
- }
-
- @Test(expected=IOException.class)
- @SuppressWarnings("unchecked")
- public void testExecuteRequestHandleResponseIOException() throws Exception {
- final HttpGet httpget = new HttpGet("https://somehost:444/stuff");
-
- Mockito.when(client.doExecute(
- new HttpHost("somehost", 444, "https"), httpget, null)).thenReturn(response);
-
- final HttpClientResponseHandler<HttpResponse> handler = Mockito.mock(HttpClientResponseHandler.class);
-
- Mockito.when(handler.handleResponse(response)).thenThrow(new IOException());
-
- try {
- client.execute(httpget, handler);
- } catch (final IOException ex) {
- Mockito.verify(client).doExecute(
- Mockito.eq(new HttpHost("somehost", 444, "https")),
- Mockito.same(httpget),
- (HttpContext) Mockito.isNull());
- Mockito.verify(originResponse).close();
- throw ex;
- }
- }
-
- @Test(expected=RuntimeException.class)
- @SuppressWarnings("unchecked")
- public void testExecuteRequestHandleResponseHttpException() throws Exception {
- final HttpGet httpget = new HttpGet("https://somehost:444/stuff");
-
- Mockito.when(client.doExecute(
- new HttpHost("somehost", 444, "https"), httpget, null)).thenReturn(response);
-
- final HttpClientResponseHandler<HttpResponse> handler = Mockito.mock(HttpClientResponseHandler.class);
-
- Mockito.when(handler.handleResponse(response)).thenThrow(new RuntimeException());
-
- try {
- client.execute(httpget, handler);
- } catch (final RuntimeException ex) {
- Mockito.verify(client).doExecute(
- Mockito.eq(new HttpHost("somehost", 444, "https")),
- Mockito.same(httpget),
- (HttpContext) Mockito.isNull());
- Mockito.verify(response).close();
- throw ex;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestConnectExec.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestConnectExec.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestConnectExec.java
deleted file mode 100644
index 8410aa7..0000000
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestConnectExec.java
+++ /dev/null
@@ -1,357 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-package org.apache.hc.client5.http.impl.sync;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.util.Collections;
-import java.util.Map;
-
-import org.apache.hc.client5.http.HttpRoute;
-import org.apache.hc.client5.http.RouteInfo;
-import org.apache.hc.client5.http.auth.AuthChallenge;
-import org.apache.hc.client5.http.auth.AuthScheme;
-import org.apache.hc.client5.http.auth.AuthScope;
-import org.apache.hc.client5.http.auth.ChallengeType;
-import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
-import org.apache.hc.client5.http.entity.EntityBuilder;
-import org.apache.hc.client5.http.impl.auth.BasicScheme;
-import org.apache.hc.client5.http.protocol.AuthenticationStrategy;
-import org.apache.hc.client5.http.protocol.HttpClientContext;
-import org.apache.hc.client5.http.sync.ExecChain;
-import org.apache.hc.client5.http.sync.ExecRuntime;
-import org.apache.hc.client5.http.sync.methods.HttpGet;
-import org.apache.hc.core5.http.ClassicHttpRequest;
-import org.apache.hc.core5.http.ClassicHttpResponse;
-import org.apache.hc.core5.http.ConnectionReuseStrategy;
-import org.apache.hc.core5.http.HttpException;
-import org.apache.hc.core5.http.HttpHeaders;
-import org.apache.hc.core5.http.HttpHost;
-import org.apache.hc.core5.http.HttpRequest;
-import org.apache.hc.core5.http.HttpResponse;
-import org.apache.hc.core5.http.HttpVersion;
-import org.apache.hc.core5.http.io.entity.StringEntity;
-import org.apache.hc.core5.http.message.BasicClassicHttpResponse;
-import org.apache.hc.core5.http.protocol.HttpProcessor;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-
-@SuppressWarnings({"boxing","static-access"}) // test code
-public class TestConnectExec {
-
- @Mock
- private ConnectionReuseStrategy reuseStrategy;
- @Mock
- private HttpProcessor proxyHttpProcessor;
- @Mock
- private AuthenticationStrategy proxyAuthStrategy;
- @Mock
- private ExecRuntime execRuntime;
- @Mock
- private ExecChain execChain;
-
- private ConnectExec exec;
- private HttpHost target;
- private HttpHost proxy;
-
- @Before
- public void setup() throws Exception {
- MockitoAnnotations.initMocks(this);
- exec = new ConnectExec(reuseStrategy, proxyHttpProcessor, proxyAuthStrategy);
- target = new HttpHost("foo", 80);
- proxy = new HttpHost("bar", 8888);
- }
-
- @Test
- public void testExecAcquireConnection() throws Exception {
- final HttpRoute route = new HttpRoute(target);
- final HttpClientContext context = new HttpClientContext();
- final ClassicHttpRequest request = new HttpGet("http://bar/test");
- final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
- response.setEntity(EntityBuilder.create()
- .setStream(new ByteArrayInputStream(new byte[]{}))
- .build());
- context.setUserToken("Blah");
-
- Mockito.when(execRuntime.isConnectionAcquired()).thenReturn(false);
- Mockito.when(execRuntime.execute(
- Mockito.same(request),
- Mockito.<HttpClientContext>any())).thenReturn(response);
- Mockito.when(reuseStrategy.keepAlive(
- Mockito.same(request),
- Mockito.same(response),
- Mockito.<HttpClientContext>any())).thenReturn(false);
- final ExecChain.Scope scope = new ExecChain.Scope(route, request, execRuntime, context);
- exec.execute(request, scope, execChain);
- Mockito.verify(execRuntime).acquireConnection(route, "Blah", context);
- Mockito.verify(execRuntime).connect(context);
- }
-
- @Test
- public void testEstablishDirectRoute() throws Exception {
- final HttpRoute route = new HttpRoute(target);
- final HttpClientContext context = new HttpClientContext();
- final ClassicHttpRequest request = new HttpGet("http://bar/test");
-
- final ConnectionState connectionState = new ConnectionState();
- Mockito.doAnswer(connectionState.connectAnswer()).when(execRuntime).connect(Mockito.<HttpClientContext>any());
- Mockito.when(execRuntime.isConnected()).thenAnswer(connectionState.isConnectedAnswer());
-
- final ExecChain.Scope scope = new ExecChain.Scope(route, request, execRuntime, context);
- exec.execute(request, scope, execChain);
-
- Mockito.verify(execRuntime).connect(context);
- Mockito.verify(execRuntime, Mockito.never()).execute(Mockito.<ClassicHttpRequest>any(), Mockito.<HttpClientContext>any());
- }
-
- @Test
- public void testEstablishRouteDirectProxy() throws Exception {
- final HttpRoute route = new HttpRoute(target, null, proxy, false);
- final HttpClientContext context = new HttpClientContext();
- final ClassicHttpRequest request = new HttpGet("http://bar/test");
-
- final ConnectionState connectionState = new ConnectionState();
- Mockito.doAnswer(connectionState.connectAnswer()).when(execRuntime).connect(Mockito.<HttpClientContext>any());
- Mockito.when(execRuntime.isConnected()).thenAnswer(connectionState.isConnectedAnswer());
-
- final ExecChain.Scope scope = new ExecChain.Scope(route, request, execRuntime, context);
- exec.execute(request, scope, execChain);
-
- Mockito.verify(execRuntime).connect(context);
- Mockito.verify(execRuntime, Mockito.never()).execute(Mockito.<ClassicHttpRequest>any(), Mockito.<HttpClientContext>any());
- }
-
- @Test
- public void testEstablishRouteViaProxyTunnel() throws Exception {
- final HttpRoute route = new HttpRoute(target, null, proxy, true);
- final HttpClientContext context = new HttpClientContext();
- final ClassicHttpRequest request = new HttpGet("http://bar/test");
- final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
-
- final ConnectionState connectionState = new ConnectionState();
- Mockito.doAnswer(connectionState.connectAnswer()).when(execRuntime).connect(Mockito.<HttpClientContext>any());
- Mockito.when(execRuntime.isConnected()).thenAnswer(connectionState.isConnectedAnswer());
- Mockito.when(execRuntime.execute(
- Mockito.<ClassicHttpRequest>any(),
- Mockito.<HttpClientContext>any())).thenReturn(response);
-
- final ExecChain.Scope scope = new ExecChain.Scope(route, request, execRuntime, context);
- exec.execute(request, scope, execChain);
-
- Mockito.verify(execRuntime).connect(context);
- final ArgumentCaptor<ClassicHttpRequest> reqCaptor = ArgumentCaptor.forClass(ClassicHttpRequest.class);
- Mockito.verify(execRuntime).execute(
- reqCaptor.capture(),
- Mockito.same(context));
- final HttpRequest connect = reqCaptor.getValue();
- Assert.assertNotNull(connect);
- Assert.assertEquals("CONNECT", connect.getMethod());
- Assert.assertEquals(HttpVersion.HTTP_1_1, connect.getVersion());
- Assert.assertEquals("foo:80", connect.getRequestUri());
- }
-
- @Test(expected = HttpException.class)
- public void testEstablishRouteViaProxyTunnelUnexpectedResponse() throws Exception {
- final HttpRoute route = new HttpRoute(target, null, proxy, true);
- final HttpClientContext context = new HttpClientContext();
- final ClassicHttpRequest request = new HttpGet("http://bar/test");
- final ClassicHttpResponse response = new BasicClassicHttpResponse(101, "Lost");
-
- final ConnectionState connectionState = new ConnectionState();
- Mockito.doAnswer(connectionState.connectAnswer()).when(execRuntime).connect(Mockito.<HttpClientContext>any());
- Mockito.when(execRuntime.isConnected()).thenAnswer(connectionState.isConnectedAnswer());
- Mockito.when(execRuntime.execute(
- Mockito.<ClassicHttpRequest>any(),
- Mockito.<HttpClientContext>any())).thenReturn(response);
-
- final ExecChain.Scope scope = new ExecChain.Scope(route, request, execRuntime, context);
- exec.execute(request, scope, execChain);
- }
-
- @Test(expected = HttpException.class)
- public void testEstablishRouteViaProxyTunnelFailure() throws Exception {
- final HttpRoute route = new HttpRoute(target, null, proxy, true);
- final HttpClientContext context = new HttpClientContext();
- final ClassicHttpRequest request = new HttpGet("http://bar/test");
- final ClassicHttpResponse response = new BasicClassicHttpResponse(500, "Boom");
- response.setEntity(new StringEntity("Ka-boom"));
-
- final ConnectionState connectionState = new ConnectionState();
- Mockito.doAnswer(connectionState.connectAnswer()).when(execRuntime).connect(Mockito.<HttpClientContext>any());
- Mockito.when(execRuntime.isConnected()).thenAnswer(connectionState.isConnectedAnswer());
- Mockito.when(execRuntime.execute(
- Mockito.<ClassicHttpRequest>any(),
- Mockito.<HttpClientContext>any())).thenReturn(response);
-
- final ExecChain.Scope scope = new ExecChain.Scope(route, request, execRuntime, context);
- try {
- exec.execute(request, scope, execChain);
- } catch (final TunnelRefusedException ex) {
- Assert.assertEquals("Ka-boom", ex.getResponseMessage());
- Mockito.verify(execRuntime).disconnect();
- Mockito.verify(execRuntime).discardConnection();
- throw ex;
- }
- }
-
- @Test
- public void testEstablishRouteViaProxyTunnelRetryOnAuthChallengePersistentConnection() throws Exception {
- final HttpRoute route = new HttpRoute(target, null, proxy, true);
- final HttpClientContext context = new HttpClientContext();
- final ClassicHttpRequest request = new HttpGet("http://bar/test");
- final ClassicHttpResponse response1 = new BasicClassicHttpResponse(407, "Huh?");
- response1.setHeader(HttpHeaders.PROXY_AUTHENTICATE, "Basic realm=test");
- final InputStream instream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3}));
- response1.setEntity(EntityBuilder.create()
- .setStream(instream1)
- .build());
- final ClassicHttpResponse response2 = new BasicClassicHttpResponse(200, "OK");
-
- final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
- credentialsProvider.setCredentials(new AuthScope(proxy), new UsernamePasswordCredentials("user", "pass".toCharArray()));
- context.setCredentialsProvider(credentialsProvider);
-
- final ConnectionState connectionState = new ConnectionState();
- Mockito.doAnswer(connectionState.connectAnswer()).when(execRuntime).connect(Mockito.<HttpClientContext>any());
- Mockito.when(execRuntime.isConnected()).thenAnswer(connectionState.isConnectedAnswer());
- Mockito.when(reuseStrategy.keepAlive(
- Mockito.same(request),
- Mockito.<HttpResponse>any(),
- Mockito.<HttpClientContext>any())).thenReturn(Boolean.TRUE);
- Mockito.when(execRuntime.execute(
- Mockito.<ClassicHttpRequest>any(),
- Mockito.<HttpClientContext>any())).thenReturn(response1, response2);
-
- Mockito.when(proxyAuthStrategy.select(
- Mockito.eq(ChallengeType.PROXY),
- Mockito.<Map<String, AuthChallenge>>any(),
- Mockito.<HttpClientContext>any())).thenReturn(Collections.<AuthScheme>singletonList(new BasicScheme()));
-
- final ExecChain.Scope scope = new ExecChain.Scope(route, request, execRuntime, context);
- exec.execute(request, scope, execChain);
-
- Mockito.verify(execRuntime).connect(context);
- Mockito.verify(instream1).close();
- }
-
- @Test
- public void testEstablishRouteViaProxyTunnelRetryOnAuthChallengeNonPersistentConnection() throws Exception {
- final HttpRoute route = new HttpRoute(target, null, proxy, true);
- final HttpClientContext context = new HttpClientContext();
- final ClassicHttpRequest request = new HttpGet("http://bar/test");
- final ClassicHttpResponse response1 = new BasicClassicHttpResponse(407, "Huh?");
- response1.setHeader(HttpHeaders.PROXY_AUTHENTICATE, "Basic realm=test");
- final InputStream instream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3}));
- response1.setEntity(EntityBuilder.create()
- .setStream(instream1)
- .build());
- final ClassicHttpResponse response2 = new BasicClassicHttpResponse(200, "OK");
-
- final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
- credentialsProvider.setCredentials(new AuthScope(proxy), new UsernamePasswordCredentials("user", "pass".toCharArray()));
- context.setCredentialsProvider(credentialsProvider);
-
- final ConnectionState connectionState = new ConnectionState();
- Mockito.doAnswer(connectionState.connectAnswer()).when(execRuntime).connect(Mockito.<HttpClientContext>any());
- Mockito.when(execRuntime.isConnected()).thenAnswer(connectionState.isConnectedAnswer());
- Mockito.when(reuseStrategy.keepAlive(
- Mockito.same(request),
- Mockito.<HttpResponse>any(),
- Mockito.<HttpClientContext>any())).thenReturn(Boolean.FALSE);
- Mockito.when(execRuntime.execute(
- Mockito.<ClassicHttpRequest>any(),
- Mockito.<HttpClientContext>any())).thenReturn(response1, response2);
-
- Mockito.when(proxyAuthStrategy.select(
- Mockito.eq(ChallengeType.PROXY),
- Mockito.<Map<String, AuthChallenge>>any(),
- Mockito.<HttpClientContext>any())).thenReturn(Collections.<AuthScheme>singletonList(new BasicScheme()));
-
- final ExecChain.Scope scope = new ExecChain.Scope(route, request, execRuntime, context);
- exec.execute(request, scope, execChain);
-
- Mockito.verify(execRuntime).connect(context);
- Mockito.verify(instream1, Mockito.never()).close();
- Mockito.verify(execRuntime).disconnect();
- }
-
- @Test(expected = HttpException.class)
- public void testEstablishRouteViaProxyTunnelMultipleHops() throws Exception {
- final HttpHost proxy1 = new HttpHost("this", 8888);
- final HttpHost proxy2 = new HttpHost("that", 8888);
- final HttpRoute route = new HttpRoute(target, null, new HttpHost[] {proxy1, proxy2},
- true, RouteInfo.TunnelType.TUNNELLED, RouteInfo.LayerType.LAYERED);
- final HttpClientContext context = new HttpClientContext();
- final ClassicHttpRequest request = new HttpGet("http://bar/test");
-
- final ConnectionState connectionState = new ConnectionState();
- Mockito.doAnswer(connectionState.connectAnswer()).when(execRuntime).connect(Mockito.<HttpClientContext>any());
- Mockito.when(execRuntime.isConnected()).thenAnswer(connectionState.isConnectedAnswer());
-
- final ExecChain.Scope scope = new ExecChain.Scope(route, request, execRuntime, context);
- exec.execute(request, scope, execChain);
- }
-
- static class ConnectionState {
-
- private boolean connected;
-
- public Answer connectAnswer() {
-
- return new Answer() {
-
- @Override
- public Object answer(final InvocationOnMock invocationOnMock) throws Throwable {
- connected = true;
- return null;
- }
-
- };
- }
-
- public Answer<Boolean> isConnectedAnswer() {
-
- return new Answer<Boolean>() {
-
- @Override
- public Boolean answer(final InvocationOnMock invocationOnMock) throws Throwable {
- return connected;
- }
-
- };
-
- };
- }
-
-}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestContentCompressionExec.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestContentCompressionExec.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestContentCompressionExec.java
deleted file mode 100644
index d3e1bfd..0000000
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestContentCompressionExec.java
+++ /dev/null
@@ -1,229 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-package org.apache.hc.client5.http.impl.sync;
-
-import org.apache.hc.client5.http.HttpRoute;
-import org.apache.hc.client5.http.StandardMethods;
-import org.apache.hc.client5.http.config.RequestConfig;
-import org.apache.hc.client5.http.entity.DecompressingEntity;
-import org.apache.hc.client5.http.entity.GzipDecompressingEntity;
-import org.apache.hc.client5.http.protocol.HttpClientContext;
-import org.apache.hc.client5.http.sync.ExecChain;
-import org.apache.hc.client5.http.sync.ExecRuntime;
-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.io.entity.StringEntity;
-import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
-import org.apache.hc.core5.http.message.BasicClassicHttpResponse;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
-
-@RunWith(MockitoJUnitRunner.class)
-public class TestContentCompressionExec {
-
- @Mock
- private ExecRuntime execRuntime;
- @Mock
- private ExecChain execChain;
- @Mock
- private ClassicHttpRequest originaRequest;
-
- private HttpClientContext context;
- private HttpHost host;
- private ExecChain.Scope scope;
- private ContentCompressionExec impl;
-
- @Before
- public void setup() {
- host = new HttpHost("somehost", 80);
- context = HttpClientContext.create();
- scope = new ExecChain.Scope(new HttpRoute(host), originaRequest, execRuntime, context);
- impl = new ContentCompressionExec();
- }
-
-
- @Test
- public void testContentEncodingNoEntity() throws Exception {
- final ClassicHttpRequest request = new BasicClassicHttpRequest(StandardMethods.GET.name(), host, "/");
- final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
-
- Mockito.when(execChain.proceed(request, scope)).thenReturn(response);
-
- impl.execute(request, scope, execChain);
-
- final HttpEntity entity = response.getEntity();
- Assert.assertNull(entity);
- }
-
- @Test
- public void testNoContentEncoding() throws Exception {
- final ClassicHttpRequest request = new BasicClassicHttpRequest(StandardMethods.GET.name(), host, "/");
- final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
- final StringEntity original = new StringEntity("plain stuff");
- response.setEntity(original);
-
- Mockito.when(execChain.proceed(request, scope)).thenReturn(response);
-
- impl.execute(request, scope, execChain);
-
- final HttpEntity entity = response.getEntity();
- Assert.assertNotNull(entity);
- Assert.assertTrue(entity instanceof StringEntity);
- }
-
- @Test
- public void testGzipContentEncoding() throws Exception {
- final ClassicHttpRequest request = new BasicClassicHttpRequest(StandardMethods.GET.name(), host, "/");
- final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
- final StringEntity original = new StringEntity("encoded stuff");
- original.setContentEncoding("GZip");
- response.setEntity(original);
-
- Mockito.when(execChain.proceed(request, scope)).thenReturn(response);
-
- impl.execute(request, scope, execChain);
-
- final HttpEntity entity = response.getEntity();
- Assert.assertNotNull(entity);
- Assert.assertTrue(entity instanceof DecompressingEntity);
- }
-
- @Test
- public void testGzipContentEncodingZeroLength() throws Exception {
- final ClassicHttpRequest request = new BasicClassicHttpRequest(StandardMethods.GET.name(), host, "/");
- final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
- final StringEntity original = new StringEntity("");
- original.setContentEncoding("GZip");
- response.setEntity(original);
-
- Mockito.when(execChain.proceed(request, scope)).thenReturn(response);
-
- impl.execute(request, scope, execChain);
-
- final HttpEntity entity = response.getEntity();
- Assert.assertNotNull(entity);
- Assert.assertTrue(entity instanceof StringEntity);
- }
-
- @Test
- public void testXGzipContentEncoding() throws Exception {
- final ClassicHttpRequest request = new BasicClassicHttpRequest(StandardMethods.GET.name(), host, "/");
- final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
- final StringEntity original = new StringEntity("encoded stuff");
- original.setContentEncoding("x-gzip");
- response.setEntity(original);
-
- Mockito.when(execChain.proceed(request, scope)).thenReturn(response);
-
- impl.execute(request, scope, execChain);
-
- final HttpEntity entity = response.getEntity();
- Assert.assertNotNull(entity);
- Assert.assertTrue(entity instanceof DecompressingEntity);
- }
-
- @Test
- public void testDeflateContentEncoding() throws Exception {
- final ClassicHttpRequest request = new BasicClassicHttpRequest(StandardMethods.GET.name(), host, "/");
- final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
- final StringEntity original = new StringEntity("encoded stuff");
- original.setContentEncoding("deFlaTe");
- response.setEntity(original);
-
- Mockito.when(execChain.proceed(request, scope)).thenReturn(response);
-
- impl.execute(request, scope, execChain);
-
- final HttpEntity entity = response.getEntity();
- Assert.assertNotNull(entity);
- Assert.assertTrue(entity instanceof DecompressingEntity);
- }
-
- @Test
- public void testIdentityContentEncoding() throws Exception {
- final ClassicHttpRequest request = new BasicClassicHttpRequest(StandardMethods.GET.name(), host, "/");
- final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
- final StringEntity original = new StringEntity("encoded stuff");
- original.setContentEncoding("identity");
- response.setEntity(original);
-
- Mockito.when(execChain.proceed(request, scope)).thenReturn(response);
-
- impl.execute(request, scope, execChain);
-
- final HttpEntity entity = response.getEntity();
- Assert.assertNotNull(entity);
- Assert.assertTrue(entity instanceof StringEntity);
- }
-
- @Test(expected=HttpException.class)
- public void testUnknownContentEncoding() throws Exception {
- final ClassicHttpRequest request = new BasicClassicHttpRequest(StandardMethods.GET.name(), host, "/");
- final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
- final StringEntity original = new StringEntity("encoded stuff");
- original.setContentEncoding("whatever");
- response.setEntity(original);
-
- impl = new ContentCompressionExec(false);
-
- Mockito.when(execChain.proceed(request, scope)).thenReturn(response);
-
- impl.execute(request, scope, execChain);
- }
-
- @Test
- public void testContentEncodingRequestParameter() throws Exception {
- final ClassicHttpRequest request = new BasicClassicHttpRequest(StandardMethods.GET.name(), host, "/");
- final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
- final StringEntity original = new StringEntity("encoded stuff");
- original.setContentEncoding("GZip");
- response.setEntity(original);
-
- final RequestConfig config = RequestConfig.custom()
- .setContentCompressionEnabled(false)
- .build();
-
- context.setAttribute(HttpClientContext.REQUEST_CONFIG, config);
-
- Mockito.when(execChain.proceed(request, scope)).thenReturn(response);
-
- impl.execute(request, scope, execChain);
-
- final HttpEntity entity = response.getEntity();
- Assert.assertNotNull(entity);
- Assert.assertFalse(entity instanceof GzipDecompressingEntity);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestCookieIdentityComparator.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestCookieIdentityComparator.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestCookieIdentityComparator.java
deleted file mode 100644
index a989396..0000000
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestCookieIdentityComparator.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-package org.apache.hc.client5.http.impl.sync;
-
-import org.apache.hc.client5.http.cookie.CookieIdentityComparator;
-import org.apache.hc.client5.http.impl.cookie.BasicClientCookie;
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- * Simple tests for {@link CookieIdentityComparator}.
- */
-public class TestCookieIdentityComparator {
-
- @Test
- public void testCookieIdentityComparasionByName() {
- final CookieIdentityComparator comparator = new CookieIdentityComparator();
- final BasicClientCookie c1 = new BasicClientCookie("name", "value1");
- final BasicClientCookie c2 = new BasicClientCookie("name", "value2");
- Assert.assertTrue(comparator.compare(c1, c2) == 0);
-
- final BasicClientCookie c3 = new BasicClientCookie("name1", "value");
- final BasicClientCookie c4 = new BasicClientCookie("name2", "value");
- Assert.assertFalse(comparator.compare(c3, c4) == 0);
- }
-
- @Test
- public void testCookieIdentityComparasionByNameAndDomain() {
- final CookieIdentityComparator comparator = new CookieIdentityComparator();
- final BasicClientCookie c1 = new BasicClientCookie("name", "value1");
- c1.setDomain("www.domain.com");
- final BasicClientCookie c2 = new BasicClientCookie("name", "value2");
- c2.setDomain("www.domain.com");
- Assert.assertTrue(comparator.compare(c1, c2) == 0);
-
- final BasicClientCookie c3 = new BasicClientCookie("name", "value1");
- c3.setDomain("www.domain.com");
- final BasicClientCookie c4 = new BasicClientCookie("name", "value2");
- c4.setDomain("domain.com");
- Assert.assertFalse(comparator.compare(c3, c4) == 0);
- }
-
- @Test
- public void testCookieIdentityComparasionByNameAndNullDomain() {
- final CookieIdentityComparator comparator = new CookieIdentityComparator();
- final BasicClientCookie c1 = new BasicClientCookie("name", "value1");
- c1.setDomain(null);
- final BasicClientCookie c2 = new BasicClientCookie("name", "value2");
- c2.setDomain(null);
- Assert.assertTrue(comparator.compare(c1, c2) == 0);
-
- final BasicClientCookie c3 = new BasicClientCookie("name", "value1");
- c3.setDomain("www.domain.com");
- final BasicClientCookie c4 = new BasicClientCookie("name", "value2");
- c4.setDomain(null);
- Assert.assertFalse(comparator.compare(c3, c4) == 0);
- }
-
- @Test
- public void testCookieIdentityComparasionByNameAndLocalHost() {
- final CookieIdentityComparator comparator = new CookieIdentityComparator();
- final BasicClientCookie c1 = new BasicClientCookie("name", "value1");
- c1.setDomain("localhost");
- final BasicClientCookie c2 = new BasicClientCookie("name", "value2");
- c2.setDomain("localhost");
- Assert.assertTrue(comparator.compare(c1, c2) == 0);
-
- final BasicClientCookie c3 = new BasicClientCookie("name", "value1");
- c3.setDomain("localhost.local");
- final BasicClientCookie c4 = new BasicClientCookie("name", "value2");
- c4.setDomain("localhost");
- Assert.assertTrue(comparator.compare(c3, c4) == 0);
- }
-
- @Test
- public void testCookieIdentityComparasionByNameDomainAndPath() {
- final CookieIdentityComparator comparator = new CookieIdentityComparator();
- final BasicClientCookie c1 = new BasicClientCookie("name", "value1");
- c1.setDomain("www.domain.com");
- c1.setPath("/whatever");
- final BasicClientCookie c2 = new BasicClientCookie("name", "value2");
- c2.setDomain("www.domain.com");
- c2.setPath("/whatever");
- Assert.assertTrue(comparator.compare(c1, c2) == 0);
-
- final BasicClientCookie c3 = new BasicClientCookie("name", "value1");
- c3.setDomain("www.domain.com");
- c3.setPath("/whatever");
- final BasicClientCookie c4 = new BasicClientCookie("name", "value2");
- c4.setDomain("domain.com");
- c4.setPath("/whatever-not");
- Assert.assertFalse(comparator.compare(c3, c4) == 0);
- }
-
- @Test
- public void testCookieIdentityComparasionByNameDomainAndNullPath() {
- final CookieIdentityComparator comparator = new CookieIdentityComparator();
- final BasicClientCookie c1 = new BasicClientCookie("name", "value1");
- c1.setDomain("www.domain.com");
- c1.setPath("/");
- final BasicClientCookie c2 = new BasicClientCookie("name", "value2");
- c2.setDomain("www.domain.com");
- c2.setPath(null);
- Assert.assertTrue(comparator.compare(c1, c2) == 0);
-
- final BasicClientCookie c3 = new BasicClientCookie("name", "value1");
- c3.setDomain("www.domain.com");
- c3.setPath("/whatever");
- final BasicClientCookie c4 = new BasicClientCookie("name", "value2");
- c4.setDomain("domain.com");
- c4.setPath(null);
- Assert.assertFalse(comparator.compare(c3, c4) == 0);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestDefaultBackoffStrategy.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestDefaultBackoffStrategy.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestDefaultBackoffStrategy.java
deleted file mode 100644
index 6e31465..0000000
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestDefaultBackoffStrategy.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-package org.apache.hc.client5.http.impl.sync;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.net.ConnectException;
-import java.net.SocketTimeoutException;
-
-import org.apache.hc.core5.http.ConnectionRequestTimeoutException;
-import org.apache.hc.core5.http.HttpResponse;
-import org.apache.hc.core5.http.HttpStatus;
-import org.apache.hc.core5.http.message.BasicHttpResponse;
-import org.junit.Before;
-import org.junit.Test;
-
-
-public class TestDefaultBackoffStrategy {
-
- private DefaultBackoffStrategy impl;
-
- @Before
- public void setUp() {
- impl = new DefaultBackoffStrategy();
- }
-
- @Test
- public void backsOffForSocketTimeouts() {
- assertTrue(impl.shouldBackoff(new SocketTimeoutException()));
- }
-
- @Test
- public void backsOffForConnectionTimeouts() {
- assertTrue(impl.shouldBackoff(new ConnectException()));
- }
-
- @Test
- public void doesNotBackOffForConnectionManagerTimeout() {
- assertFalse(impl.shouldBackoff(new ConnectionRequestTimeoutException()));
- }
-
- @Test
- public void backsOffForServiceUnavailable() {
- final HttpResponse resp = new BasicHttpResponse(HttpStatus.SC_SERVICE_UNAVAILABLE, "Service Unavailable");
- assertTrue(impl.shouldBackoff(resp));
- }
-
- @Test
- public void doesNotBackOffForNon503StatusCodes() {
- for(int i = 100; i <= 599; i++) {
- if (i == HttpStatus.SC_SERVICE_UNAVAILABLE) {
- continue;
- }
- final HttpResponse resp = new BasicHttpResponse(i, "Foo");
- assertFalse(impl.shouldBackoff(resp));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestDefaultHttpRequestRetryHandler.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestDefaultHttpRequestRetryHandler.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestDefaultHttpRequestRetryHandler.java
deleted file mode 100644
index e771ca2..0000000
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestDefaultHttpRequestRetryHandler.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-package org.apache.hc.client5.http.impl.sync;
-
-import java.io.IOException;
-import java.net.UnknownHostException;
-
-import org.apache.hc.client5.http.ConnectTimeoutException;
-import org.apache.hc.client5.http.sync.methods.HttpGet;
-import org.junit.Assert;
-import org.junit.Test;
-
-
-@SuppressWarnings("boxing") // test class
-public class TestDefaultHttpRequestRetryHandler {
-
- @Test
- public void noRetryOnConnectTimeout() throws Exception {
- final HttpGet request = new HttpGet("/");
-
- final DefaultHttpRequestRetryHandler retryHandler = new DefaultHttpRequestRetryHandler();
- Assert.assertEquals(3, retryHandler.getRetryCount());
-
- Assert.assertFalse(retryHandler.retryRequest(request, new ConnectTimeoutException(), 1, null));
- }
-
- @Test
- public void noRetryOnUnknownHost() throws Exception {
- final HttpGet request = new HttpGet("/");
-
- final DefaultHttpRequestRetryHandler retryHandler = new DefaultHttpRequestRetryHandler();
-
- Assert.assertFalse(retryHandler.retryRequest(request, new UnknownHostException(), 1, null));
- }
-
- @Test
- public void noRetryOnAbortedRequests() throws Exception{
- final HttpGet request = new HttpGet("/");
- request.abort();
-
- final DefaultHttpRequestRetryHandler retryHandler = new DefaultHttpRequestRetryHandler();
-
- Assert.assertFalse(retryHandler.retryRequest(request, new IOException(), 3, null));
- }
-
- @Test
- public void retryOnNonAbortedRequests() throws Exception{
- final HttpGet request = new HttpGet("/");
-
- final DefaultHttpRequestRetryHandler retryHandler = new DefaultHttpRequestRetryHandler();
-
- Assert.assertTrue(retryHandler.retryRequest(request, new IOException(), 3, null));
- }
-
- @Test
- public void noRetryOnConnectionTimeout() throws Exception{
- final HttpGet request = new HttpGet("/");
-
- final DefaultHttpRequestRetryHandler retryHandler = new DefaultHttpRequestRetryHandler();
-
- Assert.assertFalse(retryHandler.retryRequest(request, new ConnectTimeoutException(), 3, null));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestDefaultServiceUnavailableRetryStrategy.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestDefaultServiceUnavailableRetryStrategy.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestDefaultServiceUnavailableRetryStrategy.java
deleted file mode 100644
index 5175963..0000000
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestDefaultServiceUnavailableRetryStrategy.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-package org.apache.hc.client5.http.impl.sync;
-
-import java.util.Date;
-
-import org.apache.hc.client5.http.utils.DateUtils;
-import org.apache.hc.core5.http.HttpHeaders;
-import org.apache.hc.core5.http.HttpResponse;
-import org.apache.hc.core5.http.message.BasicHttpResponse;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-public class TestDefaultServiceUnavailableRetryStrategy {
-
- private DefaultServiceUnavailableRetryStrategy impl;
-
- @Before
- public void setup() {
- this.impl = new DefaultServiceUnavailableRetryStrategy(3, 1234);
- }
-
- @Test
- public void testBasics() throws Exception {
- final HttpResponse response1 = new BasicHttpResponse(503, "Oppsie");
- Assert.assertTrue(this.impl.retryRequest(response1, 1, null));
- Assert.assertTrue(this.impl.retryRequest(response1, 2, null));
- Assert.assertTrue(this.impl.retryRequest(response1, 3, null));
- Assert.assertFalse(this.impl.retryRequest(response1, 4, null));
- final HttpResponse response2 = new BasicHttpResponse(500, "Big Time Oppsie");
- Assert.assertFalse(this.impl.retryRequest(response2, 1, null));
-
- Assert.assertEquals(1234, this.impl.getRetryInterval(response1, null));
- }
-
- @Test
- public void testRetryAfterHeaderAsLong() throws Exception {
- final HttpResponse response = new BasicHttpResponse(503, "Oppsie");
- response.setHeader(HttpHeaders.RETRY_AFTER, "321");
-
- Assert.assertEquals(321000, this.impl.getRetryInterval(response, null));
- }
-
- @Test
- public void testRetryAfterHeaderAsDate() throws Exception {
- this.impl = new DefaultServiceUnavailableRetryStrategy(3, 1);
- final HttpResponse response = new BasicHttpResponse(503, "Oppsie");
-
- response.setHeader(HttpHeaders.RETRY_AFTER, DateUtils.formatDate(new Date(System.currentTimeMillis() + 100000L)));
-
- Assert.assertTrue(this.impl.getRetryInterval(response, null) > 1);
- }
-
- @Test
- public void testRetryAfterHeaderAsPastDate() throws Exception {
- final HttpResponse response = new BasicHttpResponse(503, "Oppsie");
-
- response.setHeader(HttpHeaders.RETRY_AFTER, DateUtils.formatDate(new Date(System.currentTimeMillis() - 100000L)));
-
- Assert.assertEquals(0, this.impl.getRetryInterval(response, null));
- }
-
- @Test
- public void testInvalidRetryAfterHeader() throws Exception {
- final DefaultServiceUnavailableRetryStrategy impl = new DefaultServiceUnavailableRetryStrategy(3, 1234);
-
- final HttpResponse response = new BasicHttpResponse(503, "Oppsie");
- response.setHeader(HttpHeaders.RETRY_AFTER, "Stuff");
-
- Assert.assertEquals(1234, impl.getRetryInterval(response, null));
- }
-
-}