mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Removed ChronicleHash.context() method and changed acquireContext() return type from deprecated MapKeyContext to Closeable
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
package eg;
|
||||
|
||||
import net.openhft.chronicle.core.io.Closeable;
|
||||
import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig;
|
||||
import net.openhft.chronicle.map.ChronicleMap;
|
||||
import net.openhft.chronicle.map.ChronicleMapBuilder;
|
||||
import net.openhft.chronicle.map.MapKeyContext;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
@@ -51,8 +50,7 @@ public class TestNesterInterfaceMarshal {
|
||||
TestInstrumentVOInterface intrumentVOInterface = map.newValueInstance();
|
||||
|
||||
|
||||
try (MapKeyContext<?, TestInstrumentVOInterface> wc = map.acquireContext
|
||||
("KEY1", intrumentVOInterface)) {
|
||||
try (Closeable c = map.acquireContext("KEY1", intrumentVOInterface)) {
|
||||
intrumentVOInterface.setSymbol("Flyer");
|
||||
intrumentVOInterface.setCurrencyCode("USA");
|
||||
intrumentVOInterface.setSizeOfInstrumentIDArray(2);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,6 +2,7 @@ package net.openhft.chronicle.map;
|
||||
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver;
|
||||
import net.openhft.chronicle.core.io.Closeable;
|
||||
import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig;
|
||||
import net.openhft.chronicle.map.fromdocs.BondVOInterface;
|
||||
import net.openhft.lang.values.LongValue;
|
||||
@@ -257,11 +258,10 @@ public class ChronicleMapImportExportTest {
|
||||
LongValue value = expected.newValueInstance();
|
||||
|
||||
// this will add the entry
|
||||
try (MapKeyContext<?, LongValue> context = expected.acquireContext("one", value)) {
|
||||
assertEquals(0, context.get().getValue());
|
||||
assert value == context.get();
|
||||
LongValue value1 = context.get();
|
||||
value1.addValue(1);
|
||||
try (Closeable c =
|
||||
expected.acquireContext("one", value)) {
|
||||
assertEquals(0, value.getValue());
|
||||
value.addValue(1);
|
||||
}
|
||||
|
||||
expected.getAll(file);
|
||||
@@ -294,14 +294,12 @@ public class ChronicleMapImportExportTest {
|
||||
final BondVOInterface value = expected.newValueInstance();
|
||||
|
||||
// this will add the entry
|
||||
try (MapKeyContext context = expected.acquireContext("one", value)) {
|
||||
try (Closeable c = expected.acquireContext("one", value)) {
|
||||
value.setCoupon(8.98);
|
||||
BondVOInterface.MarketPx marketPxIntraDayHistoryAt =
|
||||
value.getMarketPxIntraDayHistoryAt(1);
|
||||
|
||||
marketPxIntraDayHistoryAt.setAskPx(12.0);
|
||||
|
||||
assert value == context.get();
|
||||
}
|
||||
|
||||
expected.getAll(file);
|
||||
|
||||
@@ -20,6 +20,8 @@ package net.openhft.chronicle.map;
|
||||
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.google.common.primitives.Ints;
|
||||
import net.openhft.chronicle.bytes.BytesStore;
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.hash.replication.SingleChronicleHashReplication;
|
||||
import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig;
|
||||
import net.openhft.lang.model.DataValueClasses;
|
||||
@@ -732,7 +734,8 @@ public class ChronicleMapTest {
|
||||
map.getUsing(key, value);
|
||||
|
||||
} else {
|
||||
try (MapKeyContext wc = map.acquireContext(key, value)) {
|
||||
try (net.openhft.chronicle.core.io.Closeable c =
|
||||
map.acquireContext(key, value)) {
|
||||
if (value.length() < value0.length() - 1)
|
||||
value.append(value0);
|
||||
else if (value.length() > value0.length())
|
||||
@@ -824,8 +827,8 @@ public class ChronicleMapTest {
|
||||
map.getUsing(key, value);
|
||||
|
||||
} else {
|
||||
try (MapKeyContext wc = map.acquireContext(key,
|
||||
value)) {
|
||||
try (net.openhft.chronicle.core.io.Closeable c =
|
||||
map.acquireContext(key, value)) {
|
||||
if (value.length() < value0.length() - 1)
|
||||
value.append(value0);
|
||||
else if (value.length() > value0.length())
|
||||
@@ -923,21 +926,27 @@ public class ChronicleMapTest {
|
||||
long n;
|
||||
// 75% read
|
||||
if (rand.nextBoolean() || rand.nextBoolean()) {
|
||||
try (MapKeyContext<?, LongValue> c = map.context(sb)) {
|
||||
if (c.containsKey()) {
|
||||
try (ExternalMapQueryContext<?, LongValue, ?> c =
|
||||
map.queryContext(sb)) {
|
||||
MapEntry<?, LongValue> entry = c.entry();
|
||||
if (entry != null) {
|
||||
// Attempt to pass abstraction hierarchies
|
||||
n = c.entry().readVolatileLong(c.valueOffset()) + 1;
|
||||
Data<LongValue> v = entry.value();
|
||||
n = v.bytes().readVolatileLong(v.offset()) + 1;
|
||||
} else {
|
||||
n = 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
try (MapKeyContext<?, LongValue> wc = map.context(sb)) {
|
||||
wc.updateLock().lock();
|
||||
if (wc.containsKey()) {
|
||||
n = wc.entry().addLong(wc.valueOffset(), 1);
|
||||
try (ExternalMapQueryContext<CharSequence, LongValue, ?> c =
|
||||
map.queryContext(sb)) {
|
||||
c.updateLock().lock();
|
||||
MapEntry<?, LongValue> entry = c.entry();
|
||||
if (entry != null) {
|
||||
Data<LongValue> v = entry.value();
|
||||
n = ((BytesStore) v.bytes()).addAndGetLong(v.offset(), 1);
|
||||
} else {
|
||||
wc.put(ONE);
|
||||
c.insert(c.absentEntry(), c.wrapValueAsData(ONE));
|
||||
n = 1;
|
||||
}
|
||||
}
|
||||
@@ -1012,7 +1021,8 @@ public class ChronicleMapTest {
|
||||
j += independence) {
|
||||
key.setValue(j * factor);
|
||||
long n;
|
||||
try (MapKeyContext wc = map.acquireContext(key, value)) {
|
||||
try (net.openhft.chronicle.core.io.Closeable c =
|
||||
map.acquireContext(key, value)) {
|
||||
n = value.addValue(1);
|
||||
}
|
||||
assert n > 0 && n < 1000 : "Counter corrupted " + n;
|
||||
@@ -1638,48 +1648,47 @@ public class ChronicleMapTest {
|
||||
LongValue value = nativeLongValue();
|
||||
|
||||
// this will add the entry
|
||||
try (MapKeyContext<?, LongValue> context = map.acquireContext("one", value)) {
|
||||
assertEquals(0, context.get().getValue());
|
||||
assert value == context.get();
|
||||
LongValue value1 = context.get();
|
||||
value1.addValue(1);
|
||||
try (net.openhft.chronicle.core.io.Closeable c = map.acquireContext("one", value)) {
|
||||
assertEquals(0, value.getValue());
|
||||
value.addValue(1);
|
||||
}
|
||||
|
||||
// check that the entry was added
|
||||
try (MapKeyContext<?, LongValue> context = map.context("one")) {
|
||||
assertEquals(true, context.containsKey());
|
||||
LongValue v = context.getUsing(value);
|
||||
try (ExternalMapQueryContext<CharSequence, LongValue, ?> c = map.queryContext("one")) {
|
||||
MapEntry<CharSequence, LongValue> entry = c.entry();
|
||||
assertNotNull(entry);
|
||||
LongValue v = entry.value().getUsing(value);
|
||||
assert v == value;
|
||||
assertEquals(1, v.getValue());
|
||||
}
|
||||
|
||||
// this will remove the entry
|
||||
try (MapKeyContext<?, LongValue> context = map.context("one")) {
|
||||
context.remove();
|
||||
try (ExternalMapQueryContext<CharSequence, LongValue, ?> c = map.queryContext("one")) {
|
||||
c.updateLock().lock();
|
||||
c.remove(c.entry());
|
||||
}
|
||||
|
||||
// check that the entry was removed
|
||||
try (MapKeyContext<?, LongValue> context = map.context("one")) {
|
||||
context.updateLock().lock();
|
||||
assertEquals(false, context.containsKey());
|
||||
assertEquals(null, context.get());
|
||||
try (ExternalMapQueryContext<CharSequence, LongValue, ?> c = map.queryContext("one")) {
|
||||
c.updateLock().lock();
|
||||
assertNotNull(c.absentEntry());
|
||||
}
|
||||
|
||||
try (MapKeyContext<?, LongValue> context = map.acquireContext("one", value)) {
|
||||
assert value == context.get();
|
||||
assertEquals(0, context.get().getValue());
|
||||
try (net.openhft.chronicle.core.io.Closeable c =
|
||||
map.acquireContext("one", value)) {
|
||||
assertEquals(0, value.getValue());
|
||||
}
|
||||
|
||||
try (MapKeyContext<?, LongValue> context = map.acquireContext("one", value)) {
|
||||
assert value == context.get();
|
||||
context.get().addValue(1);
|
||||
try (net.openhft.chronicle.core.io.Closeable c =
|
||||
map.acquireContext("one", value)) {
|
||||
value.addValue(1);
|
||||
}
|
||||
|
||||
// check that the entry was removed
|
||||
try (MapKeyContext<?, LongValue> context = map.context("one")) {
|
||||
LongValue v = context.getUsing(value);
|
||||
try (ExternalMapQueryContext<CharSequence, LongValue, ?> c = map.queryContext("one")) {
|
||||
LongValue v = c.entry().value().getUsing(value);
|
||||
assert value == v;
|
||||
assertEquals(1, context.get().getValue());
|
||||
assertEquals(1, c.entry().value().get().getValue());
|
||||
}
|
||||
|
||||
map.close();
|
||||
@@ -1733,7 +1742,7 @@ public class ChronicleMapTest {
|
||||
|
||||
try (final ChronicleMap<CharSequence, String> map = builder.create()) {
|
||||
// this will add the entry
|
||||
try (MapKeyContext<?, String> context = map.acquireContext("one", "")) {
|
||||
try (net.openhft.chronicle.core.io.Closeable c = map.acquireContext("one", "")) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
@@ -1751,7 +1760,8 @@ public class ChronicleMapTest {
|
||||
.create()) {
|
||||
StringBuilder value = new StringBuilder();
|
||||
|
||||
try (MapKeyContext<?, CharSequence> context = map.acquireContext("one", value)) {
|
||||
try (net.openhft.chronicle.core.io.Closeable c =
|
||||
map.acquireContext("one", value)) {
|
||||
value.append("Hello World");
|
||||
}
|
||||
|
||||
@@ -1771,56 +1781,58 @@ public class ChronicleMapTest {
|
||||
|
||||
LongValue value = DataValueClasses.newDirectReference(LongValue.class);
|
||||
|
||||
try (MapKeyContext<?, LongValue> context = map.context("one")) {
|
||||
assertEquals(false, context.containsKey());
|
||||
assertEquals(null, context.get());
|
||||
try (ExternalMapQueryContext<CharSequence, LongValue, ?> c = map.queryContext("one")) {
|
||||
assertNotNull(c.absentEntry());
|
||||
}
|
||||
|
||||
try (MapKeyContext<?, LongValue> context = map.acquireContext("one", value)) {
|
||||
try (net.openhft.chronicle.core.io.Closeable c =
|
||||
map.acquireContext("one", value)) {
|
||||
value.setValue(10);
|
||||
}
|
||||
|
||||
// this will add the entry
|
||||
try (MapKeyContext<?, LongValue> context = map.acquireContext("one", value)) {
|
||||
LongValue value1 = context.get();
|
||||
value1.addValue(1);
|
||||
try (net.openhft.chronicle.core.io.Closeable c =
|
||||
map.acquireContext("one", value)) {
|
||||
value.addValue(1);
|
||||
}
|
||||
|
||||
// check that the entry was added
|
||||
try (MapKeyContext<?, LongValue> context = map.context("one")) {
|
||||
assertEquals(true, context.containsKey());
|
||||
assertEquals(11, context.get().getValue());
|
||||
try (ExternalMapQueryContext<CharSequence, LongValue, ?> c = map.queryContext("one")) {
|
||||
MapEntry<CharSequence, LongValue> entry = c.entry();
|
||||
assertNotNull(entry);
|
||||
assertEquals(11, entry.value().get().getValue());
|
||||
}
|
||||
|
||||
// this will remove the entry
|
||||
try (MapKeyContext<?, LongValue> context = map.context("one")) {
|
||||
context.remove();
|
||||
try (ExternalMapQueryContext<CharSequence, LongValue, ?> c = map.queryContext("one")) {
|
||||
c.updateLock().lock();
|
||||
c.remove(c.entry());
|
||||
}
|
||||
|
||||
// check that the entry was removed
|
||||
try (MapKeyContext<?, LongValue> context = map.context("one")) {
|
||||
assertEquals(false, context.containsKey());
|
||||
assertEquals(null, context.get());
|
||||
try (ExternalMapQueryContext<CharSequence, LongValue, ?> c = map.queryContext("one")) {
|
||||
assertNotNull(c.absentEntry());
|
||||
}
|
||||
|
||||
try (MapKeyContext<?, LongValue> context = map.acquireContext("one", value)) {
|
||||
assertEquals(0, context.get().getValue());
|
||||
try (net.openhft.chronicle.core.io.Closeable c =
|
||||
map.acquireContext("one", value)) {
|
||||
assertEquals(0, value.getValue());
|
||||
}
|
||||
|
||||
value.setValue(1);
|
||||
|
||||
try (MapKeyContext<?, LongValue> lockedEntry = map.context("one")) {
|
||||
assertEquals(1, lockedEntry.get().getValue());
|
||||
try (ExternalMapQueryContext<CharSequence, LongValue, ?> c = map.queryContext("one")) {
|
||||
assertEquals(1, c.entry().value().get().getValue());
|
||||
}
|
||||
|
||||
try (MapKeyContext<?, LongValue> context = map.acquireContext("one", value)) {
|
||||
LongValue value1 = context.get();
|
||||
value1.addValue(1);
|
||||
try (net.openhft.chronicle.core.io.Closeable c =
|
||||
map.acquireContext("one", value)) {
|
||||
value.addValue(1);
|
||||
}
|
||||
|
||||
// check that the entry was removed
|
||||
try (MapKeyContext<?, LongValue> context = map.context("one")) {
|
||||
LongValue value1 = context.get();
|
||||
try (ExternalMapQueryContext<CharSequence, LongValue, ?> c = map.queryContext("one")) {
|
||||
LongValue value1 = c.entry().value().get();
|
||||
assertEquals(2, value1.getValue());
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package net.openhft.chronicle.map;
|
||||
import net.openhft.lang.model.DataValueClasses;
|
||||
import net.openhft.lang.model.constraints.MaxSize;
|
||||
import net.openhft.lang.values.IntValue;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
@@ -74,7 +73,8 @@ public class DemoChronicleMapTest {
|
||||
for (int i = 0; i < maxEntries; i++) {
|
||||
key.setValue(i);
|
||||
|
||||
try (MapKeyContext wc = map.acquireContext(key, value)) {
|
||||
try (net.openhft.chronicle.core.io.Closeable c =
|
||||
map.acquireContext(key, value)) {
|
||||
value.setSymbol("IBM-" + i);
|
||||
value.addAtomicOrderQty(1000);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import net.openhft.chronicle.core.io.Closeable;
|
||||
import net.openhft.chronicle.hash.function.SerializableFunction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.Assert;
|
||||
@@ -277,12 +278,8 @@ public class ReplicationCheckingMap<K, V> implements ChronicleMap<K, V> {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public MapKeyContext<K, V> acquireContext(@NotNull K key, @NotNull V usingValue) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapKeyContext<K, V> context(K key) {
|
||||
public Closeable acquireContext(
|
||||
@NotNull K key, @NotNull V usingValue) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ import net.openhft.lang.model.DataValueClasses;
|
||||
import net.openhft.lang.values.LongValue;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.Closeable;
|
||||
@@ -92,7 +91,8 @@ public class TCPSocketReplicationNativeTest {
|
||||
|
||||
LongValue value = DataValueClasses.newDirectReference(LongValue.class);
|
||||
|
||||
try (MapKeyContext<Integer, LongValue> c = map1.acquireContext(1, value)) {
|
||||
try (net.openhft.chronicle.core.io.Closeable c =
|
||||
map1.acquireContext(1, value)) {
|
||||
value.setValue(10);
|
||||
}
|
||||
|
||||
@@ -108,11 +108,13 @@ public class TCPSocketReplicationNativeTest {
|
||||
|
||||
LongValue value = DataValueClasses.newDirectReference(LongValue.class);
|
||||
|
||||
try (MapKeyContext<Integer, LongValue> c = map1.acquireContext(1, value)) {
|
||||
try (net.openhft.chronicle.core.io.Closeable c =
|
||||
map1.acquireContext(1, value)) {
|
||||
value.setValue(10);
|
||||
}
|
||||
|
||||
try (MapKeyContext<Integer, LongValue> c = map1.acquireContext(1, value)) {
|
||||
try (net.openhft.chronicle.core.io.Closeable c =
|
||||
map1.acquireContext(1, value)) {
|
||||
value.setValue(20);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package net.openhft.chronicle.map;
|
||||
import eg.TestInstrumentVOInterface;
|
||||
import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
@@ -46,7 +45,7 @@ public class TcpReplicationWithAcquireContextTest {
|
||||
TestInstrumentVOInterface instrumentVOInterface = map1.newValueInstance();
|
||||
|
||||
|
||||
try (MapKeyContext<?, TestInstrumentVOInterface> wc =
|
||||
try (net.openhft.chronicle.core.io.Closeable c =
|
||||
map1.acquireContext("KEY1", instrumentVOInterface)) {
|
||||
instrumentVOInterface.setSymbol("Flyer");
|
||||
instrumentVOInterface.setCurrencyCode("USA");
|
||||
|
||||
@@ -20,7 +20,7 @@ package net.openhft.chronicle.map.fromdocs;
|
||||
|
||||
import net.openhft.chronicle.map.ChronicleMap;
|
||||
import net.openhft.chronicle.map.ChronicleMapBuilder;
|
||||
import net.openhft.chronicle.map.MapKeyContext;
|
||||
import net.openhft.chronicle.map.ExternalMapQueryContext;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
@@ -60,7 +60,8 @@ public class OpenJDKAndHashMapExamplesTest {
|
||||
.createPersistedTo(file);
|
||||
|
||||
BondVOInterface bondVO = chm.newValueInstance();
|
||||
try (MapKeyContext wc = chm.acquireContext("369604103", bondVO)) {
|
||||
try (net.openhft.chronicle.core.io.Closeable c =
|
||||
chm.acquireContext("369604103", bondVO)) {
|
||||
bondVO.setIssueDate(parseYYYYMMDD("20130915"));
|
||||
bondVO.setMaturityDate(parseYYYYMMDD("20140915"));
|
||||
bondVO.setCoupon(5.0 / 100); // 5.0%
|
||||
@@ -80,8 +81,9 @@ public class OpenJDKAndHashMapExamplesTest {
|
||||
.entries(1000)
|
||||
.createPersistedTo(file);
|
||||
|
||||
try (MapKeyContext<String, BondVOInterface> c = chmB.context("369604103")) {
|
||||
BondVOInterface bond = c.get();
|
||||
try (ExternalMapQueryContext<String, BondVOInterface, ?> c =
|
||||
chmB.queryContext("369604103")) {
|
||||
BondVOInterface bond = c.entry().value().get();
|
||||
if (bond != null) {
|
||||
assertEquals(5.0 / 100, bond.getCoupon(), 0.0);
|
||||
|
||||
@@ -97,7 +99,8 @@ public class OpenJDKAndHashMapExamplesTest {
|
||||
|
||||
BondVOInterface bond = chm.newValueInstance();
|
||||
// lookup the key and give me a reference I can update in a thread safe way.
|
||||
try (MapKeyContext<String, BondVOInterface> c = chm.acquireContext("369604103", bond)) {
|
||||
try (net.openhft.chronicle.core.io.Closeable c =
|
||||
chm.acquireContext("369604103", bond)) {
|
||||
// found a key and bond has been set
|
||||
// get directly without touching the rest of the record.
|
||||
long _matDate = bond.getMaturityDate();
|
||||
|
||||
@@ -110,9 +110,10 @@ public class StatelessChronicleMapTest extends JSR166TestCase {
|
||||
return d.containsValue(value);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public MapKeyContext<K, V> context(K key) {
|
||||
return d.context(key);
|
||||
public net.openhft.chronicle.core.io.Closeable acquireContext(@NotNull K key, @NotNull V usingValue) {
|
||||
return d.acquireContext(key, usingValue);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -180,12 +181,6 @@ public class StatelessChronicleMapTest extends JSR166TestCase {
|
||||
return d.acquireUsing(key, usingValue);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public MapKeyContext<K, V> acquireContext(@NotNull K key, @NotNull V usingValue) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R getMapped(K key, @NotNull SerializableFunction<? super V, R> function) {
|
||||
return d.getMapped(key, function);
|
||||
|
||||
Reference in New Issue
Block a user