You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by sb...@apache.org on 2016/02/09 18:58:25 UTC

incubator-geode git commit: GEODE-602: CI failure: OutOfOffHeapMemoryDUnitTest.testSimpleOutOfOffHeapMemoryMemberDisconnects

Repository: incubator-geode
Updated Branches:
  refs/heads/develop dd49add59 -> 7bb0819cd


GEODE-602: CI failure: OutOfOffHeapMemoryDUnitTest.testSimpleOutOfOffHeapMemoryMemberDisconnects

Adding InternalDistributedSystem.getAnyInstance() to await() condition that waits for 30 seconds.
Also replaced all other waitCriteria() with Avaitility in this test suite.


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

Branch: refs/heads/develop
Commit: 7bb0819cd802d2646d10c7e826b6000bd82a0b4d
Parents: dd49add
Author: Swapnil Bawaskar <sb...@pivotal.io>
Authored: Mon Feb 8 17:20:12 2016 -0800
Committer: Swapnil Bawaskar <sb...@pivotal.io>
Committed: Tue Feb 9 09:58:04 2016 -0800

----------------------------------------------------------------------
 .../offheap/OutOfOffHeapMemoryDUnitTest.java    | 132 +++++--------------
 1 file changed, 30 insertions(+), 102 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7bb0819c/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/OutOfOffHeapMemoryDUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/OutOfOffHeapMemoryDUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/OutOfOffHeapMemoryDUnitTest.java
index bb6b8e0..cd20ad1 100755
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/OutOfOffHeapMemoryDUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/OutOfOffHeapMemoryDUnitTest.java
@@ -17,6 +17,8 @@
 package com.gemstone.gemfire.internal.offheap;
 
 import java.util.Properties;
+import java.util.concurrent.Callable;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicReference;
 
@@ -40,6 +42,10 @@ import com.gemstone.gemfire.internal.util.StopWatch;
 import com.gemstone.gemfire.test.dunit.Host;
 import com.gemstone.gemfire.test.dunit.SerializableRunnable;
 
+
+import static com.jayway.awaitility.Awaitility.with;
+import static org.hamcrest.CoreMatchers.equalTo;
+
 /**
  * Test behavior of region when running out of off-heap memory.
  * 
@@ -63,21 +69,6 @@ public class OutOfOffHeapMemoryDUnitTest extends CacheTestCase {
     super.setUp();
     addExpectedException(OutOfOffHeapMemoryException.class.getSimpleName());
   }
-  
-//  public static void caseSetUp() {
-//    //disconnectAllFromDS();
-//    for (int i = 0; i < Host.getHost(0).getVMCount(); i++) {
-//      Host.getHost(0).getVM(i).invoke(new SerializableRunnable() {
-//        public void run() {
-//          InternalDistributedSystem ids = InternalDistributedSystem.getAnyInstance();
-//          if (ids != null && ids.isConnected()) {
-//            logger.warn(OutOfOffHeapMemoryDUnitTest.class.getSimpleName() + " found DistributedSystem connection from previous test: {}", ids);
-//            ids.disconnect();
-//          }
-//        }
-//      });
-//    }
-//  }
 
   @Override
   public void tearDown2() throws Exception {
@@ -152,28 +143,14 @@ public class OutOfOffHeapMemoryDUnitTest extends CacheTestCase {
       ooohme = e;
     }
     assertNotNull(ooohme);
-    
-    // wait for cache to close and system to disconnect
-    final WaitCriterion waitForDisconnect = new WaitCriterion() {
-      public boolean done() {
-        return cache.isClosed() && !system.isConnected() && dm.isClosed();
-      }
-      public String description() {
-        return "Waiting for cache, system and dm to close";
-      }
-    };
-    waitForCriterion(waitForDisconnect, 10*1000, 100, true);
-    
+
+    with().pollInterval(100, TimeUnit.MILLISECONDS).await().atMost(10, TimeUnit.SECONDS).until(() ->
+        cache.isClosed() && !system.isConnected() && dm.isClosed());
+
     // wait for cache instance to be nulled out
-    final WaitCriterion waitForNull = new WaitCriterion() {
-      public boolean done() {
-        return GemFireCacheImpl.getInstance() == null;
-      }
-      public String description() {
-        return "Waiting for GemFireCacheImpl to null its instance";
-      }
-    };
-    waitForCriterion(waitForNull, 10*1000, 100, true);
+    with().pollInterval(100, TimeUnit.MILLISECONDS).await().atMost(10, TimeUnit.SECONDS).until(()->
+        GemFireCacheImpl.getInstance() == null && InternalDistributedSystem.getAnyInstance() == null);
+
     assertNull(GemFireCacheImpl.getInstance());
     
     // verify system was closed out due to OutOfOffHeapMemoryException
@@ -203,10 +180,6 @@ public class OutOfOffHeapMemoryDUnitTest extends CacheTestCase {
     } catch (DistributedSystemDisconnectedException expected) {
       assertRootCause(expected, OutOfOffHeapMemoryException.class);
     }
-    
-    // verify Cache and IDS are nulled out
-    assertNull(GemFireCacheImpl.getInstance());
-    assertNull(InternalDistributedSystem.getAnyInstance());
   }
   
   private void assertRootCause(Throwable throwable, Class<?> expected) {
@@ -306,72 +279,27 @@ public class OutOfOffHeapMemoryDUnitTest extends CacheTestCase {
         public void run() {
           final int countMembersPlusLocator = vmCount+1-1; // +1 for locator, -1 for OOOHME member
           final int countOtherMembers = vmCount-1-1; // -1 for self, -1 for OOOHME member
-          
-          final WaitCriterion waitForDisconnect = new WaitCriterion() {
-            public boolean done() {
-              InternalDistributedSystem ids = (InternalDistributedSystem)OutOfOffHeapMemoryDUnitTest.system.get();
-              DistributedRegion dr = (DistributedRegion)OutOfOffHeapMemoryDUnitTest.cache.get().getRegion(name);
-              return countMembersPlusLocator == ids.getDistributionManager().getDistributionManagerIds().size()
-                  && countOtherMembers == dr.getDistributionAdvisor().getNumProfiles();
-            }
-            public String description() {
-              String msg = "";
-              InternalDistributedSystem ids = (InternalDistributedSystem)OutOfOffHeapMemoryDUnitTest.system.get();
-              int currentMemberCount = ids.getDistributionManager().getDistributionManagerIds().size();
-              if (countMembersPlusLocator != currentMemberCount) {
-                msg += " expected " + countMembersPlusLocator + " members but found " + currentMemberCount;
-              }
-              DistributedRegion dr = (DistributedRegion)OutOfOffHeapMemoryDUnitTest.cache.get().getRegion(name);
-              int profileCount = dr.getDistributionAdvisor().getNumProfiles();
-              if (countOtherMembers != profileCount) {
-                msg += " expected " + countOtherMembers + " profiles but found " + profileCount;
-              }
-              return msg;
-            }
+
+          with().pollInterval(10, TimeUnit.MILLISECONDS).await().atMost(30, TimeUnit.SECONDS).until(numDistributionManagers(), equalTo(countMembersPlusLocator));
+          with().pollInterval(10, TimeUnit.MILLISECONDS).await().atMost(30, TimeUnit.SECONDS).until(numProfiles(), equalTo(countOtherMembers));
+
+        }
+
+        private Callable<Integer> numProfiles() {
+          return () -> {
+            DistributedRegion dr = (DistributedRegion)OutOfOffHeapMemoryDUnitTest.cache.get().getRegion(name);
+            return dr.getDistributionAdvisor().getNumProfiles();
+          };
+        }
+
+        private Callable<Integer> numDistributionManagers() {
+          return () -> {
+            InternalDistributedSystem ids = (InternalDistributedSystem)OutOfOffHeapMemoryDUnitTest.system.get();
+            return ids.getDistributionManager().getDistributionManagerIds().size();
           };
-          waitForCriterion(waitForDisconnect, 30*1000, 10, true);
         }
       });
     }
   }
 
-//  private static void foo() {
-//    final WaitCriterion waitForDisconnect = new WaitCriterion() {
-//      public boolean done() {
-//        return cache.isClosed() && !system.isConnected() && dm.isClosed();
-//      }
-//      public String description() {
-//        return "Waiting for cache, system and dm to close";
-//      }
-//    };
-//    waitForCriterion(waitForDisconnect, 10*1000, 100, true);
-//  }
-  
-  // setUp() and caseSetUp() are commented out -- they were in place because of incompatible DistributedSystem bleed over from earlier DUnit tests
-  
-//@Override
-//public void setUp() throws Exception {
-//  super.setUp();
-//  long begin = System.currentTimeMillis();
-//  Cache gfc = null;
-//  while (gfc == null) {
-//    try {
-//      gfc = getCache();
-//      break;
-//    } catch (IllegalStateException e) {
-//      if (System.currentTimeMillis() > begin+60*1000) {
-//        fail("OutOfOffHeapMemoryDUnitTest waited too long to getCache", e);
-//      } else if (e.getMessage().contains("A connection to a distributed system already exists in this VM.  It has the following configuration")) {
-//        InternalDistributedSystem ids = InternalDistributedSystem.getAnyInstance();
-//        if (ids != null && ids.isConnected()) {
-//          ids.getLogWriter().warning("OutOfOffHeapMemoryDUnitTest found DistributedSystem connection from previous test", e);
-//          ids.disconnect();
-//        }
-//      } else {
-//        throw e;
-//      }
-//    }
-//  }
-//}
-
 }