You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2017/05/09 19:58:12 UTC
[20/50] [abbrv] httpcomponents-core git commit: [HTTPCORE-454] Add a
Timeout class that extends TimeValue. Add missing methods for MICROSECONDS
and NANOSECONDS TimeUnits.
[HTTPCORE-454] Add a Timeout class that extends TimeValue. Add missing methods for MICROSECONDS and NANOSECONDS TimeUnits.
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1792538 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/401ab249
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/401ab249
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/401ab249
Branch: refs/heads/trunk
Commit: 401ab2497bee953f988138d1ab0d493b29930fd3
Parents: 586bfb7
Author: Gary D. Gregory <gg...@apache.org>
Authored: Mon Apr 24 19:39:59 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Mon Apr 24 19:39:59 2017 +0000
----------------------------------------------------------------------
.../java/org/apache/hc/core5/util/Timeout.java | 35 +++++++++++++++---
.../org/apache/hc/core5/util/TestTimeout.java | 39 ++++++++++++++++++++
2 files changed, 68 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/401ab249/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java b/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java
index a7ee542..4cb3c38 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java
@@ -48,12 +48,12 @@ public class Timeout extends TimeValue {
/**
* An undefined timeout represented as -1 {@code MILLISECONDS}.
*/
- public static final Timeout UNDEFINED_MILLISECONDS = new Timeout(UNDEFINED, TimeUnit.MILLISECONDS);
+ public static final Timeout UNDEFINED_MILLISECONDS = new Timeout(INT_UNDEFINED, TimeUnit.MILLISECONDS);
/**
* An undefined timeout represented as -1 {@code SECONDS}.
*/
- public static final Timeout UNDEFINED_SECONDS = new Timeout(UNDEFINED, TimeUnit.SECONDS);
+ public static final Timeout UNDEFINED_SECONDS = new Timeout(INT_UNDEFINED, TimeUnit.SECONDS);
/**
* Creates a Timeout.
@@ -93,6 +93,17 @@ public class Timeout extends TimeValue {
/**
* Creates a Timeout.
*
+ * @param microseconds
+ * the duration in seconds and the given {@code timeUnit}.
+ * @return a Timeout
+ */
+ public static Timeout ofMicroseconds(final long microseconds) {
+ return of(microseconds, TimeUnit.MICROSECONDS);
+ }
+
+ /**
+ * Creates a Timeout.
+ *
* @param milliseconds
* the duration in milliseconds and the given {@code timeUnit}.
* @return a Timeout
@@ -115,6 +126,17 @@ public class Timeout extends TimeValue {
/**
* Creates a Timeout.
*
+ * @param nanoseconds
+ * the duration in seconds and the given {@code timeUnit}.
+ * @return a Timeout
+ */
+ public static Timeout ofNanoseconds(final long nanoseconds) {
+ return of(nanoseconds, TimeUnit.NANOSECONDS);
+ }
+
+ /**
+ * Creates a Timeout.
+ *
* @param seconds
* the duration in seconds and the given {@code timeUnit}.
* @return a Timeout
@@ -123,9 +145,10 @@ public class Timeout extends TimeValue {
return of(seconds, TimeUnit.SECONDS);
}
+
private static long validateDuration(final long duration) {
- if (duration < UNDEFINED) {
- throw new IllegalArgumentException("Duration may not be less than " + UNDEFINED);
+ if (duration < INT_UNDEFINED) {
+ throw new IllegalArgumentException("Duration may not be less than " + INT_UNDEFINED);
}
return duration;
}
@@ -158,7 +181,7 @@ public class Timeout extends TimeValue {
* @return Whether this timeout is undefined.
*/
public boolean isUndefinedMilliseconds() {
- return getDuration() == UNDEFINED && getTimeUnit() == TimeUnit.MILLISECONDS;
+ return getDuration() == INT_UNDEFINED && getTimeUnit() == TimeUnit.MILLISECONDS;
}
/**
@@ -167,7 +190,7 @@ public class Timeout extends TimeValue {
* @return Whether this timeout is undefined.
*/
public boolean isUndefinedSeconds() {
- return getDuration() == UNDEFINED && getTimeUnit() == TimeUnit.SECONDS;
+ return getDuration() == INT_UNDEFINED && getTimeUnit() == TimeUnit.SECONDS;
}
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/401ab249/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeout.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeout.java b/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeout.java
index 271a348..0fc3740 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeout.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeout.java
@@ -92,6 +92,45 @@ public class TestTimeout {
Assert.assertFalse(Timeout.DISABLED.isUndefinedSeconds());
}
+ private void testFactory(final TimeUnit timeUnit) {
+ Assert.assertEquals(timeUnit, Timeout.of(1, timeUnit).getTimeUnit());
+ }
+
+ @Test
+ public void testFactoryForDays() {
+ testFactory(TimeUnit.DAYS);
+ }
+
+ @Test
+ public void testFactoryForHours() {
+ testFactory(TimeUnit.HOURS);
+ }
+
+ @Test
+ public void testFactoryForMicroseconds() {
+ testFactory(TimeUnit.MICROSECONDS);
+ }
+
+ @Test
+ public void testFactoryForMillisseconds() {
+ testFactory(TimeUnit.MILLISECONDS);
+ }
+
+ @Test
+ public void testFactoryForMinutes() {
+ testFactory(TimeUnit.MINUTES);
+ }
+
+ @Test
+ public void testFactoryForNanoseconds() {
+ testFactory(TimeUnit.NANOSECONDS);
+ }
+
+ @Test
+ public void testFactoryForSeconds() {
+ testFactory(TimeUnit.SECONDS);
+ }
+
@Test
public void testMaxInt() {
test(Integer.MAX_VALUE);