[java-support] branch master updated: JSPT-89 Fix test by making class follow javadoc

Rod Widdowson rdw at steadingsoftware.com
Tue Jun 4 06:04:26 EDT 2019


This is an automated email from the git hooks/post-receive script.

rdw pushed a commit to branch master
in repository java-support.

View the commit online:
http://git.shibboleth.net/view/?p=java-support.git;a=commit;h=9df63ce4d7ee0008b255b4f5d89eb1a37ff7e4c1

The following commit(s) were added to refs/heads/master by this push:
       new  9df63ce   JSPT-89 Fix test by making class follow javadoc
9df63ce is described below

commit 9df63ce4d7ee0008b255b4f5d89eb1a37ff7e4c1
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Tue Jun 4 10:59:24 2019 +0100

    JSPT-89 Fix test by making class follow javadoc
    
    https://issues.shibboleth.net/jira/browse/JSPT-89
    
    Brent points out that the implementation, not the test was wrong.
    Apply his patch to the class and revert the test changes, then turn it back on.
---
 .../support/httpclient/IdleConnectionSweeper.java    | 11 ++++++++++-
 .../support/httpclient/IdleConectionSweeperTest.java | 20 ++++----------------
 2 files changed, 14 insertions(+), 17 deletions(-)

diff --git a/src/main/java/net/shibboleth/utilities/java/support/httpclient/IdleConnectionSweeper.java b/src/main/java/net/shibboleth/utilities/java/support/httpclient/IdleConnectionSweeper.java
index 2acd53e..d9b6277 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/httpclient/IdleConnectionSweeper.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/httpclient/IdleConnectionSweeper.java
@@ -24,6 +24,7 @@ import java.util.TimerTask;
 import java.util.concurrent.TimeUnit;
 
 import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 
 import net.shibboleth.utilities.java.support.component.DestroyedComponentException;
 import net.shibboleth.utilities.java.support.component.DestructableComponent;
@@ -44,6 +45,9 @@ public class IdleConnectionSweeper implements DestructableComponent {
      */
     private boolean createdTimer;
 
+    /** Time at which the sweeper last executed. */
+    @Nullable private Instant executionTime;
+
     /** HttpClientConnectionManager whose connections will be swept. */
     @Nonnull private final HttpClientConnectionManager connectionManager;
 
@@ -83,6 +87,7 @@ public class IdleConnectionSweeper implements DestructableComponent {
 
         sweeper = new TimerTask() {
             public void run() {
+                executionTime = Instant.now();
                 connectionManager.closeIdleConnections(idleTimeout.toMillis(), TimeUnit.MILLISECONDS);
             }
         };
@@ -101,7 +106,11 @@ public class IdleConnectionSweeper implements DestructableComponent {
             throw new DestroyedComponentException();
         }
 
-        return Instant.ofEpochMilli(sweeper.scheduledExecutionTime());
+        if (executionTime != null) {
+            return executionTime;
+        } else {
+            return Instant.ofEpochMilli(sweeper.scheduledExecutionTime());
+        }
     }
 
     /** {@inheritDoc} */
diff --git a/src/test/java/net/shibboleth/utilities/java/support/httpclient/IdleConectionSweeperTest.java b/src/test/java/net/shibboleth/utilities/java/support/httpclient/IdleConectionSweeperTest.java
index aa3c4f2..bc4d38c 100644
--- a/src/test/java/net/shibboleth/utilities/java/support/httpclient/IdleConectionSweeperTest.java
+++ b/src/test/java/net/shibboleth/utilities/java/support/httpclient/IdleConectionSweeperTest.java
@@ -32,18 +32,12 @@ public class IdleConectionSweeperTest {
 
     private final Duration SWEEP_INTERVAL = Duration.ofMillis(50);
 
-    @Test(enabled = false) public void test() throws Exception {
+    @Test public void test() throws Exception {
         PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
 
         IdleConnectionSweeper sweeper = new IdleConnectionSweeper(connectionManager, Duration.ofMillis(30), SWEEP_INTERVAL);
         Thread.sleep(75);
-        long scheduledPlus =sweeper.scheduledExecutionTime().plus(SWEEP_INTERVAL).toEpochMilli();
-        long now = Instant.now().toEpochMilli();
-        if (now > scheduledPlus) {
-            Assert.assertTrue(scheduledPlus >= now);
-            
-        }
-        Assert.assertTrue(scheduledPlus >= now);
+        Assert.assertTrue(sweeper.scheduledExecutionTime().plus(SWEEP_INTERVAL).isAfter(Instant.now()));
 
         sweeper.destroy();
         Assert.assertTrue(sweeper.isDestroyed());
@@ -57,14 +51,8 @@ public class IdleConectionSweeperTest {
 
         Timer timer = new Timer(true);
         sweeper = new IdleConnectionSweeper(connectionManager, Duration.ofMillis(30), SWEEP_INTERVAL, timer);
-        Thread.sleep(10);
-        scheduledPlus =sweeper.scheduledExecutionTime().plus(SWEEP_INTERVAL).toEpochMilli();
-        now = Instant.now().toEpochMilli();
-        if (now > scheduledPlus) {
-            Assert.assertTrue(scheduledPlus >= now);
-            
-        }
-        Assert.assertTrue(scheduledPlus >= now);
+        Thread.sleep(75);
+        Assert.assertTrue(sweeper.scheduledExecutionTime().plus(SWEEP_INTERVAL).isAfter(Instant.now()));
 
         sweeper.destroy();
         Assert.assertTrue(sweeper.isDestroyed());

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list