From 06fcaa4c718d0bdacee3945c86d5d4363842cdd9 Mon Sep 17 00:00:00 2001 From: Rob Austin Date: Thu, 25 Dec 2014 19:40:35 +0000 Subject: [PATCH] added byte[][] value test case --- .../chronicle/map/CHMUseCasesTest.java | 56 ++++++++++++++++++- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java b/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java index abe9e45ed..1ff200aeb 100644 --- a/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java +++ b/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java @@ -114,7 +114,24 @@ public class CHMUseCasesTest { if (typeOfMap == TypeOfMap.REPLICATED) { // see HCOLL-265 Chronicle Maps with Identical char[] values are not equal1 - if (map1.keyClass() == char[].class || map1.valueClass() == char[].class) { + if (map1.valueClass() == char[].class || + map1.valueClass() == byte[].class || + map1.valueClass() == byte[][].class) { + + waitTillEqual(5000); + + assertArrayValueEquals(map1, map2); + if (typeOfMap == TypeOfMap.SIMPLE) + checkJsonSerilization(); + + return; + } + + + // see HCOLL-265 Chronicle Maps with Identical char[] values are not equal1 + if (map1.keyClass() == char[].class || + map1.keyClass() == byte[][].class) { + return; } @@ -145,8 +162,17 @@ public class CHMUseCasesTest { else if (map1.valueClass() == char[].class) Assert.assertArrayEquals((char[]) map1.get(key), (char[]) map2.get(key)); + else if (map1.valueClass() == byte[][].class) { + byte[][] o1 = (byte[][]) map1.get(key); + byte[][] o2 = (byte[][]) map2.get(key); - else throw new IllegalStateException("unsupported type"); + + Assert.assertEquals(o1.length, o2.length); + for (int i = 0; i < o1.length; i++) { + Assert.assertArrayEquals(o1[i], o2[i]); + } + + } else throw new IllegalStateException("unsupported type"); } } @@ -166,7 +192,9 @@ public class CHMUseCasesTest { actual.putAll(file); - if (map1.keyClass() == char[].class || map1.valueClass() == char[].class) { + if (map1.valueClass() == char[].class || + map1.valueClass() == byte[].class || + map1.valueClass() == byte[][].class) { assertArrayValueEquals(map1, actual); } else { Assert.assertEquals(map1, actual); @@ -321,6 +349,28 @@ public class CHMUseCasesTest { } + @Test + public void testByteArrayArrayValue() throws ExecutionException, InterruptedException, IOException { + + int valueSize = 10; + + char[] expected = new char[valueSize]; + Arrays.fill(expected, 'X'); + + ChronicleMapBuilder builder = ChronicleMapBuilder + .of(byte[].class, byte[][].class); + + try (ChronicleMap map = newInstance(builder)) { + byte[] bytes1 = "value1".getBytes(); + byte[] bytes2 = "value2".getBytes(); + byte[][] value = {bytes1,bytes2}; + map.put("Key".getBytes(), value); + + assertEquals(value, map.get("Key".getBytes())); + mapChecks(); + } + } + @Test public void bondExample() throws IOException, InterruptedException {