From dc43dd2b1e564dd33c55ea2432415a4856fed378 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 4 Feb 2015 20:00:52 +0000 Subject: [PATCH] Add debugging to detect when stores are unmapped (clean up) --- .../chronicle/map/CHMUseCasesTest.java | 19 +++++++--- .../chronicle/map/ChronicleMapTest.java | 36 ++++++++++++------- .../chronicle/map/LargeEntriesTest.java | 29 ++++++++++----- 3 files changed, 58 insertions(+), 26 deletions(-) diff --git a/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java b/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java index b5c25d5ec..f3db0d210 100644 --- a/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java +++ b/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java @@ -7,15 +7,13 @@ import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig; import net.openhft.chronicle.map.fromdocs.BondVOInterface; import net.openhft.lang.io.ByteBufferBytes; import net.openhft.lang.io.Bytes; +import net.openhft.lang.io.MappedStore; import net.openhft.lang.io.serialization.BytesMarshallable; import net.openhft.lang.io.serialization.impl.*; import net.openhft.lang.model.constraints.MaxSize; import net.openhft.lang.model.constraints.NotNull; import net.openhft.lang.values.*; -import org.junit.After; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.*; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -2622,6 +2620,19 @@ public class CHMUseCasesTest { } } } + + + @BeforeClass + public static void initGlobals() { + assertFalse("Unfriendly clean in a previous test", MappedStore.unfriendlyClean.getAndSet(false)); + + } + + @After + public void systemGC() { + System.gc(); + assertFalse("Unfriendly clean", MappedStore.unfriendlyClean.getAndSet(false)); + } } interface IData extends BytesMarshallable { diff --git a/src/test/java/net/openhft/chronicle/map/ChronicleMapTest.java b/src/test/java/net/openhft/chronicle/map/ChronicleMapTest.java index d60bb18c9..bbdfcd11f 100755 --- a/src/test/java/net/openhft/chronicle/map/ChronicleMapTest.java +++ b/src/test/java/net/openhft/chronicle/map/ChronicleMapTest.java @@ -22,14 +22,13 @@ import com.google.common.collect.HashBiMap; import com.google.common.primitives.Ints; import net.openhft.chronicle.hash.replication.SingleChronicleHashReplication; import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig; +import net.openhft.lang.io.MappedStore; import net.openhft.lang.model.DataValueClasses; import net.openhft.lang.model.DataValueGenerator; import net.openhft.lang.values.IntValue; import net.openhft.lang.values.LongValue; import net.openhft.lang.values.LongValue$$Native; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.*; import java.io.BufferedReader; import java.io.File; @@ -182,16 +181,14 @@ public class ChronicleMapTest { public void testByteArrayPersistenceFileReuse() throws Exception { final File persistenceFile = Builder.getPersistenceFile(); - for (int i = 0; i < 2; i++) { - ChronicleMap map = ChronicleMapBuilder.of(byte[].class, byte[] - .class).createPersistedTo(persistenceFile); - - byte[] o = map.get("hello".getBytes()); - System.out.println(o == null ? "null" : new String(o)); - map.put("hello".getBytes(), "world".getBytes()); - } - + for (int i = 0; i < 3; i++) + try (ChronicleMap map = ChronicleMapBuilder.of(byte[].class, byte[] + .class).createPersistedTo(persistenceFile)) { + byte[] o = map.get("hello".getBytes()); + System.out.println(o == null ? "null" : new String(o)); + map.put("hello".getBytes(), "world".getBytes()); + } } @Test @@ -661,7 +658,7 @@ public class ChronicleMapTest { @Test public void testLargerEntries() { for (int segments : new int[]{128, 256, 512, 1024}) { - int entries = 1000000, entrySize = 512; + int entries = 100000, entrySize = 512; ChronicleMapBuilder builder = ChronicleMapBuilder .of(CharSequence.class, CharSequence.class) .entries(entries * 11 / 10) @@ -869,6 +866,7 @@ public class ChronicleMapTest { static final LongValue ONE = DataValueClasses.newInstance(LongValue.class); + static { ONE.setValue(1); } @@ -1827,5 +1825,17 @@ public class ChronicleMapTest { map.close(); } + + @BeforeClass + public static void initGlobals() { + assertFalse("Unfriendly clean in a previous test", MappedStore.unfriendlyClean.getAndSet(false)); + + } + + @After + public void systemGC() { + System.gc(); + assertFalse("Unfriendly clean", MappedStore.unfriendlyClean.getAndSet(false)); + } } diff --git a/src/test/java/net/openhft/chronicle/map/LargeEntriesTest.java b/src/test/java/net/openhft/chronicle/map/LargeEntriesTest.java index 338d18dc9..08782ebe5 100644 --- a/src/test/java/net/openhft/chronicle/map/LargeEntriesTest.java +++ b/src/test/java/net/openhft/chronicle/map/LargeEntriesTest.java @@ -20,7 +20,10 @@ package net.openhft.chronicle.map; import net.openhft.lang.io.DirectBytes; import net.openhft.lang.io.DirectStore; +import net.openhft.lang.io.MappedStore; import net.openhft.lang.io.serialization.impl.SnappyStringMarshaller; +import org.junit.After; +import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; @@ -29,10 +32,7 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.util.*; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; +import java.util.concurrent.*; import static org.junit.Assert.*; @@ -48,7 +48,7 @@ public class LargeEntriesTest { File file = File.createTempFile("largeEntries" + System.currentTimeMillis(), ".deleteme"); file.deleteOnExit(); - final ChronicleMap map = ChronicleMapBuilder + try (final ChronicleMap map = ChronicleMapBuilder .of(String.class, String.class) .valueMarshaller(SnappyStringMarshaller.INSTANCE) .actualSegments(1) // to force an error. @@ -56,8 +56,7 @@ public class LargeEntriesTest { .averageKeySize(10) .averageValueSize(ENTRY_SIZE) .putReturnsNull(true) - .createPersistedTo(file); - { + .createPersistedTo(file)) { warmUpCompression(ENTRY_SIZE); int threads = 4; //Runtime.getRuntime().availableProcessors(); ExecutorService es = Executors.newFixedThreadPool(threads); @@ -84,8 +83,8 @@ public class LargeEntriesTest { operations * ENTRIES * ENTRY_SIZE / 1e6 / (time / 1e3)); } es.shutdown(); - if (es.isTerminated()) - map.close(); + es.awaitTermination(1, TimeUnit.MINUTES); + assertTrue(es.isTerminated()); } } @@ -215,4 +214,16 @@ public class LargeEntriesTest { xml.close(); return baos.toString().substring(0, entrySize); } + + @BeforeClass + public static void initGlobals() { + assertFalse("Unfriendly clean in a previous test", MappedStore.unfriendlyClean.getAndSet(false)); + + } + + @After + public void systemGC() { + System.gc(); + assertFalse("Unfriendly clean", MappedStore.unfriendlyClean.getAndSet(false)); + } }