hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1791355 - in /httpcomponents/httpcore/trunk/httpcore5/src: main/java/org/apache/hc/core5/pool/ main/java/org/apache/hc/core5/util/ test/java/org/apache/hc/core5/pool/
Date Fri, 14 Apr 2017 11:14:28 GMT
Author: olegk
Date: Fri Apr 14 11:14:28 2017
New Revision: 1791355

URL: http://svn.apache.org/viewvc?rev=1791355&view=rev
Log:
Added convenience validation methods to TimeValue

Modified:
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/pool/LeaseRequest.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/pool/StrictConnPool.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
    httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/pool/TestStrictConnPool.java

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/pool/LeaseRequest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/pool/LeaseRequest.java?rev=1791355&r1=1791354&r2=1791355&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/pool/LeaseRequest.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/pool/LeaseRequest.java
Fri Apr 14 11:14:28 2017
@@ -46,8 +46,8 @@ class LeaseRequest<T, C extends Graceful
     private volatile Exception ex;
 
     static long calculateDeadline(final long currentTimeMillis, final TimeValue timeValue)
{
-        final long time = timeValue.getDuration() > 0 ? currentTimeMillis + timeValue.toMillis()
: Long.MAX_VALUE;
-        if (time < 0 && timeValue.getDuration() > 0) {
+        final long time = TimeValue.isPositive(timeValue) ? currentTimeMillis + timeValue.toMillis()
: Long.MAX_VALUE;
+        if (time < 0 && TimeValue.isPositive(timeValue)) {
             return Long.MAX_VALUE;
         } else {
             return time;

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/pool/StrictConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/pool/StrictConnPool.java?rev=1791355&r1=1791354&r2=1791355&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/pool/StrictConnPool.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/pool/StrictConnPool.java
Fri Apr 14 11:14:28 2017
@@ -570,8 +570,7 @@ public class StrictConnPool<T, C extends
 
     @Override
     public void closeIdle(final TimeValue idleTime) {
-        Args.notNull(idleTime, "Idle time");
-        final long deadline = System.currentTimeMillis() - (idleTime.getDuration() > 0
? idleTime.toMillis() : 0);
+        final long deadline = System.currentTimeMillis() - (TimeValue.isPositive(idleTime)
? idleTime.toMillis() : 0);
         enumAvailable(new Callback<PoolEntry<T, C>>() {
 
             @Override

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java?rev=1791355&r1=1791354&r2=1791355&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
Fri Apr 14 11:14:28 2017
@@ -90,6 +90,14 @@ public class TimeValue {
         return new TimeValue(seconds, TimeUnit.SECONDS);
     }
 
+    public static boolean isPositive(final TimeValue timeValue) {
+        return timeValue != null && timeValue.getDuration() > 0;
+    }
+
+    public static boolean isNonNegative(final TimeValue timeValue) {
+        return timeValue != null && timeValue.getDuration() >= 0;
+    }
+
     private final long duration;
 
     private final TimeUnit timeUnit;

Modified: httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/pool/TestStrictConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/pool/TestStrictConnPool.java?rev=1791355&r1=1791354&r2=1791355&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/pool/TestStrictConnPool.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/pool/TestStrictConnPool.java
Fri Apr 14 11:14:28 2017
@@ -532,12 +532,6 @@ public class TestStrictConnPool {
     }
 
     @Test(expected=IllegalArgumentException.class)
-    public void testCloseIdleInvalid() throws Exception {
-        final StrictConnPool<String, HttpConnection> pool = new StrictConnPool<>(2,
2);
-        pool.closeIdle(null);
-    }
-
-    @Test(expected=IllegalArgumentException.class)
     public void testGetStatsInvalid() throws Exception {
         final StrictConnPool<String, HttpConnection> pool = new StrictConnPool<>(2,
2);
         pool.getStats(null);



Mime
View raw message