From e2020e3ff225428fb30e94ed334694cf2f57422f Mon Sep 17 00:00:00 2001 From: Rob Austin Date: Mon, 27 Apr 2015 10:26:51 +0100 Subject: [PATCH] testing off heap interfaces with String[] Conflicts: src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java --- .../converters/DataValueConverter.java | 17 ++++-- .../chronicle/map/CHMUseCasesTest.java | 53 +++++++++++++++++++ 2 files changed, 67 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/openhft/xstream/converters/DataValueConverter.java b/src/main/java/net/openhft/xstream/converters/DataValueConverter.java index 07b08ae2d..47b05bc79 100644 --- a/src/main/java/net/openhft/xstream/converters/DataValueConverter.java +++ b/src/main/java/net/openhft/xstream/converters/DataValueConverter.java @@ -103,7 +103,18 @@ public class DataValueConverter implements Converter { final String fieldName = "_" + fileModel.name(); - Field field = o.getClass().getDeclaredField(fieldName); + Field field; + + try { + field = o.getClass().getDeclaredField(fieldName); + } catch (NoSuchFieldException e1) { + + throw new ConversionException("JSON conversion of Classes containing " + + "arrays is not " + + "currently supported" + + ", the following field could not be found=" + fileModel.name(), e1); + } + field.setAccessible(true); final Object[] o1 = (Object[]) field.get(o); @@ -122,8 +133,8 @@ public class DataValueConverter implements Converter { } writer.endNode(); - } catch (NoSuchFieldException | IllegalAccessException e1) { - throw new ConversionException("", e1); + } catch (IllegalAccessException e) { + throw new ConversionException("", e); } continue; diff --git a/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java b/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java index 737e623ba..66dfb9749 100644 --- a/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java +++ b/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java @@ -354,6 +354,56 @@ public class CHMUseCasesTest { } + + interface I1 { + String getStrAt( @MaxSize(10) int i); + void setStrAt(@MaxSize(10) int i, @MaxSize(10) String str); + } + + @Test + public void testArrayOfString() throws ExecutionException, InterruptedException, + IOException { + + ChronicleMapBuilder builder = ChronicleMapBuilder + .of(CharSequence.class, I1.class) + .entries(10); + + try (ChronicleMap map = newInstance(builder)) { + + { + final I1 i1 = map.newValueInstance(); + i1.setStrAt(1, "Hello"); + i1.setStrAt(2, "World"); + map.put("Key1", i1); + } + + { + final I1 i1 = map.newValueInstance(); + i1.setStrAt(1, "Hello2"); + i1.setStrAt(2, "World2"); + map.put("Key2", i1); + } + + { + final I1 key = map.get("Key1"); + + assertEquals("Hello", key.getStrAt(1)); + assertEquals("World", key.getStrAt(2)); + } + + { + final I1 key = map.get("Key2"); + + assertEquals("Hello2", key.getStrAt(1)); + assertEquals("World2", key.getStrAt(2)); + } + + // todo not currently supported for arrays + // mapChecks(); + } + } + + @Test public void testCharArrayValue() throws ExecutionException, InterruptedException, IOException { @@ -469,6 +519,9 @@ public class CHMUseCasesTest { } + + + @Test public void testKeyValueSizeBySample() throws ExecutionException, InterruptedException, IOException {