From 8a816054d39f7c36c1146b71e1b74555f39c5d67 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Fri, 11 Sep 2015 15:26:02 +0100 Subject: [PATCH] Reduce line padding. --- .../chronicle/hash/hashing/Hasher.java | 7 +- .../hash/replication/AbstractReplication.java | 5 - .../hash/replication/ConnectionListener.java | 2 - .../hash/replication/ReplicationHub.java | 17 +- .../internal/DataValueBytesMarshallers.java | 2 - .../internal/DoubleMarshaller.java | 1 - .../map/AbstractChannelReplicator.java | 5 - .../openhft/chronicle/map/BuildVersion.java | 3 - .../chronicle/map/ChannelProvider.java | 1 - .../map/ChroncileMapJsonSerializer.java | 2 - .../map/EngineReplicationLangBytes.java | 2 - .../net/openhft/chronicle/map/MapBuilder.java | 1 - .../net/openhft/chronicle/map/Replica.java | 7 - .../chronicle/map/ReplicatedChronicleMap.java | 8 - .../openhft/chronicle/map/Replicators.java | 2 - .../chronicle/map/StatelessChronicleMap.java | 18 - .../openhft/chronicle/map/TcpReplicator.java | 16 - .../chronicle/map/UdpChannelReplicator.java | 1 - .../openhft/chronicle/map/UdpReplicator.java | 1 - .../chronicle/map/VanillaChronicleMap.java | 3 - .../openhft/chronicle/map/WriterWithSize.java | 19 +- .../AbstractChronicleMapConverter.java | 91 +++--- .../converters/ByteBufferConverter.java | 5 - .../converters/DataValueConverter.java | 84 +++-- .../StatelessChronicleMapConverter.java | 2 - .../java/eg/OffHeapByteArrayExampleTest.java | 14 +- .../java/eg/TestInstrumentVOInterface.java | 6 - .../openhft/chronicle/TestReplication.java | 17 +- .../chronicle/map/BuildVersionTest.java | 2 - .../chronicle/map/CHMUseCasesTest.java | 308 +++++++----------- .../map/ChronicleMapImportExportTest.java | 8 - .../chronicle/map/ChronicleMapTest.java | 117 +++---- .../chronicle/map/EntryCountMapTest.java | 12 +- .../map/KeySegmentDistributionTest.java | 1 - .../chronicle/map/KeyValueInstanceTest.java | 52 ++- .../net/openhft/chronicle/map/MarkTest.java | 37 +-- .../map/NoTcpReplicationSoakTest.java | 18 +- .../openhft/chronicle/map/SerializerTest.java | 1 - .../chronicle/map/SingleMapChannelTest.java | 2 - .../chronicle/map/StatelessClientTest.java | 73 ++--- .../map/TCPSocketReplication4WayMapTest.java | 1 - .../map/TCPSocketReplicationTest.java | 6 +- .../map/TcpReplicationLargeEntryTest.java | 13 +- .../chronicle/map/TcpReplicationSoakTest.java | 10 +- ...ReplicationWithAcquireUsingLockedTest.java | 17 - .../map/TcpTimeBasedReplicationSoakTest.java | 13 +- .../chronicle/map/TestReplication.java | 8 - .../map/TimeBasedReplicationTest.java | 1 - .../map/fromdocs/BondVOInterface$$Native.java | 42 +-- .../BondVOInterface$MarketPx$$Native.java | 35 +- .../map/jsr166/map/ChronicleMapTest.java | 1 - .../chronicle/map/jsr166/map/MapCheck.java | 1 - .../set/Issue24ChronicleSetTest.java | 3 - 53 files changed, 384 insertions(+), 740 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/hash/hashing/Hasher.java b/src/main/java/net/openhft/chronicle/hash/hashing/Hasher.java index 164e61201..44285ee5b 100644 --- a/src/main/java/net/openhft/chronicle/hash/hashing/Hasher.java +++ b/src/main/java/net/openhft/chronicle/hash/hashing/Hasher.java @@ -27,10 +27,12 @@ public final class Hasher { // https://github.com/google/guava/blob/fa95e381e665d8ee9639543b99ed38020c8de5ef // /guava/src/com/google/common/hash/Murmur3_128HashFunction.java - private static final long C1 = 0x87c37b91114253d5L; private static final long C2 = 0x4cf5ad432745937fL; + private Hasher() { + } + /** * Returns the hash code for {@code len} continuous bytes of the given {@code input} object, * starting from the given offset. The abstraction of input as ordered byte sequence and @@ -134,7 +136,6 @@ public final class Hasher { return h1; } - private static long fmix64(long k) { k ^= k >>> 33; k *= 0xff51afd7ed558ccdL; @@ -187,6 +188,4 @@ public final class Hasher { long h2 = 0L; return finalize(8L, h1, h2); } - - private Hasher() {} } diff --git a/src/main/java/net/openhft/chronicle/hash/replication/AbstractReplication.java b/src/main/java/net/openhft/chronicle/hash/replication/AbstractReplication.java index db6fffd51..c455edcd3 100644 --- a/src/main/java/net/openhft/chronicle/hash/replication/AbstractReplication.java +++ b/src/main/java/net/openhft/chronicle/hash/replication/AbstractReplication.java @@ -128,8 +128,6 @@ public abstract class AbstractReplication implements Serializable { return engineReplicationLangBytesConsumer; } - - @NotNull public B tcpTransportAndNetwork(@Nullable TcpTransportAndNetworkConfig tcpConfig) { this.tcpConfig = tcpConfig; @@ -156,14 +154,12 @@ public abstract class AbstractReplication implements Serializable { return (B) this; } - @NotNull public B connectionListener(@Nullable ConnectionListener connectionListener) { this.connectionListener = connectionListener; return (B) this; } - /** * Configures if the node, provided with replication, created by this builder, should * replicate only local data, last updated with own identifier, or all data currently @@ -185,7 +181,6 @@ public abstract class AbstractReplication implements Serializable { return (B) this; } - /** * Creates a Replication instance with the given node (server) identifier. * diff --git a/src/main/java/net/openhft/chronicle/hash/replication/ConnectionListener.java b/src/main/java/net/openhft/chronicle/hash/replication/ConnectionListener.java index 974b73e72..89b367b8b 100644 --- a/src/main/java/net/openhft/chronicle/hash/replication/ConnectionListener.java +++ b/src/main/java/net/openhft/chronicle/hash/replication/ConnectionListener.java @@ -29,7 +29,6 @@ public interface ConnectionListener { */ void onConnect(SocketAddress address, byte identifier, boolean isServer); - /** * @param address the address that we have been disconnected from * @param identifier the identifer the address that we have been disconnected from or Byte @@ -37,5 +36,4 @@ public interface ConnectionListener { */ void onDisconnect(SocketAddress address, byte identifier); - } \ No newline at end of file diff --git a/src/main/java/net/openhft/chronicle/hash/replication/ReplicationHub.java b/src/main/java/net/openhft/chronicle/hash/replication/ReplicationHub.java index 06ca875cf..4c9781cd8 100644 --- a/src/main/java/net/openhft/chronicle/hash/replication/ReplicationHub.java +++ b/src/main/java/net/openhft/chronicle/hash/replication/ReplicationHub.java @@ -51,6 +51,14 @@ import java.util.Arrays; */ public final class ReplicationHub extends AbstractReplication { + private final ReplicationChannel[] channels; + + private ReplicationHub(byte localIdentifier, Builder builder) { + super(localIdentifier, builder); + + channels = new ReplicationChannel[builder.maxNumberOfChannels]; + } + /** * Creates and returns a new {@link ReplicationHub.Builder}. * @@ -61,21 +69,12 @@ public final class ReplicationHub extends AbstractReplication { return new Builder(); } - private final ReplicationChannel[] channels; - - private ReplicationHub(byte localIdentifier, Builder builder) { - super(localIdentifier, builder); - - channels = new ReplicationChannel[builder.maxNumberOfChannels]; - } - @Override public String toString() { return "ReplicationHub{" + super.toString() + ", channels=" + Arrays.toString(channels) + '}'; } - /** * Returns the maximum number of channels could be {@linkplain #createChannel(int) created} for * this {@code ReplicationHub}. diff --git a/src/main/java/net/openhft/chronicle/hash/serialization/internal/DataValueBytesMarshallers.java b/src/main/java/net/openhft/chronicle/hash/serialization/internal/DataValueBytesMarshallers.java index eda8910a9..99fe55659 100644 --- a/src/main/java/net/openhft/chronicle/hash/serialization/internal/DataValueBytesMarshallers.java +++ b/src/main/java/net/openhft/chronicle/hash/serialization/internal/DataValueBytesMarshallers.java @@ -68,7 +68,6 @@ public final class DataValueBytesMarshallers { } } - public static Class acquireReaderClass(Class tClass) { DataValueClasses.directClassFor(tClass); Class readerClass = readersClassMap.get(tClass); @@ -192,7 +191,6 @@ public final class DataValueBytesMarshallers { return sb.toString(); } - private static String bytesReaderName(Class type, boolean simple) { return (simple ? type.getSimpleName() : type.getName()) + "$$BytesReader"; } diff --git a/src/main/java/net/openhft/chronicle/hash/serialization/internal/DoubleMarshaller.java b/src/main/java/net/openhft/chronicle/hash/serialization/internal/DoubleMarshaller.java index 2f58ad4ac..353c07390 100644 --- a/src/main/java/net/openhft/chronicle/hash/serialization/internal/DoubleMarshaller.java +++ b/src/main/java/net/openhft/chronicle/hash/serialization/internal/DoubleMarshaller.java @@ -42,7 +42,6 @@ public enum DoubleMarshaller implements BytesInterop, BytesReader remaining) { long newSize = start + entrySize; @@ -648,7 +644,6 @@ abstract class AbstractChannelReplicator implements Closeable { } } - public void setSuccessfullyConnected() { connectionAttempts = 0; } diff --git a/src/main/java/net/openhft/chronicle/map/BuildVersion.java b/src/main/java/net/openhft/chronicle/map/BuildVersion.java index 54d95956e..105aabba7 100644 --- a/src/main/java/net/openhft/chronicle/map/BuildVersion.java +++ b/src/main/java/net/openhft/chronicle/map/BuildVersion.java @@ -52,7 +52,6 @@ class BuildVersion { // do nothing } - // another way to get the version is to read it from the manifest final String versionFromManifest = getVersionFromManifest(); @@ -75,7 +74,6 @@ class BuildVersion { return ChronicleMapBuilder.class.getPackage().getImplementationVersion(); } - /** * reads the pom file to get this version, only to be used for development or within the IDE. * @@ -105,5 +103,4 @@ class BuildVersion { } } - } \ No newline at end of file diff --git a/src/main/java/net/openhft/chronicle/map/ChannelProvider.java b/src/main/java/net/openhft/chronicle/map/ChannelProvider.java index 332f43dec..f8e0c1608 100644 --- a/src/main/java/net/openhft/chronicle/map/ChannelProvider.java +++ b/src/main/java/net/openhft/chronicle/map/ChannelProvider.java @@ -319,7 +319,6 @@ final class ChannelProvider implements Closeable { return channelProvider; channelProvider = new ChannelProvider(hub); - TcpTransportAndNetworkConfig tcpConfig = hub.tcpTransportAndNetwork(); if (tcpConfig != null) { diff --git a/src/main/java/net/openhft/chronicle/map/ChroncileMapJsonSerializer.java b/src/main/java/net/openhft/chronicle/map/ChroncileMapJsonSerializer.java index 6079698aa..673043691 100644 --- a/src/main/java/net/openhft/chronicle/map/ChroncileMapJsonSerializer.java +++ b/src/main/java/net/openhft/chronicle/map/ChroncileMapJsonSerializer.java @@ -48,7 +48,6 @@ class JsonSerializer { } } - static synchronized void putAll(File fromFile, Map map, List jsonConverters) throws IOException { final XStream xstream = xStream(map, jsonConverters); @@ -115,4 +114,3 @@ class JsonSerializer { } } - diff --git a/src/main/java/net/openhft/chronicle/map/EngineReplicationLangBytes.java b/src/main/java/net/openhft/chronicle/map/EngineReplicationLangBytes.java index 65f48f25c..f97179f8f 100644 --- a/src/main/java/net/openhft/chronicle/map/EngineReplicationLangBytes.java +++ b/src/main/java/net/openhft/chronicle/map/EngineReplicationLangBytes.java @@ -94,8 +94,6 @@ public interface EngineReplicationLangBytes extends Closeable { void setLastModificationTime(byte identifier, long timestamp); - - /** * notifies when there is a changed to the modification iterator */ diff --git a/src/main/java/net/openhft/chronicle/map/MapBuilder.java b/src/main/java/net/openhft/chronicle/map/MapBuilder.java index 98497d5e4..d057b9eb4 100644 --- a/src/main/java/net/openhft/chronicle/map/MapBuilder.java +++ b/src/main/java/net/openhft/chronicle/map/MapBuilder.java @@ -49,7 +49,6 @@ public interface MapBuilder> { */ C putReturnsNull(boolean putReturnsNull); - /** * Configures if the maps created by this {@code MapBuilder} should return {@code null} * instead of the last mapped value on {@link ChronicleMap#remove(Object) diff --git a/src/main/java/net/openhft/chronicle/map/Replica.java b/src/main/java/net/openhft/chronicle/map/Replica.java index 7198e9fe2..eff3d1b3f 100644 --- a/src/main/java/net/openhft/chronicle/map/Replica.java +++ b/src/main/java/net/openhft/chronicle/map/Replica.java @@ -67,7 +67,6 @@ interface Replica extends Closeable, EngineReplicationLangBytes { */ long lastModificationTime(byte remoteIdentifier); - void setLastModificationTime(byte identifier, long timestamp); /** @@ -142,7 +141,6 @@ interface Replica extends Closeable, EngineReplicationLangBytes { */ int sizeOfEntry(@NotNull Bytes entry, int chronicleId); - /** * check that the identifier in the entry is from this node * @@ -152,7 +150,6 @@ interface Replica extends Closeable, EngineReplicationLangBytes { */ boolean identifierCheck(@NotNull Bytes entry, int chronicleId); - /** * The map implements this method to save its contents. * @param entry the byte location of the entry to be stored @@ -182,8 +179,6 @@ interface Replica extends Closeable, EngineReplicationLangBytes { @NotNull VanillaChronicleMap.SegmentState segmentState, @NotNull Bytes source); - - } /** @@ -252,7 +247,6 @@ interface Replica extends Closeable, EngineReplicationLangBytes { public void onBeforeEntry() { } - /** * its possible that the entry should now be ignored, for example although rare its * identifier may have recently been changed by another thread, so its no longer applicable @@ -266,6 +260,5 @@ interface Replica extends Closeable, EngineReplicationLangBytes { public abstract boolean shouldBeIgnored(final Bytes entry, final int chronicleId); } - } diff --git a/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java b/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java index cf559ea22..a231232fe 100644 --- a/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java @@ -426,7 +426,6 @@ final class ReplicatedChronicleMap.Segment segment, long pos) { for (long next = modIterSet.nextSetBit(0L); next > 0L; @@ -617,7 +613,6 @@ final class ReplicatedChronicleMap 0L && changes.nextSetBit(0L) != NOT_FOUND); } - /** * @param entryCallback call this to get an entry, this class will take care of the locking * @return true if an entry was processed diff --git a/src/main/java/net/openhft/chronicle/map/Replicators.java b/src/main/java/net/openhft/chronicle/map/Replicators.java index 04c471885..52d7020d6 100644 --- a/src/main/java/net/openhft/chronicle/map/Replicators.java +++ b/src/main/java/net/openhft/chronicle/map/Replicators.java @@ -68,7 +68,6 @@ final class Replicators { static Replicator tcp(final AbstractReplication replication) { return new Replicator() { - @Override protected Closeable applyTo(@NotNull final ChronicleMapBuilder builder, @NotNull final Replica replica, @@ -132,7 +131,6 @@ final class Replicators { @Override public Bytes resizeBuffer(int newCapacity) { - if (newCapacity < out.capacity()) throw new IllegalStateException("it not possible to resize the buffer smaller"); diff --git a/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java b/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java index 7a73c9f8b..247574eb3 100755 --- a/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java @@ -301,7 +301,6 @@ class StatelessChronicleMap implements ChronicleMap, Closeable, Clon clientChannel = null; } - } /** @@ -506,7 +505,6 @@ class StatelessChronicleMap implements ChronicleMap, Closeable, Clon @Nullable public V getUsing(K key, V usingValue) { - final long startTime = System.currentTimeMillis(); ThreadLocalCopies copies; @@ -820,7 +818,6 @@ class StatelessChronicleMap implements ChronicleMap, Closeable, Clon } } - } public void putAll(@NotNull Map map) { @@ -884,7 +881,6 @@ class StatelessChronicleMap implements ChronicleMap, Closeable, Clon outBytesLock.unlock(); } - if (!putReturnsNull) { inBytesLock.lock(); try { @@ -964,7 +960,6 @@ class StatelessChronicleMap implements ChronicleMap, Closeable, Clon outBytes.writeByte((byte) event.ordinal()); - return markSizeLocation(); } @@ -1038,7 +1033,6 @@ class StatelessChronicleMap implements ChronicleMap, Closeable, Clon private Bytes blockingFetchReadOnly(long timeoutTime, final long transactionId) { - assert inBytesLock.isHeldByCurrentThread(); // assert !outBytesLock.isHeldByCurrentThread(); try { @@ -1108,7 +1102,6 @@ class StatelessChronicleMap implements ChronicleMap, Closeable, Clon NativeBytes.UNSAFE.throwException(throwable); } - return inBytes; } @@ -1167,7 +1160,6 @@ class StatelessChronicleMap implements ChronicleMap, Closeable, Clon break; } - // time out the old transaction id if (System.currentTimeMillis() - timeoutTime > parkedTransactionTimeStamp) { @@ -1208,7 +1200,6 @@ class StatelessChronicleMap implements ChronicleMap, Closeable, Clon inBytesLock.lock(); } - /** * reads up to the number of byte in {@code requiredNumberOfBytes} * @@ -1220,7 +1211,6 @@ class StatelessChronicleMap implements ChronicleMap, Closeable, Clon @SuppressWarnings("UnusedReturnValue") private Bytes receiveBytesFromSocket(int requiredNumberOfBytes, long timeoutTime) throws IOException { - // assert !outBytesLock.isHeldByCurrentThread(); assert inBytesLock.isHeldByCurrentThread(); @@ -1269,14 +1259,12 @@ class StatelessChronicleMap implements ChronicleMap, Closeable, Clon limitOfLast = outBuffer.limit(); - while (outBuffer.remaining() > 0) { int len = clientChannel.write(outBuffer); if (len == -1) throw new IORuntimeException("Disconnection to server"); - // if we have queued threads then we don't have to write all the bytes as the other // threads will write the remains bytes. if (outBuffer.remaining() > 0 && outBytesLock.hasQueuedThreads() && @@ -1306,7 +1294,6 @@ class StatelessChronicleMap implements ChronicleMap, Closeable, Clon assert outBytes.readByte(locationOfSize - 1) >= LONG_SIZE.ordinal(); - final long size = outBytes.position() - locationOfSize; final long pos = outBytes.position(); outBytes.position(locationOfSize); @@ -1372,7 +1359,6 @@ class StatelessChronicleMap implements ChronicleMap, Closeable, Clon assert !inBytesLock.isHeldByCurrentThread(); long start = outBytes.position(); - assert outBytes.position() == start; outBytes.limit(outBytes.capacity()); return valueWriterWithSize.writeInLoop(outBytes, value, writer, copies); @@ -1489,7 +1475,6 @@ class StatelessChronicleMap implements ChronicleMap, Closeable, Clon outBytesLock.unlock(); } - return readBoolean(transactionId, startTime); } @@ -1505,7 +1490,6 @@ class StatelessChronicleMap implements ChronicleMap, Closeable, Clon try { final long sizeLocation = writeEventAnSkip(eventId); - copies = writeKey(key); copies = writeValue(value1, copies); writeValue(value2, copies); @@ -1514,7 +1498,6 @@ class StatelessChronicleMap implements ChronicleMap, Closeable, Clon outBytesLock.unlock(); } - return readBoolean(transactionId, startTime); } @@ -1679,7 +1662,6 @@ class StatelessChronicleMap implements ChronicleMap, Closeable, Clon outBytesLock.unlock(); } - if (eventReturnsNull(eventId)) return null; diff --git a/src/main/java/net/openhft/chronicle/map/TcpReplicator.java b/src/main/java/net/openhft/chronicle/map/TcpReplicator.java index c78b72017..0092eb085 100644 --- a/src/main/java/net/openhft/chronicle/map/TcpReplicator.java +++ b/src/main/java/net/openhft/chronicle/map/TcpReplicator.java @@ -394,7 +394,6 @@ final class TcpReplicator extends AbstractChannelReplicator implements Clo // null check (Attached)key.attachment(); // connectionListener.onDiconnect( ((SocketChannel)key.channel()).socket().getInetAddress(), ((Attached)key.attachment()).remoteIdentifier); - closeEarlyAndQuietly(key.channel()); } @@ -533,7 +532,6 @@ final class TcpReplicator extends AbstractChannelReplicator implements Clo final String localVersion = BuildVersion.version(); final String remoteVersion = attached.serverVersion; - if (!remoteVersion.equals(localVersion)) { byte remoteIdentifier = attached.remoteIdentifier; LOG.warn("DIFFERENT CHRONICLE-MAP VERSIONS : " + @@ -582,7 +580,6 @@ final class TcpReplicator extends AbstractChannelReplicator implements Clo attached.remoteIdentifier = remoteIdentifier; - // todo OZAN : add call to onConnectedListener. //connectionListener. onConnected(channel.socket().getInetAddress() , attached // .remoteIdentifier, attached.isServer ); @@ -1058,7 +1055,6 @@ final class TcpReplicator extends AbstractChannelReplicator implements Clo */ class TcpSocketChannelEntryWriter { - @NotNull private final EntryCallback entryCallback; // if uncompletedWork is set ( not null ) , this must be completed before any further work @@ -1227,7 +1223,6 @@ final class TcpReplicator extends AbstractChannelReplicator implements Clo return len; } - /** * used to send an single zero byte if we have not send any data for up to the * localHeartbeatInterval @@ -1244,7 +1239,6 @@ final class TcpReplicator extends AbstractChannelReplicator implements Clo in().writeLong(localHeartbeatInterval); } - public boolean doWork() { return uncompletedWork != null && uncompletedWork.doWork(in()); } @@ -1467,7 +1461,6 @@ final class TcpReplicator extends AbstractChannelReplicator implements Clo return null; } - public long readRemoteHeartbeatIntervalFromBuffer() { return (out.remaining() >= 8) ? out.readLong() : Long.MIN_VALUE; } @@ -1504,7 +1497,6 @@ class StatelessServerConnector { private final SerializationBuilder valueSerializationBuilder; private final int tcpBufferSize; - StatelessServerConnector( @NotNull VanillaChronicleMap map, @NotNull final BufferResizer bufferResizer, int tcpBufferSize, @@ -1535,7 +1527,6 @@ class StatelessServerConnector { int headerSize = reader.readInt(); reader.skip(headerSize); - // these methods don't return a result to the client or don't return a result to the // client immediately switch (event) { @@ -1560,7 +1551,6 @@ class StatelessServerConnector { final long sizeLocation = reflectTransactionId(writer.in(), transactionId); - // these methods return a result switch (event) { @@ -1664,7 +1654,6 @@ class StatelessServerConnector { return null; } - @Nullable public Work mapForKey(@NotNull ByteBufferBytes reader, @NotNull TcpReplicator.TcpSocketChannelEntryWriter writer, long sizeLocation) { @@ -1769,11 +1758,9 @@ class StatelessServerConnector { return null; } - @Nullable private Work applicationVersion(@NotNull TcpReplicator.TcpSocketChannelEntryWriter writer, final long sizeLocation) { - final long remaining = writer.in().remaining(); try { String result = map.applicationVersion(); @@ -1788,11 +1775,9 @@ class StatelessServerConnector { return null; } - @Nullable private Work persistedDataVersion(@NotNull TcpReplicator.TcpSocketChannelEntryWriter writer, final long sizeLocation) { - final long remaining = writer.in().remaining(); try { String result = map.persistedDataVersion(); @@ -2132,7 +2117,6 @@ class StatelessServerConnector { out.position(pos); } - } private void writeException(@NotNull TcpReplicator.TcpSocketChannelEntryWriter out, Throwable e) { diff --git a/src/main/java/net/openhft/chronicle/map/UdpChannelReplicator.java b/src/main/java/net/openhft/chronicle/map/UdpChannelReplicator.java index 43ae9c2d0..63efdf046 100644 --- a/src/main/java/net/openhft/chronicle/map/UdpChannelReplicator.java +++ b/src/main/java/net/openhft/chronicle/map/UdpChannelReplicator.java @@ -102,7 +102,6 @@ class UdpChannelReplicator extends AbstractChannelReplicator implements Replica. * binds to the server socket and process data This method will block until interrupted */ - @Override void processEvent() { try { diff --git a/src/main/java/net/openhft/chronicle/map/UdpReplicator.java b/src/main/java/net/openhft/chronicle/map/UdpReplicator.java index 6a55263ad..eb8127a30 100644 --- a/src/main/java/net/openhft/chronicle/map/UdpReplicator.java +++ b/src/main/java/net/openhft/chronicle/map/UdpReplicator.java @@ -59,7 +59,6 @@ final class UdpReplicator extends UdpChannelReplicator implements Replica.Modifi private static class UdpSocketChannelEntryWriter implements EntryWriter { - private final EntryCallback entryCallback; private final UdpChannelReplicator udpReplicator; private final Replicators.OutBuffer outBuffer; diff --git a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java index ba19b0119..86b687c67 100755 --- a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java @@ -1697,7 +1697,6 @@ class VanillaChronicleMap, super.close(); } - @Override public void dontPutOnClose() { if (removed) @@ -1943,7 +1942,6 @@ class VanillaChronicleMap, } long lockTime = System.nanoTime() - startWriteLock; - if (lockTime > 1e8 && LOG.isInfoEnabled()) LOG.info("Thread took " + lockTime / 1000000 + "ms to release the lock, (Was there a GC?)"); } @@ -1959,7 +1957,6 @@ class VanillaChronicleMap, "replicated map"); } - final MultiStoreBytes reuse(MultiStoreBytes entry, long offset) { entry.setBytesOffset(bytes, offset); entry.position(metaDataBytes); diff --git a/src/main/java/net/openhft/chronicle/map/WriterWithSize.java b/src/main/java/net/openhft/chronicle/map/WriterWithSize.java index 3ab1b0605..09acda594 100644 --- a/src/main/java/net/openhft/chronicle/map/WriterWithSize.java +++ b/src/main/java/net/openhft/chronicle/map/WriterWithSize.java @@ -27,6 +27,15 @@ import org.jetbrains.annotations.Nullable; import java.nio.BufferOverflowException; +interface BufferResizer { + + /** + * @param newCapacity + * @return the newly resize buffer + */ + Bytes resizeBuffer(int newCapacity); +} + final class WriterWithSize { private final SizeMarshaller sizeMarshaller; private final Object originalWriter; @@ -73,7 +82,6 @@ final class WriterWithSize { return out; } - public ThreadLocalCopies writeNullable(Bytes out, T t, @Nullable ThreadLocalCopies copies) { out.writeBoolean(t == null); if (t == null) @@ -106,12 +114,3 @@ final class WriterWithSize { return writeInLoop(out, t, writer, copies); } } - -interface BufferResizer { - - /** - * @param newCapacity - * @return the newly resize buffer - */ - Bytes resizeBuffer(int newCapacity); -} diff --git a/src/main/java/net/openhft/xstream/converters/AbstractChronicleMapConverter.java b/src/main/java/net/openhft/xstream/converters/AbstractChronicleMapConverter.java index 5c40e197d..84f5c06d6 100644 --- a/src/main/java/net/openhft/xstream/converters/AbstractChronicleMapConverter.java +++ b/src/main/java/net/openhft/xstream/converters/AbstractChronicleMapConverter.java @@ -32,7 +32,6 @@ import java.util.Map; */ class AbstractChronicleMapConverter implements Converter { - private final Map map; private final Class mapClazz; @@ -41,6 +40,50 @@ class AbstractChronicleMapConverter implements Converter { this.mapClazz = map.getClass(); } + private static E deserialize(@NotNull UnmarshallingContext unmarshallingContext, + @NotNull HierarchicalStreamReader reader) { + + switch (reader.getNodeName()) { + + case "java.util.Collections$EmptySet": + return (E) Collections.EMPTY_SET; + + case "java.util.Collections$EmptyList": + return (E) Collections.EMPTY_LIST; + + case "java.util.Collections$EmptyMap": + case "java.util.Collections.EmptyMap": + return (E) Collections.EMPTY_MAP; + + } + + return (E) unmarshallingContext.convertAnother(null, forName(reader.getNodeName())); + } + + private static Class forName(String clazz) { + + try { + return Class.forName(clazz); + } catch (ClassNotFoundException e) { + + boolean isNative = clazz.endsWith("$$Native"); + boolean isHeap = clazz.endsWith("$$Heap"); + + if (!isNative && !isHeap) + throw new ConversionException("class=" + clazz, e); + + final String nativeInterface = isNative ? clazz.substring(0, clazz.length() - + "$$Native".length()) : clazz.substring(0, clazz.length() - + "$$Heap".length()); + try { + DataValueClasses.newDirectInstance(Class.forName(clazz)); + return Class.forName(nativeInterface); + } catch (Exception e1) { + throw new ConversionException("class=" + clazz, e1); + } + + } + } @Override public boolean canConvert(Class aClass) { @@ -48,7 +91,6 @@ class AbstractChronicleMapConverter implements Converter { return mapClazz.isAssignableFrom(aClass); } - @Override public void marshal(Object o, HierarchicalStreamWriter writer, MarshallingContext marshallingContext) { @@ -109,50 +151,5 @@ class AbstractChronicleMapConverter implements Converter { return null; } - private static E deserialize(@NotNull UnmarshallingContext unmarshallingContext, - @NotNull HierarchicalStreamReader reader) { - - switch (reader.getNodeName()) { - - case "java.util.Collections$EmptySet": - return (E) Collections.EMPTY_SET; - - case "java.util.Collections$EmptyList": - return (E) Collections.EMPTY_LIST; - - case "java.util.Collections$EmptyMap": - case "java.util.Collections.EmptyMap": - return (E) Collections.EMPTY_MAP; - - } - - return (E) unmarshallingContext.convertAnother(null, forName(reader.getNodeName())); - } - - private static Class forName(String clazz) { - - try { - return Class.forName(clazz); - } catch (ClassNotFoundException e) { - - boolean isNative = clazz.endsWith("$$Native"); - boolean isHeap = clazz.endsWith("$$Heap"); - - if (!isNative && !isHeap) - throw new ConversionException("class=" + clazz, e); - - final String nativeInterface = isNative ? clazz.substring(0, clazz.length() - - "$$Native".length()) : clazz.substring(0, clazz.length() - - "$$Heap".length()); - try { - DataValueClasses.newDirectInstance(Class.forName(clazz)); - return Class.forName(nativeInterface); - } catch (Exception e1) { - throw new ConversionException("class=" + clazz, e1); - } - - } - } - } diff --git a/src/main/java/net/openhft/xstream/converters/ByteBufferConverter.java b/src/main/java/net/openhft/xstream/converters/ByteBufferConverter.java index abf67e50b..80c15d584 100644 --- a/src/main/java/net/openhft/xstream/converters/ByteBufferConverter.java +++ b/src/main/java/net/openhft/xstream/converters/ByteBufferConverter.java @@ -42,17 +42,14 @@ public class ByteBufferConverter implements Converter { marshallingContext.convertAnother(buffer.position()); writer.endNode(); - writer.startNode("capacity"); marshallingContext.convertAnother(buffer.capacity()); writer.endNode(); - writer.startNode("limit"); marshallingContext.convertAnother(buffer.limit()); writer.endNode(); - writer.startNode("isDirect"); marshallingContext.convertAnother(buffer.isDirect()); writer.endNode(); @@ -74,7 +71,6 @@ public class ByteBufferConverter implements Converter { throw new ConversionException("", e); } - writer.endNode(); buffer.limit(limit); @@ -88,7 +84,6 @@ public class ByteBufferConverter implements Converter { int position = (Integer) unmarshallingContext.convertAnother(null, int.class); reader.moveUp(); - reader.moveDown(); int capacity = (Integer) unmarshallingContext.convertAnother(null, int.class); reader.moveUp(); diff --git a/src/main/java/net/openhft/xstream/converters/DataValueConverter.java b/src/main/java/net/openhft/xstream/converters/DataValueConverter.java index 04b29a063..9d1d9b29b 100644 --- a/src/main/java/net/openhft/xstream/converters/DataValueConverter.java +++ b/src/main/java/net/openhft/xstream/converters/DataValueConverter.java @@ -37,7 +37,6 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Map; - /** * @author Rob Austin. */ @@ -45,6 +44,45 @@ public class DataValueConverter implements Converter { private static final Logger LOG = LoggerFactory.getLogger(DataValueConverter.class); + private static Object toNativeValueObjects(HierarchicalStreamReader reader, + final Class aClass, + UnmarshallingContext context) { + + final Object o = DataValueClasses.newDirectInstance(aClass); + + try { + + final BeanInfo info = Introspector.getBeanInfo(o.getClass()); // new BeanGenerator + + for (PropertyDescriptor p : info.getPropertyDescriptors()) { + + if (!p.getName().equals("value")) + continue; + + final String value = reader.getValue(); + + if (StringValue.class.isAssignableFrom(o.getClass())) { + ((StringValue) o).setValue(value); + return o; + } + + final Class propertyType = p.getPropertyType(); + + final Object o1 = context.convertAnother(value, propertyType); + p.getWriteMethod().invoke(o, o1); + + return o; + + } + + } catch (Exception e) { + throw new ConversionException("class=" + aClass.getName(), e); + } + + throw new ConversionException("setValue(..) method not found in class=" + + aClass.getCanonicalName()); + } + @Override public void marshal(Object o, HierarchicalStreamWriter writer, MarshallingContext context) { @@ -78,7 +116,6 @@ public class DataValueConverter implements Converter { throw new ConversionException("class=" + canonicalName); } - try { DataValueModel dataValueModel = DataValueModels.acquireModel(interfaceClass(o.getClass())); @@ -138,7 +175,6 @@ public class DataValueConverter implements Converter { continue; } - try { final Method readMethod = fileModel.getter(); @@ -161,7 +197,6 @@ public class DataValueConverter implements Converter { LOG.error("class=" + fileModel.name(), e); } - } } catch (ClassNotFoundException e) { @@ -188,7 +223,6 @@ public class DataValueConverter implements Converter { return Class.forName(nodeName); } - @Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { @@ -289,46 +323,6 @@ public class DataValueConverter implements Converter { } } - - private static Object toNativeValueObjects(HierarchicalStreamReader reader, - final Class aClass, - UnmarshallingContext context) { - - final Object o = DataValueClasses.newDirectInstance(aClass); - - try { - - final BeanInfo info = Introspector.getBeanInfo(o.getClass()); // new BeanGenerator - - for (PropertyDescriptor p : info.getPropertyDescriptors()) { - - if (!p.getName().equals("value")) - continue; - - final String value = reader.getValue(); - - if (StringValue.class.isAssignableFrom(o.getClass())) { - ((StringValue) o).setValue(value); - return o; - } - - final Class propertyType = p.getPropertyType(); - - final Object o1 = context.convertAnother(value, propertyType); - p.getWriteMethod().invoke(o, o1); - - return o; - - } - - } catch (Exception e) { - throw new ConversionException("class=" + aClass.getName(), e); - } - - throw new ConversionException("setValue(..) method not found in class=" + - aClass.getCanonicalName()); - } - @Override public boolean canConvert(Class clazz) { final String canonicalName = clazz.getCanonicalName(); diff --git a/src/main/java/net/openhft/xstream/converters/StatelessChronicleMapConverter.java b/src/main/java/net/openhft/xstream/converters/StatelessChronicleMapConverter.java index b634e157f..b6711eb33 100644 --- a/src/main/java/net/openhft/xstream/converters/StatelessChronicleMapConverter.java +++ b/src/main/java/net/openhft/xstream/converters/StatelessChronicleMapConverter.java @@ -73,9 +73,7 @@ public class StatelessChronicleMapConverter extends AbstractChronicleMapCo throw new ConversionException("", e); } - } - } diff --git a/src/test/java/eg/OffHeapByteArrayExampleTest.java b/src/test/java/eg/OffHeapByteArrayExampleTest.java index 94d394c83..fe6e5f385 100644 --- a/src/test/java/eg/OffHeapByteArrayExampleTest.java +++ b/src/test/java/eg/OffHeapByteArrayExampleTest.java @@ -30,13 +30,6 @@ import org.junit.Test; public class OffHeapByteArrayExampleTest { public static final char EXPECTED = 'b'; - - interface ByteArray { - void setByteValueAt(@MaxSize(7) int index, ByteValue value); - - ByteValue getByteValueAt(int index); - } - private static ChronicleMap chm; @BeforeClass @@ -61,7 +54,6 @@ public class OffHeapByteArrayExampleTest { ByteArray value = chm.newValueInstance(); LongValue key = chm.newKeyInstance(); - key.setValue(1); // this is kind of like byteValue[1] = 'b' @@ -83,4 +75,10 @@ public class OffHeapByteArrayExampleTest { Assert.assertEquals(EXPECTED, actual); } + + interface ByteArray { + void setByteValueAt(@MaxSize(7) int index, ByteValue value); + + ByteValue getByteValueAt(int index); + } } diff --git a/src/test/java/eg/TestInstrumentVOInterface.java b/src/test/java/eg/TestInstrumentVOInterface.java index b41317291..c3fe6ce95 100644 --- a/src/test/java/eg/TestInstrumentVOInterface.java +++ b/src/test/java/eg/TestInstrumentVOInterface.java @@ -23,30 +23,24 @@ import net.openhft.lang.model.constraints.MaxSize; */ public interface TestInstrumentVOInterface { - int getSizeOfInstrumentIDArray(); void setSizeOfInstrumentIDArray(int sizeOfInstrumentIDArray); - String getSymbol(); void setSymbol(@MaxSize(20) String symbol); - String getCurrencyCode(); void setCurrencyCode(@MaxSize(4) String currencyCode); - void setInstrumentIDAt(@MaxSize(2) int location, TestInstrumentIDVOInterface instrumentID); TestInstrumentIDVOInterface getInstrumentIDAt(int location); - interface TestInstrumentIDVOInterface { - String getIdSource(); void setIdSource(@MaxSize(6) String idSource); diff --git a/src/test/java/net/openhft/chronicle/TestReplication.java b/src/test/java/net/openhft/chronicle/TestReplication.java index dbf8c4f9e..1408c4f1d 100755 --- a/src/test/java/net/openhft/chronicle/TestReplication.java +++ b/src/test/java/net/openhft/chronicle/TestReplication.java @@ -32,11 +32,13 @@ import java.util.Map; */ public class TestReplication { + public static final int SIZE = 1000; + private Map> maps = new HashMap<>(); + private ReplicationHub hubOnServer1; @Test public void testAllDataGetsReplicated() throws InterruptedException { - TcpTransportAndNetworkConfig tcpConfigServer1 = TcpTransportAndNetworkConfig.of(8082); @@ -49,36 +51,23 @@ public class TestReplication { .replication((byte) 2, tcpConfigServer2) .create(); - final ChronicleMap map1 = ChronicleMapBuilder.of(Integer.class, Integer.class) .replication((byte) 3, tcpConfigServer1) .create(); - for (int i = 0; i < 70000; i++) { map1.put(i, i); } - for (int i = 0; i < 10; i++) { Thread.sleep(100); System.out.println(map2.size()); } - Assert.assertEquals(map1.size(), map2.size()); } - - public static final int SIZE = 1000; - private Map> maps = new HashMap<>(); - - - private ReplicationHub hubOnServer1; - - - } diff --git a/src/test/java/net/openhft/chronicle/map/BuildVersionTest.java b/src/test/java/net/openhft/chronicle/map/BuildVersionTest.java index 7af12448a..ca1aec1a2 100644 --- a/src/test/java/net/openhft/chronicle/map/BuildVersionTest.java +++ b/src/test/java/net/openhft/chronicle/map/BuildVersionTest.java @@ -26,14 +26,12 @@ import java.io.IOException; */ public class BuildVersionTest { - @Test public void test() throws IOException, InterruptedException { // checks that we always get a version Assert.assertNotNull(BuildVersion.version()); } - /** * check that the map records the version * diff --git a/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java b/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java index a3ba24d9e..dc136abf7 100644 --- a/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java +++ b/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java @@ -46,41 +46,61 @@ import static net.openhft.chronicle.map.StatelessClientTest.localClient; import static net.openhft.chronicle.map.fromdocs.OpenJDKAndHashMapExamplesTest.parseYYYYMMDD; import static org.junit.Assert.*; +enum ToString implements Function { + INSTANCE; + + @Override + public String apply(Object o) { + return String.valueOf(o); + } + +} + +interface IBean { + long getLong(); + + void setLong(long num); + + double getDouble(); + + void setDouble(double d); + + int getInt(); + + void setInt(int i); + + void setInnerAt(@MaxSize(7) int index, Inner inner); + + Inner getInnerAt(int index); + + /* nested interface - empowering an Off-Heap hierarchical “TIER of prices” + as array[ ] value */ + interface Inner { + + String getMessage(); + + void setMessage(@MaxSize(20) String px); + + } +} + /** * This test enumerates common use cases for keys and values. */ @RunWith(value = Parameterized.class) public class CHMUseCasesTest { - - enum TypeOfMap {STATELESS, SIMPLE, SIMPLE_PERSISTED, REPLICATED} - + static volatile int i = 0; private final TypeOfMap typeOfMap; Collection closeables = new ArrayList(); + ChronicleMap map1; + ChronicleMap map2; public CHMUseCasesTest(TypeOfMap typeOfMap) { this.typeOfMap = typeOfMap; } - @After - public void after() { - for (Closeable c : closeables) { - - try { - c.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - closeables.clear(); - map2 = null; - map1 = null; - } - - ChronicleMap map1; - ChronicleMap map2; - @Parameterized.Parameters public static Collection data() { return asList(new Object[][]{ @@ -105,6 +125,36 @@ public class CHMUseCasesTest { } + private static void appendMode(ByteBuffer valueA) { + valueA.position(valueA.limit()); + valueA.limit(valueA.capacity()); + } + + public static Map mapOf(K k, V v, Object... keysAndValues) { + Map ret = new LinkedHashMap<>(); + ret.put(k, v); + for (int i = 0; i < keysAndValues.length - 1; i += 2) { + Object key = keysAndValues[i]; + Object value = keysAndValues[i + 1]; + ret.put((K) key, (V) value); + } + return ret; + } + + @After + public void after() { + for (Closeable c : closeables) { + + try { + c.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + closeables.clear(); + map2 = null; + map1 = null; + } /** * * waits until map1 and map2 show the same value @@ -124,7 +174,6 @@ public class CHMUseCasesTest { } } - private void mapChecks() { if (typeOfMap == TypeOfMap.REPLICATED) { @@ -142,7 +191,6 @@ public class CHMUseCasesTest { return; } - // see HCOLL-265 Chronicle Maps with Identical char[] values are not equal1 if (map1.keyClass() == char[].class || map1.keyClass() == byte[][].class) { @@ -150,12 +198,10 @@ public class CHMUseCasesTest { return; } - if (ByteBuffer.class.isAssignableFrom(map1.valueClass()) || ByteBuffer.class.isAssignableFrom(map1.keyClass())) return; - waitTillEqual(5000); assertEquals(map1, map2); } @@ -169,7 +215,6 @@ public class CHMUseCasesTest { assertEquals(map1.size(), map2.size()); - for (Object key : map1.keySet()) { if (map1.valueClass() == byte[].class) @@ -181,7 +226,6 @@ public class CHMUseCasesTest { byte[][] o1 = (byte[][]) map1.get(key); byte[][] o2 = (byte[][]) map2.get(key); - Assert.assertEquals(o1.length, o2.length); for (int i = 0; i < o1.length; i++) { Assert.assertArrayEquals(o1[i], o2[i]); @@ -192,7 +236,6 @@ public class CHMUseCasesTest { } } - private void checkJsonSerilization() { File file = null; try { @@ -217,7 +260,6 @@ public class CHMUseCasesTest { try (ChronicleMap actual = builder.create()) { actual.putAll(file); - if (map1.valueClass() == char[].class || map1.valueClass() == byte[].class || map1.valueClass() == byte[][].class) { @@ -234,8 +276,6 @@ public class CHMUseCasesTest { } } - static volatile int i = 0; - private ChronicleMap newInstance(ChronicleMapBuilder builder) throws IOException { switch (typeOfMap) { @@ -277,7 +317,6 @@ public class CHMUseCasesTest { .heartBeatInterval(1, TimeUnit.SECONDS) .tcpBufferSize(1024 * 64); - map2 = builder .replication((byte) 1, tcpConfig1) .instance() @@ -302,10 +341,8 @@ public class CHMUseCasesTest { } - } - case STATELESS: { { final TcpTransportAndNetworkConfig tcpConfig1 = TcpTransportAndNetworkConfig @@ -313,7 +350,6 @@ public class CHMUseCasesTest { .heartBeatInterval(1, TimeUnit.SECONDS) .tcpBufferSize(1024 * 64); - map2 = builder .replication((byte) 1, tcpConfig1) .instance() @@ -336,37 +372,6 @@ public class CHMUseCasesTest { } } - static class PrefixStringFunction implements Function { - private final String prefix; - - public PrefixStringFunction(@NotNull String prefix) { - this.prefix = prefix; - } - - @Override - public String apply(String s) { - return prefix + s; - } - - @Override - public boolean equals(Object obj) { - return obj instanceof PrefixStringFunction && - prefix.equals(((PrefixStringFunction) obj).prefix); - } - - @Override - public String toString() { - return prefix; - } - } - - - - interface I1 { - String getStrAt( @MaxSize(10) int i); - void setStrAt(@MaxSize(10) int i, @MaxSize(10) String str); - } - @Test public void testArrayOfString() throws ExecutionException, InterruptedException, IOException { @@ -410,7 +415,6 @@ public class CHMUseCasesTest { } } - @Test public void testCharArrayValue() throws ExecutionException, InterruptedException, IOException { @@ -430,7 +434,6 @@ public class CHMUseCasesTest { } } - @Ignore @Test public void testByteArrayArrayValue() throws ExecutionException, InterruptedException, IOException { @@ -502,7 +505,6 @@ public class CHMUseCasesTest { } } - @Test public void testEntrySpanningSeveralChunks() throws ExecutionException, InterruptedException, IOException { @@ -524,10 +526,6 @@ public class CHMUseCasesTest { } } - - - - @Test public void testKeyValueSizeBySample() throws ExecutionException, InterruptedException, IOException { @@ -544,7 +542,6 @@ public class CHMUseCasesTest { } } - @Test public void testLargeCharSequenceValue() throws ExecutionException, InterruptedException, IOException { @@ -568,7 +565,6 @@ public class CHMUseCasesTest { public void testStringStringMap() throws ExecutionException, InterruptedException, IOException { - ChronicleMapBuilder builder = ChronicleMapBuilder .of(String.class, String.class); @@ -582,23 +578,6 @@ public class CHMUseCasesTest { } } - - private static class StringPrefixUnaryOperator implements UnaryOperator, Serializable { - - private String prefix; - - StringPrefixUnaryOperator(final String prefix1) { - prefix = prefix1; - } - - @Override - public String update(String s) { - return prefix + s; - } - - } - - @Test public void testStringStringMapMutableValue() throws ExecutionException, InterruptedException, IOException { @@ -644,7 +623,6 @@ public class CHMUseCasesTest { } } - /** * CharSequence is more efficient when object creation is avoided. The key can only be on heap * and variable length serialised. @@ -655,7 +633,6 @@ public class CHMUseCasesTest { if (typeOfMap == TypeOfMap.STATELESS) return; // Function supported by the STATELESS client - ChronicleMapBuilder builder = ChronicleMapBuilder .of(CharSequence.class, CharSequence.class); @@ -674,7 +651,6 @@ public class CHMUseCasesTest { map.remove("key-1"); assertNull(map.getUsing(key, value)); - assertEquals("New World", map.getMapped("Hello", new Function() { @Override @@ -714,14 +690,12 @@ public class CHMUseCasesTest { } } - @Test public void testAcquireUsingWithCharSequence() throws IOException { if (typeOfMap == TypeOfMap.STATELESS) return; // getUsingLocked supported by the STATELESS client - ChronicleMapBuilder builder = ChronicleMapBuilder .of(CharSequence.class, CharSequence.class); @@ -761,7 +735,6 @@ public class CHMUseCasesTest { } } - @Test public void testGetUsingWithIntValueNoValue() throws IOException { @@ -785,14 +758,12 @@ public class CHMUseCasesTest { } } - @Test(expected = IllegalStateException.class) public void testAcquireUsingWithIntValueNoValue() throws IOException { if (typeOfMap == TypeOfMap.STATELESS) throw new IllegalStateException(); // acquireUsingLocked supported by the STATELESS - ChronicleMapBuilder builder = ChronicleMapBuilder .of(CharSequence.class, IntValue.class); @@ -811,7 +782,6 @@ public class CHMUseCasesTest { } } - @Test(expected = IllegalArgumentException.class) public void testAcquireUsingImmutableUsing() throws IOException { @@ -823,7 +793,6 @@ public class CHMUseCasesTest { try (ChronicleMap map = newInstance(builder)) { - IntValue using = map.newKeyInstance(); using.setValue(1); @@ -849,7 +818,6 @@ public class CHMUseCasesTest { try (ChronicleMap map = newInstance(builder)) { - IntValue key = map.newKeyInstance(); key.setValue(1); @@ -923,7 +891,6 @@ public class CHMUseCasesTest { } } - /** * StringValue represents any bean which contains a String Value */ @@ -1054,7 +1021,6 @@ public class CHMUseCasesTest { @Test public void testIntegerIntegerMap() throws ExecutionException, InterruptedException, IOException { - if (typeOfMap == TypeOfMap.STATELESS) return; // Function supported by the STATELESS client @@ -1074,7 +1040,6 @@ public class CHMUseCasesTest { map.put(key1, value1); assertEquals(value1, map.get(key1)); - key2 = 2; value2 = 22; map.put(key2, value2); @@ -1122,11 +1087,9 @@ public class CHMUseCasesTest { @Test public void testLongLongMap() throws ExecutionException, InterruptedException, IOException { - if (typeOfMap == TypeOfMap.STATELESS) return; - ChronicleMapBuilder builder = ChronicleMapBuilder .of(Long.class, Long.class); @@ -1176,11 +1139,9 @@ public class CHMUseCasesTest { @Test public void testDoubleDoubleMap() throws ExecutionException, InterruptedException, IOException { - if (typeOfMap == TypeOfMap.STATELESS) return; - ChronicleMapBuilder builder = ChronicleMapBuilder .of(Double.class, Double.class); @@ -1220,14 +1181,12 @@ public class CHMUseCasesTest { } catch (Exception todoMoreSpecificException) { } - } } @Test public void testByteArrayByteArrayMap() throws ExecutionException, InterruptedException, IOException { - if (typeOfMap == TypeOfMap.STATELESS) return; @@ -1247,7 +1206,6 @@ public class CHMUseCasesTest { map.put(key1, value1); - assertTrue(Arrays.equals(new byte[]{11, 11}, map.getMapped(key1, new Function() { @Override public byte[] apply(byte[] s) { @@ -1273,11 +1231,9 @@ public class CHMUseCasesTest { byte[] a2 = map.get(key1); assertTrue(Arrays.equals(new byte[]{12, 10}, a2)); - } } - // @Ignore("HCOLL-268 JSON serialisation issue") @Test public void testByteBufferByteBufferDefaultKeyValueMarshaller() throws ExecutionException, @@ -1291,7 +1247,6 @@ public class CHMUseCasesTest { try (ChronicleMap map = newInstance(builder)) { - ByteBuffer key1 = ByteBuffer.wrap(new byte[]{1, 1, 1, 1}); ByteBuffer key2 = ByteBuffer.wrap(new byte[]{2, 2, 2, 2}); ByteBuffer value1 = ByteBuffer.wrap(new byte[]{11, 11, 11, 11}); @@ -1301,14 +1256,12 @@ public class CHMUseCasesTest { assertBBEquals(value2, map.get(key1)); assertNull(map.get(key2)); - map.put(key1, value1); mapChecks(); } } - @Test public void testByteBufferByteBufferMap() throws ExecutionException, InterruptedException, IOException { @@ -1324,7 +1277,6 @@ public class CHMUseCasesTest { try (ChronicleMap map = newInstance(builder)) { - ByteBuffer key1 = ByteBuffer.wrap(new byte[]{1, 1, 1, 1}); ByteBuffer key2 = ByteBuffer.wrap(new byte[]{2, 2, 2, 2}); ByteBuffer value1 = ByteBuffer.wrap(new byte[]{11, 11, 11, 11}); @@ -1392,12 +1344,10 @@ public class CHMUseCasesTest { valueA.flip(); } - value1.clear(); value1.putInt(12345); value1.flip(); - try (WriteContext wc = map.acquireUsingLocked(key1, valueB)) { assertBBEquals(value1, valueB); appendMode(valueB); @@ -1419,11 +1369,6 @@ public class CHMUseCasesTest { } } - private static void appendMode(ByteBuffer valueA) { - valueA.position(valueA.limit()); - valueA.limit(valueA.capacity()); - } - //@Ignore("HCOLL-268 JSON serialisation issue") @Test public void testByteBufferDirectByteBufferMap() throws ExecutionException, InterruptedException, IOException { @@ -1438,7 +1383,6 @@ public class CHMUseCasesTest { try (ChronicleMap map = newInstance(builder)) { - ByteBuffer key1 = ByteBuffer.wrap(new byte[]{1, 1, 1, 1}); ByteBuffer key2 = ByteBuffer.wrap(new byte[]{2, 2, 2, 2}); ByteBuffer value1 = ByteBuffer.allocateDirect(4); @@ -1501,7 +1445,6 @@ public class CHMUseCasesTest { IntValue value1 = map.newValueInstance(); IntValue value2 = map.newValueInstance(); - key1.setValue(1); value1.setValue(11); map.put(key1, value1); @@ -1595,7 +1538,6 @@ public class CHMUseCasesTest { } } - /** * For unsigned int -> unsigned int entries, the key can be on heap or off heap. */ @@ -1610,7 +1552,6 @@ public class CHMUseCasesTest { try (ChronicleMap map = newInstance(builder)) { - UnsignedIntValue key1 = map.newKeyInstance(); UnsignedIntValue key2 = map.newKeyInstance(); UnsignedIntValue value1 = map.newValueInstance(); @@ -1701,7 +1642,6 @@ public class CHMUseCasesTest { // this may change due to alignment // assertEquals(6, entrySize(map)); - // assertEquals(1, ((VanillaChronicleMap) map).maxChunksPerEntry); IntValue key1 = map.newKeyInstance(); IntValue key2 = map.newKeyInstance(); @@ -1782,7 +1722,6 @@ public class CHMUseCasesTest { @Test public void testIntValueUnsignedShortValueMap() throws IOException { - if (typeOfMap == TypeOfMap.STATELESS) return; @@ -1791,7 +1730,6 @@ public class CHMUseCasesTest { try (ChronicleMap map = newInstance(builder)) { - // this may change due to alignment // assertEquals(8, entrySize(map)); assertEquals(1, ((VanillaChronicleMap) map).maxChunksPerEntry); @@ -1882,7 +1820,6 @@ public class CHMUseCasesTest { try (ChronicleMap map = newInstance(builder)) { - assertEquals(1, ((VanillaChronicleMap) map).maxChunksPerEntry); IntValue key1 = map.newKeyInstance(); IntValue key2 = map.newKeyInstance(); @@ -1970,7 +1907,6 @@ public class CHMUseCasesTest { try (ChronicleMap map = newInstance(builder)) { - // TODO should be 5, but shorter fields based on range doesn't seem to be implemented // on data value generation level yet //assertEquals(8, entrySize(map)); this may change due to alignmented @@ -1981,7 +1917,6 @@ public class CHMUseCasesTest { UnsignedByteValue value1 = map.newValueInstance(); UnsignedByteValue value2 = map.newValueInstance(); - key1.setValue(1); value1.setValue(11); map.put(key1, value1); @@ -2064,7 +1999,6 @@ public class CHMUseCasesTest { try (ChronicleMap map = newInstance(builder)) { - assertEquals(1, ((VanillaChronicleMap) map).maxChunksPerEntry); IntValue key1 = map.newKeyInstance(); @@ -2072,7 +2006,6 @@ public class CHMUseCasesTest { BooleanValue value1 = map.newValueInstance(); BooleanValue value2 = map.newValueInstance(); - key1.setValue(1); value1.setValue(true); map.put(key1, value1); @@ -2147,7 +2080,6 @@ public class CHMUseCasesTest { @Test public void testFloatValueFloatValueMap() throws IOException { - if (typeOfMap == TypeOfMap.STATELESS) return; // getUsingLocked supported by the STATELESS client @@ -2163,7 +2095,6 @@ public class CHMUseCasesTest { FloatValue value1 = map.newValueInstance(); FloatValue value2 = map.newValueInstance(); - key1.setValue(1); value1.setValue(11); map.put(key1, value1); @@ -2232,7 +2163,6 @@ public class CHMUseCasesTest { } } - /** * For double values, the key can be on heap or off heap. */ @@ -2257,7 +2187,6 @@ public class CHMUseCasesTest { DoubleValue value1 = map.newValueInstance(); DoubleValue value2 = map.newValueInstance(); - key1.setValue(1); value1.setValue(11); assertEquals(null, map.get(key1)); @@ -2334,7 +2263,6 @@ public class CHMUseCasesTest { @Test public void testLongValueLongValueMap() throws IOException { - if (typeOfMap == TypeOfMap.STATELESS) return; @@ -2352,7 +2280,6 @@ public class CHMUseCasesTest { LongValue value1 = map.newValueInstance(); LongValue value2 = map.newValueInstance(); - key1.setValue(1); value1.setValue(11); assertEquals(null, map.get(key1)); @@ -2438,7 +2365,6 @@ public class CHMUseCasesTest { .of(String.class, (Class>) (Class) List.class) .valueMarshaller(ListMarshaller.of(new StringMarshaller(8))); - try (ChronicleMap> map = newInstance(builder)) { map.put("1", Collections.emptyList()); map.put("2", asList("two-A")); @@ -2482,7 +2408,6 @@ public class CHMUseCasesTest { .of(String.class, (Class>) (Class) Set.class) .valueMarshaller(SetMarshaller.of(new StringMarshaller(8))); - try (ChronicleMap> map = newInstance(builder)) { map.put("1", Collections.emptySet()); map.put("2", new LinkedHashSet(asList("one"))); @@ -2515,7 +2440,6 @@ public class CHMUseCasesTest { } } - @Test public void testMapStringStringValue() throws IOException { @@ -2527,7 +2451,6 @@ public class CHMUseCasesTest { .valueMarshaller(MapMarshaller.of(new StringMarshaller(16), new StringMarshaller (16))); - try (ChronicleMap> map = newInstance(builder)) { map.put("1", Collections.emptyMap()); map.put("2", mapOf("one", "uni")); @@ -2554,11 +2477,9 @@ public class CHMUseCasesTest { } } - @Test public void testMapStringIntegerValue() throws IOException { - if (typeOfMap == TypeOfMap.STATELESS) return; // getUsingLocked not supported by the STATELESS client @@ -2606,17 +2527,6 @@ public class CHMUseCasesTest { } } - public static Map mapOf(K k, V v, Object... keysAndValues) { - Map ret = new LinkedHashMap<>(); - ret.put(k, v); - for (int i = 0; i < keysAndValues.length - 1; i += 2) { - Object key = keysAndValues[i]; - Object value = keysAndValues[i + 1]; - ret.put((K) key, (V) value); - } - return ret; - } - @Test public void testGeneratedDataValue() throws IOException { @@ -2643,44 +2553,52 @@ public class CHMUseCasesTest { } } + enum TypeOfMap {STATELESS, SIMPLE, SIMPLE_PERSISTED, REPLICATED} -} + interface I1 { + String getStrAt(@MaxSize(10) int i); -enum ToString implements Function { - INSTANCE; + void setStrAt(@MaxSize(10) int i, @MaxSize(10) String str); + } + + static class PrefixStringFunction implements Function { + private final String prefix; + + public PrefixStringFunction(@NotNull String prefix) { + this.prefix = prefix; + } + + @Override + public String apply(String s) { + return prefix + s; + } + + @Override + public boolean equals(Object obj) { + return obj instanceof PrefixStringFunction && + prefix.equals(((PrefixStringFunction) obj).prefix); + } + + @Override + public String toString() { + return prefix; + } + } + + private static class StringPrefixUnaryOperator implements UnaryOperator, Serializable { + + private String prefix; + + StringPrefixUnaryOperator(final String prefix1) { + prefix = prefix1; + } + + @Override + public String update(String s) { + return prefix + s; + } - @Override - public String apply(Object o) { - return String.valueOf(o); } } -interface IBean { - long getLong(); - - void setLong(long num); - - double getDouble(); - - void setDouble(double d); - - int getInt(); - - void setInt(int i); - - void setInnerAt(@MaxSize(7) int index, Inner inner); - - Inner getInnerAt(int index); - - /* nested interface - empowering an Off-Heap hierarchical “TIER of prices” - as array[ ] value */ - interface Inner { - - String getMessage(); - - void setMessage(@MaxSize(20) String px); - - } -} - diff --git a/src/test/java/net/openhft/chronicle/map/ChronicleMapImportExportTest.java b/src/test/java/net/openhft/chronicle/map/ChronicleMapImportExportTest.java index 708a2484b..ea0a26ee2 100644 --- a/src/test/java/net/openhft/chronicle/map/ChronicleMapImportExportTest.java +++ b/src/test/java/net/openhft/chronicle/map/ChronicleMapImportExportTest.java @@ -177,7 +177,6 @@ public class ChronicleMapImportExportTest { } } - @Test public void testFromHashMap() throws IOException, InterruptedException { @@ -191,13 +190,11 @@ public class ChronicleMapImportExportTest { map.put(1, "one"); map.put(2, "two"); - final XStream xstream = new XStream(new JettisonMappedXmlDriver()); xstream.setMode(XStream.NO_REFERENCES); xstream.toXML(map, new FileOutputStream(file)); - try (ChronicleMap expected = ChronicleMapBuilder .of(Integer.class, String.class) .averageValueSize(10) @@ -215,11 +212,9 @@ public class ChronicleMapImportExportTest { Assert.assertEquals("two", expected.get(2)); } - file.deleteOnExit(); } - @Test public void testToJsonWithStatelessClient() throws IOException, InterruptedException { File file = new File(TMP + "/chronicle-map-" + System.nanoTime() + ".json"); @@ -238,7 +233,6 @@ public class ChronicleMapImportExportTest { actual.putAll(file); - Assert.assertEquals(expected, actual); actual.getAll(file2); @@ -255,7 +249,6 @@ public class ChronicleMapImportExportTest { file2.delete(); } - @Test public void testWithLongValue() throws IOException, InterruptedException { @@ -291,7 +284,6 @@ public class ChronicleMapImportExportTest { } } - @Test public void testBondVOInterface() throws IOException, InterruptedException { diff --git a/src/test/java/net/openhft/chronicle/map/ChronicleMapTest.java b/src/test/java/net/openhft/chronicle/map/ChronicleMapTest.java index f083720f7..1cfbea702 100755 --- a/src/test/java/net/openhft/chronicle/map/ChronicleMapTest.java +++ b/src/test/java/net/openhft/chronicle/map/ChronicleMapTest.java @@ -103,6 +103,20 @@ public class ChronicleMapTest { return file; } + private static void printStatus() { + if (!new File("/proc/self/status").exists()) return; + try { + BufferedReader br = new BufferedReader(new FileReader("/proc/self/status")); + for (String line; (line = br.readLine()) != null; ) + if (line.startsWith("Vm")) + System.out.print(line.replaceAll(" +", " ") + ", "); + + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + private ChronicleMap getViewTestMap(int noOfElements) throws IOException { ChronicleMap map = ChronicleMapBuilder.of(Integer.class, CharSequence.class) @@ -124,20 +138,6 @@ public class ChronicleMapTest { } - private static void printStatus() { - if (!new File("/proc/self/status").exists()) return; - try { - BufferedReader br = new BufferedReader(new FileReader("/proc/self/status")); - for (String line; (line = br.readLine()) != null; ) - if (line.startsWith("Vm")) - System.out.print(line.replaceAll(" +", " ") + ", "); - - br.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - @Test public void testRemoveWithKey() { @@ -184,7 +184,6 @@ public class ChronicleMapTest { } } - @Test public void testByteArrayPersistenceFileReuse() throws IOException { final File persistenceFile = Builder.getPersistenceFile(); @@ -201,7 +200,6 @@ public class ChronicleMapTest { persistenceFile.delete(); - } @Test @@ -244,7 +242,6 @@ public class ChronicleMapTest { } } - @Ignore("HCOLL-265 Chronicle Maps with Identical byte[] & char[] values are not equal") @Test public void testEqualsByteArray() { @@ -267,7 +264,6 @@ public class ChronicleMapTest { } } - @Test public void testSize() { @@ -693,7 +689,6 @@ public class ChronicleMapTest { } } - @Ignore("Possible candidate for TC JVM crashes") @Test public void testAcquireFromMultipleThreads() throws InterruptedException { @@ -840,7 +835,6 @@ public class ChronicleMapTest { .averageKeySize(14) .averageValueSize(value0.length() + 4); - // File tmpFile = File.createTempFile("testAcquirePerf", ".deleteme"); // tmpFile.deleteOnExit(); //createPersistedTo(tmpFile); @@ -1083,7 +1077,6 @@ public class ChronicleMapTest { } printStatus(); - tmpFile.delete(); } es.shutdown(); @@ -1276,7 +1269,6 @@ public class ChronicleMapTest { } - @Test public void mapPutReflectedInViews() throws IOException { try (ChronicleMap map = getViewTestMap(3)) { @@ -1295,7 +1287,6 @@ public class ChronicleMapTest { } } - @Test public void entrySetRemoveReflectedInMapAndOtherViews() throws IOException { try (ChronicleMap map = getViewTestMap(3)) { @@ -1311,7 +1302,6 @@ public class ChronicleMapTest { } } - @Test public void keySetRemoveReflectedInMapAndOtherViews() throws IOException { try (ChronicleMap map = getViewTestMap(3)) { @@ -1368,7 +1358,6 @@ public class ChronicleMapTest { } } - @Test public void keySetIteratorRemoveReflectedInMapAndOtherViews() throws IOException { try (ChronicleMap map = getViewTestMap(3)) { @@ -1474,7 +1463,6 @@ public class ChronicleMapTest { } } - @Test public void entrySetRetainAllReflectedInMapAndOtherViews() throws IOException { try (ChronicleMap map = getViewTestMap(3)) { @@ -1496,7 +1484,6 @@ public class ChronicleMapTest { } } - @Test public void keySetRetainAllReflectedInMapAndOtherViews() throws IOException { try (ChronicleMap map = getViewTestMap(3)) { @@ -1642,7 +1629,6 @@ public class ChronicleMapTest { ++sum; } - assertEquals(noOfElements, sum); } } @@ -1674,7 +1660,6 @@ public class ChronicleMapTest { } - @Test public void testEntriesSpanningSeveralChunksPutRemoveReplace() throws IOException, InterruptedException { ChronicleMapBuilder builder = ChronicleMapBuilder.of(CharSequence.class, CharSequence.class) @@ -1722,7 +1707,6 @@ public class ChronicleMapTest { } - @Test public void equalsTest() throws IOException { try (final ChronicleMap map1 = ChronicleMapBuilder @@ -1741,43 +1725,8 @@ public class ChronicleMapTest { } } - } - private static final class IncrementRunnable implements Runnable { - - private final ChronicleMap map; - - private final CharSequence key; - - private final int iterations; - - private final CyclicBarrier barrier; - - private IncrementRunnable(ChronicleMap map, CharSequence key, int iterations, CyclicBarrier barrier) { - this.map = map; - this.key = key; - this.iterations = iterations; - this.barrier = barrier; - } - - @Override - public void run() { - try { - LongValue value = new LongValue$$Native(); - barrier.await(); - for (int i = 0; i < iterations; i++) { - map.acquireUsing(key, value); - value.addAtomicValue(1); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - } - - @Test public void testPutLongValue() throws IOException { final ChronicleMapBuilder builder = ChronicleMapBuilder @@ -1857,13 +1806,11 @@ public class ChronicleMapTest { } } - @Test public void testByteArrayKeySizeBySample() throws IOException { TcpTransportAndNetworkConfig serverConfig = TcpTransportAndNetworkConfig.of(8877) .name("serverMap"); - // this test only appear to fail when we reuse the mapFile for (int i = 0; i < 2; i++) { @@ -1874,14 +1821,12 @@ public class ChronicleMapTest { try (ChronicleMap map2 = localClient(8877)) { - byte[] key = new byte[14]; System.arraycopy("A".getBytes(), 0, key, 0, "A".length()); byte[][] value = {new byte[11], new byte[11]}; System.arraycopy("A".getBytes(), 0, value[0], 0, "A".length()); System.arraycopy("A".getBytes(), 0, value[1], 0, "A".length()); - map2.put(key, value); Assert.assertNotNull(map2.get(key)); } @@ -1994,6 +1939,38 @@ public class ChronicleMapTest { tmpFile.delete(); } + private static final class IncrementRunnable implements Runnable { + + private final ChronicleMap map; + + private final CharSequence key; + + private final int iterations; + + private final CyclicBarrier barrier; + + private IncrementRunnable(ChronicleMap map, CharSequence key, int iterations, CyclicBarrier barrier) { + this.map = map; + this.key = key; + this.iterations = iterations; + this.barrier = barrier; + } + + @Override + public void run() { + try { + LongValue value = new LongValue$$Native(); + barrier.await(); + for (int i = 0; i < iterations; i++) { + map.acquireUsing(key, value); + value.addAtomicValue(1); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + } + } - diff --git a/src/test/java/net/openhft/chronicle/map/EntryCountMapTest.java b/src/test/java/net/openhft/chronicle/map/EntryCountMapTest.java index 4209a0211..1a5ab02d0 100644 --- a/src/test/java/net/openhft/chronicle/map/EntryCountMapTest.java +++ b/src/test/java/net/openhft/chronicle/map/EntryCountMapTest.java @@ -35,9 +35,10 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; public class EntryCountMapTest { + static final String TMP = System.getProperty("java.io.tmpdir"); + static final int ecmTests = Integer.getInteger("ecm.tests", 5); double score = 0; int scoreCount = 0; - static final String TMP = System.getProperty("java.io.tmpdir"); static File getPersistenceFile() throws IOException { File file = File.createTempFile("ecm-chm-test", ".deleteme"); @@ -55,7 +56,9 @@ public class EntryCountMapTest { return mapBuilder.createPersistedTo(getPersistenceFile()); } - static final int ecmTests = Integer.getInteger("ecm.tests", 5); + private static int moreThanMaxSize(int maxSize) { + return maxSize * 14 / 10 + 300; + } @Ignore("HCOLL-279 fix net.openhft.chronicle.map.EntryCountMapTest#testVerySmall") @Test @@ -188,7 +191,6 @@ public class EntryCountMapTest { final int maxKeySize = "key:".length() + (int) round(log10(moreThanMaxSize(maxSize) * stride + counter)) + 1; - return es.submit(new Callable() { @Override public Void call() { @@ -258,10 +260,6 @@ public class EntryCountMapTest { } - private static int moreThanMaxSize(int maxSize) { - return maxSize * 14 / 10 + 300; - } - private void dumpMapStats(int segments, int minSize, ChronicleMap map) { long[] a = ((VanillaChronicleMap) map).segmentSizes(); diff --git a/src/test/java/net/openhft/chronicle/map/KeySegmentDistributionTest.java b/src/test/java/net/openhft/chronicle/map/KeySegmentDistributionTest.java index 067118b24..70835f310 100644 --- a/src/test/java/net/openhft/chronicle/map/KeySegmentDistributionTest.java +++ b/src/test/java/net/openhft/chronicle/map/KeySegmentDistributionTest.java @@ -40,7 +40,6 @@ public class KeySegmentDistributionTest { keySegmentDistributionTest(1000, 5); } - public void keySegmentDistributionTest(int size, int segments) { ChronicleMap map = ChronicleMapBuilder .of(CharSequence.class, Integer.class) diff --git a/src/test/java/net/openhft/chronicle/map/KeyValueInstanceTest.java b/src/test/java/net/openhft/chronicle/map/KeyValueInstanceTest.java index ef37727f6..ede431632 100644 --- a/src/test/java/net/openhft/chronicle/map/KeyValueInstanceTest.java +++ b/src/test/java/net/openhft/chronicle/map/KeyValueInstanceTest.java @@ -39,7 +39,6 @@ public class KeyValueInstanceTest { } } - @Test(expected = IllegalStateException.class) public void testNewKeyValueInstanceWithMapType() { try (ChronicleMap map = ChronicleMapBuilder @@ -63,6 +62,30 @@ public class KeyValueInstanceTest { } } + @Test + public void testNewKeyValueInstanceWithListType() { + try (ChronicleMap map = ChronicleMapBuilder + .of(HashMap.class, IBean.class) + .create()) { + + map.newKeyInstance(); + Object value = map.newValueInstance(); + + assertTrue(value.getClass().getCanonicalName().endsWith("$$Native")); + + } + } + + @Test(expected = IllegalStateException.class) + public void testNewKeyValueInstanceWithByteArray() { + try (ChronicleMap map = ChronicleMapBuilder + .of(byte[].class, byte[].class) + .create()) { + + map.newKeyInstance(); + map.newValueInstance(); + } + } interface IBean { long getLong(); @@ -77,31 +100,4 @@ public class KeyValueInstanceTest { void setInt(int i); } - - @Test - public void testNewKeyValueInstanceWithListType() { - try (ChronicleMap map = ChronicleMapBuilder - .of(HashMap.class, IBean.class) - .create()) { - - map.newKeyInstance(); - Object value = map.newValueInstance(); - - assertTrue(value.getClass().getCanonicalName().endsWith("$$Native")); - - - } - } - - - @Test(expected = IllegalStateException.class) - public void testNewKeyValueInstanceWithByteArray() { - try (ChronicleMap map = ChronicleMapBuilder - .of(byte[].class, byte[].class) - .create()) { - - map.newKeyInstance(); - map.newValueInstance(); - } - } } diff --git a/src/test/java/net/openhft/chronicle/map/MarkTest.java b/src/test/java/net/openhft/chronicle/map/MarkTest.java index 989464616..047f706ac 100644 --- a/src/test/java/net/openhft/chronicle/map/MarkTest.java +++ b/src/test/java/net/openhft/chronicle/map/MarkTest.java @@ -16,7 +16,6 @@ package net.openhft.chronicle.map; - import net.openhft.lang.MemoryUnit; import org.junit.Test; @@ -32,6 +31,24 @@ public class MarkTest { static int ENTRIES = 25_000_000; + private static void test(Function, + ChronicleMap> createMap) { + long ms = System.currentTimeMillis(); + try (ChronicleMap map = createMap.apply(ChronicleMapBuilder + .of(Integer.class, Integer.class) + .entries(ENTRIES) + .entriesPerSegment((1 << 17) / 3) + .putReturnsNull(true) + .removeReturnsNull(true))) { + + Random r = ThreadLocalRandom.current(); + for (int i = 0; i < ENTRIES; i++) { + map.put(r.nextInt(), r.nextInt()); + } + } + System.out.println(System.currentTimeMillis() - ms); + } + @Test(timeout = 25000) public void inMemoryTest() { test(new Function, ChronicleMap>() { @@ -69,22 +86,4 @@ public class MarkTest { db.delete(); } } - - private static void test(Function, - ChronicleMap> createMap) { - long ms = System.currentTimeMillis(); - try (ChronicleMap map = createMap.apply(ChronicleMapBuilder - .of(Integer.class, Integer.class) - .entries(ENTRIES) - .entriesPerSegment((1 << 17) / 3) - .putReturnsNull(true) - .removeReturnsNull(true))) { - - Random r = ThreadLocalRandom.current(); - for (int i = 0; i < ENTRIES; i++) { - map.put(r.nextInt(), r.nextInt()); - } - } - System.out.println(System.currentTimeMillis() - ms); - } } diff --git a/src/test/java/net/openhft/chronicle/map/NoTcpReplicationSoakTest.java b/src/test/java/net/openhft/chronicle/map/NoTcpReplicationSoakTest.java index fad9e798f..52c53565a 100644 --- a/src/test/java/net/openhft/chronicle/map/NoTcpReplicationSoakTest.java +++ b/src/test/java/net/openhft/chronicle/map/NoTcpReplicationSoakTest.java @@ -41,12 +41,13 @@ import java.util.concurrent.atomic.AtomicInteger; */ public class NoTcpReplicationSoakTest { + static int s_port = 8010; + Set threads; + AtomicInteger task = new AtomicInteger(); private ReplicatedChronicleMap map1; private ReplicatedChronicleMap map2; private IntValue value; - static int s_port = 8010; private long time; - TimeProvider timeProvider = new TimeProvider() { @Override public long currentTimeMillis() { @@ -54,16 +55,13 @@ public class NoTcpReplicationSoakTest { } }; - @Before public void setup() throws IOException { value = DataValueClasses.newDirectReference(IntValue.class); ((Byteable) value).bytes(new ByteBufferBytes(ByteBuffer.allocateDirect(4)), 0); - { - map1 = (ReplicatedChronicleMap) ChronicleMapBuilder.of(Integer.class, CharSequence.class) .replication((byte) 1) .timeProvider(timeProvider) @@ -83,10 +81,8 @@ public class NoTcpReplicationSoakTest { } s_port += 2; - } - @After public void tearDown() throws InterruptedException { @@ -101,8 +97,6 @@ public class NoTcpReplicationSoakTest { System.gc(); } - Set threads; - @Before public void sampleThreads() { threads = Thread.getAllStackTraces().keySet(); @@ -113,8 +107,6 @@ public class NoTcpReplicationSoakTest { StatelessClientTest.checkThreadsShutdown(threads); } - AtomicInteger task = new AtomicInteger(); - @Test public void testSoakTestWithRandomData() throws IOException, InterruptedException { ExecutorService executorService = Executors.newSingleThreadExecutor(); @@ -125,7 +117,6 @@ public class NoTcpReplicationSoakTest { Random rnd = new Random(j); - if (rnd.nextInt(10) < 2) time++; @@ -216,8 +207,5 @@ public class NoTcpReplicationSoakTest { } } - - - } diff --git a/src/test/java/net/openhft/chronicle/map/SerializerTest.java b/src/test/java/net/openhft/chronicle/map/SerializerTest.java index d6fbd9692..89a2327d2 100644 --- a/src/test/java/net/openhft/chronicle/map/SerializerTest.java +++ b/src/test/java/net/openhft/chronicle/map/SerializerTest.java @@ -62,7 +62,6 @@ public class SerializerTest { } - @Test public void testValueMarshallable() { testReadWriteValue("Test"); diff --git a/src/test/java/net/openhft/chronicle/map/SingleMapChannelTest.java b/src/test/java/net/openhft/chronicle/map/SingleMapChannelTest.java index 30cfa474a..fea10a0b3 100644 --- a/src/test/java/net/openhft/chronicle/map/SingleMapChannelTest.java +++ b/src/test/java/net/openhft/chronicle/map/SingleMapChannelTest.java @@ -44,8 +44,6 @@ public class SingleMapChannelTest { private ReplicationHub hubA; private ReplicationHub hubB; - - @Before public void setup() throws IOException { diff --git a/src/test/java/net/openhft/chronicle/map/StatelessClientTest.java b/src/test/java/net/openhft/chronicle/map/StatelessClientTest.java index 926f7f20b..c3592292f 100644 --- a/src/test/java/net/openhft/chronicle/map/StatelessClientTest.java +++ b/src/test/java/net/openhft/chronicle/map/StatelessClientTest.java @@ -43,32 +43,11 @@ import static org.junit.Assert.assertTrue; */ @Ignore public class StatelessClientTest { - private static final Logger LOG = LoggerFactory.getLogger(StatelessClientTest.class); - public static final int SIZE = 2500; + private static final Logger LOG = LoggerFactory.getLogger(StatelessClientTest.class); static int s_port = 9070; - - enum ToString implements Function { - INSTANCE; - - @Override - public String apply(Object obj) { - return obj.toString(); - } - } - Set threads; - @Before - public void sampleThreads() { - threads = Thread.getAllStackTraces().keySet(); - } - - @After - public void checkThreadsShutdown() { - checkThreadsShutdown(threads); - } - public static void checkThreadsShutdown(Set threads) { // give them a change to stop if there were killed. try { @@ -103,6 +82,20 @@ public class StatelessClientTest { } } + public static ChronicleMap localClient(int port) throws IOException { + return createClientOf(new InetSocketAddress("localhost", port)); + } + + @Before + public void sampleThreads() { + threads = Thread.getAllStackTraces().keySet(); + } + + @After + public void checkThreadsShutdown() { + checkThreadsShutdown(threads); + } + @Test(timeout = 10000) public void testMapForKeyWithEntry() throws IOException, InterruptedException { int port = s_port++; @@ -128,10 +121,6 @@ public class StatelessClientTest { } } - public static ChronicleMap localClient(int port) throws IOException { - return createClientOf(new InetSocketAddress("localhost", port)); - } - @Test(timeout = 10000) public void testMapForKeyWhenNoEntry() throws IOException, InterruptedException { int port = s_port++; @@ -150,7 +139,6 @@ public class StatelessClientTest { } } - @Test(timeout = 10000) public void testBufferOverFlowPutAllAndEntrySet() throws IOException, InterruptedException { int port = s_port++; @@ -204,7 +192,6 @@ public class StatelessClientTest { } } - /** * test that when the map is full and exception is thrown back to the user * @@ -224,7 +211,6 @@ public class StatelessClientTest { .create()) { try (ChronicleMap statelessMap = localClient(port)) { - for (int i = 0; i < size; i++) { statelessMap.put(i, "hello"); } @@ -331,12 +317,10 @@ public class StatelessClientTest { assertEquals("hello", statelessMap.get("hello")); assertEquals(1, statelessMap.size()); - } } } - @Test(timeout = 10000) public void testIsEmpty() throws IOException, InterruptedException { @@ -350,12 +334,10 @@ public class StatelessClientTest { assertTrue(statelessMap.isEmpty()); assertEquals(0, statelessMap.size()); - } } } - @Test(timeout = 10000) public void testStringKeyMapPutIfAbsentIntoStatelessMap() throws IOException, InterruptedException { @@ -468,7 +450,6 @@ public class StatelessClientTest { } } - @Test(timeout = 10000) public void testLargeEntries() throws IOException, InterruptedException { @@ -493,14 +474,12 @@ public class StatelessClientTest { assertEquals(new String(value), statelessMap.get(1)); assertEquals(1, statelessMap.size()); - assertEquals(null, statelessMap.get(0)); assertEquals(1, statelessMap.size()); } } } - @Test(timeout = 10000) public void testGetAndEntryWeDontHave() throws IOException, InterruptedException, ExecutionException { @@ -552,7 +531,6 @@ public class StatelessClientTest { serverMap2.close(); } - @Test public void testThreadSafeness() throws IOException, InterruptedException { @@ -592,7 +570,6 @@ public class StatelessClientTest { }); } - for (int i = 0; i < count; i++) { final int j = i; @@ -625,7 +602,6 @@ public class StatelessClientTest { } }); - } latch.await(25, TimeUnit.SECONDS); @@ -643,10 +619,8 @@ public class StatelessClientTest { } - } - @Test public void testPutsStatelessClientWithReplication() throws IOException, InterruptedException { @@ -659,7 +633,6 @@ public class StatelessClientTest { long startTime = System.currentTimeMillis(); - // server try (ChronicleMap server = ChronicleMapBuilder .of(Integer.class, Integer.class) @@ -672,7 +645,6 @@ public class StatelessClientTest { .replication((byte) 2, TcpTransportAndNetworkConfig.of(8046, new InetSocketAddress("localhost", 8047))).create()) { - // stateless client try (ChronicleMap client = localClient(8046)) { @@ -695,7 +667,6 @@ public class StatelessClientTest { }); } - for (int i = 0; i < count; i++) { final int j = i; @@ -728,7 +699,6 @@ public class StatelessClientTest { } }); - } latch.await(25, TimeUnit.SECONDS); @@ -748,7 +718,6 @@ public class StatelessClientTest { } - @Test(timeout = 10000) public void testCreateWithByteArrayKeyValue() throws IOException, InterruptedException { @@ -816,8 +785,14 @@ public class StatelessClientTest { } } + enum ToString implements Function { + INSTANCE; + + @Override + public String apply(Object obj) { + return obj.toString(); + } + } + } - - - diff --git a/src/test/java/net/openhft/chronicle/map/TCPSocketReplication4WayMapTest.java b/src/test/java/net/openhft/chronicle/map/TCPSocketReplication4WayMapTest.java index 3dff67a59..ac86098e4 100644 --- a/src/test/java/net/openhft/chronicle/map/TCPSocketReplication4WayMapTest.java +++ b/src/test/java/net/openhft/chronicle/map/TCPSocketReplication4WayMapTest.java @@ -122,7 +122,6 @@ public class TCPSocketReplication4WayMapTest { @Test public void testBufferOverflowPutIfAbsent() throws IOException, InterruptedException { - for (int i = 0; i < 1024; i++) { map1.putIfAbsent(i, "EXAMPLE-1"); } diff --git a/src/test/java/net/openhft/chronicle/map/TCPSocketReplicationTest.java b/src/test/java/net/openhft/chronicle/map/TCPSocketReplicationTest.java index 335159a3a..b1942e37d 100644 --- a/src/test/java/net/openhft/chronicle/map/TCPSocketReplicationTest.java +++ b/src/test/java/net/openhft/chronicle/map/TCPSocketReplicationTest.java @@ -40,6 +40,7 @@ import static org.junit.Assert.assertTrue; public class TCPSocketReplicationTest { static int s_port = 12050; + Set threads; private ChronicleMap map1; private ChronicleMap map2; @@ -71,8 +72,6 @@ public class TCPSocketReplicationTest { System.gc(); } - Set threads; - @Before public void sampleThreads() { threads = Thread.getAllStackTraces().keySet(); @@ -118,7 +117,6 @@ public class TCPSocketReplicationTest { assertTrue(!map1.isEmpty()); } - @Test public void test2() throws IOException, InterruptedException { @@ -130,7 +128,6 @@ public class TCPSocketReplicationTest { map2.put(1, "EXAMPLE-1"); - // allow time for the recompilation to resolve waitTillEqual(5000); @@ -157,7 +154,6 @@ public class TCPSocketReplicationTest { assertTrue(map1.isEmpty()); } - @Test public void testBufferOverflow() throws IOException, InterruptedException { diff --git a/src/test/java/net/openhft/chronicle/map/TcpReplicationLargeEntryTest.java b/src/test/java/net/openhft/chronicle/map/TcpReplicationLargeEntryTest.java index 2b947c926..9b8368eca 100644 --- a/src/test/java/net/openhft/chronicle/map/TcpReplicationLargeEntryTest.java +++ b/src/test/java/net/openhft/chronicle/map/TcpReplicationLargeEntryTest.java @@ -37,14 +37,13 @@ import java.util.concurrent.TimeUnit; */ public class TcpReplicationLargeEntryTest { - private ChronicleMap map1; - private ChronicleMap map2; - static int s_port = 8010; int valueSize = (int) MemoryUnit.MEGABYTES.toBytes(1); - char[] valueX = new char[valueSize - 100]; char[] valueY = new char[valueSize - 100]; + Set threads; + private ChronicleMap map1; + private ChronicleMap map2; @Before public void setup() throws IOException { @@ -60,7 +59,6 @@ public class TcpReplicationLargeEntryTest { .heartBeatInterval(1, TimeUnit.SECONDS) .tcpBufferSize(1024 * 64); - map1 = ChronicleMapBuilder.of(Integer.class, CharSequence.class) .constantValueSizeBySample(sampleValue) .entries(2) @@ -88,7 +86,6 @@ public class TcpReplicationLargeEntryTest { s_port += 2; } - @After public void tearDown() throws InterruptedException { @@ -103,8 +100,6 @@ public class TcpReplicationLargeEntryTest { System.gc(); } - Set threads; - @Before public void sampleThreads() { threads = Thread.getAllStackTraces().keySet(); @@ -115,7 +110,6 @@ public class TcpReplicationLargeEntryTest { StatelessClientTest.checkThreadsShutdown(threads); } - @Test public void testLargeValues() throws IOException, InterruptedException { @@ -134,7 +128,6 @@ public class TcpReplicationLargeEntryTest { } - private void waitTillEqual(final int timeOutMs) throws InterruptedException { Map map1UnChanged = new HashMap(); diff --git a/src/test/java/net/openhft/chronicle/map/TcpReplicationSoakTest.java b/src/test/java/net/openhft/chronicle/map/TcpReplicationSoakTest.java index d44b2d586..2e06a5a13 100644 --- a/src/test/java/net/openhft/chronicle/map/TcpReplicationSoakTest.java +++ b/src/test/java/net/openhft/chronicle/map/TcpReplicationSoakTest.java @@ -41,11 +41,11 @@ import java.util.concurrent.TimeUnit; */ public class TcpReplicationSoakTest { - + static int s_port = 8093; + Set threads; private ChronicleMap map1; private ChronicleMap map2; private IntValue value; - static int s_port = 8093; @Before public void setup() throws IOException { @@ -60,7 +60,6 @@ public class TcpReplicationSoakTest { .heartBeatInterval(1, TimeUnit.SECONDS) .tcpBufferSize(1024 * 64); - map1 = ChronicleMapBuilder.of(Integer.class, CharSequence.class) .entries(Builder.SIZE + Builder.SIZE) .actualSegments(1) @@ -86,7 +85,6 @@ public class TcpReplicationSoakTest { s_port += 2; } - @After public void tearDown() throws InterruptedException { @@ -101,8 +99,6 @@ public class TcpReplicationSoakTest { System.gc(); } - Set threads; - @Before public void sampleThreads() { threads = Thread.getAllStackTraces().keySet(); @@ -113,7 +109,6 @@ public class TcpReplicationSoakTest { StatelessClientTest.checkThreadsShutdown(threads); } - @Test public void testSoakTestWithRandomData() throws IOException, InterruptedException { try { @@ -146,7 +141,6 @@ public class TcpReplicationSoakTest { } - private void waitTillEqual(final int timeOutMs) throws InterruptedException { Map map1UnChanged = new HashMap(); diff --git a/src/test/java/net/openhft/chronicle/map/TcpReplicationWithAcquireUsingLockedTest.java b/src/test/java/net/openhft/chronicle/map/TcpReplicationWithAcquireUsingLockedTest.java index 0f593a3c1..e99d2b1af 100644 --- a/src/test/java/net/openhft/chronicle/map/TcpReplicationWithAcquireUsingLockedTest.java +++ b/src/test/java/net/openhft/chronicle/map/TcpReplicationWithAcquireUsingLockedTest.java @@ -28,11 +28,9 @@ import java.net.InetSocketAddress; */ public class TcpReplicationWithAcquireUsingLockedTest { - @Test public void testReplicationWithAcquireUsingLocked() throws InterruptedException { - TcpTransportAndNetworkConfig config1 = TcpTransportAndNetworkConfig.of(8076); ChronicleMap map2a = null; @@ -48,7 +46,6 @@ public class TcpReplicationWithAcquireUsingLockedTest { TcpTransportAndNetworkConfig config2 = TcpTransportAndNetworkConfig.of(8077, new InetSocketAddress("127.0.0.1", 8076)); - try (ChronicleMap map2 = ChronicleMapBuilder.of(CharSequence.class, TestInstrumentVOInterface.class) @@ -60,14 +57,12 @@ public class TcpReplicationWithAcquireUsingLockedTest { //Store some data into MAP1 TestInstrumentVOInterface instrumentVOInterface = map1.newValueInstance(); - try (WriteContext wc = map1.acquireUsingLocked("KEY1", instrumentVOInterface)) { instrumentVOInterface.setSymbol("Flyer"); instrumentVOInterface.setCurrencyCode("USA"); } - int t = 0; for (; t < 5000; t++) { if (map1.equals(map2)) @@ -75,19 +70,15 @@ public class TcpReplicationWithAcquireUsingLockedTest { Thread.sleep(1); } - Assert.assertEquals(map1a, map2a); } } - } - @Test public void testReplicationWithEmptyOffHeapObject() throws InterruptedException { - TcpTransportAndNetworkConfig config1 = TcpTransportAndNetworkConfig.of(8076); ChronicleMap map2a = null; @@ -105,7 +96,6 @@ public class TcpReplicationWithAcquireUsingLockedTest { TcpTransportAndNetworkConfig config2 = TcpTransportAndNetworkConfig .of(8077, new InetSocketAddress("127.0.0.1", 8076)); - try (ChronicleMap map2 = ChronicleMapBuilder.of(CharSequence.class, TestInstrumentVOInterface.class) @@ -121,7 +111,6 @@ public class TcpReplicationWithAcquireUsingLockedTest { map2a.put("hello", instrumentVOInterface); - int t = 0; for (; t < 5000; t++) { if (map1.equals(map2)) @@ -133,14 +122,11 @@ public class TcpReplicationWithAcquireUsingLockedTest { } } - } - @Test public void testReplicationWithOffHeapObject() throws InterruptedException { - TcpTransportAndNetworkConfig config1 = TcpTransportAndNetworkConfig.of(8076); ChronicleMap map2a = null; @@ -158,7 +144,6 @@ public class TcpReplicationWithAcquireUsingLockedTest { TcpTransportAndNetworkConfig config2 = TcpTransportAndNetworkConfig.of(8077, new InetSocketAddress("127.0.0.1", 8076)); - try (ChronicleMap map2 = ChronicleMapBuilder.of(CharSequence.class, TestInstrumentVOInterface.class) @@ -175,7 +160,6 @@ public class TcpReplicationWithAcquireUsingLockedTest { map2a.put("hello", instrumentVOInterface); - int t = 0; for (; t < 5000; t++) { if (map1.equals(map2)) @@ -187,7 +171,6 @@ public class TcpReplicationWithAcquireUsingLockedTest { } } - } } diff --git a/src/test/java/net/openhft/chronicle/map/TcpTimeBasedReplicationSoakTest.java b/src/test/java/net/openhft/chronicle/map/TcpTimeBasedReplicationSoakTest.java index 2b65e9a90..461c21751 100644 --- a/src/test/java/net/openhft/chronicle/map/TcpTimeBasedReplicationSoakTest.java +++ b/src/test/java/net/openhft/chronicle/map/TcpTimeBasedReplicationSoakTest.java @@ -40,13 +40,13 @@ import java.util.concurrent.TimeUnit; */ public class TcpTimeBasedReplicationSoakTest { - + static int s_port = 8010; + int t = 0; + Set threads; private ChronicleMap map1; private ChronicleMap map2; private IntValue value; - static int s_port = 8010; private TimeProvider timeProvider; - int t = 0; @Before public void setup() throws IOException { @@ -72,7 +72,6 @@ public class TcpTimeBasedReplicationSoakTest { final TcpTransportAndNetworkConfig tcpConfig1 = TcpTransportAndNetworkConfig.of(s_port, endpoint); - map1 = ChronicleMapBuilder.of(Integer.class, CharSequence.class) .entries(Builder.SIZE) .timeProvider(timeProvider) @@ -92,7 +91,6 @@ public class TcpTimeBasedReplicationSoakTest { s_port += 2; } - @After public void tearDown() throws InterruptedException { @@ -107,8 +105,6 @@ public class TcpTimeBasedReplicationSoakTest { System.gc(); } - Set threads; - @Before public void sampleThreads() { threads = Thread.getAllStackTraces().keySet(); @@ -119,7 +115,6 @@ public class TcpTimeBasedReplicationSoakTest { StatelessClientTest.checkThreadsShutdown(threads); } - @Test public void testSoakTestWithRandomData() throws IOException, InterruptedException { @@ -149,7 +144,6 @@ public class TcpTimeBasedReplicationSoakTest { } - private void waitTillUnchanged(final int timeOutMs) throws InterruptedException { Map map1UnChanged = new HashMap(); @@ -171,7 +165,6 @@ public class TcpTimeBasedReplicationSoakTest { break; } - } } diff --git a/src/test/java/net/openhft/chronicle/map/TestReplication.java b/src/test/java/net/openhft/chronicle/map/TestReplication.java index edaf95f6f..d725e781b 100644 --- a/src/test/java/net/openhft/chronicle/map/TestReplication.java +++ b/src/test/java/net/openhft/chronicle/map/TestReplication.java @@ -29,11 +29,9 @@ import java.net.InetSocketAddress; */ public class TestReplication { - @Test public void testAllDataGetsReplicated() throws InterruptedException { - TcpTransportAndNetworkConfig tcpConfigServer1 = TcpTransportAndNetworkConfig.of(8092); @@ -46,13 +44,11 @@ public class TestReplication { .replication((byte) 2, tcpConfigServer2) .create(); - final ChronicleMap map1 = ChronicleMapBuilder.of(Integer.class, Integer.class) .replication((byte) 3, tcpConfigServer1) .create(); - for (int i = 0; i < 70000; i++) { map1.put(i, i); } @@ -62,7 +58,6 @@ public class TestReplication { System.out.println(map2.size()); } - Assert.assertEquals(map1.size(),map2.size()); } @@ -82,7 +77,6 @@ public class TestReplication { { final File tempFile = File.createTempFile("test", "chron"); - server1 = ChronicleMapBuilder.of(String.class, String.class) .replication( (byte) 1).createPersistedTo @@ -112,7 +106,6 @@ public class TestReplication { String actual; - // we have a while loop here as we have to wait a few seconds for the data to replicate do { actual = server2.get("key"); @@ -124,6 +117,5 @@ public class TestReplication { } - } diff --git a/src/test/java/net/openhft/chronicle/map/TimeBasedReplicationTest.java b/src/test/java/net/openhft/chronicle/map/TimeBasedReplicationTest.java index ba1d063b7..6b7dac5da 100644 --- a/src/test/java/net/openhft/chronicle/map/TimeBasedReplicationTest.java +++ b/src/test/java/net/openhft/chronicle/map/TimeBasedReplicationTest.java @@ -36,7 +36,6 @@ public class TimeBasedReplicationTest extends JSR166TestCase { public static final byte IDENTIFIER = 1; - Set threads; @Before diff --git a/src/test/java/net/openhft/chronicle/map/fromdocs/BondVOInterface$$Native.java b/src/test/java/net/openhft/chronicle/map/fromdocs/BondVOInterface$$Native.java index 5f05ad8bf..813180345 100644 --- a/src/test/java/net/openhft/chronicle/map/fromdocs/BondVOInterface$$Native.java +++ b/src/test/java/net/openhft/chronicle/map/fromdocs/BondVOInterface$$Native.java @@ -16,7 +16,6 @@ package net.openhft.chronicle.map.fromdocs; - import net.openhft.lang.io.Bytes; import net.openhft.lang.io.serialization.BytesMarshallable; import net.openhft.lang.model.Byteable; @@ -33,52 +32,47 @@ public class BondVOInterface$$Native private static final int MATURITYDATE = 16; private static final int ENTRY = 24; private static final int MARKETPXINTRADAYHISTORY = 28; + private static final int SYMBOL = 308; private final BondVOInterface$MarketPx$$Native _marketPxIntraDayHistory[] = new BondVOInterface$MarketPx$$Native[7]; + private Bytes _bytes; + private long _offset; + { for (int i = 0; i < 7; i++) _marketPxIntraDayHistory[i] = new BondVOInterface$MarketPx$$Native(); } - private static final int SYMBOL = 308; - - - private Bytes _bytes; - private long _offset; - - - - public void setCoupon(double $) { - _bytes.writeDouble(_offset + COUPON, $); - } public double getCoupon() { return _bytes.readDouble(_offset + COUPON); } + public void setCoupon(double $) { + _bytes.writeDouble(_offset + COUPON, $); + } + public double addAtomicCoupon(double $) { return _bytes.addAtomicDouble(_offset + COUPON, $); } public boolean compareAndSwapCoupon(double _1, double _2) { return _bytes.compareAndSwapDouble(_offset + COUPON, _1, _2); } - public void setIssueDate(long $) { - _bytes.writeLong(_offset + ISSUEDATE, $); - } - public long getIssueDate() { return _bytes.readLong(_offset + ISSUEDATE); } - - - public void setMaturityDate(long $) { - _bytes.writeLong(_offset + MATURITYDATE, $); + public void setIssueDate(long $) { + _bytes.writeLong(_offset + ISSUEDATE, $); } public long getMaturityDate() { return _bytes.readLong(_offset + MATURITYDATE); } + public void setMaturityDate(long $) { + _bytes.writeLong(_offset + MATURITYDATE, $); + } + public long addAtomicMaturityDate(long $) { return _bytes.addAtomicLong(_offset + MATURITYDATE, $); } public void unlockEntry() { @@ -93,16 +87,14 @@ public class BondVOInterface$$Native return _marketPxIntraDayHistory[i]; } - + public java.lang.String getSymbol() { + return _bytes.readUTFΔ(_offset + SYMBOL); + } public void setSymbol(java.lang.String $) { _bytes.writeUTFΔ(_offset + SYMBOL, 20, $); } - public java.lang.String getSymbol() { - return _bytes.readUTFΔ(_offset + SYMBOL); - } - @Override public void copyFrom(BondVOInterface from) { setCoupon(from.getCoupon()); diff --git a/src/test/java/net/openhft/chronicle/map/fromdocs/BondVOInterface$MarketPx$$Native.java b/src/test/java/net/openhft/chronicle/map/fromdocs/BondVOInterface$MarketPx$$Native.java index 219db44df..d3be77046 100644 --- a/src/test/java/net/openhft/chronicle/map/fromdocs/BondVOInterface$MarketPx$$Native.java +++ b/src/test/java/net/openhft/chronicle/map/fromdocs/BondVOInterface$MarketPx$$Native.java @@ -33,60 +33,49 @@ public class BondVOInterface$MarketPx$$Native private static final int MATURITYPX = 24; private static final int PARPX = 32; - private Bytes _bytes; private long _offset; - - - public void setAskPx(double $) { - _bytes.writeDouble(_offset + ASKPX, $); - } - public double getAskPx() { return _bytes.readDouble(_offset + ASKPX); } - - - public void setBidPx(double $) { - _bytes.writeDouble(_offset + BIDPX, $); + public void setAskPx(double $) { + _bytes.writeDouble(_offset + ASKPX, $); } public double getBidPx() { return _bytes.readDouble(_offset + BIDPX); } - - - public void setCallPx(double $) { - _bytes.writeDouble(_offset + CALLPX, $); + public void setBidPx(double $) { + _bytes.writeDouble(_offset + BIDPX, $); } public double getCallPx() { return _bytes.readDouble(_offset + CALLPX); } - - - public void setMaturityPx(double $) { - _bytes.writeDouble(_offset + MATURITYPX, $); + public void setCallPx(double $) { + _bytes.writeDouble(_offset + CALLPX, $); } public double getMaturityPx() { return _bytes.readDouble(_offset + MATURITYPX); } - - - public void setParPx(double $) { - _bytes.writeDouble(_offset + PARPX, $); + public void setMaturityPx(double $) { + _bytes.writeDouble(_offset + MATURITYPX, $); } public double getParPx() { return _bytes.readDouble(_offset + PARPX); } + public void setParPx(double $) { + _bytes.writeDouble(_offset + PARPX, $); + } + @Override public void copyFrom(BondVOInterface.MarketPx from) { setAskPx(from.getAskPx()); diff --git a/src/test/java/net/openhft/chronicle/map/jsr166/map/ChronicleMapTest.java b/src/test/java/net/openhft/chronicle/map/jsr166/map/ChronicleMapTest.java index eef59fc03..e94c79fc3 100644 --- a/src/test/java/net/openhft/chronicle/map/jsr166/map/ChronicleMapTest.java +++ b/src/test/java/net/openhft/chronicle/map/jsr166/map/ChronicleMapTest.java @@ -36,7 +36,6 @@ import static org.junit.Assert.*; public class ChronicleMapTest extends JSR166TestCase { - static ChronicleMap newShmIntString(int size) throws IOException { return ChronicleMapBuilder.of(Integer.class, CharSequence.class) .averageValueSize(1) diff --git a/src/test/java/net/openhft/chronicle/map/jsr166/map/MapCheck.java b/src/test/java/net/openhft/chronicle/map/jsr166/map/MapCheck.java index 68dba0515..b13416747 100644 --- a/src/test/java/net/openhft/chronicle/map/jsr166/map/MapCheck.java +++ b/src/test/java/net/openhft/chronicle/map/jsr166/map/MapCheck.java @@ -109,7 +109,6 @@ public class MapCheck { serTest(size); } - static Map newMap() { try { return ChronicleMapBuilder.of(Object.class, Object.class).create(); diff --git a/src/test/java/net/openhft/chronicle/set/Issue24ChronicleSetTest.java b/src/test/java/net/openhft/chronicle/set/Issue24ChronicleSetTest.java index 0d02eefb6..559e761ba 100644 --- a/src/test/java/net/openhft/chronicle/set/Issue24ChronicleSetTest.java +++ b/src/test/java/net/openhft/chronicle/set/Issue24ChronicleSetTest.java @@ -66,7 +66,6 @@ public class Issue24ChronicleSetTest { } System.out.println("Finished all threads"); - } public static class WorkerThread implements Runnable { @@ -92,13 +91,11 @@ public class Issue24ChronicleSetTest { set.addAll(nomenclatures); - Set strings = new HashSet<>( selectRandomSubset(nomenclatures, nomenclatures.size() / 2)); set.addAll(strings); - Set toRemove = new HashSet<>(); Random generator = new Random(); for (int j = 0; j < 3; j++) {