From 8cca97f573a32dd84777963052da19036ecdaaf8 Mon Sep 17 00:00:00 2001 From: leventov Date: Thu, 13 Nov 2014 13:28:13 +0300 Subject: [PATCH 1/5] HCOLL-204 fail with sensible message, if value of interface which is supposed to have byteable impl is attempted to be used with ChronicleMapBuilder (but not OffHeapUpdatableChronicleMapBuilder) --- .../openhft/chronicle/map/AbstractChronicleMapBuilder.java | 2 +- .../java/net/openhft/chronicle/map/DemoChronicleMapTest.java | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/map/AbstractChronicleMapBuilder.java b/src/main/java/net/openhft/chronicle/map/AbstractChronicleMapBuilder.java index 92d42a2b6..432b64bfc 100644 --- a/src/main/java/net/openhft/chronicle/map/AbstractChronicleMapBuilder.java +++ b/src/main/java/net/openhft/chronicle/map/AbstractChronicleMapBuilder.java @@ -136,7 +136,7 @@ public abstract class AbstractChronicleMapBuilder> eventListener = MapEventListeners.nop(); private V defaultValue = null; - private DefaultValueProvider defaultValueProvider = NullValueProvider.INSTANCE; + private DefaultValueProvider defaultValueProvider = null; private PrepareValueBytes prepareValueBytes = null; private SingleChronicleHashReplication singleHashReplication = null; diff --git a/src/test/java/net/openhft/chronicle/map/DemoChronicleMapTest.java b/src/test/java/net/openhft/chronicle/map/DemoChronicleMapTest.java index 886420120..c85c8f86f 100755 --- a/src/test/java/net/openhft/chronicle/map/DemoChronicleMapTest.java +++ b/src/test/java/net/openhft/chronicle/map/DemoChronicleMapTest.java @@ -17,7 +17,6 @@ public class DemoChronicleMapTest { File file = File.createTempFile("DummyOrders", ".test"); file.deleteOnExit(); int maxEntries = 1000; -// ChronicleMap map = ChronicleMapBuilder ChronicleMap map = OffHeapUpdatableChronicleMapBuilder .of(IntValue.class, DemoOrderVOInterface.class) .putReturnsNull(true) @@ -37,7 +36,6 @@ public class DemoChronicleMapTest { map.acquireUsing(key, value); - // TODO Shouldn't throw an NPE, because acquire should set the value. value.setSymbol("IBM-" + i); value.addAtomicOrderQty(1000); @@ -61,7 +59,6 @@ public class DemoChronicleMapTest { File file = File.createTempFile("DummyOrders", ".test"); file.deleteOnExit(); int maxEntries = 1000; -// ChronicleMap map = ChronicleMapBuilder ChronicleMap map = OffHeapUpdatableChronicleMapBuilder .of(IntValue.class, DemoOrderVOInterface.class) .putReturnsNull(true) @@ -80,7 +77,6 @@ public class DemoChronicleMapTest { key.setValue(i); try (WriteContext wc = map.acquireUsingLocked(key, value)) { - // TODO Shouldn't throw an NPE, because acquire should set the value. value.setSymbol("IBM-" + i); value.addAtomicOrderQty(1000); } From 87155a7ea1779e53922b3282d59327cc9eb7e793 Mon Sep 17 00:00:00 2001 From: Rob Austin Date: Thu, 13 Nov 2014 10:42:18 +0000 Subject: [PATCH 2/5] improved the three way repliaction tests --- .../map/TCPSocketReplication3VoidValueTest.java | 9 +++++---- .../map/TCPSocketReplication3wayPutReturnsNullTest.java | 3 ++- .../chronicle/map/TCPSocketReplication3wayTest.java | 3 ++- .../set/SetForTCPSocketReplication3wayTest.java | 3 ++- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/test/java/net/openhft/chronicle/map/TCPSocketReplication3VoidValueTest.java b/src/test/java/net/openhft/chronicle/map/TCPSocketReplication3VoidValueTest.java index 9a4dcee0a..11d741f60 100755 --- a/src/test/java/net/openhft/chronicle/map/TCPSocketReplication3VoidValueTest.java +++ b/src/test/java/net/openhft/chronicle/map/TCPSocketReplication3VoidValueTest.java @@ -82,12 +82,12 @@ public class TCPSocketReplication3VoidValueTest { assertEquals(null, map1.put(2, null)); assertEquals(null, map2.put(5, null)); - assertEquals(null, map2.put(6,null)); + assertEquals(null, map2.put(6, null)); map1.remove(2); map2.remove(3); map1.remove(3); - map2.put(5,null); + map2.put(5, null); // allow time for the recompilation to resolve assertTrue(waitTillEqual(5000)); @@ -102,7 +102,7 @@ public class TCPSocketReplication3VoidValueTest { public void testClear() throws IOException, InterruptedException { assertEquals(null, map1.put(1, null)); - assertEquals(null, map1.put(2,null)); + assertEquals(null, map1.put(2, null)); assertEquals(null, map2.put(5, null)); assertEquals(null, map2.put(6, null)); @@ -123,7 +123,8 @@ public class TCPSocketReplication3VoidValueTest { int t = 0; for (; t < timeOutMs; t++) { if (map1.equals(map2) && - map1.equals(map3)) + map1.equals(map3) && + map2.equals(map3)) return true; Thread.sleep(1); } diff --git a/src/test/java/net/openhft/chronicle/map/TCPSocketReplication3wayPutReturnsNullTest.java b/src/test/java/net/openhft/chronicle/map/TCPSocketReplication3wayPutReturnsNullTest.java index 02b00f377..3af0a9cc2 100755 --- a/src/test/java/net/openhft/chronicle/map/TCPSocketReplication3wayPutReturnsNullTest.java +++ b/src/test/java/net/openhft/chronicle/map/TCPSocketReplication3wayPutReturnsNullTest.java @@ -145,7 +145,8 @@ public class TCPSocketReplication3wayPutReturnsNullTest { int t = 0; for (; t < timeOutMs; t++) { if (map1.equals(map2) && - map1.equals(map3)) + map1.equals(map3) + && map2.equals(map3)) break; Thread.sleep(1); } diff --git a/src/test/java/net/openhft/chronicle/map/TCPSocketReplication3wayTest.java b/src/test/java/net/openhft/chronicle/map/TCPSocketReplication3wayTest.java index 7c359968b..bd5f058b1 100755 --- a/src/test/java/net/openhft/chronicle/map/TCPSocketReplication3wayTest.java +++ b/src/test/java/net/openhft/chronicle/map/TCPSocketReplication3wayTest.java @@ -154,7 +154,8 @@ public class TCPSocketReplication3wayTest { int t = 0; for (; t < timeOutMs; t++) { if (map1.equals(map2) && - map1.equals(map3)) + map1.equals(map3) + && map2.equals(map3)) break; Thread.sleep(1); } diff --git a/src/test/java/net/openhft/chronicle/set/SetForTCPSocketReplication3wayTest.java b/src/test/java/net/openhft/chronicle/set/SetForTCPSocketReplication3wayTest.java index 98b75f4dd..98f889388 100644 --- a/src/test/java/net/openhft/chronicle/set/SetForTCPSocketReplication3wayTest.java +++ b/src/test/java/net/openhft/chronicle/set/SetForTCPSocketReplication3wayTest.java @@ -148,7 +148,8 @@ public class SetForTCPSocketReplication3wayTest { int t = 0; for (; t < timeOutMs; t++) { if (set1.equals(set2) && - set1.equals(set3)) + set1.equals(set3) && + set2.equals(set3)) break; Thread.sleep(1); } From 74424fae0935996bff13141a042693aedbe33e1f Mon Sep 17 00:00:00 2001 From: Rob Austin Date: Thu, 13 Nov 2014 10:43:10 +0000 Subject: [PATCH 3/5] removed unwanted sleep --- .../net/openhft/chronicle/map/StatelessChronicleMap.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java b/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java index 465aa0b88..5b9be429b 100644 --- a/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java @@ -237,12 +237,7 @@ class StatelessChronicleMap implements ChronicleMap, Closeable { if (closeables != null) closeables.closeQuietly(); closeables = null; - try { - // give time to close - Thread.sleep(100); - } catch (InterruptedException e) { - // - } + } /** @@ -399,7 +394,7 @@ class StatelessChronicleMap implements ChronicleMap, Closeable { } - public synchronized V acquireUsing(@NotNull K key, V usingValue) { + public synchronized V acquireUsing(@NotNull K key, V usingValue) { throw new UnsupportedOperationException("acquireUsing() is not supported for stateless " + "clients"); } From 52130fa9180a6bbce1082dfed15a24cf08d3e9bc Mon Sep 17 00:00:00 2001 From: Rob Austin Date: Thu, 13 Nov 2014 11:04:40 +0000 Subject: [PATCH 4/5] improved javadoc --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6c5b08040..9264d1fbf 100644 --- a/README.md +++ b/README.md @@ -310,14 +310,14 @@ the ChronicleMapBuilder can also be used to return the ChronicleMap, see the exa ChronicleMap map = ChronicleMapBuilder.of(Integer.class, CharSequence.class).create(); ``` -One way to achieve good performance is to focus on unnecessary object creation as this reduces +One way to achieve good performance is to focus on unnecessary object creation, as this reduces the amount of work that has to be carried out by the Garbage Collector. As such ChronicleMap supports the following methods : - [`V getUsing(K key, V value);`](http://openhft.github.io/Chronicle-Map/apidocs/net/openhft/chronicle/map/ChronicleMap.html#getUsing-K-V-) - [`V acquireUsing(K key, V value);`](http://openhft.github.io/Chronicle-Map/apidocs/net/openhft/chronicle/map/ChronicleMap.html#acquireUsing-K-V-) - - ReadContext getUsingLocked(@NotNull K key, @NotNull V usingValue); - - WriteContext acquireUsingLocked(@NotNull K key, @NotNull V usingValue); + - [`ReadContext getUsingLocked(@NotNull K key, @NotNull V usingValue);`] (https://github.com/OpenHFT/Chronicle-Map#off-heap-storage-and-how-using-a-proxy-object-can-improve-performance) + - [`WriteContext acquireUsingLocked(@NotNull K key, @NotNull V usingValue);`] (https://github.com/OpenHFT/Chronicle-Map#acquireusinglocked) These methods let you provide the object which the data will be written to, even if the object is From 745ba99c9c44d519ade17016d60f22801f8fa8d4 Mon Sep 17 00:00:00 2001 From: Rob Austin Date: Thu, 13 Nov 2014 11:08:48 +0000 Subject: [PATCH 5/5] removed white space --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 9264d1fbf..7385846ad 100644 --- a/README.md +++ b/README.md @@ -364,7 +364,6 @@ that entry has to be deserialised onto the java heap so that you can use its val ``` java for(int i=1;i<=10;i++) { Value v = get(key) - } ``` this would create 10 separate instances of the value. As each time get() is called the map has to