You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2016/01/09 00:37:45 UTC
[44/45] incubator-geode git commit: GEODE-701: fix double free in
unit test
GEODE-701: fix double free in unit test
The failure was caused by LifecycleListenerJUnitTest setting
a system property and then not unsetting it when it completed.
testClose now asserts that the system property must be initially
false when it runs.
LifecycleListenerJUnitTest now unsets the property in a finally
block after setting it.
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/0c0850cb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/0c0850cb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/0c0850cb
Branch: refs/heads/feature/GEODE-715
Commit: 0c0850cb6f70e937c7c2ad76249db4853b344eb9
Parents: 57d8486
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Wed Jan 6 16:57:26 2016 -0800
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Fri Jan 8 13:53:04 2016 -0800
----------------------------------------------------------------------
.../offheap/LifecycleListenerJUnitTest.java | 23 ++++++++++++--------
.../offheap/SimpleMemoryAllocatorJUnitTest.java | 7 +-----
2 files changed, 15 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/0c0850cb/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/LifecycleListenerJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/LifecycleListenerJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/LifecycleListenerJUnitTest.java
index c886e43..4fba65b 100755
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/LifecycleListenerJUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/LifecycleListenerJUnitTest.java
@@ -78,9 +78,6 @@ public class LifecycleListenerJUnitTest {
@Test
public void testCallbacksAreCalledAfterCreate() {
LifecycleListener.addLifecycleListener(this.listener);
- // saj
- System.getProperties().put("gemfire.free-off-heap-memory", "true");
- // saj above
UnsafeMemoryChunk slab = new UnsafeMemoryChunk(1024); // 1k
SimpleMemoryAllocatorImpl ma = SimpleMemoryAllocatorImpl.create(new NullOutOfOffHeapMemoryListener(), new NullOffHeapMemoryStats(),
new UnsafeMemoryChunk[] { slab });
@@ -89,7 +86,7 @@ public class LifecycleListenerJUnitTest {
Assert.assertEquals(0, this.afterReuseCallbacks.size());
Assert.assertEquals(0, this.beforeCloseCallbacks.size());
- ma.close();
+ closeAndFree(ma);
Assert.assertEquals(1, this.afterCreateCallbacks.size());
Assert.assertEquals(0, this.afterReuseCallbacks.size());
@@ -103,7 +100,7 @@ public class LifecycleListenerJUnitTest {
LifecycleListener.addLifecycleListener(this.listener);
- System.getProperties().put("gemfire.free-off-heap-memory", "false");
+ assertEquals(false, Boolean.getBoolean(SimpleMemoryAllocatorImpl.FREE_OFF_HEAP_MEMORY_PROPERTY));
UnsafeMemoryChunk slab = new UnsafeMemoryChunk(1024); // 1k
SimpleMemoryAllocatorImpl ma = createAllocator(new NullOutOfOffHeapMemoryListener(), new NullOffHeapMemoryStats(), new UnsafeMemoryChunk[] { slab });
@@ -146,13 +143,21 @@ public class LifecycleListenerJUnitTest {
}
}
+ private void closeAndFree(SimpleMemoryAllocatorImpl ma) {
+ assertEquals(false, Boolean.getBoolean(SimpleMemoryAllocatorImpl.FREE_OFF_HEAP_MEMORY_PROPERTY));
+ System.setProperty(SimpleMemoryAllocatorImpl.FREE_OFF_HEAP_MEMORY_PROPERTY, "true");
+ try {
+ ma.close();
+ } finally {
+ System.clearProperty(SimpleMemoryAllocatorImpl.FREE_OFF_HEAP_MEMORY_PROPERTY);
+ }
+ }
+
@Test
public void testCallbacksAreCalledAfterReuseWithFreeTrue() {
LifecycleListener.addLifecycleListener(this.listener);
- System.getProperties().put("gemfire.free-off-heap-memory", "true");
-
UnsafeMemoryChunk slab = new UnsafeMemoryChunk(1024); // 1k
SimpleMemoryAllocatorImpl ma = SimpleMemoryAllocatorImpl.create(new NullOutOfOffHeapMemoryListener(), new NullOffHeapMemoryStats(), new UnsafeMemoryChunk[] { slab });
@@ -160,7 +165,7 @@ public class LifecycleListenerJUnitTest {
Assert.assertEquals(0, this.afterReuseCallbacks.size());
Assert.assertEquals(0, this.beforeCloseCallbacks.size());
- ma.close();
+ closeAndFree(ma);
Assert.assertEquals(1, this.afterCreateCallbacks.size());
Assert.assertEquals(0, this.afterReuseCallbacks.size());
@@ -173,7 +178,7 @@ public class LifecycleListenerJUnitTest {
Assert.assertEquals(0, this.afterReuseCallbacks.size());
Assert.assertEquals(1, this.beforeCloseCallbacks.size());
- ma.close();
+ closeAndFree(ma);
Assert.assertEquals(2, this.afterCreateCallbacks.size());
Assert.assertEquals(0, this.afterReuseCallbacks.size());
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/0c0850cb/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorJUnitTest.java
index 6bc488d..3c10382 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorJUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorJUnitTest.java
@@ -24,7 +24,6 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.atomic.AtomicReference;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -438,13 +437,9 @@ public class SimpleMemoryAllocatorJUnitTest {
}
}
- /* This test fails intermittently.
- * Disabling it until this test case is fixed. GEODE-701
- * Sonar test coverage job has failed due to this test failure.
- */
- @Ignore("Disabled for GEODE-701")
@Test
public void testClose() {
+ assertEquals(false, Boolean.getBoolean(SimpleMemoryAllocatorImpl.FREE_OFF_HEAP_MEMORY_PROPERTY));
UnsafeMemoryChunk slab = new UnsafeMemoryChunk(1024*1024);
boolean freeSlab = true;
UnsafeMemoryChunk[] slabs = new UnsafeMemoryChunk[]{slab};