mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
HCOLL-185 refactored VanillaChronicleMap and ReplicatedChronicleMap; split BytesMapEventListener from MapEventListener; many bug fixes and optimizations; Stateless client queries without serialization/deserialization not working yet
This commit is contained in:
@@ -33,11 +33,10 @@ public class CHMMetaDataTest {
|
||||
@Test
|
||||
public void testAccessTimes() throws IOException {
|
||||
File file = new File(TMP, "testAccessTimes");
|
||||
MapEventListener<String, String, ChronicleMap<String, String>> listener =
|
||||
BytesMapEventListener listener =
|
||||
new StringStringMapEventListener(new AtomicLong(1));
|
||||
ChronicleMap<String, String> map = ChronicleMapBuilder.of(String.class, String.class)
|
||||
.metaDataBytes(8)
|
||||
.eventListener(listener).create();
|
||||
.metaDataBytes(8).bytesEventListener(listener).create();
|
||||
|
||||
try {
|
||||
map.put("a", "aye");
|
||||
@@ -63,7 +62,7 @@ public class CHMMetaDataTest {
|
||||
}
|
||||
|
||||
private static class StringStringMapEventListener
|
||||
extends MapEventListener<String, String, ChronicleMap<String, String>> {
|
||||
extends BytesMapEventListener {
|
||||
private static final long serialVersionUID = 0L;
|
||||
|
||||
private final AtomicLong timeStamps;
|
||||
@@ -73,27 +72,20 @@ public class CHMMetaDataTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGetFound(ChronicleMap<String, String> map, Bytes entry, int metaDataBytes,
|
||||
String key, String value) {
|
||||
assertEquals(8, metaDataBytes);
|
||||
entry.writeLong(0, timeStamps.incrementAndGet());
|
||||
public void onGetFound(Bytes entry, long metaDataPos, long keyPos, long valuePos) {
|
||||
entry.writeLong(metaDataPos, timeStamps.incrementAndGet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPut(ChronicleMap<String, String> map, Bytes entry, int metaDataBytes,
|
||||
boolean added, String key, String replacedValue, String value, long pos,
|
||||
SharedSegment segment) {
|
||||
assertEquals(8, metaDataBytes);
|
||||
public void onPut(Bytes entry, long metaDataPos, long keyPos, long valuePos, boolean added) {
|
||||
if (added)
|
||||
assertEquals(0, entry.readLong());
|
||||
entry.writeLong(0, timeStamps.incrementAndGet());
|
||||
assertEquals(0, entry.readLong(metaDataPos));
|
||||
entry.writeLong(metaDataPos, timeStamps.incrementAndGet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove(ChronicleMap<String, String> map, Bytes entry, int metaDataBytes,
|
||||
String key, String value, long pos, SharedSegment segment) {
|
||||
assertEquals(8, metaDataBytes);
|
||||
System.out.println("Removed " + key + "/" + value + " with ts of " + entry.readLong(0));
|
||||
public void onRemove(Bytes entry, long metaDataPos, long keyPos, long valuePos) {
|
||||
System.out.println("Removed entry with ts of " + entry.readLong(metaDataPos));;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-5
@@ -50,13 +50,12 @@ public class EventListenerTestWithTCPSocketReplication {
|
||||
final AtomicBoolean wasRemoved = new AtomicBoolean(false);
|
||||
final AtomicReference<CharSequence> valueRemoved = new AtomicReference<CharSequence>();
|
||||
|
||||
final MapEventListener<Integer, CharSequence, ChronicleMap<Integer, CharSequence>> eventListener = new
|
||||
MapEventListener<Integer, CharSequence, ChronicleMap<Integer, CharSequence>>() {
|
||||
final MapEventListener<Integer, CharSequence> eventListener = new
|
||||
MapEventListener<Integer, CharSequence>() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public void onPut(ChronicleMap<Integer, CharSequence> map, Bytes entry, int metaDataBytes, boolean added, Integer key,
|
||||
CharSequence value, CharSequence replacedValue) {
|
||||
public void onPut(Integer key, CharSequence value, CharSequence replacedValue) {
|
||||
putWasCalled.getAndSet(true);
|
||||
keyRef.set(key);
|
||||
valueRef.set(value);
|
||||
@@ -64,7 +63,7 @@ public class EventListenerTestWithTCPSocketReplication {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove(ChronicleMap<Integer, CharSequence> map, Bytes entry, int metaDataBytes, Integer key, CharSequence value) {
|
||||
public void onRemove(Integer key, CharSequence value) {
|
||||
wasRemoved.set(true);
|
||||
valueRemoved.set(value);
|
||||
}
|
||||
|
||||
@@ -247,18 +247,20 @@ public class TimeBasedReplicationTest extends JSR166TestCase {
|
||||
current(timeProvider);
|
||||
|
||||
// we do a put at the current time
|
||||
map.put("key-1", "value-1");
|
||||
String key1 = "key-1";
|
||||
map.put(key1, "value-1");
|
||||
assertEquals(1, map.size());
|
||||
assertEquals("value-1", map.get("key-1"));
|
||||
assertEquals("value-1", map.get(key1));
|
||||
|
||||
// now test assume that we receive a late update to the map, the following update should be ignored
|
||||
final long late = System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(5);
|
||||
assertEquals(null, map.remove("key-1", "value-2", IDENTIFIER, late));
|
||||
// now test assume that we receive a late update to the map,
|
||||
// the following update should be ignored
|
||||
late(timeProvider);
|
||||
assertFalse(map.remove(key1, "value-2"));
|
||||
|
||||
// we'll now flip the time back to the current in order to do the read the result
|
||||
current(timeProvider);
|
||||
assertEquals(1, map.size());
|
||||
assertEquals("value-1", map.get("key-1"));
|
||||
assertEquals("value-1", map.get(key1));
|
||||
assertTrue(map.containsValue("value-1"));
|
||||
assertFalse(map.containsValue("value-2"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user