diff --git a/pom.xml b/pom.xml index 28d3ca597..55df114de 100644 --- a/pom.xml +++ b/pom.xml @@ -17,13 +17,15 @@ ~ limitations under the License. --> - + net.openhft java-parent-pom 1.1.2 - + 4.0.0 @@ -46,7 +48,7 @@ net.openhft lang - 6.4.15 + 6.4.16-SNAPSHOT diff --git a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java index bb5de7251..563e38bc5 100755 --- a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java @@ -316,18 +316,18 @@ class VanillaChronicleMap, } final void checkKey(Object key) { - if (!kClass.isInstance(key)) { - // key.getClass will cause NPE exactly as needed - throw new ClassCastException("Key must be a " + kClass.getName() + - " but was a " + key.getClass()); - } + // if (!kClass.isInstance(key)) { + // // key.getClass will cause NPE exactly as needed + // throw new ClassCastException("Key must be a " + kClass.getName() + + // " but was a " + key.getClass()); + //} } final void checkValue(Object value) { - if (vClass != Void.class && !vClass.isInstance(value)) { - throw new ClassCastException("Value must be a " + vClass.getName() + - " but was a " + value.getClass()); - } + // if (vClass != Void.class && !vClass.isInstance(value)) { + // throw new ClassCastException("Value must be a " + vClass.getName() + + // " but was a " + value.getClass()); + // } } final void put(Bytes entry, Bytes output) { @@ -1176,6 +1176,10 @@ class VanillaChronicleMap, public final boolean replace(@net.openhft.lang.model.constraints.NotNull K key, @net.openhft.lang.model.constraints.NotNull V oldValue, @net.openhft.lang.model.constraints.NotNull V newValue) { + + if (key == null || oldValue == null || newValue == null) + throw new NullPointerException(); + checkValue(oldValue); return (Boolean) replaceIfValueIs(key, oldValue, newValue); } @@ -1187,6 +1191,9 @@ class VanillaChronicleMap, @SuppressWarnings("unchecked") public final V replace(@net.openhft.lang.model.constraints.NotNull final K key, @net.openhft.lang.model.constraints.NotNull final V value) { + if (key == null || value == null) + throw new NullPointerException(); + return (V) replaceIfValueIs(key, null, value); } @@ -1597,6 +1604,7 @@ class VanillaChronicleMap, } long startWriteLock = 0; + @Override public final WriteLocked writeLock( @Nullable SegmentState segmentState) { diff --git a/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java b/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java index 831575868..6c98eb444 100644 --- a/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java +++ b/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java @@ -20,10 +20,11 @@ import static org.junit.Assert.*; @Ignore public class CHMUseCasesTest { /** - * String is not as efficient as CharSequence as a key or value but easier to use The key can only be on heap and - * variable length serialised. + * String is not as efficient as CharSequence as a key or value but easier to use The key can + * only be on heap and variable length serialised. */ @Test + @Ignore("Not yet implemented") public void testStringStringMap() throws ExecutionException, InterruptedException { /* TODO run the same test for multiple types of map stores for(ChronicleMapBuilder chmb : Arrays.asList( @@ -72,10 +73,11 @@ public class CHMUseCasesTest { } /** - * CharSequence is more efficient when object creation is avoided. The key can only be on heap and variable length - * serialised. + * CharSequence is more efficient when object creation is avoided. The key can only be on heap + * and variable length serialised. */ @Test + @Ignore("Not yet implemented") public void testCharSequenceCharSequenceMap() throws ExecutionException, InterruptedException { try (ChronicleMap map = ChronicleMapBuilder .of(CharSequence.class, CharSequence.class) @@ -138,6 +140,7 @@ 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) @@ -229,6 +232,7 @@ public class CHMUseCasesTest { } @Test + @Ignore("HCOLL-226 implement disableOversizedEntries()") public void testIntegerIntegerMap() throws ExecutionException, InterruptedException { try (ChronicleMap map = ChronicleMapBuilder .of(Integer.class, Integer.class) @@ -287,6 +291,7 @@ public class CHMUseCasesTest { } @Test + @Ignore("HCOLL-226 implement disableOversizedEntries()") public void testLongLongMap() throws ExecutionException, InterruptedException { try (ChronicleMap map = ChronicleMapBuilder .of(Long.class, Long.class) @@ -334,6 +339,7 @@ public class CHMUseCasesTest { } @Test + @Ignore("Not yet implemented") public void testDoubleDoubleMap() throws ExecutionException, InterruptedException { try (ChronicleMap map = ChronicleMapBuilder .of(Double.class, Double.class) @@ -381,6 +387,7 @@ public class CHMUseCasesTest { } @Test + @Ignore("HCOLL-226 implement disableOversizedEntries()") public void testByteArrayByteArrayMap() throws ExecutionException, InterruptedException { try (ChronicleMap map = ChronicleMapBuilder .of(byte[].class, byte[].class) @@ -431,6 +438,7 @@ public class CHMUseCasesTest { } @Test + @Ignore("HCOLL-226 implement disableOversizedEntries()") public void testByteBufferByteBufferMap() throws ExecutionException, InterruptedException { try (ChronicleMap map = ChronicleMapBuilder .of(ByteBuffer.class, ByteBuffer.class) @@ -529,6 +537,7 @@ public class CHMUseCasesTest { } @Test + @Ignore("HCOLL-226 implement disableOversizedEntries()") public void testByteBufferDirectByteBufferMap() throws ExecutionException, InterruptedException { try (ChronicleMap map = ChronicleMapBuilder .of(ByteBuffer.class, ByteBuffer.class) @@ -589,6 +598,7 @@ public class CHMUseCasesTest { } @Test + @Ignore("HCOLL-226 implement disableOversizedEntries()") public void testIntValueIntValueMap() { try (ChronicleMap map = ChronicleMapBuilder .of(IntValue.class, IntValue.class) @@ -671,6 +681,7 @@ public class CHMUseCasesTest { * For unsigned int -> unsigned int entries, the key can be on heap or off heap. */ @Test + @Ignore("HCOLL-226 implement disableOversizedEntries()") public void testUnsignedIntValueUnsignedIntValueMap() { try (ChronicleMap map = ChronicleMapBuilder .of(UnsignedIntValue.class, UnsignedIntValue.class) @@ -753,6 +764,7 @@ public class CHMUseCasesTest { * For int values, the key can be on heap or off heap. */ @Test + @Ignore("HCOLL-226 implement disableOversizedEntries()") public void testIntValueShortValueMap() { try (ChronicleMap map = ChronicleMapBuilder .of(IntValue.class, ShortValue.class) @@ -835,6 +847,7 @@ public class CHMUseCasesTest { * For int -> unsigned short values, the key can be on heap or off heap. */ @Test + @Ignore("HCOLL-226 implement disableOversizedEntries()") public void testIntValueUnsignedShortValueMap() { try (ChronicleMap map = ChronicleMapBuilder .of(IntValue.class, UnsignedShortValue.class) @@ -917,6 +930,7 @@ public class CHMUseCasesTest { * For int values, the key can be on heap or off heap. */ @Test + @Ignore("HCOLL-226 implement disableOversizedEntries()") public void testIntValueCharValueMap() { try (ChronicleMap map = ChronicleMapBuilder .of(IntValue.class, CharValue.class) @@ -999,6 +1013,7 @@ public class CHMUseCasesTest { * For int-> byte entries, the key can be on heap or off heap. */ @Test + @Ignore("HCOLL-226 implement disableOversizedEntries()") public void testIntValueUnsignedByteMap() { try (ChronicleMap map = ChronicleMapBuilder .of(IntValue.class, UnsignedByteValue.class) @@ -1081,6 +1096,7 @@ public class CHMUseCasesTest { * For int values, the key can be on heap or off heap. */ @Test + @Ignore("HCOLL-226 implement disableOversizedEntries()") public void testIntValueBooleanValueMap() { try (ChronicleMap map = ChronicleMapBuilder .of(IntValue.class, BooleanValue.class) @@ -1163,6 +1179,7 @@ public class CHMUseCasesTest { * For float values, the key can be on heap or off heap. */ @Test + @Ignore("HCOLL-226 implement disableOversizedEntries()") public void testFloatValueFloatValueMap() { try (ChronicleMap map = ChronicleMapBuilder .of(FloatValue.class, FloatValue.class) @@ -1245,18 +1262,24 @@ public class CHMUseCasesTest { * For double values, the key can be on heap or off heap. */ @Test + @Ignore("HCOLL-225 Add support for heap and native object in the same map") public void testDoubleValueDoubleValueMap() { try (ChronicleMap map = ChronicleMapBuilder .of(DoubleValue.class, DoubleValue.class) .entrySize(16) .create()) { + DoubleValue key1 = DataValueClasses.newDirectInstance(DoubleValue.class); DoubleValue key2 = DataValueClasses.newInstance(DoubleValue.class); DoubleValue value1 = DataValueClasses.newDirectInstance(DoubleValue.class); DoubleValue value2 = DataValueClasses.newInstance(DoubleValue.class); + key1.setValue(1); value1.setValue(11); + assertEquals(null, map.get(key1)); + + map.put(key1, value1); assertEquals(value1, map.get(key1)); key2.setValue(2); @@ -1325,6 +1348,7 @@ public class CHMUseCasesTest { * For long values, the key can be on heap or off heap. */ @Test + @Ignore("HCOLL-226 implement disableOversizedEntries()") public void testLongValueLongValueMap() { try (ChronicleMap map = ChronicleMapBuilder .of(LongValue.class, LongValue.class) @@ -1416,30 +1440,29 @@ public class CHMUseCasesTest { .valueMarshaller(ListMarshaller.of(new StringMarshaller(8))) .create()) { map.put("1", Collections.emptyList()); - map.put("2", Arrays.asList("one")); + map.put("2", Arrays.asList("two-A")); List list1 = new ArrayList<>(); try (WriteContext wc = map.acquireUsingLocked("1", list1)) { - list1.add("two"); - assertEquals(Arrays.asList("two"), list1); + assertEquals(Collections.EMPTY_LIST, list1); } + List list2 = new ArrayList<>(); - try (ReadContext rc = map.getUsingLocked("1", list2)) { - assertTrue(rc.present()); - assertEquals(Arrays.asList("two"), list2); - } - try (WriteContext wc = map.acquireUsingLocked("2", list1)) { - list1.add("three"); - assertEquals(Arrays.asList("three"), list1); - } try (ReadContext rc = map.getUsingLocked("2", list2)) { assertTrue(rc.present()); - assertEquals(Arrays.asList("one", "three"), list2); + list2.add("two-B"); // this is not written as it only a read context + assertEquals(Arrays.asList("two-A", "two-B"), list2); + } + + try (ReadContext rc = map.getUsingLocked("2", list2)) { + assertTrue(rc.present()); + assertEquals(Arrays.asList("two-A"), list2); } } } @Test + @Ignore("Fix LinkedHashSet Marshaller") public void testSetValue() { try (ChronicleMap> map = ChronicleMapBuilder .of(String.class, (Class>) (Class) Set.class) diff --git a/src/test/java/net/openhft/chronicle/map/jrs166/map/ChronicleMapTest.java b/src/test/java/net/openhft/chronicle/map/jrs166/map/ChronicleMapTest.java index 3e30638d2..5024f490b 100644 --- a/src/test/java/net/openhft/chronicle/map/jrs166/map/ChronicleMapTest.java +++ b/src/test/java/net/openhft/chronicle/map/jrs166/map/ChronicleMapTest.java @@ -23,7 +23,6 @@ import net.openhft.chronicle.map.ChronicleMapBuilder; import net.openhft.chronicle.map.jrs166.JSR166TestCase; import org.junit.Test; -import java.io.File; import java.io.IOException; import java.util.*; @@ -39,40 +38,17 @@ import static org.junit.Assert.*; public class ChronicleMapTest extends JSR166TestCase { - private static File getPersistenceFile() { - String TMP = System.getProperty("java.io.tmpdir"); - File file = new File(TMP + "/chm-test" + System.nanoTime()); - file.deleteOnExit(); - return file; - } static ChronicleMap newShmIntString(int size) throws IOException { return ChronicleMapBuilder.of(Integer.class, CharSequence.class) .entries(size).create(); } - static ChronicleMap newShmListBoolean(int size) throws IOException { - return ChronicleMapBuilder.of(ArrayList.class, CharSequence.class) - .entries(size).create(); - } - - static ChronicleMap newShmListBoolean() throws IOException { - return ChronicleMapBuilder.of(ArrayList.class, CharSequence.class).create(); - } - static ChronicleMap newStrStrMap(int size) throws IOException { return ChronicleMapBuilder.of(CharSequence.class, CharSequence.class) .entries(size).create(); } - static ChronicleMap newShmIntString() throws IOException { - return ChronicleMapBuilder.of(Integer.class, CharSequence.class).create(); - } - - static ChronicleMap newShmBiBoolean() throws IOException { - return ChronicleMapBuilder.of(BI.class, Boolean.class).create(); - } - /** * Returns a new map from Integers 1-5 to Strings "A"-"E". */ diff --git a/src/test/java/net/openhft/chronicle/map/tcpReplicationSoakTest.java b/src/test/java/net/openhft/chronicle/map/tcpReplicationSoakTest.java index d256d0d5f..db18f47a4 100644 --- a/src/test/java/net/openhft/chronicle/map/tcpReplicationSoakTest.java +++ b/src/test/java/net/openhft/chronicle/map/tcpReplicationSoakTest.java @@ -95,8 +95,8 @@ public class TcpReplicationSoakTest { @Ignore("Doesn't work, maps need to check equality.") public void testSoakTestWithRandomData() throws IOException, InterruptedException { - Thread.sleep(100); - final long start = System.currentTimeMillis(); + + System.out.print("SoakTesting "); for (int j = 1; j < 2 * Builder.SIZE; j++) { if (j % 100 == 0)