Add debugging to detect when stores are unmapped (clean up)

This commit is contained in:
Peter Lawrey
2015-02-04 20:00:52 +00:00
parent e4aa1cf396
commit dc43dd2b1e
3 changed files with 58 additions and 26 deletions
@@ -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 {
@@ -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<byte[], byte[]> 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<byte[], byte[]> 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<CharSequence, CharSequence> 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));
}
}
@@ -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<String, String> map = ChronicleMapBuilder
try (final ChronicleMap<String, String> 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));
}
}