diff --git a/src/main/java/net/openhft/chronicle/map/ChronicleMap.java b/src/main/java/net/openhft/chronicle/map/ChronicleMap.java index 6cb467c72..50e4a4c68 100755 --- a/src/main/java/net/openhft/chronicle/map/ChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/ChronicleMap.java @@ -30,7 +30,6 @@ import java.io.File; import java.io.IOException; import java.util.Map; import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.Future; /** * Extension of {@link ConcurrentMap} interface, stores the data off-heap. @@ -202,14 +201,14 @@ public interface ChronicleMap extends ConcurrentMap, ChronicleHash { /** * Apply a mutator to the value for a key and return a result. A write lock is assumed.

If - * there is no entry for this key it will be created and the value empty. + * there is no entry for this key null will be returned * * @param return type. * @param key to apply the mapping to * @param mutator to alter the value and calculate a result * @return the result of the function. */ - R putWithMapping(K key, @NotNull Mutator mutator); + R putWith(K key, @NotNull Mutator mutator); /** * exports all the entries to a {@link java.io.File} storing them in JSON format, an attempt is diff --git a/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java b/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java index ca8e98736..c01c4e5c7 100644 --- a/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java @@ -757,14 +757,13 @@ final class ReplicatedChronicleMap implements ChronicleMap, Closeable, Clon @Nullable @Override - public R putWithMapping(@Nullable K key, @NotNull Mutator mutator) { + public R putWith(@Nullable K key, @NotNull Mutator mutator) { if (key == null) throw keyNotNullNPE(); return fetchObject(UPDATE_FOR_KEY, key, mutator); diff --git a/src/main/java/net/openhft/chronicle/map/TcpReplicator.java b/src/main/java/net/openhft/chronicle/map/TcpReplicator.java index 4f1be0981..a2616f745 100644 --- a/src/main/java/net/openhft/chronicle/map/TcpReplicator.java +++ b/src/main/java/net/openhft/chronicle/map/TcpReplicator.java @@ -1442,7 +1442,7 @@ class StatelessServerConnector { final K key = keyReaderWithSize.read(reader, null); final Mutator mutator = (Mutator) reader.readObject(); try { - Object result = map.putWithMapping(key, mutator); + Object result = map.putWith(key, mutator); writer.writeObject(result); } catch (Throwable e) { LOG.info("", e); diff --git a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java index 227682409..4a27b2ac0 100755 --- a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java @@ -559,7 +559,7 @@ class VanillaChronicleMap, } @Override - public R putWithMapping(K key, @NotNull Mutator mutator) { + public R putWith(K key, @NotNull Mutator mutator) { if (!(CharSequence.class.isAssignableFrom(vClass))) { @@ -575,8 +575,8 @@ class VanillaChronicleMap, R result = mutator.update(entry.value()); ((MutableLockedEntry) entry).value(result); + return result; } - } @@ -2707,7 +2707,7 @@ class VanillaChronicleMap, extends MutableLockedEntry implements WriteContext { - private boolean wasPresent; + private boolean wasPresent = true; WriteLocked(SegmentState segmentState) { super(segmentState); diff --git a/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java b/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java index 0b7a6205c..06e0176ec 100644 --- a/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java +++ b/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java @@ -1,7 +1,6 @@ package net.openhft.chronicle.map; import net.openhft.lang.io.serialization.impl.*; -import net.openhft.lang.model.DataValueClasses; import net.openhft.lang.values.*; import org.junit.Ignore; import org.junit.Test; @@ -74,17 +73,14 @@ public class CHMUseCasesTest { .create()) { map.put("Hello", "World"); - try { - map.putWithMapping("Hello", new Mutator() { - @Override - public String update(String s) { - return "New " + s; - } - }); - } catch (Exception ignored) { - ignored.printStackTrace(); - } + map.putWith("Hello", new Mutator() { + @Override + public String update(String s) { + return "New " + s; + } + }); + } } @@ -129,7 +125,7 @@ public class CHMUseCasesTest { } })); - assertEquals("New World !!", map.putWithMapping(new StringBuilder("Hello"), new + assertEquals("New World !!", map.putWith(new StringBuilder("Hello"), new Mutator() { @Override public CharSequence update(CharSequence s) { @@ -140,7 +136,7 @@ public class CHMUseCasesTest { assertEquals("New World !!", map.get("Hello").toString()); - assertEquals(null, map.putWithMapping(new StringBuilder("no-key"), new + assertEquals(null, map.putWith(new StringBuilder("no-key"), new Mutator() { @Override public CharSequence update(CharSequence s) { @@ -156,16 +152,15 @@ public class CHMUseCasesTest { * StringValue represents any bean which contains a String Value */ @Test - @Ignore("Not yet implemented") public void testStringValueStringValueMap() { try (ChronicleMap map = ChronicleMapBuilder .of(StringValue.class, StringValue.class) .checkSerializedValues() // for testing purposes only .create()) { - StringValue key1 = DataValueClasses.newDirectInstance(StringValue.class); - StringValue key2 = DataValueClasses.newInstance(StringValue.class); - StringValue value1 = DataValueClasses.newDirectInstance(StringValue.class); - StringValue value2 = DataValueClasses.newInstance(StringValue.class); + StringValue key1 = ChronicleMapBuilder.newInstance(StringValue.class, true); + StringValue key2 = ChronicleMapBuilder.newInstance(StringValue.class, true); + StringValue value1 = ChronicleMapBuilder.newInstance(StringValue.class, false); + StringValue value2 = ChronicleMapBuilder.newInstance(StringValue.class, false); key1.setValue(new StringBuilder("1")); value1.setValue("11"); @@ -248,7 +243,6 @@ public class CHMUseCasesTest { } @Test - @Ignore("HCOLL-226 implement disableOversizedEntries()") public void testIntegerIntegerMap() throws ExecutionException, InterruptedException { try (ChronicleMap map = ChronicleMapBuilder .of(Integer.class, Integer.class) @@ -289,7 +283,7 @@ public class CHMUseCasesTest { })); try { - map.putWithMapping(1, new Mutator() { + map.putWith(1, new Mutator() { @Override public Integer update(Integer s) { return s + 1; @@ -332,7 +326,7 @@ public class CHMUseCasesTest { })); try { - map.putWithMapping(1L, new Mutator() { + map.putWith(1L, new Mutator() { @Override public Long update(Long s) { return s + 1; @@ -346,7 +340,6 @@ public class CHMUseCasesTest { } @Test - @Ignore("Not yet implemented") public void testDoubleDoubleMap() throws ExecutionException, InterruptedException { try (ChronicleMap map = ChronicleMapBuilder .of(Double.class, Double.class) @@ -376,7 +369,7 @@ public class CHMUseCasesTest { })); try { - map.putWithMapping(1.0, new Mutator() { + map.putWith(1.0, new Mutator() { @Override public Double update(Double s) { return s + 1; @@ -391,7 +384,6 @@ public class CHMUseCasesTest { } @Test - @Ignore("HCOLL-226 implement disableOversizedEntries()") public void testByteArrayByteArrayMap() throws ExecutionException, InterruptedException { try (ChronicleMap map = ChronicleMapBuilder .of(byte[].class, byte[].class) @@ -404,9 +396,12 @@ public class CHMUseCasesTest { byte[] value2 = {22, 22, 22, 22}; assertNull(map.put(key1, value1)); assertTrue(Arrays.equals(value1, map.put(key1, value2))); - assertTrue(Arrays.equals(value1, map.get(key1))); + assertTrue(Arrays.equals(value2, map.get(key1))); assertNull(map.get(key2)); + map.put(key1, value1); + + assertTrue(Arrays.equals(new byte[]{11, 11}, map.mapForKey(key1, new Function() { @Override public byte[] apply(byte[] s) { @@ -420,7 +415,7 @@ public class CHMUseCasesTest { } })); - assertTrue(Arrays.equals(new byte[]{12, 10}, map.putWithMapping(key1, new Mutator() { + assertTrue(Arrays.equals(new byte[]{12, 10}, map.putWith(key1, new Mutator() { @Override public byte[] update(byte[] s) { s[0]++; @@ -429,16 +424,15 @@ public class CHMUseCasesTest { } }))); - assertTrue(Arrays.equals(new byte[]{12, 10, 11, 11}, map.get(key1))); + byte[] a2 = map.get(key1); + assertTrue(Arrays.equals(new byte[]{12, 10}, a2)); - byte[] key3 = {3, 3, 3, 3}; - byte[] value3 = {4, 4, 4, 4}; } } @Test - @Ignore("HCOLL-226 implement disableOversizedEntries()") + @Ignore("Not enough available space") public void testByteBufferByteBufferMap() throws ExecutionException, InterruptedException { try (ChronicleMap map = ChronicleMapBuilder .of(ByteBuffer.class, ByteBuffer.class) @@ -467,7 +461,7 @@ public class CHMUseCasesTest { assertBBEquals(ByteBuffer.wrap(new byte[]{11, 11}), map.mapForKey(key1, function)); assertEquals(null, map.mapForKey(key2, function)); - assertBBEquals(ByteBuffer.wrap(new byte[]{12, 10}), map.putWithMapping(key1, new Mutator() { + assertBBEquals(ByteBuffer.wrap(new byte[]{12, 10}), map.putWith(key1, new Mutator() { @Override public ByteBuffer update(ByteBuffer s) { s.put(0, (byte) (s.get(0) + 1)); @@ -531,7 +525,7 @@ public class CHMUseCasesTest { } @Test - @Ignore("HCOLL-226 implement disableOversizedEntries()") + @Ignore("Not enough available space") public void testByteBufferDirectByteBufferMap() throws ExecutionException, InterruptedException { try (ChronicleMap map = ChronicleMapBuilder .of(ByteBuffer.class, ByteBuffer.class) @@ -562,7 +556,7 @@ public class CHMUseCasesTest { assertBBEquals(ByteBuffer.wrap(new byte[]{11, 11}), map.mapForKey(key1, function)); assertEquals(null, map.mapForKey(key2, function)); - assertBBEquals(ByteBuffer.wrap(new byte[]{12, 10}), map.putWithMapping(key1, new Mutator() { + assertBBEquals(ByteBuffer.wrap(new byte[]{12, 10}), map.putWith(key1, new Mutator() { @Override public ByteBuffer update(ByteBuffer s) { s.put(0, (byte) (s.get(0) + 1)); diff --git a/src/test/java/net/openhft/chronicle/map/ReplicationCheckingMap.java b/src/test/java/net/openhft/chronicle/map/ReplicationCheckingMap.java index 125d851ed..4e6ca162b 100644 --- a/src/test/java/net/openhft/chronicle/map/ReplicationCheckingMap.java +++ b/src/test/java/net/openhft/chronicle/map/ReplicationCheckingMap.java @@ -223,8 +223,8 @@ public class ReplicationCheckingMap implements ChronicleMap { } @Override - public R putWithMapping(K key, @NotNull Mutator mutator) { - return map1.putWithMapping(key, mutator); + public R putWith(K key, @NotNull Mutator mutator) { + return map1.putWith(key, mutator); } @Override diff --git a/src/test/java/net/openhft/chronicle/map/jrs166/map/StatelessChronicleMapTest.java b/src/test/java/net/openhft/chronicle/map/jrs166/map/StatelessChronicleMapTest.java index 9e126666a..4da1cc290 100755 --- a/src/test/java/net/openhft/chronicle/map/jrs166/map/StatelessChronicleMapTest.java +++ b/src/test/java/net/openhft/chronicle/map/jrs166/map/StatelessChronicleMapTest.java @@ -175,8 +175,8 @@ public class StatelessChronicleMapTest extends JSR166TestCase { } @Override - public R putWithMapping(K key, @NotNull Mutator mutator) { - return d.putWithMapping(key, mutator); + public R putWith(K key, @NotNull Mutator mutator) { + return d.putWith(key, mutator); } @Override