Use more specific ChronicleHashClosedException instead of IllegalStateException, when methods of ChronicleHash are called after hash.close(). Actualize ChronicleHash.close() javadoc.

This commit is contained in:
leventov
2016-08-05 23:22:51 +07:00
parent f9edc314bb
commit ba8227ade1
5 changed files with 69 additions and 5 deletions
@@ -17,6 +17,7 @@
package net.openhft.chronicle.map;
import net.openhft.chronicle.hash.ChronicleHashClosedException;
import net.openhft.chronicle.hash.impl.stage.hash.ChainingInterface;
import org.junit.Assert;
import org.junit.Test;
@@ -34,6 +35,38 @@ public class MapCloseTest {
map.close();
}
@Test(expected = ChronicleHashClosedException.class)
public void testGetAfterCloseThrowsChronicleHashClosedException() throws InterruptedException {
ChronicleMap<Integer, Integer> map =
ChronicleMap.of(Integer.class, Integer.class).entries(1).create();
Thread t = new Thread(() -> map.close());
t.start();
t.join();
map.get(1);
}
@Test(expected = ChronicleHashClosedException.class)
public void testIterationAfterCloseThrowsChronicleHashClosedException()
throws InterruptedException {
ChronicleMap<Integer, Integer> map =
ChronicleMap.of(Integer.class, Integer.class).entries(1).create();
Thread t = new Thread(() -> map.close());
t.start();
t.join();
map.forEach((k, v) -> {});
}
@Test(expected = ChronicleHashClosedException.class)
public void testSizeAfterCloseThrowsChronicleHashClosedException()
throws InterruptedException {
ChronicleMap<Integer, Integer> map =
ChronicleMap.of(Integer.class, Integer.class).entries(1).create();
Thread t = new Thread(() -> map.close());
t.start();
t.join();
map.size();
}
@Test(expected = RuntimeException.class)
public void closeWithContextInAnotherThreadTest() throws InterruptedException {
ChronicleMap<Integer, Integer> map =