mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
HCOLL-155 added two of peters tests and them implemented the code accordingly - the test are net.openhft.chronicle.map.ChronicleMapTest#testOffheapAcquireUsingLocked and net.openhft.chronicle.map.ChronicleMapTest#testOnheapAcquireUsingLocked
This commit is contained in:
@@ -38,6 +38,7 @@ 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 {
|
||||
@@ -469,7 +470,7 @@ public class ChronicleMapTest {
|
||||
|
||||
@Test
|
||||
public void testGetWithoutAcquireFirst() throws Exception {
|
||||
ChronicleMap<CharSequence, LongValue> map = getSharedMap(10 , 1, 24);
|
||||
ChronicleMap<CharSequence, LongValue> map = getSharedMap(10, 1, 24);
|
||||
assertNull(map.getUsing("key", DataValueClasses.newDirectReference(LongValue.class)));
|
||||
|
||||
map.close();
|
||||
@@ -1249,4 +1250,59 @@ public class ChronicleMapTest {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOffheapAcquireUsingLocked() throws IOException {
|
||||
OffHeapUpdatableChronicleMapBuilder<CharSequence, LongValue> builder = OffHeapUpdatableChronicleMapBuilder
|
||||
.of(CharSequence.class, LongValue.class)
|
||||
.entries(1000)
|
||||
.entrySize(16);
|
||||
File tmpFile = File.createTempFile("testAcquireUsingLocked", ".deleteme");
|
||||
tmpFile.deleteOnExit();
|
||||
final ChronicleMap<CharSequence, LongValue> map = builder.createWithFile(tmpFile);
|
||||
|
||||
LongValue value = nativeLongValue();
|
||||
try (LockedEntry<?, LongValue> lockedEntry = map.acquireUsingWriteLocked("one", value)) {
|
||||
lockedEntry.value().addValue(1);
|
||||
}
|
||||
|
||||
try (LockedEntry<?, LongValue> lockedEntry = map.acquireUsingReadLocked("two", value)) {
|
||||
assertEquals(null, lockedEntry.value());
|
||||
}
|
||||
|
||||
try (LockedEntry<?, LongValue> lockedEntry = map.acquireUsingReadLocked("one", value)) {
|
||||
assertEquals(1, lockedEntry.value().getValue());
|
||||
}
|
||||
map.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnheapAcquireUsingLocked() throws IOException {
|
||||
ChronicleMapBuilder<CharSequence, LongValue> builder = ChronicleMapBuilder
|
||||
.of(CharSequence.class, LongValue.class)
|
||||
.entries(1000)
|
||||
.entrySize(40);
|
||||
File tmpFile = File.createTempFile("testAcquireUsingLocked", ".deleteme");
|
||||
tmpFile.deleteOnExit();
|
||||
final ChronicleMap<CharSequence, LongValue> map = builder.createWithFile(tmpFile);
|
||||
|
||||
LongValue value = DataValueClasses.newInstance(LongValue.class);
|
||||
|
||||
|
||||
try (LockedEntry<?, LongValue> lockedEntry = map.acquireUsingWriteLocked("one", value)) {
|
||||
lockedEntry.value().addValue(1);
|
||||
}
|
||||
|
||||
try (LockedEntry<?, LongValue> lockedEntry = map.acquireUsingReadLocked("two", value)) {
|
||||
assertEquals(null, lockedEntry.value());
|
||||
}
|
||||
|
||||
try (LockedEntry<?, LongValue> lockedEntry = map.acquireUsingReadLocked("one", value)) {
|
||||
assertEquals(1, lockedEntry.value().getValue());
|
||||
}
|
||||
|
||||
map.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -252,12 +252,12 @@ public class ReplicationCheckingMap<K, V> implements ChronicleMap<K, V> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public SegmentLock acquireUsingReadLocked(K key, V usingValue) {
|
||||
public LockedEntry acquireUsingReadLocked(K key, V usingValue) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SegmentLock acquireUsingWriteLocked(K key, V usingValue) {
|
||||
public LockedEntry acquireUsingWriteLocked(K key, V usingValue) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ package net.openhft.chronicle.map.jrs166.map;
|
||||
import net.openhft.chronicle.map.ChronicleMap;
|
||||
import net.openhft.chronicle.map.ChronicleMapBuilder;
|
||||
import net.openhft.chronicle.hash.TcpReplicationConfig;
|
||||
import net.openhft.chronicle.map.SegmentLock;
|
||||
import net.openhft.chronicle.map.LockedEntry;
|
||||
import net.openhft.chronicle.map.jrs166.JSR166TestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.Test;
|
||||
@@ -151,12 +151,12 @@ public class StatelessChronicleMapTest extends JSR166TestCase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public SegmentLock acquireUsingReadLocked(K key, V usingValue) {
|
||||
public LockedEntry acquireUsingReadLocked(K key, V usingValue) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SegmentLock acquireUsingWriteLocked(K key, V usingValue) {
|
||||
public LockedEntry acquireUsingWriteLocked(K key, V usingValue) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user