geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bschucha...@apache.org
Subject [11/50] [abbrv] incubator-geode git commit: GEODE-467: fix race in off-heap memory monitor tests
Date Thu, 05 Nov 2015 20:35:48 GMT
GEODE-467: fix race in off-heap memory monitor tests

I think this may have been caused by the monitor thread
continuing to run after the unit tests call stopMonitor.
They now call a flavor of the method that joins on the
monitor thread.


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

Branch: refs/heads/feature/GEODE-77
Commit: 9d8e568b4b00085b5f2cf8b7d049027211b3f7d1
Parents: d177a3f
Author: Darrel Schneider <dschneider@pivotal.io>
Authored: Tue Oct 27 14:16:18 2015 -0700
Committer: Darrel Schneider <dschneider@pivotal.io>
Committed: Tue Oct 27 14:19:09 2015 -0700

----------------------------------------------------------------------
 .../cache/control/OffHeapMemoryMonitor.java     | 23 +++++++++++++++-----
 .../cache/OffHeapEvictionDUnitTest.java         |  2 +-
 ...rtitionedRegionOffHeapEvictionDUnitTest.java |  2 +-
 .../control/MemoryMonitorOffHeapJUnitTest.java  |  2 +-
 4 files changed, 21 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9d8e568b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/control/OffHeapMemoryMonitor.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/control/OffHeapMemoryMonitor.java
b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/control/OffHeapMemoryMonitor.java
index c4e9df6..86ccad5 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/control/OffHeapMemoryMonitor.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/control/OffHeapMemoryMonitor.java
@@ -59,6 +59,7 @@ public class OffHeapMemoryMonitor implements ResourceMonitor, MemoryUsageListene
   private boolean hasEvictionThreshold = false;
 
   private OffHeapMemoryUsageListener offHeapMemoryUsageListener;
+  private Thread memoryListenerThread;
   
   private final InternalResourceManager resourceManager;
   private final ResourceAdvisor resourceAdvisor;
@@ -93,11 +94,12 @@ public class OffHeapMemoryMonitor implements ResourceMonitor, MemoryUsageListene
 
       this.offHeapMemoryUsageListener = new OffHeapMemoryUsageListener(getBytesUsed());
       ThreadGroup group = LoggingThreadGroup.createThreadGroup("OffHeapMemoryMonitor Threads",
logger);
-      Thread memoryListenerThread = new Thread(group, this.offHeapMemoryUsageListener);
-      memoryListenerThread.setName(memoryListenerThread.getName() + " OffHeapMemoryListener");
-      memoryListenerThread.setPriority(Thread.MAX_PRIORITY);
-      memoryListenerThread.setDaemon(true);
-      memoryListenerThread.start();
+      Thread t = new Thread(group, this.offHeapMemoryUsageListener);
+      t.setName(t.getName() + " OffHeapMemoryListener");
+      t.setPriority(Thread.MAX_PRIORITY);
+      t.setDaemon(true);
+      t.start();
+      this.memoryListenerThread = t;
       
       this.memoryAllocator.addMemoryUsageListener(this);
       
@@ -110,6 +112,9 @@ public class OffHeapMemoryMonitor implements ResourceMonitor, MemoryUsageListene
    */
   @Override
   public void stopMonitoring() {
+    stopMonitoring(false);
+  }
+  public void stopMonitoring(boolean waitForThread) {
     synchronized (this) {
       if (!this.started) {
         return;
@@ -122,6 +127,14 @@ public class OffHeapMemoryMonitor implements ResourceMonitor, MemoryUsageListene
         this.offHeapMemoryUsageListener.notifyAll();
       }
 
+      if (waitForThread && this.memoryListenerThread != null) {
+        try {
+          this.memoryListenerThread.join();
+        } catch (InterruptedException e) {
+          Thread.currentThread().interrupt();
+        }
+      }
+      this.memoryListenerThread = null;
       this.started = false;
     }
   }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9d8e568b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/OffHeapEvictionDUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/OffHeapEvictionDUnitTest.java
b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/OffHeapEvictionDUnitTest.java
index 57cdfae..386f8ce 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/OffHeapEvictionDUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/OffHeapEvictionDUnitTest.java
@@ -78,7 +78,7 @@ public class OffHeapEvictionDUnitTest extends EvictionDUnitDisabledTest
{
       getLogWriter().info("cache= " + cache);
       getLogWriter().info("cache closed= " + cache.isClosed());
       cache.getResourceManager().setEvictionOffHeapPercentage(85);
-      ((GemFireCacheImpl) cache).getResourceManager().getOffHeapMonitor().stopMonitoring();
+      ((GemFireCacheImpl) cache).getResourceManager().getOffHeapMonitor().stopMonitoring(true);
       getLogWriter().info("eviction= "+cache.getResourceManager().getEvictionOffHeapPercentage());
       getLogWriter().info("critical= "+cache.getResourceManager().getCriticalOffHeapPercentage());
     }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9d8e568b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/PartitionedRegionOffHeapEvictionDUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/PartitionedRegionOffHeapEvictionDUnitTest.java
b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/PartitionedRegionOffHeapEvictionDUnitTest.java
index f07c5b1..cd5e962 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/PartitionedRegionOffHeapEvictionDUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/PartitionedRegionOffHeapEvictionDUnitTest.java
@@ -85,7 +85,7 @@ public class PartitionedRegionOffHeapEvictionDUnitTest extends
     
     setEvictionPercentage(85);
     OffHeapMemoryMonitor ohmm = ((GemFireCacheImpl) getCache()).getResourceManager().getOffHeapMonitor();
-    ohmm.stopMonitoring();
+    ohmm.stopMonitoring(true);
 
     ohmm.updateStateAndSendEvent(94371840);
   }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9d8e568b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/control/MemoryMonitorOffHeapJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/control/MemoryMonitorOffHeapJUnitTest.java
b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/control/MemoryMonitorOffHeapJUnitTest.java
index d7a875c..bf8be0a 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/control/MemoryMonitorOffHeapJUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/control/MemoryMonitorOffHeapJUnitTest.java
@@ -92,7 +92,7 @@ public class MemoryMonitorOffHeapJUnitTest {
     
     monitor.setEvictionThreshold(50.0f);  
     monitor.setCriticalThreshold(75.0f);
-    monitor.stopMonitoring();
+    monitor.stopMonitoring(true);
     
     assertEquals(524288, internalManager.getStats().getOffHeapEvictionThreshold());
     assertEquals(786432, internalManager.getStats().getOffHeapCriticalThreshold());


Mime
View raw message