geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jinmeil...@apache.org
Subject [49/64] [abbrv] incubator-geode git commit: GEODE-923 In test changed "System.currentTimeMillis" to "System.nanoTime()" as Connection mgr uses nanotime
Date Thu, 31 Mar 2016 15:23:12 GMT
GEODE-923 In test changed "System.currentTimeMillis" to "System.nanoTime()" as Connection mgr
uses nanotime


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/48af841f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/48af841f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/48af841f

Branch: refs/heads/feature/GEODE-17-2
Commit: 48af841fcb4c9377dbe76837724933530e4faf15
Parents: 67f9d7c
Author: Hitesh Khamesra <hkhamesra@pivotal.io>
Authored: Wed Mar 30 14:08:31 2016 -0700
Committer: Hitesh Khamesra <hkhamesra@pivotal.io>
Committed: Wed Mar 30 14:08:31 2016 -0700

----------------------------------------------------------------------
 .../pooling/ConnectionManagerJUnitTest.java     | 26 ++++++++++----------
 1 file changed, 13 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/48af841f/geode-core/src/test/java/com/gemstone/gemfire/cache/client/internal/pooling/ConnectionManagerJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/cache/client/internal/pooling/ConnectionManagerJUnitTest.java
b/geode-core/src/test/java/com/gemstone/gemfire/cache/client/internal/pooling/ConnectionManagerJUnitTest.java
index 538a0a3..1250d5a 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/cache/client/internal/pooling/ConnectionManagerJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/cache/client/internal/pooling/ConnectionManagerJUnitTest.java
@@ -231,6 +231,7 @@ public class ConnectionManagerJUnitTest {
   
   @Test
   public void testIdleExpiration() throws InterruptedException, AllConnectionsInUseException,
NoAvailableServersException {
+    final long nanoToMillis = 1000000;
     final long idleTimeout = 300;
     manager = new ConnectionManagerImpl("pool",  factory, endpointManager, 5, 2, idleTimeout,
-1, logger, 60 * 1000, cancelCriterion, poolStats);
     manager.start(background);
@@ -266,19 +267,18 @@ public class ConnectionManagerJUnitTest {
     Assert.assertEquals(0,factory.closes);
     Assert.assertEquals(0,poolStats.getIdleExpire());    
     
+    long startInNanos = System.nanoTime();
     {
-      long start = System.currentTimeMillis();
    // make sure a thread local connection that has been passivated can idle-expire
       manager.passivate(conn1, true);
       
       synchronized(factory) {
-        long remaining = TIMEOUT;
-        while(factory.destroys < 1 && remaining > 0) {
-          factory.wait(remaining); 
-          remaining = TIMEOUT - (System.currentTimeMillis() - start);
+        long waitTime = TIMEOUT * nanoToMillis + startInNanos;
+        while(factory.destroys < 1 && (waitTime - System.nanoTime()) > 0) {
+          factory.wait(idleTimeout); 
         }
       }
-      long elapsed = System.currentTimeMillis() - start;
+      long elapsed = (System.nanoTime() - startInNanos)/nanoToMillis;
       Assert.assertTrue("Elapsed " + elapsed + " is less than idle timeout "
           + idleTimeout,
           elapsed >= idleTimeout && elapsed <= idleTimeout + 100);
@@ -288,6 +288,8 @@ public class ConnectionManagerJUnitTest {
       Assert.assertEquals(1,poolStats.getIdleExpire());
     }
 
+    startInNanos = System.nanoTime();
+    
     // now return all other connections to pool and verify that just 2 expire
     manager.returnConnection(conn2);
     manager.returnConnection(conn3);
@@ -295,18 +297,16 @@ public class ConnectionManagerJUnitTest {
     manager.returnConnection(conn5);
 
     {
-      long start = System.currentTimeMillis();
       synchronized(factory) {
-        long remaining = TIMEOUT;
-        while(factory.destroys < 3 && remaining > 0) {
-          factory.wait(remaining); 
-          remaining = TIMEOUT - (System.currentTimeMillis() - start);
+        long waitTime = TIMEOUT * nanoToMillis + startInNanos;
+        while(factory.destroys < 3 && (waitTime - System.nanoTime()) > 0) {
+          factory.wait(idleTimeout); 
         }
       }
-      long elapsed = System.currentTimeMillis() - start;
+      long elapsed = (System.nanoTime() - startInNanos)/nanoToMillis;
       Assert.assertTrue("Elapsed " + elapsed + " is less than idle timeout "
               + idleTimeout,
-              elapsed + ALLOWABLE_ERROR_IN_EXPIRATION >= idleTimeout);
+              elapsed >= idleTimeout && elapsed <= idleTimeout + 100);
       Assert.assertEquals(5,factory.creates);
       Assert.assertEquals(3,factory.destroys);
       Assert.assertEquals(3,factory.closes);


Mime
View raw message