diff --git a/src/main/java/net/openhft/chronicle/hash/ChronicleHashClosedException.java b/src/main/java/net/openhft/chronicle/hash/ChronicleHashClosedException.java index 71526102e..cdc12e6ec 100644 --- a/src/main/java/net/openhft/chronicle/hash/ChronicleHashClosedException.java +++ b/src/main/java/net/openhft/chronicle/hash/ChronicleHashClosedException.java @@ -16,10 +16,12 @@ package net.openhft.chronicle.hash; +import net.openhft.chronicle.core.io.ClosedIllegalStateException; + /** * Thrown when a {@link ChronicleHash} is accessed after {@link ChronicleHash#close()}. */ -public final class ChronicleHashClosedException extends IllegalStateException { +public final class ChronicleHashClosedException extends ClosedIllegalStateException { private static final long serialVersionUID = 0L; public ChronicleHashClosedException(ChronicleHash hash) { @@ -29,4 +31,8 @@ public final class ChronicleHashClosedException extends IllegalStateException { public ChronicleHashClosedException(String chronicleHashIdentityString) { super("Access to " + chronicleHashIdentityString + " after close()"); } + + public ChronicleHashClosedException(String s, Throwable t) { + super(s, t); + } } diff --git a/src/main/java/net/openhft/chronicle/hash/impl/VanillaChronicleHash.java b/src/main/java/net/openhft/chronicle/hash/impl/VanillaChronicleHash.java index aa55b94cc..275ee0cc2 100644 --- a/src/main/java/net/openhft/chronicle/hash/impl/VanillaChronicleHash.java +++ b/src/main/java/net/openhft/chronicle/hash/impl/VanillaChronicleHash.java @@ -20,8 +20,10 @@ import net.openhft.chronicle.algo.locks.*; import net.openhft.chronicle.bytes.BytesStore; import net.openhft.chronicle.bytes.MappedBytesStoreFactory; import net.openhft.chronicle.bytes.NativeBytesStore; +import net.openhft.chronicle.core.Jvm; import net.openhft.chronicle.core.Maths; import net.openhft.chronicle.core.OS; +import net.openhft.chronicle.core.io.AbstractCloseable; import net.openhft.chronicle.core.io.ReferenceOwner; import net.openhft.chronicle.hash.*; import net.openhft.chronicle.hash.impl.util.BuildVersion; @@ -69,7 +71,7 @@ import static net.openhft.chronicle.map.ChronicleHashCorruptionImpl.report; public abstract class VanillaChronicleHash, SC extends HashSegmentContext, - ECQ extends ExternalHashQueryContext> + ECQ extends ExternalHashQueryContext> extends AbstractCloseable implements ChronicleHash, Marshallable { public static final long TIER_COUNTERS_AREA_SIZE = 64; @@ -680,7 +682,13 @@ public abstract class VanillaChronicleHash map = - ChronicleMap.of(Integer.class, Integer.class).entries(1).create(); + of(Integer.class, Integer.class).entries(1).create(); ExternalMapQueryContext cxt = map.queryContext(1); map.close(); } @@ -39,7 +40,7 @@ public class MapCloseTest { @Test(expected = ChronicleHashClosedException.class) public void testGetAfterCloseThrowsChronicleHashClosedException() throws InterruptedException { ChronicleMap map = - ChronicleMap.of(Integer.class, Integer.class).entries(1).create(); + of(Integer.class, Integer.class).entries(1).create(); Thread t = new Thread(() -> map.close()); t.start(); t.join(); @@ -50,7 +51,7 @@ public class MapCloseTest { public void testIterationAfterCloseThrowsChronicleHashClosedException() throws InterruptedException { ChronicleMap map = - ChronicleMap.of(Integer.class, Integer.class).entries(1).create(); + of(Integer.class, Integer.class).entries(1).create(); Thread t = new Thread(() -> map.close()); t.start(); t.join(); @@ -62,18 +63,18 @@ public class MapCloseTest { public void testSizeAfterCloseThrowsChronicleHashClosedException() throws InterruptedException { ChronicleMap map = - ChronicleMap.of(Integer.class, Integer.class).entries(1).create(); + of(Integer.class, Integer.class).entries(1).create(); Thread t = new Thread(() -> map.close()); t.start(); t.join(); map.size(); } - @Test(expected = RuntimeException.class) + @Test public void closeWithContextInAnotherThreadTest() throws InterruptedException { LOCK_TIMEOUT_SECONDS = 2; ChronicleMap map = - ChronicleMap.of(Integer.class, Integer.class).entries(1).create(); + of(Integer.class, Integer.class).entries(1).create(); Object lock = new Object(); CountDownLatch latch = new CountDownLatch(1); synchronized (lock) { @@ -93,11 +94,19 @@ public class MapCloseTest { LOCK_TIMEOUT_SECONDS = 60; } + @Test(expected = ChronicleHashClosedException.class) + public void testRemainingAutoResizesAfterClose() { + ChronicleMap map = of(Integer.class, Integer.class).entries(1).create(); + map.close(); + map.remainingAutoResizes(); + } + + @Test public void vanillaChronicleHashAllContextsExpungeTest() throws InterruptedException { VanillaChronicleMap map = (VanillaChronicleMap) - ChronicleMap.of(Integer.class, Integer.class).entries(1).create(); + of(Integer.class, Integer.class).entries(1).create(); Semaphore semaphore = new Semaphore(0); CountDownLatch latch = new CountDownLatch(2); class MapAccessThread extends Thread {