mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
HCOLL-155 removed acquireUsingReadLocked and acquireUsingWriteLocked to WriteContext<K,V> acquireUsingLocked(@NotNull K key, @NotNull V usingValue); and ReadContext<K,V> getUsingLocked(@NotNull K key, @NotNull V usingValue);
This commit is contained in:
@@ -103,6 +103,9 @@ public interface ChronicleMap<K, V> extends ConcurrentMap<K, V>, ChronicleHash {
|
||||
*/
|
||||
V getUsing(K key, V usingValue);
|
||||
|
||||
// todo document
|
||||
ReadContext<K,V> getUsingLocked(@NotNull K key, @NotNull V usingValue);
|
||||
|
||||
/**
|
||||
* Acquire a value for a key, creating if absent.
|
||||
*
|
||||
@@ -142,9 +145,8 @@ public interface ChronicleMap<K, V> extends ConcurrentMap<K, V>, ChronicleHash {
|
||||
|
||||
|
||||
// todo document
|
||||
LockedEntry<K,V> acquireUsingReadLocked(@NotNull K key, @NotNull V usingValue);
|
||||
WriteContext<K,V> acquireUsingLocked(@NotNull K key, @NotNull V usingValue);
|
||||
|
||||
|
||||
// todo document
|
||||
LockedEntry<K,V> acquireUsingWriteLocked(@NotNull K key, @NotNull V usingValue);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ package net.openhft.chronicle.map;
|
||||
/**
|
||||
* @author Rob Austin.
|
||||
*/
|
||||
public interface LockedEntry<K, V> extends AutoCloseable {
|
||||
interface Context<K, V> extends AutoCloseable {
|
||||
|
||||
/**
|
||||
* call this to unlock the maps segment
|
||||
@@ -0,0 +1,10 @@
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
/**
|
||||
* @author Rob Austin.
|
||||
*/
|
||||
public interface ReadContext<K,V> extends Context<K,V> {
|
||||
|
||||
boolean present();
|
||||
|
||||
}
|
||||
@@ -255,7 +255,7 @@ class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, KI>,
|
||||
return (Segment) segments[segmentNum];
|
||||
}
|
||||
|
||||
LockedEntry<K, V> acquireUsing(K key, V value, LockType lockTypeType) {
|
||||
<T extends Context> 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<K, KI, MKI extends MetaBytesInterop<K, KI>,
|
||||
v = value;
|
||||
}
|
||||
|
||||
//todo set dirty when using replication on
|
||||
|
||||
lock.value(v);
|
||||
lock.key(key);
|
||||
|
||||
return lock;
|
||||
return (T) lock;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -401,12 +401,12 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public LockedEntry acquireUsingReadLocked(K key, V usingValue) {
|
||||
public WriteContext<K,V> acquireUsingLocked(K key, V usingValue) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LockedEntry acquireUsingWriteLocked(K key, V usingValue) {
|
||||
public ReadContext<K,V> getUsingLocked(K key, V usingValue) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
@@ -353,52 +353,47 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, KI>,
|
||||
replaceIfPresent);
|
||||
}
|
||||
|
||||
private enum LockType {READ_LOCK, WRITE_LOCK}
|
||||
|
||||
@Override
|
||||
public V get(Object key) {
|
||||
|
||||
try (LockedEntry<K, V> kvLockedEntry = acquireUsing((K) key, null,
|
||||
LockType.READ_LOCK)) {
|
||||
return kvLockedEntry.value();
|
||||
try (Context<K, V> entry = lookupUsing((K) key, null,
|
||||
LockType.READ_LOCK)) {
|
||||
return entry.value();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public V getUsing(K key, V usingValue) {
|
||||
|
||||
try (LockedEntry<K, V> kvLockedEntry = acquireUsing(key, usingValue,
|
||||
try (Context<K, V> entry = lookupUsing(key, usingValue,
|
||||
LockType.READ_LOCK)) {
|
||||
return kvLockedEntry.value();
|
||||
return entry.value();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LockedEntry<K, V> acquireUsingReadLocked(K key, V usingValue) {
|
||||
return this.acquireUsing(key, usingValue, LockType.READ_LOCK);
|
||||
public WriteContext<K, V> acquireUsingLocked(K key, V usingValue) {
|
||||
return this.lookupUsing(key, usingValue, LockType.WRITE_LOCK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LockedEntry<K, V> 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<K, V> 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<K, V> kvLockedEntry = acquireUsing(key, usingValue, LockType.WRITE_LOCK)) {
|
||||
return kvLockedEntry.value();
|
||||
try (Context<K, V> kvContext = lookupUsing(key, usingValue, LockType.WRITE_LOCK)) {
|
||||
return kvContext.value();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
enum LockType {READ_LOCK, WRITE_LOCK}
|
||||
|
||||
LockedEntry<K, V> acquireUsing(K key, V value, LockType lockTypeType) {
|
||||
<T extends Context> 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<K, KI, MKI extends MetaBytesInterop<K, KI>,
|
||||
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<K, KI, MKI extends MetaBytesInterop<K, KI>,
|
||||
private MultiMap hashLookup;
|
||||
private long nextPosToSearchFrom = 0L;
|
||||
|
||||
final MutableLockedEntry<K, V, MKI, KI> readUnlock = new MutableLockedEntry<K, V, MKI, KI>() {
|
||||
final ReadLocked<K, V, MKI, KI> readUnlock = new ReadLocked<K, V, MKI, KI>() {
|
||||
@Override
|
||||
public void close() {
|
||||
Segment.this.readUnlock();
|
||||
@@ -702,29 +678,60 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, KI>,
|
||||
/**
|
||||
* close for native values does not call put on close
|
||||
*/
|
||||
final MutableLockedEntry<K, V, MKI, KI> nativeWriteUnlock = new MutableLockedEntry<K, V,
|
||||
MKI, KI>() {
|
||||
final MutableLockedEntry<K, V, MKI, KI> nativeWriteUnlock = new WriteLocked<K, V, MKI, KI>() {
|
||||
@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<K, V, MKI, KI>
|
||||
heapWriteUnlock = new MutableLockedEntry<K, V, MKI, KI>() {
|
||||
heapWriteUnlock = new WriteLocked<K, V, MKI, KI>() {
|
||||
|
||||
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<K, KI, MKI extends MetaBytesInterop<K, KI>,
|
||||
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<K, KI, MKI extends MetaBytesInterop<K, KI>,
|
||||
}
|
||||
}
|
||||
|
||||
static abstract class MutableLockedEntry<K, V, MKI, KI> implements LockedEntry<K, V> {
|
||||
static abstract class MutableLockedEntry<K, V, MKI, KI> implements Context<K, V> {
|
||||
ThreadLocalCopies copies;
|
||||
MKI metaKeyInterop;
|
||||
KI keyInterop;
|
||||
@@ -1630,7 +1641,7 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, KI>,
|
||||
return key;
|
||||
}
|
||||
|
||||
public void key(K key) {
|
||||
void key(K key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@@ -1638,10 +1649,35 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, KI>,
|
||||
return value;
|
||||
}
|
||||
|
||||
public void value(V value) {
|
||||
void value(V value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static abstract class ReadLocked<K, V, MKI, KI> extends MutableLockedEntry<K, V, MKI,
|
||||
KI> implements ReadContext<K, V> {
|
||||
|
||||
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<K, V, MKI, KI> extends MutableLockedEntry<K, V, MKI,
|
||||
KI> implements WriteContext<K, V> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
/**
|
||||
* @author Rob Austin.
|
||||
*/
|
||||
public interface WriteContext<K, V> extends Context<K, V> {
|
||||
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();
|
||||
}
|
||||
@@ -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<CharSequence, LongValue> builder = OffHeapUpdatableChronicleMapBuilder
|
||||
@@ -1262,17 +1262,49 @@ public class ChronicleMapTest {
|
||||
final ChronicleMap<CharSequence, LongValue> map = builder.createWithFile(tmpFile);
|
||||
|
||||
LongValue value = nativeLongValue();
|
||||
try (LockedEntry<?, LongValue> lockedEntry = map.acquireUsingWriteLocked("one", value)) {
|
||||
lockedEntry.value().addValue(1);
|
||||
|
||||
|
||||
// this will add the entry
|
||||
try (WriteContext<?, LongValue> context = map.acquireUsingLocked("one", value)) {
|
||||
assertEquals(0, context.value().getValue());
|
||||
|
||||
LongValue value1 = context.value();
|
||||
value1.addValue(1);
|
||||
}
|
||||
|
||||
try (LockedEntry<?, LongValue> lockedEntry = map.acquireUsingReadLocked("two", value)) {
|
||||
assertEquals(null, lockedEntry.value());
|
||||
// check that the entry was added
|
||||
try (ReadContext<?, LongValue> context = map.getUsingLocked("one", value)) {
|
||||
assertEquals(true, context.present());
|
||||
assertEquals(1, context.value().getValue());
|
||||
}
|
||||
|
||||
try (LockedEntry<?, LongValue> lockedEntry = map.acquireUsingReadLocked("one", value)) {
|
||||
assertEquals(1, lockedEntry.value().getValue());
|
||||
|
||||
// this will remove the entry
|
||||
try (WriteContext<?, LongValue> context = map.acquireUsingLocked("one", value)) {
|
||||
context.removeEntry();
|
||||
}
|
||||
|
||||
// check that the entry was removed
|
||||
try (ReadContext<?, LongValue> context = map.getUsingLocked("one", value)) {
|
||||
assertEquals(false, context.present());
|
||||
assertEquals(null, context.value());
|
||||
}
|
||||
|
||||
|
||||
try (WriteContext<?, LongValue> context = map.acquireUsingLocked("one", value)) {
|
||||
assertEquals(0, context.value().getValue());
|
||||
}
|
||||
|
||||
|
||||
try (WriteContext<?, LongValue> context = map.acquireUsingLocked("one", value)) {
|
||||
context.value().addValue(1);
|
||||
}
|
||||
|
||||
// check that the entry was removed
|
||||
try (ReadContext<?, LongValue> 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<?, LongValue> lockedEntry = map.acquireUsingWriteLocked("one", value)) {
|
||||
lockedEntry.value().addValue(1);
|
||||
try (ReadContext<?, LongValue> context = map.getUsingLocked("one", value)) {
|
||||
assertEquals(false, context.present());
|
||||
assertEquals(null, context.value());
|
||||
}
|
||||
|
||||
try (LockedEntry<?, LongValue> lockedEntry = map.acquireUsingReadLocked("two", value)) {
|
||||
assertEquals(null, lockedEntry.value());
|
||||
// this wont add the entry
|
||||
try (WriteContext<?, LongValue> context = map.acquireUsingLocked("one", value)) {
|
||||
context.value().addValue(1);
|
||||
context.dontPutOnClose();
|
||||
}
|
||||
|
||||
try (LockedEntry<?, LongValue> lockedEntry = map.acquireUsingReadLocked("one", value)) {
|
||||
try (ReadContext<?, LongValue> context = map.getUsingLocked("one", value)) {
|
||||
assertEquals(false, context.present());
|
||||
assertEquals(null, context.value());
|
||||
}
|
||||
|
||||
value.setValue(10);
|
||||
|
||||
// this will add the entry
|
||||
try (WriteContext<?, LongValue> context = map.acquireUsingLocked("one", value)) {
|
||||
LongValue value1 = context.value();
|
||||
value1.addValue(1);
|
||||
}
|
||||
|
||||
// check that the entry was added
|
||||
try (ReadContext<?, LongValue> context = map.getUsingLocked("one", value)) {
|
||||
assertEquals(true, context.present());
|
||||
assertEquals(11, context.value().getValue());
|
||||
}
|
||||
|
||||
|
||||
// this will remove the entry
|
||||
try (WriteContext<?, LongValue> context = map.acquireUsingLocked("one", value)) {
|
||||
context.removeEntry();
|
||||
}
|
||||
|
||||
// check that the entry was removed
|
||||
try (ReadContext<?, LongValue> context = map.getUsingLocked("one", value)) {
|
||||
assertEquals(false, context.present());
|
||||
assertEquals(null, context.value());
|
||||
}
|
||||
|
||||
value.setValue(1);
|
||||
|
||||
try (WriteContext<?, LongValue> context = map.acquireUsingLocked("one", value)) {
|
||||
assertEquals(1, context.value().getValue());
|
||||
}
|
||||
|
||||
try (ReadContext<?, LongValue> lockedEntry = map.getUsingLocked("one", value)) {
|
||||
assertEquals(1, lockedEntry.value().getValue());
|
||||
}
|
||||
|
||||
try (WriteContext<?, LongValue> context = map.acquireUsingLocked("one", value)) {
|
||||
context.value().addValue(1);
|
||||
}
|
||||
|
||||
// check that the entry was removed
|
||||
try (ReadContext<?, LongValue> context = map.getUsingLocked("one", value)) {
|
||||
assertEquals(2, context.value().getValue());
|
||||
}
|
||||
|
||||
map.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,7 +225,6 @@ public class ReplicationCheckingMap<K, V> implements ChronicleMap<K, V> {
|
||||
@Override
|
||||
public Set<Entry<K, V>> entrySet() {
|
||||
|
||||
|
||||
return check(new Call<K, V>() {
|
||||
@Override
|
||||
public Object method(ConcurrentMap<K, V> map) {
|
||||
@@ -252,12 +251,12 @@ public class ReplicationCheckingMap<K, V> implements ChronicleMap<K, V> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public LockedEntry acquireUsingReadLocked(K key, V usingValue) {
|
||||
public WriteContext<K, V> acquireUsingLocked(K key, V usingValue) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LockedEntry acquireUsingWriteLocked(K key, V usingValue) {
|
||||
public ReadContext<K, V> getUsingLocked(K key, V usingValue) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
@@ -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<K, V> acquireUsingLocked(K key, V usingValue) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LockedEntry acquireUsingWriteLocked(K key, V usingValue) {
|
||||
public ReadContext<K, V> 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<Integer, String> 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)) {
|
||||
|
||||
Reference in New Issue
Block a user