[java-support] branch master updated: JSPT-89 Rework IdleConnectionSweeperTest.
Rod Widdowson
rdw at steadingsoftware.com
Thu Jul 25 06:44:37 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=1be5e90dc3df5e755a8e7a936486cac947d719d0
The following commit(s) were added to refs/heads/master by this push:
new 1be5e90 JSPT-89 Rework IdleConnectionSweeperTest.
1be5e90 is described below
commit 1be5e90dc3df5e755a8e7a936486cac947d719d0
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Thu Jul 25 11:31:52 2019 +0100
JSPT-89 Rework IdleConnectionSweeperTest.
https://issues.shibboleth.net/jira/browse/JSPT-89
Rather than inferring anything we actually look to see if we have been called.
Since windows scheduling in VMs appears to suck (particular with late model java versions)
we also take two shots.
---
.../httpclient/IdleConectionSweeperTest.java | 46 ++++++++++++++++++----
1 file changed, 38 insertions(+), 8 deletions(-)
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 bc4d38c..68b87dd 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
@@ -18,26 +18,35 @@
package net.shibboleth.utilities.java.support.httpclient;
import java.time.Duration;
-import java.time.Instant;
import java.util.Timer;
-
-import net.shibboleth.utilities.java.support.component.DestroyedComponentException;
+import java.util.concurrent.TimeUnit;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.testng.Assert;
import org.testng.annotations.Test;
+import net.shibboleth.utilities.java.support.component.DestroyedComponentException;
+
/** {@link IdleConnectionSweeper} unit test. */
public class IdleConectionSweeperTest {
private final Duration SWEEP_INTERVAL = Duration.ofMillis(50);
@Test public void test() throws Exception {
- PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
+ MyCm connectionManager = new MyCm();
IdleConnectionSweeper sweeper = new IdleConnectionSweeper(connectionManager, Duration.ofMillis(30), SWEEP_INTERVAL);
- Thread.sleep(75);
- Assert.assertTrue(sweeper.scheduledExecutionTime().plus(SWEEP_INTERVAL).isAfter(Instant.now()));
+ Thread.yield(); // for luck.
+ if (!connectionManager.isCloseCalled()) {
+ Thread.sleep(25+SWEEP_INTERVAL.toMillis());
+ Thread.yield();
+ if (!connectionManager.isCloseCalled()) {
+ // Windows sometimes takes its time...
+ Thread.sleep(25+SWEEP_INTERVAL.toMillis());
+ Thread.yield();
+ Assert.assertTrue(connectionManager.isCloseCalled());
+ }
+ }
sweeper.destroy();
Assert.assertTrue(sweeper.isDestroyed());
@@ -49,10 +58,21 @@ public class IdleConectionSweeperTest {
// expected this
}
+ connectionManager = new MyCm();
+
Timer timer = new Timer(true);
sweeper = new IdleConnectionSweeper(connectionManager, Duration.ofMillis(30), SWEEP_INTERVAL, timer);
- Thread.sleep(75);
- Assert.assertTrue(sweeper.scheduledExecutionTime().plus(SWEEP_INTERVAL).isAfter(Instant.now()));
+ Thread.yield();
+ if (!connectionManager.isCloseCalled()) {
+ Thread.sleep(SWEEP_INTERVAL.toMillis());
+ Thread.yield();
+ if (!connectionManager.isCloseCalled()) {
+ // Windows sometimes takes its time...
+ Thread.sleep(SWEEP_INTERVAL.toMillis());
+ Thread.yield();
+ Assert.assertTrue(connectionManager.isCloseCalled());
+ }
+ }
sweeper.destroy();
Assert.assertTrue(sweeper.isDestroyed());
@@ -66,4 +86,14 @@ public class IdleConectionSweeperTest {
timer.cancel();
}
+ private class MyCm extends PoolingHttpClientConnectionManager {
+ private boolean closeCalled;
+ public void closeIdleConnections(long idletime, TimeUnit timeUnit) {
+ closeCalled = true;
+ super.closeIdleConnections(idletime, timeUnit);
+ }
+ public boolean isCloseCalled() {
+ return closeCalled;
+ }
+ }
}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list