From f8a1872d326235a8cc73a6785f120a46b41001bb Mon Sep 17 00:00:00 2001 From: Rob Austin Date: Tue, 28 Oct 2014 13:13:35 +0000 Subject: [PATCH] HCOLL-167 fixed key set by added a compact method --- .../chronicle/map/StatelessChronicleMap.java | 27 ++++++++++--------- .../openhft/chronicle/map/TcpReplicator.java | 10 +++---- .../chronicle/map/StatelessClientTest.java | 5 ---- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java b/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java index 95db26acd..bede82aa7 100644 --- a/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java @@ -605,20 +605,15 @@ class StatelessChronicleMap implements ChronicleMap, Closeable { final Set> result = new HashSet>(); - int count = 0; - long total = 0; for (; ; ) { boolean hasMoreEntries = in.readBoolean(); - - count++; - // number of entries in the chunk long size = in.readInt(); for (int i = 0; i < size; i++) { - total++; + K k = keyValueSerializer.readKey(in); V v = keyValueSerializer.readValue(in); result.add(new Entry(k, v)); @@ -627,20 +622,24 @@ class StatelessChronicleMap implements ChronicleMap, Closeable { if (!hasMoreEntries) break; - if (in.remaining() == 0) { - bytes.clear(); - bytes.buffer().clear(); - } else { - buffer.compact(); - } + compact(in); in = blockingFetchReadOnly(timeoutTime, transactionId); } - LOG.info("total=" + total); + return result; } + private void compact(Bytes in) { + if (in.remaining() == 0) { + bytes.clear(); + bytes.buffer().clear(); + } else { + buffer.compact(); + } + } + @NotNull public synchronized Set keySet() { @@ -671,6 +670,8 @@ class StatelessChronicleMap implements ChronicleMap, Closeable { if (!hasMoreEntries) break; + compact(in); + in = blockingFetchReadOnly(timeoutTime, transactionId); } diff --git a/src/main/java/net/openhft/chronicle/map/TcpReplicator.java b/src/main/java/net/openhft/chronicle/map/TcpReplicator.java index 3dccdf906..20de266f3 100644 --- a/src/main/java/net/openhft/chronicle/map/TcpReplicator.java +++ b/src/main/java/net/openhft/chronicle/map/TcpReplicator.java @@ -1647,7 +1647,7 @@ class StatelessServerConnector { // we've filled up the buffer, so lets give another channel a chance to send // some data, we don't know the max key size, we will use the entrySize instead if (writer.remaining() <= maxEntrySizeBytes) { - writeHeader(writer, sizeLocation, count, true, 0); + writeHeader(writer, sizeLocation, count, true); return false; } @@ -1656,7 +1656,7 @@ class StatelessServerConnector { writeKey(key, writer); } - writeHeader(writer, sizeLocation, count, false, 0); + writeHeader(writer, sizeLocation, count, false); return true; } }; @@ -1695,7 +1695,7 @@ class StatelessServerConnector { // some data, we don't know the max key size, we will use the entrySize instead if (writer.remaining() <= maxEntrySizeBytes) { - writeHeader(writer, sizeLocation, count, true, i.incrementAndGet()); + writeHeader(writer, sizeLocation, count, true); return false; } @@ -1706,7 +1706,7 @@ class StatelessServerConnector { } - writeHeader(writer, sizeLocation, count, false, i.incrementAndGet()); + writeHeader(writer, sizeLocation, count, false); return true; } @@ -1737,7 +1737,7 @@ class StatelessServerConnector { } private void writeHeader(Bytes writer, long sizeLocation, int count, - final boolean hasAnotherChunk, int seq) { + final boolean hasAnotherChunk) { final long end = writer.position(); final int size = (int) (end - sizeLocation); writer.position(sizeLocation); diff --git a/src/test/java/net/openhft/chronicle/map/StatelessClientTest.java b/src/test/java/net/openhft/chronicle/map/StatelessClientTest.java index 8e99f6f29..effba2381 100644 --- a/src/test/java/net/openhft/chronicle/map/StatelessClientTest.java +++ b/src/test/java/net/openhft/chronicle/map/StatelessClientTest.java @@ -256,16 +256,11 @@ public class StatelessClientTest { Map payload = new HashMap(); - - // todo still fails for large values for (int i = 0; i < 1000; i++) { payload.put(i, "some value=" + i); } - statelessMap1.putAll(payload); - - Assert.assertTrue(statelessMap1.equals(payload));