From ef0cd0f96fdc399d496b89469aed0edc16ba445c Mon Sep 17 00:00:00 2001 From: Rob Austin Date: Sun, 2 Nov 2014 18:35:26 +0000 Subject: [PATCH] HCOLL-155 removed acquireUsingReadLocked and acquireUsingWriteLocked to WriteContext acquireUsingLocked(@NotNull K key, @NotNull V usingValue); and ReadContext getUsingLocked(@NotNull K key, @NotNull V usingValue); --- .../openhft/chronicle/map/ChronicleMap.java | 8 +- .../map/{LockedEntry.java => Context.java} | 2 +- .../openhft/chronicle/map/ReadContext.java | 10 + .../chronicle/map/ReplicatedChronicleMap.java | 6 +- .../chronicle/map/StatelessChronicleMap.java | 4 +- .../chronicle/map/VanillaChronicleMap.java | 190 +++++++++++------- .../openhft/chronicle/map/WriteContext.java | 13 ++ .../chronicle/map/ChronicleMapTest.java | 105 ++++++++-- .../chronicle/map/ReplicationCheckingMap.java | 5 +- .../jrs166/map/StatelessChronicleMapTest.java | 106 +++++----- 10 files changed, 297 insertions(+), 152 deletions(-) rename src/main/java/net/openhft/chronicle/map/{LockedEntry.java => Context.java} (94%) create mode 100644 src/main/java/net/openhft/chronicle/map/ReadContext.java create mode 100644 src/main/java/net/openhft/chronicle/map/WriteContext.java diff --git a/src/main/java/net/openhft/chronicle/map/ChronicleMap.java b/src/main/java/net/openhft/chronicle/map/ChronicleMap.java index 79f60e5cd..3e9012866 100644 --- a/src/main/java/net/openhft/chronicle/map/ChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/ChronicleMap.java @@ -103,6 +103,9 @@ public interface ChronicleMap extends ConcurrentMap, ChronicleHash { */ V getUsing(K key, V usingValue); + // todo document + ReadContext getUsingLocked(@NotNull K key, @NotNull V usingValue); + /** * Acquire a value for a key, creating if absent. * @@ -142,9 +145,8 @@ public interface ChronicleMap extends ConcurrentMap, ChronicleHash { // todo document - LockedEntry acquireUsingReadLocked(@NotNull K key, @NotNull V usingValue); + WriteContext acquireUsingLocked(@NotNull K key, @NotNull V usingValue); + - // todo document - LockedEntry acquireUsingWriteLocked(@NotNull K key, @NotNull V usingValue); } diff --git a/src/main/java/net/openhft/chronicle/map/LockedEntry.java b/src/main/java/net/openhft/chronicle/map/Context.java similarity index 94% rename from src/main/java/net/openhft/chronicle/map/LockedEntry.java rename to src/main/java/net/openhft/chronicle/map/Context.java index 5cc3b807c..f6728fb40 100644 --- a/src/main/java/net/openhft/chronicle/map/LockedEntry.java +++ b/src/main/java/net/openhft/chronicle/map/Context.java @@ -21,7 +21,7 @@ package net.openhft.chronicle.map; /** * @author Rob Austin. */ -public interface LockedEntry extends AutoCloseable { +interface Context extends AutoCloseable { /** * call this to unlock the maps segment diff --git a/src/main/java/net/openhft/chronicle/map/ReadContext.java b/src/main/java/net/openhft/chronicle/map/ReadContext.java new file mode 100644 index 000000000..188ac65e0 --- /dev/null +++ b/src/main/java/net/openhft/chronicle/map/ReadContext.java @@ -0,0 +1,10 @@ +package net.openhft.chronicle.map; + +/** + * @author Rob Austin. + */ +public interface ReadContext extends Context { + + boolean present(); + +} diff --git a/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java b/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java index 32a31e82e..88abf77df 100644 --- a/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java @@ -255,7 +255,7 @@ class ReplicatedChronicleMap, return (Segment) segments[segmentNum]; } - LockedEntry acquireUsing(K key, V value, LockType lockTypeType) { + T lookupUsing(K key, V value, LockType lockTypeType) { checkKey(key); ThreadLocalCopies copies = keyInteropProvider.getCopies(null); KI keyInterop = keyInteropProvider.get(copies, originalKeyInterop); @@ -285,10 +285,12 @@ class ReplicatedChronicleMap, v = value; } + //todo set dirty when using replication on + lock.value(v); lock.key(key); - return lock; + return (T) lock; } diff --git a/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java b/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java index a186baa90..531e118ac 100644 --- a/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java @@ -401,12 +401,12 @@ class StatelessChronicleMap implements ChronicleMap, Closeable { } @Override - public LockedEntry acquireUsingReadLocked(K key, V usingValue) { + public WriteContext acquireUsingLocked(K key, V usingValue) { throw new UnsupportedOperationException(); } @Override - public LockedEntry acquireUsingWriteLocked(K key, V usingValue) { + public ReadContext getUsingLocked(K key, V usingValue) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java index d8dd18848..514358abf 100644 --- a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java @@ -353,52 +353,47 @@ class VanillaChronicleMap, replaceIfPresent); } + private enum LockType {READ_LOCK, WRITE_LOCK} + @Override public V get(Object key) { - try (LockedEntry kvLockedEntry = acquireUsing((K) key, null, - LockType.READ_LOCK)) { - return kvLockedEntry.value(); + try (Context entry = lookupUsing((K) key, null, + LockType.READ_LOCK)) { + return entry.value(); } } @Override public V getUsing(K key, V usingValue) { - try (LockedEntry kvLockedEntry = acquireUsing(key, usingValue, + try (Context entry = lookupUsing(key, usingValue, LockType.READ_LOCK)) { - return kvLockedEntry.value(); + return entry.value(); } } @Override - public LockedEntry acquireUsingReadLocked(K key, V usingValue) { - return this.acquireUsing(key, usingValue, LockType.READ_LOCK); + public WriteContext acquireUsingLocked(K key, V usingValue) { + return this.lookupUsing(key, usingValue, LockType.WRITE_LOCK); } @Override - public LockedEntry acquireUsingWriteLocked(K key, V usingValue) { - return this.acquireUsing(key, usingValue, LockType.WRITE_LOCK); - - //todo call put() on close of a on-heap value - - //todo set dirty when using replication on + public ReadContext getUsingLocked(K key, V usingValue) { + return this.lookupUsing(key, usingValue, LockType.READ_LOCK); } - // todo remove @Override public V acquireUsing(K key, V usingValue) { - try (LockedEntry kvLockedEntry = acquireUsing(key, usingValue, LockType.WRITE_LOCK)) { - return kvLockedEntry.value(); + try (Context kvContext = lookupUsing(key, usingValue, LockType.WRITE_LOCK)) { + return kvContext.value(); } } - enum LockType {READ_LOCK, WRITE_LOCK} - - LockedEntry acquireUsing(K key, V value, LockType lockTypeType) { + T lookupUsing(K key, V value, LockType lockTypeType) { checkKey(key); ThreadLocalCopies copies = keyInteropProvider.getCopies(null); KI keyInterop = keyInteropProvider.get(copies, originalKeyInterop); @@ -418,41 +413,22 @@ class VanillaChronicleMap, segmentHash, lockTypeType == LockType.WRITE_LOCK); - // we want to call put on heap objects that don't currently exist in the map - if (v == null && !isNativeValueClass && lockTypeType == LockType.WRITE_LOCK) { - lock.copies = copies; - lock.metaKeyInterop = metaKeyInterop; - lock.keyInterop = keyInterop; - lock.segmentHash = segmentHash; + lock.copies = copies; + lock.metaKeyInterop = metaKeyInterop; + lock.keyInterop = keyInterop; + lock.segmentHash = segmentHash; + + if (v == null && lockTypeType == LockType.WRITE_LOCK) { v = value; } lock.value(v); lock.key(key); - return lock; + return (T) lock; } - /* - checkKey(key); - ThreadLocalCopies copies = keyInteropProvider.getCopies(null); - KI keyInterop = keyInteropProvider.get(copies, originalKeyInterop); - copies = metaKeyInteropProvider.getCopies(copies); - MKI metaKeyInterop = - metaKeyInteropProvider.get(copies, originalMetaKeyInterop, keyInterop, key); - long hash = metaKeyInterop.hash(keyInterop, key); - int segmentNum = getSegment(hash); - long segmentHash = segmentHash(hash); - Segment segment = segments[segmentNum]; - - try (LockedEntry lock = create ? segment.writeLock() : segment.readLock()) { - return segment.acquireWithoutLock(copies, metaKeyInterop, keyInterop, key, value, - segmentHash, create); - }*/ - - // } - @Override public boolean containsKey(final Object k) { checkKey(k); @@ -692,7 +668,7 @@ class VanillaChronicleMap, private MultiMap hashLookup; private long nextPosToSearchFrom = 0L; - final MutableLockedEntry readUnlock = new MutableLockedEntry() { + final ReadLocked readUnlock = new ReadLocked() { @Override public void close() { Segment.this.readUnlock(); @@ -702,29 +678,60 @@ class VanillaChronicleMap, /** * close for native values does not call put on close */ - final MutableLockedEntry nativeWriteUnlock = new MutableLockedEntry() { + final MutableLockedEntry nativeWriteUnlock = new WriteLocked() { @Override public void close() { Segment.this.writeUnlock(); } + + @Override + public void dontPutOnClose() { + throw new IllegalStateException("This method is not supported for native value " + + "classes"); + } + + @Override + public void removeEntry() { + if (copies != null) + removeWithoutLock(copies, metaKeyInterop, keyInterop, key(), null, segmentHash); + } + + }; /** * close for heap values calls put on close */ final MutableLockedEntry - heapWriteUnlock = new MutableLockedEntry() { + heapWriteUnlock = new WriteLocked() { + + boolean dontPutOnClose; + @Override public void close() { - - if (copies != null) + if (copies != null && !dontPutOnClose) putWithoutLock(copies, metaKeyInterop, keyInterop, key(), value(), segmentHash, true); copies = null; + dontPutOnClose = false; Segment.this.writeUnlock(); } + + @Override + public void dontPutOnClose() { + dontPutOnClose = true; + } + + @Override + public void removeEntry() { + dontPutOnClose = true; + if (copies != null) + removeWithoutLock(copies, metaKeyInterop, keyInterop, key(), null, segmentHash); + + } + + }; @@ -1146,34 +1153,38 @@ class VanillaChronicleMap, V expectedValue, long hash2) { writeLock(); try { - long keySize = metaKeyInterop.size(keyInterop, key); - hashLookup.startSearch(hash2); - for (long pos; (pos = hashLookup.nextPos()) >= 0L; ) { - long offset = offsetFromPos(pos); - MultiStoreBytes entry = entry(offset); - if (!keyEquals(keyInterop, metaKeyInterop, key, keySize, entry)) - continue; - // key is found - entry.skip(keySize); - long valueSize = readValueSize(entry); - long entryEndAddr = entry.positionAddr() + valueSize; - V valueRemoved = expectedValue != null || !removeReturnsNull - ? readValue(copies, entry, null, valueSize) : null; - if (expectedValue != null && !expectedValue.equals(valueRemoved)) - return null; - hashLookup.removePrevPos(); - decrementSize(); - free(pos, inBlocks(entryEndAddr - entryStartAddr(offset))); - notifyRemoved(offset, key, valueRemoved, pos); - return valueRemoved; - } - // key is not found - return null; + return removeWithoutLock(copies, metaKeyInterop, keyInterop, key, expectedValue, hash2); } finally { writeUnlock(); } } + private V removeWithoutLock(ThreadLocalCopies copies, MKI metaKeyInterop, KI keyInterop, K key, V expectedValue, long hash2) { + long keySize = metaKeyInterop.size(keyInterop, key); + hashLookup.startSearch(hash2); + for (long pos; (pos = hashLookup.nextPos()) >= 0L; ) { + long offset = offsetFromPos(pos); + MultiStoreBytes entry = entry(offset); + if (!keyEquals(keyInterop, metaKeyInterop, key, keySize, entry)) + continue; + // key is found + entry.skip(keySize); + long valueSize = readValueSize(entry); + long entryEndAddr = entry.positionAddr() + valueSize; + V valueRemoved = expectedValue != null || !removeReturnsNull + ? readValue(copies, entry, null, valueSize) : null; + if (expectedValue != null && !expectedValue.equals(valueRemoved)) + return null; + hashLookup.removePrevPos(); + decrementSize(); + free(pos, inBlocks(entryEndAddr - entryStartAddr(offset))); + notifyRemoved(offset, key, valueRemoved, pos); + return valueRemoved; + } + // key is not found + return null; + } + boolean containsKey(KI keyInterop, MKI metaKeyInterop, K key, long hash2) { readLock(); try { @@ -1617,7 +1628,7 @@ class VanillaChronicleMap, } } - static abstract class MutableLockedEntry implements LockedEntry { + static abstract class MutableLockedEntry implements Context { ThreadLocalCopies copies; MKI metaKeyInterop; KI keyInterop; @@ -1630,7 +1641,7 @@ class VanillaChronicleMap, return key; } - public void key(K key) { + void key(K key) { this.key = key; } @@ -1638,10 +1649,35 @@ class VanillaChronicleMap, return value; } - public void value(V value) { + void value(V value) { this.value = value; } } + + private static abstract class ReadLocked extends MutableLockedEntry implements ReadContext { + + boolean present; + + void value(V value) { + this.present = value != null; + super.value(value); + } + + /** + * @return if the value is not null + */ + @Override + public boolean present() { + return present; + } + + + } + + private static abstract class WriteLocked extends MutableLockedEntry implements WriteContext { + } } diff --git a/src/main/java/net/openhft/chronicle/map/WriteContext.java b/src/main/java/net/openhft/chronicle/map/WriteContext.java new file mode 100644 index 000000000..57555aa71 --- /dev/null +++ b/src/main/java/net/openhft/chronicle/map/WriteContext.java @@ -0,0 +1,13 @@ +package net.openhft.chronicle.map; + +/** + * @author Rob Austin. + */ +public interface WriteContext extends Context { + void dontPutOnClose(); + + void removeEntry(); + + // todo I have no idea why we have this, as this will aways be done on when calling close() + // void update(); +} diff --git a/src/test/java/net/openhft/chronicle/map/ChronicleMapTest.java b/src/test/java/net/openhft/chronicle/map/ChronicleMapTest.java index 1d9091615..29b618119 100644 --- a/src/test/java/net/openhft/chronicle/map/ChronicleMapTest.java +++ b/src/test/java/net/openhft/chronicle/map/ChronicleMapTest.java @@ -38,7 +38,6 @@ import java.util.concurrent.atomic.AtomicInteger; import static net.openhft.chronicle.map.Alignment.*; import static org.junit.Assert.*; -import static org.junit.Assert.assertEquals; @SuppressWarnings({"unchecked", "ResultOfMethodCallIgnored"}) public class ChronicleMapTest { @@ -1251,6 +1250,7 @@ public class ChronicleMapTest { } } + @Test public void testOffheapAcquireUsingLocked() throws IOException { OffHeapUpdatableChronicleMapBuilder builder = OffHeapUpdatableChronicleMapBuilder @@ -1262,17 +1262,49 @@ public class ChronicleMapTest { final ChronicleMap map = builder.createWithFile(tmpFile); LongValue value = nativeLongValue(); - try (LockedEntry lockedEntry = map.acquireUsingWriteLocked("one", value)) { - lockedEntry.value().addValue(1); + + + // this will add the entry + try (WriteContext context = map.acquireUsingLocked("one", value)) { + assertEquals(0, context.value().getValue()); + + LongValue value1 = context.value(); + value1.addValue(1); } - try (LockedEntry lockedEntry = map.acquireUsingReadLocked("two", value)) { - assertEquals(null, lockedEntry.value()); + // check that the entry was added + try (ReadContext context = map.getUsingLocked("one", value)) { + assertEquals(true, context.present()); + assertEquals(1, context.value().getValue()); } - try (LockedEntry lockedEntry = map.acquireUsingReadLocked("one", value)) { - assertEquals(1, lockedEntry.value().getValue()); + + // this will remove the entry + try (WriteContext context = map.acquireUsingLocked("one", value)) { + context.removeEntry(); } + + // check that the entry was removed + try (ReadContext context = map.getUsingLocked("one", value)) { + assertEquals(false, context.present()); + assertEquals(null, context.value()); + } + + + try (WriteContext context = map.acquireUsingLocked("one", value)) { + assertEquals(0, context.value().getValue()); + } + + + try (WriteContext context = map.acquireUsingLocked("one", value)) { + context.value().addValue(1); + } + + // check that the entry was removed + try (ReadContext context = map.getUsingLocked("one", value)) { + assertEquals(1, context.value().getValue()); + } + map.close(); } @@ -1289,18 +1321,67 @@ public class ChronicleMapTest { LongValue value = DataValueClasses.newInstance(LongValue.class); - try (LockedEntry lockedEntry = map.acquireUsingWriteLocked("one", value)) { - lockedEntry.value().addValue(1); + try (ReadContext context = map.getUsingLocked("one", value)) { + assertEquals(false, context.present()); + assertEquals(null, context.value()); } - try (LockedEntry lockedEntry = map.acquireUsingReadLocked("two", value)) { - assertEquals(null, lockedEntry.value()); + // this wont add the entry + try (WriteContext context = map.acquireUsingLocked("one", value)) { + context.value().addValue(1); + context.dontPutOnClose(); } - try (LockedEntry lockedEntry = map.acquireUsingReadLocked("one", value)) { + try (ReadContext context = map.getUsingLocked("one", value)) { + assertEquals(false, context.present()); + assertEquals(null, context.value()); + } + + value.setValue(10); + + // this will add the entry + try (WriteContext context = map.acquireUsingLocked("one", value)) { + LongValue value1 = context.value(); + value1.addValue(1); + } + + // check that the entry was added + try (ReadContext context = map.getUsingLocked("one", value)) { + assertEquals(true, context.present()); + assertEquals(11, context.value().getValue()); + } + + + // this will remove the entry + try (WriteContext context = map.acquireUsingLocked("one", value)) { + context.removeEntry(); + } + + // check that the entry was removed + try (ReadContext context = map.getUsingLocked("one", value)) { + assertEquals(false, context.present()); + assertEquals(null, context.value()); + } + + value.setValue(1); + + try (WriteContext context = map.acquireUsingLocked("one", value)) { + assertEquals(1, context.value().getValue()); + } + + try (ReadContext lockedEntry = map.getUsingLocked("one", value)) { assertEquals(1, lockedEntry.value().getValue()); } + try (WriteContext context = map.acquireUsingLocked("one", value)) { + context.value().addValue(1); + } + + // check that the entry was removed + try (ReadContext context = map.getUsingLocked("one", value)) { + assertEquals(2, context.value().getValue()); + } + map.close(); } } diff --git a/src/test/java/net/openhft/chronicle/map/ReplicationCheckingMap.java b/src/test/java/net/openhft/chronicle/map/ReplicationCheckingMap.java index 9971a8f46..faacc4dc8 100644 --- a/src/test/java/net/openhft/chronicle/map/ReplicationCheckingMap.java +++ b/src/test/java/net/openhft/chronicle/map/ReplicationCheckingMap.java @@ -225,7 +225,6 @@ public class ReplicationCheckingMap implements ChronicleMap { @Override public Set> entrySet() { - return check(new Call() { @Override public Object method(ConcurrentMap map) { @@ -252,12 +251,12 @@ public class ReplicationCheckingMap implements ChronicleMap { } @Override - public LockedEntry acquireUsingReadLocked(K key, V usingValue) { + public WriteContext acquireUsingLocked(K key, V usingValue) { throw new UnsupportedOperationException(); } @Override - public LockedEntry acquireUsingWriteLocked(K key, V usingValue) { + public ReadContext getUsingLocked(K key, V usingValue) { throw new UnsupportedOperationException(); } diff --git a/src/test/java/net/openhft/chronicle/map/jrs166/map/StatelessChronicleMapTest.java b/src/test/java/net/openhft/chronicle/map/jrs166/map/StatelessChronicleMapTest.java index 74da7aac6..e66eef94e 100644 --- a/src/test/java/net/openhft/chronicle/map/jrs166/map/StatelessChronicleMapTest.java +++ b/src/test/java/net/openhft/chronicle/map/jrs166/map/StatelessChronicleMapTest.java @@ -18,10 +18,11 @@ package net.openhft.chronicle.map.jrs166.map; +import net.openhft.chronicle.hash.TcpReplicationConfig; import net.openhft.chronicle.map.ChronicleMap; import net.openhft.chronicle.map.ChronicleMapBuilder; -import net.openhft.chronicle.hash.TcpReplicationConfig; -import net.openhft.chronicle.map.LockedEntry; +import net.openhft.chronicle.map.ReadContext; +import net.openhft.chronicle.map.WriteContext; import net.openhft.chronicle.map.jrs166.JSR166TestCase; import org.jetbrains.annotations.NotNull; import org.junit.Test; @@ -151,12 +152,12 @@ public class StatelessChronicleMapTest extends JSR166TestCase { } @Override - public LockedEntry acquireUsingReadLocked(K key, V usingValue) { - throw new UnsupportedOperationException(); + public WriteContext acquireUsingLocked(K key, V usingValue) { + throw new UnsupportedOperationException(); } @Override - public LockedEntry acquireUsingWriteLocked(K key, V usingValue) { + public ReadContext getUsingLocked(K key, V usingValue) { throw new UnsupportedOperationException(); } @@ -231,7 +232,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * clear removes all pairs */ - @Test(timeout=5000) + @Test(timeout = 5000) public void testClear() throws IOException { try (ChronicleMap map = map5(8076)) { @@ -244,7 +245,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * contains returns true for contained value */ - @Test(timeout=5000) + @Test(timeout = 5000) public void testContains() throws IOException { try (ChronicleMap map = map5(8076)) { assertTrue(map.containsValue("A")); @@ -256,7 +257,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * containsKey returns true for contained key */ - @Test(timeout=5000) + @Test(timeout = 5000) public void testContainsKey() throws IOException { try (ChronicleMap map = map5(8076)) { assertTrue(map.containsKey(one)); @@ -267,7 +268,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * containsValue returns true for held values */ - @Test(timeout=5000) + @Test(timeout = 5000) public void testContainsValue() throws IOException { try (ChronicleMap map = map5(8076)) { assertTrue(map.containsValue("A")); @@ -278,7 +279,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * get returns the correct element at the given key, or null if not present */ - @Test(timeout=5000) + @Test(timeout = 5000) public void testGet() throws IOException { try (ChronicleMap map = map5(8076)) { assertEquals("A", (String) map.get(one)); @@ -291,7 +292,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * isEmpty is true of empty map and false for non-empty */ - @Test(timeout=5000) + @Test(timeout = 5000) public void testIsEmpty() throws IOException { try (ChronicleMap empty = newShmIntString(8078)) { try (ChronicleMap map = map5(8079)) { @@ -308,7 +309,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * keySet returns a Set containing all the keys */ - @Test(timeout=5000) + @Test(timeout = 5000) public void testKeySet() throws IOException { try (ChronicleMap map = map5(8076)) { Set s = map.keySet(); @@ -324,7 +325,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * keySet.toArray returns contains all keys */ - @Test(timeout=5000) + @Test(timeout = 5000) public void testKeySetToArray() throws IOException { try (ChronicleMap map = map5(8076)) { Set s = map.keySet(); @@ -339,7 +340,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * Values.toArray contains all values */ - @Test(timeout=5000) + @Test(timeout = 5000) public void testValuesToArray() throws IOException { try (ChronicleMap map = map5(8076)) { Collection v = map.values(); @@ -358,7 +359,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * entrySet.toArray contains all entries */ - @Test(timeout=5000) + @Test(timeout = 5000) public void testEntrySetToArray() throws IOException { try (ChronicleMap map = map5(8076)) { Set s = map.entrySet(); @@ -375,7 +376,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * values collection contains all values */ - @Test(timeout=5000) + @Test(timeout = 5000) public void testValues() throws IOException { try (ChronicleMap map = map5(8076)) { Collection s = map.values(); @@ -391,7 +392,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * entrySet contains all pairs */ - @Test(timeout=5000) + @Test(timeout = 5000) public void testEntrySet() throws IOException { try (ChronicleMap map = map5(8076)) { Set s = map.entrySet(); @@ -414,7 +415,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * putAll adds all key-value pairs from the given map */ - @Test(timeout=5000) + @Test(timeout = 5000) public void testPutAll() throws IOException { try (ChronicleMap empty = newShmIntString(8076)) { @@ -435,7 +436,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * putIfAbsent works when the given key is not present */ - @Test(timeout=5000) + @Test(timeout = 5000) public void testPutIfAbsent() throws IOException { try (ChronicleMap map = map5(8076)) { map.putIfAbsent(six, "Z"); @@ -447,8 +448,8 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * putIfAbsent does not add the pair if the key is already present */ - @Test(timeout=5000) - public void testPutIfAbsent2() throws IOException { + @Test(timeout = 5000) + public void testPutIfAbsent2() throws IOException { try (ChronicleMap map = map5(8076)) { assertEquals("A", map.putIfAbsent(one, "Z")); } @@ -457,7 +458,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * replace fails when the given key is not present */ - @Test(timeout=5000) + @Test(timeout = 5000) public void testReplace() throws IOException { try (ChronicleMap map = map5(8076)) { assertNull(map.replace(six, "Z")); @@ -469,7 +470,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * replace succeeds if the key is already present */ - @Test(timeout=5000) + @Test(timeout = 5000) public void testReplace2() throws IOException { try (ChronicleMap map = map5(8076)) { @@ -481,7 +482,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * replace value fails when the given key not mapped to expected value */ - @Test(timeout=5000) + @Test(timeout = 5000) public void testReplaceValue() throws IOException { try (ChronicleMap map = map5(8076)) { @@ -495,7 +496,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * replace value succeeds when the given key mapped to expected value */ - @Test(timeout=5000) + @Test(timeout = 5000) public void testReplaceValue2 () throws IOException { try (ChronicleMap map = map5(8076)) { @@ -509,7 +510,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * remove removes the correct key-value pair from the map */ - @Test(timeout=5000) + @Test(timeout = 5000) public void testRemove() throws IOException { try (ChronicleMap map = map5(8076)) { @@ -523,7 +524,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * remove(key,value) removes only if pair present */ - @Test(timeout=5000) + @Test(timeout = 5000) public void testRemove2 () throws IOException { /* try( ChronicleMap map = map5(8076)) { @@ -539,12 +540,12 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * size returns the correct values */ - @Test(timeout=5000) + @Test(timeout = 5000) public void testSize() throws IOException { try (ChronicleMap map = map5(8076)) { try (ChronicleMap empty = newShmIntString(8078)) { - assertEquals(0, empty.size()) ; + assertEquals(0, empty.size()); assertEquals(5, map.size()); } } @@ -553,25 +554,26 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * size returns the correct values */ - @Test(timeout=5000) + @Test(timeout = 5000) public void testSize2() throws IOException { try (ChronicleMap map = map5(8076)) { try (ChronicleMap empty = newShmIntString(8078)) { - assertEquals(0, empty.size()) ; + assertEquals(0, empty.size()); assertEquals(5, map.size()); } } } + /** * size returns the correct values */ - @Test(timeout=5000) + @Test(timeout = 5000) public void testSize3() throws IOException { try (ChronicleMap map = map5(8076)) { try (ChronicleMap empty = newShmIntString(8078)) { - assertEquals(0, empty.size()) ; + assertEquals(0, empty.size()); assertEquals(5, map.size()); } } @@ -580,7 +582,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * toString contains toString of elements */ - @Test(timeout=5000) + @Test(timeout = 5000) public void testToString() throws IOException { try (ChronicleMap map = map5(8076)) { String s = map.toString(); @@ -594,7 +596,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * get(null) throws NPE */ - @Test(timeout=5000) + @Test(timeout = 5000) public void testGet_NullPointerException() throws IOException { try (ChronicleMap c = newShmIntString(8076)) { @@ -608,7 +610,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * containsKey(null) throws NPE */ - @Test(timeout=5000) + @Test(timeout = 5000) public void testContainsKey_NullPointerException() throws IOException { try (ChronicleMap c = newShmIntString(8079)) { c.containsKey(null); @@ -620,8 +622,8 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * put(null,x) throws NPE */ - @Test(timeout=5000) - public void testPut1_NullPointerException () throws IOException { + @Test(timeout = 5000) + public void testPut1_NullPointerException() throws IOException { try (ChronicleMap c = newShmIntString(8076)) { c.put(null, "whatever"); shouldThrow(); @@ -632,7 +634,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * put(x, null) throws NPE */ - @Test(timeout=5000) + @Test(timeout = 5000) public void testPut2_NullPointerException () throws IOException { try (ChronicleMap c = newShmIntString(8076)) { @@ -645,7 +647,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * putIfAbsent(null, x) throws NPE */ - @Test(timeout=5000) + @Test(timeout = 5000) public void testPutIfAbsent1_NullPointerException () throws IOException { try (ChronicleMap c = newShmIntString(8076)) { @@ -659,7 +661,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * replace(null, x) throws NPE */ - @Test(timeout=5000) + @Test(timeout = 5000) public void testReplace_NullPointerException () throws IOException { try (ChronicleMap c = newShmIntString(8076)) { @@ -672,7 +674,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * replace(null, x, y) throws NPE */ - @Test(timeout=5000) + @Test(timeout = 5000) public void testReplaceValue_NullPointerException () throws IOException { try (ChronicleMap c = newShmIntString(8076)) { @@ -686,8 +688,8 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * putIfAbsent(x, null) throws NPE */ - @Test(timeout=5000) - public void testPutIfAbsent2_NullPointerException () throws IOException { + @Test(timeout = 5000) + public void testPutIfAbsent2_NullPointerException() throws IOException { try (ChronicleMap c = newShmIntString(8076)) { c.putIfAbsent(notPresent, null); shouldThrow(); @@ -698,8 +700,8 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * replace(x, null) throws NPE */ - @Test(timeout=5000) - public void testReplace2_NullPointerException () throws IOException { + @Test(timeout = 5000) + public void testReplace2_NullPointerException() throws IOException { try (ChronicleMap c = newShmIntString(8076)) { c.replace(notPresent, null); shouldThrow(); @@ -710,7 +712,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * replace(x, null, y) throws NPE */ - @Test(timeout=5000) + @Test(timeout = 5000) public void testReplaceValue2_NullPointerException () throws IOException { try (ChronicleMap c = newShmIntString(8076)) { @@ -723,8 +725,8 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * replace(x, y, null) throws NPE */ - @Test(timeout=5000) - public void testReplaceValue3_NullPointerException () throws IOException { + @Test(timeout = 5000) + public void testReplaceValue3_NullPointerException() throws IOException { try (ChronicleMap c = newShmIntString(8076)) { c.replace(notPresent, "A", null); shouldThrow(); @@ -735,7 +737,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * remove(null) throws NPE */ - @Test(timeout=5000) + @Test(timeout = 5000) public void testRemove1_NullPointerException() throws IOException { try (ChronicleMap c = newStrStrMap(8076)) { c.put("sadsdf", "asdads"); @@ -748,7 +750,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * remove(null, x) throws NPE */ - @Test(timeout=5000) + @Test(timeout = 5000) public void testRemove2_NullPointerException () throws IOException { try (ChronicleMap c = newStrStrMap(8086)) { @@ -762,7 +764,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase { /** * remove(x, null) returns false */ - @Test(timeout=5000) + @Test(timeout = 5000) public void testRemove3() throws IOException { try (ChronicleMap c = newStrStrMap(8076)) {