diff --git a/src/main/java/net/openhft/chronicle/hash/serialization/internal/BasicCopyingMetaBytesInterop.java b/src/main/java/net/openhft/chronicle/hash/serialization/internal/BasicCopyingMetaBytesInterop.java index 8bdb4412b..c20f5cc96 100644 --- a/src/main/java/net/openhft/chronicle/hash/serialization/internal/BasicCopyingMetaBytesInterop.java +++ b/src/main/java/net/openhft/chronicle/hash/serialization/internal/BasicCopyingMetaBytesInterop.java @@ -65,6 +65,6 @@ public abstract class BasicCopyingMetaBytesInterop implements MetaBytesInt @Override public void write(W writer, Bytes bytes, E e) { - bytes.write(buffer.buffer); + bytes.write(buffer.buffer, buffer.buffer.position(), buffer.buffer.remaining()); } } diff --git a/src/main/java/net/openhft/chronicle/hash/serialization/internal/BytesBytesInterop.java b/src/main/java/net/openhft/chronicle/hash/serialization/internal/BytesBytesInterop.java index 6c5a59174..e482ceb59 100644 --- a/src/main/java/net/openhft/chronicle/hash/serialization/internal/BytesBytesInterop.java +++ b/src/main/java/net/openhft/chronicle/hash/serialization/internal/BytesBytesInterop.java @@ -44,6 +44,6 @@ public enum BytesBytesInterop implements BytesInterop { @Override public void write(Bytes bytes, Bytes e) { - bytes.write(e); + bytes.write(e, e.position(), e.remaining()); } } diff --git a/src/main/java/net/openhft/chronicle/map/BytesMapEventListener.java b/src/main/java/net/openhft/chronicle/map/BytesMapEventListener.java index 745221023..4fac85ad7 100644 --- a/src/main/java/net/openhft/chronicle/map/BytesMapEventListener.java +++ b/src/main/java/net/openhft/chronicle/map/BytesMapEventListener.java @@ -44,11 +44,13 @@ public abstract class BytesMapEventListener implements Serializable { // do nothing } - public void onPut(Bytes entry, long metaDataPos, long keyPos, long valuePos, boolean added) { + public void onPut(Bytes entry, long metaDataPos, long keyPos, long valuePos, boolean added, + boolean replicationEvent) { // do nothing } - public void onRemove(Bytes entry, long metaDataPos, long keyPos, long valuePos) { + public void onRemove(Bytes entry, long metaDataPos, long keyPos, long valuePos, + boolean replicationEvent) { // do nothing } } diff --git a/src/main/java/net/openhft/chronicle/map/ChannelProvider.java b/src/main/java/net/openhft/chronicle/map/ChannelProvider.java index 2b877a3a8..383e1eb2c 100644 --- a/src/main/java/net/openhft/chronicle/map/ChannelProvider.java +++ b/src/main/java/net/openhft/chronicle/map/ChannelProvider.java @@ -504,7 +504,7 @@ final class ChannelProvider implements Closeable { @Override public void writeExternalEntry(@NotNull Bytes entry, @NotNull Bytes destination, int na) { - destination.write(entry); + destination.write(entry, entry.position(), entry.remaining()); } @Override diff --git a/src/main/java/net/openhft/chronicle/map/MapEventListener.java b/src/main/java/net/openhft/chronicle/map/MapEventListener.java index 8535d1b29..bccf3eec0 100644 --- a/src/main/java/net/openhft/chronicle/map/MapEventListener.java +++ b/src/main/java/net/openhft/chronicle/map/MapEventListener.java @@ -81,12 +81,12 @@ public abstract class MapEventListener implements Serializable { } @Override - public void onPut(Object key, Object value, Object replacedValue) { + public void onPut(Object key, Object value, Object replacedValue, boolean replicationEvent) { LOGGER.info("{} put {} => {}", prefix, key, value); } @Override - public void onRemove(Object key, Object value) { + public void onRemove(Object key, Object value, boolean replicationEvent) { LOGGER.info("{} remove {} was {}", prefix, key, value); } } @@ -112,24 +112,24 @@ public abstract class MapEventListener implements Serializable { * as well. * *

This method is called when put is already happened. - * - * @param key the key the given value is put for + * @param key the key the given value is put for * @param newValue the value which is now associated with the given key * @param replacedValue the value which was replaced by {@code newValue}, {@code null} if the - * key was absent in the map before current {@code ChronicleMap} + * key was absent in the map before current {@code ChronicleMap} + * @param replicationEvent */ - public void onPut(K key, V newValue, @Nullable V replacedValue) { + public void onPut(K key, V newValue, @Nullable V replacedValue, boolean replicationEvent) { // do nothing } /** * This is called when an entry is removed. Misses, i. e. when {@code map.remove(key)} is * called, but key is already absent in the map, are not notified. - * - * @param key the key removed from the map + * @param key the key removed from the map * @param value the value which was associated with the given key + * @param replicationEvent */ - public void onRemove(K key, V value) { + public void onRemove(K key, V value, boolean replicationEvent) { // do nothing } } diff --git a/src/main/java/net/openhft/chronicle/map/MultiMapFactory.java b/src/main/java/net/openhft/chronicle/map/MultiMapFactory.java index ca137ab23..1a615bd24 100644 --- a/src/main/java/net/openhft/chronicle/map/MultiMapFactory.java +++ b/src/main/java/net/openhft/chronicle/map/MultiMapFactory.java @@ -21,7 +21,7 @@ package net.openhft.chronicle.map; import net.openhft.lang.Maths; import net.openhft.lang.collection.ATSDirectBitSet; import net.openhft.lang.io.DirectStore; -import net.openhft.lang.io.NativeBytes; +import net.openhft.lang.io.NativeBytesI; import static net.openhft.lang.Maths.isPowerOf2; import static net.openhft.lang.MemoryUnit.*; @@ -39,7 +39,7 @@ enum MultiMapFactory { } @Override - public MultiMap create(NativeBytes bytes, NativeBytes bitSetBytes) { + public MultiMap create(NativeBytesI bytes, NativeBytesI bitSetBytes) { return new ShortShortMultiMap(bytes, bitSetBytes); } }, @@ -50,7 +50,7 @@ enum MultiMapFactory { } @Override - public MultiMap create(NativeBytes bytes, NativeBytes bitSetBytes) { + public MultiMap create(NativeBytesI bytes, NativeBytesI bitSetBytes) { return new Int24Int24MultiMap(bytes, bitSetBytes); } }, @@ -61,7 +61,7 @@ enum MultiMapFactory { } @Override - public MultiMap create(NativeBytes bytes, NativeBytes bitSetBytes) { + public MultiMap create(NativeBytesI bytes, NativeBytesI bitSetBytes) { return new IntIntMultiMap(bytes, bitSetBytes); } }; @@ -104,5 +104,5 @@ enum MultiMapFactory { public abstract long sizeInBytes(long minCapacity); - public abstract MultiMap create(NativeBytes bytes, NativeBytes bitSetBytes); + public abstract MultiMap create(NativeBytesI bytes, NativeBytesI bitSetBytes); } diff --git a/src/main/java/net/openhft/chronicle/map/NodeDiscovery.java b/src/main/java/net/openhft/chronicle/map/NodeDiscovery.java index 137bca57d..893f9a4be 100644 --- a/src/main/java/net/openhft/chronicle/map/NodeDiscovery.java +++ b/src/main/java/net/openhft/chronicle/map/NodeDiscovery.java @@ -755,7 +755,7 @@ class DiscoveryNodeBytesMarshallable implements BytesMarshallable { return false; BOOTSTRAP_BYTES.clear(); - out.write(BOOTSTRAP_BYTES); + out.write(BOOTSTRAP_BYTES, BOOTSTRAP_BYTES.position(), BOOTSTRAP_BYTES.remaining()); ourProposedIdentifier.writeMarshallable(out); return true; diff --git a/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java b/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java index aad7653a4..28c67936d 100644 --- a/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java @@ -30,7 +30,7 @@ import net.openhft.lang.Maths; import net.openhft.lang.collection.ATSDirectBitSet; import net.openhft.lang.io.Bytes; import net.openhft.lang.io.MultiStoreBytes; -import net.openhft.lang.io.NativeBytes; +import net.openhft.lang.io.NativeBytesI; import net.openhft.lang.threadlocal.ThreadLocalCopies; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -126,7 +126,7 @@ final class ReplicatedChronicleMap.Segment createSegment( - NativeBytes segmentHeader, NativeBytes bytes, int index) { + NativeBytesI segmentHeader, NativeBytesI bytes, int index) { return new Segment(segmentHeader, bytes, index); } @@ -514,7 +514,7 @@ final class ReplicatedChronicleMap.Segment { - Segment(NativeBytes segmentHeader, NativeBytes bytes, int index) { + Segment(NativeBytesI segmentHeader, NativeBytesI bytes, int index) { super(segmentHeader, bytes, index); } @@ -766,11 +766,11 @@ final class ReplicatedChronicleMap implements FindByName { // creates a map based on the details that are sent to the map of builders @Override public void onPut(CharSequence key, MapInstanceBuilder value, - MapInstanceBuilder replacedValue) { - super.onPut(key, value, replacedValue); + MapInstanceBuilder replacedValue, boolean replicationEvent) { + super.onPut(key, value, replacedValue, replicationEvent); boolean added = replacedValue == null; if (!added || value == null) return; diff --git a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java index da1310a7d..3f8772856 100755 --- a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java @@ -230,7 +230,9 @@ class VanillaChronicleMap, } final long createMappedStoreAndSegments(BytesStore bytesStore) throws IOException { - this.ms = bytesStore; + // checks the the store has not been closed + // todo remove the CheckedBytesStore before the release + this.ms = new CheckedBytesStore(bytesStore); onHeaderCreated(); @@ -242,9 +244,9 @@ class VanillaChronicleMap, long segmentSize = segmentSize(); long headerOffset = 0; for (int i = 0; i < this.segments.length; i++) { - NativeBytes segmentHeader = - (NativeBytes) segmentHeaders.bytes(headerOffset, segmentHeaderSize); - NativeBytes segmentData = (NativeBytes) ms.bytes(offset, segmentSize); + NativeBytesI segmentHeader = + (NativeBytesI) segmentHeaders.bytes(headerOffset, segmentHeaderSize); + NativeBytesI segmentData = (NativeBytesI) ms.bytes(offset, segmentSize); this.segments[i] = createSegment(segmentHeader, segmentData, i); headerOffset += segmentHeaderSize; offset += segmentSize; @@ -306,7 +308,7 @@ class VanillaChronicleMap, return segmentHeaderSize; } - Segment createSegment(NativeBytes segmentHeader, NativeBytes bytes, int index) { + Segment createSegment(NativeBytesI segmentHeader, NativeBytesI bytes, int index) { return new Segment(segmentHeader, bytes, index); } @@ -973,7 +975,7 @@ class VanillaChronicleMap, @Override public void write(Void writer, Bytes bytes, Bytes value) { - bytes.write(value); + bytes.write(value, value.position(), value.remaining()); } } @@ -1411,8 +1413,8 @@ class VanillaChronicleMap, */ static final long LOCK_OFFSET = 0L; // 64-bit static final long SIZE_OFFSET = LOCK_OFFSET + 8L; // 32-bit - final NativeBytes segmentHeader; - final NativeBytes bytes; + final NativeBytesI segmentHeader; + final NativeBytesI bytes; final long entriesOffset; private final int index; private final SingleThreadedDirectBitSet freeList; @@ -1426,7 +1428,7 @@ class VanillaChronicleMap, /** * @param index the index of this segment held by the map */ - Segment(NativeBytes segmentHeader, NativeBytes bytes, int index) { + Segment(NativeBytesI segmentHeader, NativeBytesI bytes, int index) { this.segmentHeader = segmentHeader; this.bytes = bytes; this.index = index; @@ -1435,7 +1437,7 @@ class VanillaChronicleMap, hashLookup = createMultiMap(start); start += CACHE_LINES.align(sizeOfMultiMap() + sizeOfMultiMapBitSet(), BYTES) * multiMapsPerSegment(); - final NativeBytes bsBytes = new NativeBytes(ms.objectSerializer(), + final NativeBytesI bsBytes = new NativeBytes(ms.objectSerializer(), start, start + MultiMapFactory.sizeOfBitSetInBytes(actualChunksPerSegment), null); @@ -1453,11 +1455,11 @@ class VanillaChronicleMap, } private MultiMap createMultiMap(long start) { - final NativeBytes multiMapBytes = + final NativeBytesI multiMapBytes = new NativeBytes((ObjectSerializer) null, start, start = start + sizeOfMultiMap(), null); - final NativeBytes sizeOfMultiMapBitSetBytes = + final NativeBytesI sizeOfMultiMapBitSetBytes = new NativeBytes((ObjectSerializer) null, start, start + sizeOfMultiMapBitSet(), null); // multiMapBytes.load(); @@ -1628,7 +1630,7 @@ class VanillaChronicleMap, if (lockTime > 1e8 && LOG.isInfoEnabled()) - LOG.info("Thread took %,d ms to release lock%n", lockTime / 1000000 + "(Was there a GC?)"); + LOG.info("Thread took " + lockTime / 1000000 + "ms to release the lock, (Was there a GC?)"); } @Override @@ -1769,11 +1771,11 @@ class VanillaChronicleMap, onPut(this, segmentState.pos); if (bytesEventListener != null) { long keyPos = metaDataBytes; - bytesEventListener.onPut(entry, 0L, keyPos, segmentState.valueSizePos, true); + bytesEventListener.onPut(entry, 0L, keyPos, segmentState.valueSizePos, true, false); } if (eventListener != null) { eventListener.onPut(toKey.toInstance(copies, key, keySize), - toValue.toInstance(copies, v, valueSize), null); + toValue.toInstance(copies, v, valueSize), null, false); } return v; @@ -1877,10 +1879,10 @@ class VanillaChronicleMap, onPut(this, segmentState.pos); if (bytesEventListener != null) bytesEventListener.onPut(entry, 0L, metaDataBytes, - segmentState.valueSizePos, true); + segmentState.valueSizePos, true, false); if (eventListener != null) eventListener.onPut(toKey.toInstance(copies, key, keySize), - toValue.toInstance(copies, value, valueSize), null); + toValue.toInstance(copies, value, valueSize), null, false); return resultUnused ? null : readValue.readNull(); } @@ -1924,10 +1926,10 @@ class VanillaChronicleMap, // put callbacks onPutMaybeRemote(segmentState.pos, remote); if (bytesEventListener != null) - bytesEventListener.onPut(entry, 0L, metaDataBytes, valueSizePos, false); + bytesEventListener.onPut(entry, 0L, metaDataBytes, valueSizePos, false, remote); if (eventListener != null) { eventListener.onPut(toKey.toInstance(copies, key, keySize), - toValue.toInstance(copies, value, valueSize), prevValueInstance); + toValue.toInstance(copies, value, valueSize), prevValueInstance, remote); } return resultUnused ? null : prevValue; @@ -2164,12 +2166,12 @@ class VanillaChronicleMap, // remove callbacks onRemoveMaybeRemote(pos, remote); if (bytesEventListener != null) - bytesEventListener.onRemove(entry, 0L, metaDataBytes, valueSizePos); + bytesEventListener.onRemove(entry, 0L, metaDataBytes, valueSizePos, remote); if (eventListener != null) { V removedValueForEventListener = toValue.toInstance(copies, removedValue, valueSize); eventListener.onRemove(toKey.toInstance(copies, key, keySize), - removedValueForEventListener); + removedValueForEventListener, remote); } return booleanResult ? Boolean.TRUE : removedValue; @@ -2303,12 +2305,12 @@ class VanillaChronicleMap, onPut(this, segmentState.pos); if (bytesEventListener != null) { long keyPos = metaDataBytes; - bytesEventListener.onPut(entry, 0L, keyPos, segmentState.valueSizePos, true); + bytesEventListener.onPut(entry, 0L, keyPos, segmentState.valueSizePos, true, false); } if (eventListener != null) eventListener.onPut(toKey.toInstance(copies, key, keySize), toValue.toInstance(copies, newValue, newValueSize), - toValue.toInstance(copies, prevValue, valueSize)); + toValue.toInstance(copies, prevValue, valueSize), false); return expectedValue == null ? prevValue : Boolean.TRUE; } @@ -2574,7 +2576,7 @@ class VanillaChronicleMap, // of returnedEntry.getKey(), but it seems rather wasteful to workaround so rare // case. final long offset = segment.offsetFromPos(pos); - final NativeBytes entry = segment.reuse(this.entry, offset); + final NativeBytesI entry = segment.reuse(this.entry, offset); final long keySize = keySizeMarshaller.readSize(entry); long position = entry.position(); @@ -2583,7 +2585,7 @@ class VanillaChronicleMap, removePresent(segment, pos, entry, keySize, segmentHash, true); } - final void removePresent(Segment segment, long pos, NativeBytes entry, long keySize, + final void removePresent(Segment segment, long pos, NativeBytesI entry, long keySize, long segmentHash, boolean removeFromMultiMap) { entry.skip(keySize); segment.manageReplicationBytes(entry, true, true); @@ -2601,9 +2603,9 @@ class VanillaChronicleMap, // remove callbacks onRemove(segment, pos); if (bytesEventListener != null) - bytesEventListener.onRemove(entry, 0L, metaDataBytes, valueSizePos); + bytesEventListener.onRemove(entry, 0L, metaDataBytes, valueSizePos, false); if (eventListener != null) - eventListener.onRemove(returnedEntry.getKey(), returnedEntry.getValue()); + eventListener.onRemove(returnedEntry.getKey(), returnedEntry.getValue(), false); } } diff --git a/src/test/java/net/openhft/chronicle/map/CHMMetaDataTest.java b/src/test/java/net/openhft/chronicle/map/CHMMetaDataTest.java index d4e787013..99081f6bc 100644 --- a/src/test/java/net/openhft/chronicle/map/CHMMetaDataTest.java +++ b/src/test/java/net/openhft/chronicle/map/CHMMetaDataTest.java @@ -76,14 +76,14 @@ public class CHMMetaDataTest { } @Override - public void onPut(Bytes entry, long metaDataPos, long keyPos, long valuePos, boolean added) { + public void onPut(Bytes entry, long metaDataPos, long keyPos, long valuePos, boolean added, boolean replicationEvent) { if (added) assertEquals(0, entry.readLong(metaDataPos)); entry.writeLong(metaDataPos, timeStamps.incrementAndGet()); } @Override - public void onRemove(Bytes entry, long metaDataPos, long keyPos, long valuePos) { + public void onRemove(Bytes entry, long metaDataPos, long keyPos, long valuePos, boolean replicationEvent) { System.out.println("Removed entry with ts of " + entry.readLong(metaDataPos));; } } diff --git a/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java b/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java index 884d10213..fb68da878 100644 --- a/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java +++ b/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java @@ -480,7 +480,6 @@ public class CHMUseCasesTest { } } - @Ignore @Test public void testStringStringMap() throws ExecutionException, InterruptedException, IOException { @@ -516,7 +515,6 @@ public class CHMUseCasesTest { } - @Ignore @Test public void testStringStringMapMutableValue() throws ExecutionException, InterruptedException, IOException { @@ -2510,7 +2508,6 @@ public class CHMUseCasesTest { } } - @Ignore @Test public void testMapStringIntegerValueWithoutListMarshallers() throws IOException { ChronicleMapBuilder> builder = ChronicleMapBuilder diff --git a/src/test/java/net/openhft/chronicle/map/DemoChronicleMapTest.java b/src/test/java/net/openhft/chronicle/map/DemoChronicleMapTest.java index 952d83aa5..fb5013777 100755 --- a/src/test/java/net/openhft/chronicle/map/DemoChronicleMapTest.java +++ b/src/test/java/net/openhft/chronicle/map/DemoChronicleMapTest.java @@ -53,7 +53,6 @@ public class DemoChronicleMapTest { } } - @Ignore @Test public void testMapLocked() throws Exception { File file = File.createTempFile("DummyOrders-"+System.currentTimeMillis(), ".test"); diff --git a/src/test/java/net/openhft/chronicle/map/EventListenerWithTCPSocketReplicationTest.java b/src/test/java/net/openhft/chronicle/map/EventListenerWithTCPSocketReplicationTest.java index ec6d4ea23..019511264 100644 --- a/src/test/java/net/openhft/chronicle/map/EventListenerWithTCPSocketReplicationTest.java +++ b/src/test/java/net/openhft/chronicle/map/EventListenerWithTCPSocketReplicationTest.java @@ -56,7 +56,7 @@ public class EventListenerWithTCPSocketReplicationTest { private static final long serialVersionUID = 1L; @Override - public void onPut(Integer key, CharSequence value, CharSequence replacedValue) { + public void onPut(Integer key, CharSequence value, CharSequence replacedValue, boolean replicationEvent) { putWasCalled.getAndSet(true); keyRef.set(key); valueRef.set(value); @@ -64,7 +64,7 @@ public class EventListenerWithTCPSocketReplicationTest { } @Override - public void onRemove(Integer key, CharSequence value) { + public void onRemove(Integer key, CharSequence value, boolean replicationEvent) { wasRemoved.set(true); valueRemoved.set(value); } diff --git a/src/test/java/net/openhft/chronicle/map/MarkTest.java b/src/test/java/net/openhft/chronicle/map/MarkTest.java index bcb33eade..80f372096 100644 --- a/src/test/java/net/openhft/chronicle/map/MarkTest.java +++ b/src/test/java/net/openhft/chronicle/map/MarkTest.java @@ -43,10 +43,12 @@ public class MarkTest { }); } - - @Test(timeout = 50000) + @Test(timeout = 25000) public void persistedTest() { - final File db = Paths.get(System.getProperty("java.io.tmpdir"), "mark").toFile(); + int rnd = new Random().nextInt(); + final File db = Paths.get(System.getProperty("java.io.tmpdir"), "mark" + rnd).toFile(); + if (db.exists()) + db.delete(); try { test(new Function, ChronicleMap>() { diff --git a/src/test/java/net/openhft/chronicle/map/ReplicatedChronicleMapTest.java b/src/test/java/net/openhft/chronicle/map/ReplicatedChronicleMapTest.java index eaee51f2c..14f5d7517 100644 --- a/src/test/java/net/openhft/chronicle/map/ReplicatedChronicleMapTest.java +++ b/src/test/java/net/openhft/chronicle/map/ReplicatedChronicleMapTest.java @@ -37,11 +37,15 @@ import static org.junit.Assert.*; public class ReplicatedChronicleMapTest extends JSR166TestCase { ChronicleMap newShmIntString() throws IOException { return ChronicleMapBuilder.of(Integer.class, CharSequence.class) + .replication((byte) 1) + .entries(1000) .create(); } ChronicleMap newShmStringString() throws IOException { return ChronicleMapBuilder.of(CharSequence.class, CharSequence.class) + .replication((byte) 1) + .entries(1000) .create(); } diff --git a/src/test/java/net/openhft/chronicle/map/StatelessClientTest.java b/src/test/java/net/openhft/chronicle/map/StatelessClientTest.java index f80823660..a3bf2b922 100644 --- a/src/test/java/net/openhft/chronicle/map/StatelessClientTest.java +++ b/src/test/java/net/openhft/chronicle/map/StatelessClientTest.java @@ -269,7 +269,6 @@ public class StatelessClientTest { } } - @Ignore @Test(timeout = 10000) public void testServerPutStringKeyMap() throws IOException, InterruptedException { @@ -287,7 +286,6 @@ public class StatelessClientTest { } } - @Ignore @Test(timeout = 10000) public void testServerPutClientReplace() throws IOException, InterruptedException { @@ -330,7 +328,6 @@ public class StatelessClientTest { } - @Ignore @Test(timeout = 10000) public void testStringKeyMapPutIfAbsentIntoStatelessMap() throws IOException, InterruptedException {