From 6e7ee466d16c0a6398c1601e739d308389869b40 Mon Sep 17 00:00:00 2001 From: Eduardo Ramirez Date: Fri, 25 Oct 2024 16:49:27 -0700 Subject: [PATCH] chore: add a test that reads the flat record node using all possible types (#706) --- .../FlatRecordTraversalNodeTest.java | 423 +++++++++++++++++- ...RecordTraversalObjectNodeEqualityTest.java | 16 +- .../test/dto/kitchensink/KitchenSink.java | 91 ++++ .../hollow/test/dto/{ => movie}/Award.java | 2 +- .../test/dto/{ => movie}/CastMember.java | 2 +- .../hollow/test/dto/{ => movie}/CastRole.java | 2 +- .../hollow/test/dto/{ => movie}/Country.java | 2 +- .../test/dto/{ => movie}/MaturityRating.java | 2 +- .../hollow/test/dto/{ => movie}/Movie.java | 2 +- .../hollow/test/dto/{ => movie}/Tag.java | 2 +- .../hollow/test/dto/{ => movie}/TagValue.java | 2 +- 11 files changed, 518 insertions(+), 28 deletions(-) create mode 100644 hollow/src/test/java/com/netflix/hollow/test/dto/kitchensink/KitchenSink.java rename hollow/src/test/java/com/netflix/hollow/test/dto/{ => movie}/Award.java (85%) rename hollow/src/test/java/com/netflix/hollow/test/dto/{ => movie}/CastMember.java (87%) rename hollow/src/test/java/com/netflix/hollow/test/dto/{ => movie}/CastRole.java (61%) rename hollow/src/test/java/com/netflix/hollow/test/dto/{ => movie}/Country.java (81%) rename hollow/src/test/java/com/netflix/hollow/test/dto/{ => movie}/MaturityRating.java (93%) rename hollow/src/test/java/com/netflix/hollow/test/dto/{ => movie}/Movie.java (94%) rename hollow/src/test/java/com/netflix/hollow/test/dto/{ => movie}/Tag.java (80%) rename hollow/src/test/java/com/netflix/hollow/test/dto/{ => movie}/TagValue.java (81%) diff --git a/hollow/src/test/java/com/netflix/hollow/core/write/objectmapper/flatrecords/traversal/FlatRecordTraversalNodeTest.java b/hollow/src/test/java/com/netflix/hollow/core/write/objectmapper/flatrecords/traversal/FlatRecordTraversalNodeTest.java index 618cc1882..02d2745f3 100644 --- a/hollow/src/test/java/com/netflix/hollow/core/write/objectmapper/flatrecords/traversal/FlatRecordTraversalNodeTest.java +++ b/hollow/src/test/java/com/netflix/hollow/core/write/objectmapper/flatrecords/traversal/FlatRecordTraversalNodeTest.java @@ -6,14 +6,15 @@ import com.netflix.hollow.core.write.objectmapper.flatrecords.FakeHollowSchemaIdentifierMapper; import com.netflix.hollow.core.write.objectmapper.flatrecords.FlatRecord; import com.netflix.hollow.core.write.objectmapper.flatrecords.FlatRecordWriter; -import com.netflix.hollow.test.dto.Award; -import com.netflix.hollow.test.dto.CastMember; -import com.netflix.hollow.test.dto.CastRole; -import com.netflix.hollow.test.dto.Country; -import com.netflix.hollow.test.dto.MaturityRating; -import com.netflix.hollow.test.dto.Movie; -import com.netflix.hollow.test.dto.Tag; -import com.netflix.hollow.test.dto.TagValue; +import com.netflix.hollow.test.dto.kitchensink.KitchenSink; +import com.netflix.hollow.test.dto.movie.Award; +import com.netflix.hollow.test.dto.movie.CastMember; +import com.netflix.hollow.test.dto.movie.CastRole; +import com.netflix.hollow.test.dto.movie.Country; +import com.netflix.hollow.test.dto.movie.MaturityRating; +import com.netflix.hollow.test.dto.movie.Movie; +import com.netflix.hollow.test.dto.movie.Tag; +import com.netflix.hollow.test.dto.movie.TagValue; import org.junit.Test; import java.util.ArrayList; @@ -27,7 +28,7 @@ public class FlatRecordTraversalNodeTest { @Test public void testWalkFlatRecordThroughTheNodes() { - FlatRecord flatRecord = createTestFlatRecord(); + FlatRecord flatRecord = createMovieFlatRecord(); FlatRecordTraversalObjectNode node = new FlatRecordTraversalObjectNode(flatRecord); // primitives @@ -101,7 +102,7 @@ public void testWalkFlatRecordThroughTheNodes() { @Test public void testWalkFlatRecordUsingSchemaHints() { - FlatRecord flatRecord = createTestFlatRecord(); + FlatRecord flatRecord = createMovieFlatRecord(); FlatRecordTraversalObjectNode node = new FlatRecordTraversalObjectNode(flatRecord); // primitives @@ -174,7 +175,7 @@ public void testWalkFlatRecordUsingSchemaHints() { @Test public void testWalkFlatRecordThroughTheNodesWithNulls() { - FlatRecord flatRecord = createTestFlatRecord(); + FlatRecord flatRecord = createMovieFlatRecord(); FlatRecordTraversalObjectNode node = new FlatRecordTraversalObjectNode(flatRecord); // nulls @@ -182,7 +183,280 @@ public void testWalkFlatRecordThroughTheNodesWithNulls() { assertThat(node.getFieldNode("nonExistentField")).isNull(); } - private FlatRecord createTestFlatRecord() { + @Test + public void testWalkKitchenSinkFlatRecordThroughTheNodes() { + FlatRecord flatRecord = createKitchenSinkFlatRecord(); + FlatRecordTraversalObjectNode node = new FlatRecordTraversalObjectNode(flatRecord); + + // primitives + assertThat(node.getFieldValue("intVal")).isEqualTo(1); + assertThat(node.getFieldValue("longVal")).isEqualTo(2L); + assertThat(node.getFieldValue("floatVal")).isEqualTo(3.0f); + assertThat(node.getFieldValue("doubleVal")).isEqualTo(4.0); + assertThat(node.getFieldValue("booleanVal")).isEqualTo(true); + assertThat(node.getFieldValue("byteVal")).isEqualTo(5); + assertThat(node.getFieldValue("shortVal")).isEqualTo(6); + assertThat(node.getFieldValue("charVal")).isEqualTo(55); // '7' as int + assertThat(((FlatRecordTraversalObjectNode) node.getFieldNode("boxedIntVal")).getFieldValue("value")).isEqualTo(8); + assertThat(((FlatRecordTraversalObjectNode) node.getFieldNode("boxedLongVal")).getFieldValue("value")).isEqualTo(9L); + assertThat(((FlatRecordTraversalObjectNode) node.getFieldNode("boxedFloatVal")).getFieldValue("value")).isEqualTo(10.0f); + assertThat(((FlatRecordTraversalObjectNode) node.getFieldNode("boxedDoubleVal")).getFieldValue("value")).isEqualTo(11.0); + assertThat(((FlatRecordTraversalObjectNode) node.getFieldNode("boxedBooleanVal")).getFieldValue("value")).isEqualTo(true); + assertThat(((FlatRecordTraversalObjectNode) node.getFieldNode("boxedByteVal")).getFieldValue("value")).isEqualTo(12); + assertThat(((FlatRecordTraversalObjectNode) node.getFieldNode("boxedShortVal")).getFieldValue("value")).isEqualTo(13); + assertThat(((FlatRecordTraversalObjectNode) node.getFieldNode("boxedCharVal")).getFieldValue("value")).isEqualTo(49); // '1' as int + assertThat(((FlatRecordTraversalObjectNode) node.getFieldNode("stringVal")).getFieldValue("value")).isEqualTo("15"); + assertThat(node.getFieldValue("inlineIntVal")).isEqualTo(16); + assertThat(node.getFieldValue("inlineLongVal")).isEqualTo(17L); + assertThat(node.getFieldValue("inlineFloatVal")).isEqualTo(18.0f); + assertThat(node.getFieldValue("inlineDoubleVal")).isEqualTo(19.0); + assertThat(node.getFieldValue("inlineBooleanVal")).isEqualTo(true); + assertThat(node.getFieldValue("inlineByteVal")).isEqualTo(20); + assertThat(node.getFieldValue("inlineShortVal")).isEqualTo(21); + assertThat(node.getFieldValue("inlineCharVal")).isEqualTo(50); // '2' as int + assertThat(node.getFieldValue("inlineStringVal")).isEqualTo("23"); + assertThat(node.getFieldValue("bytesVal")).isEqualTo(new byte[]{24, 25, 26}); + assertThat(((FlatRecordTraversalObjectNode) node.getFieldNode("customTypeVal")).getFieldValue("value")).isEqualTo("27"); + + // subType + FlatRecordTraversalObjectNode subTypeNode = (FlatRecordTraversalObjectNode) node.getFieldNode("subType"); + assertThat(subTypeNode.getFieldValue("intVal")).isEqualTo(28); + assertThat(subTypeNode.getFieldValue("longVal")).isEqualTo(29L); + assertThat(subTypeNode.getFieldValue("floatVal")).isEqualTo(30.0f); + + // subTypeList + FlatRecordTraversalListNode subTypeListNode = (FlatRecordTraversalListNode) node.getFieldNode("subTypeList"); + assertThat(subTypeListNode.getObject(0).getFieldValue("intVal")).isEqualTo(31); + assertThat(subTypeListNode.getObject(0).getFieldValue("longVal")).isEqualTo(32L); + assertThat(subTypeListNode.getObject(0).getFieldValue("floatVal")).isEqualTo(33.0f); + assertThat(subTypeListNode.getObject(1).getFieldValue("intVal")).isEqualTo(34); + assertThat(subTypeListNode.getObject(1).getFieldValue("longVal")).isEqualTo(35L); + assertThat(subTypeListNode.getObject(1).getFieldValue("floatVal")).isEqualTo(36.0f); + + // subTypeSet + FlatRecordTraversalSetNode subTypeSetNode = (FlatRecordTraversalSetNode) node.getFieldNode("subTypeSet"); + assertThat(subTypeSetNode) + .extracting( + n -> ((FlatRecordTraversalObjectNode) n).getFieldValueInt("intVal"), + n -> ((FlatRecordTraversalObjectNode) n).getFieldValueLong("longVal"), + n -> ((FlatRecordTraversalObjectNode) n).getFieldValueFloat("floatVal")) + .containsExactlyInAnyOrder( + tuple(37, 38L, 39.0f), + tuple(40, 41L, 42.0f)); + + // subTypeMap + FlatRecordTraversalMapNode subTypeMapNode = (FlatRecordTraversalMapNode) node.getFieldNode("subTypeMap"); + assertThat(subTypeMapNode).hasSize(2); + assertThat(subTypeMapNode.entrySet()) + .extracting( + entry -> ((FlatRecordTraversalObjectNode) entry.getKey()).getFieldValueInt("value"), + entry -> ((FlatRecordTraversalObjectNode) entry.getValue()).getFieldValueInt("intVal"), + entry -> ((FlatRecordTraversalObjectNode) entry.getValue()).getFieldValueLong("longVal"), + entry -> ((FlatRecordTraversalObjectNode) entry.getValue()).getFieldValueFloat("floatVal")) + .containsExactlyInAnyOrder( + tuple(43, 44, 45L, 46.0f), + tuple(47, 48, 49L, 50.0f)); + + // complexMapKeyMap + FlatRecordTraversalMapNode complexMapKeyMapNode = (FlatRecordTraversalMapNode) node.getFieldNode("complexMapKeyMap"); + assertThat(complexMapKeyMapNode).hasSize(2); + assertThat(complexMapKeyMapNode.entrySet()) + .extracting( + entry -> { + FlatRecordTraversalObjectNode keyNode = (FlatRecordTraversalObjectNode) entry.getKey(); + return keyNode.getFieldValueInt("value1"); + }, + entry -> { + FlatRecordTraversalObjectNode valueNode = (FlatRecordTraversalObjectNode) entry.getValue(); + return valueNode.getFieldValueInt("intVal"); + }, + entry -> { + FlatRecordTraversalObjectNode valueNode = (FlatRecordTraversalObjectNode) entry.getValue(); + return valueNode.getFieldValueLong("longVal"); + }, + entry -> { + FlatRecordTraversalObjectNode valueNode = (FlatRecordTraversalObjectNode) entry.getValue(); + return valueNode.getFieldValueFloat("floatVal"); + }) + .containsExactlyInAnyOrder( + tuple(51, 53, 54L, 55.0f), + tuple(56, 58, 59L, 60.0f)); + + // hashableSet + FlatRecordTraversalSetNode hashableSetNode = (FlatRecordTraversalSetNode) node.getFieldNode("hashableSet"); + assertThat(hashableSetNode) + .extracting( + n -> ((FlatRecordTraversalObjectNode) n).getFieldValueInt("value1"), + n -> ((FlatRecordTraversalObjectNode) n).getFieldValueInt("value2")) + .containsExactlyInAnyOrder( + tuple(61, 62), + tuple(63, 64)); + + // hashableMap + FlatRecordTraversalMapNode hashableMapNode = (FlatRecordTraversalMapNode) node.getFieldNode("hashableMap"); + assertThat(hashableMapNode).hasSize(2); + assertThat(hashableMapNode.entrySet()) + .extracting( + entry -> { + FlatRecordTraversalObjectNode keyNode = (FlatRecordTraversalObjectNode) entry.getKey(); + return keyNode.getFieldValueInt("value1"); + }, + entry -> { + FlatRecordTraversalObjectNode valueNode = (FlatRecordTraversalObjectNode) entry.getValue(); + return valueNode.getFieldValueInt("intVal"); + }, + entry -> { + FlatRecordTraversalObjectNode valueNode = (FlatRecordTraversalObjectNode) entry.getValue(); + return valueNode.getFieldValueLong("longVal"); + }, + entry -> { + FlatRecordTraversalObjectNode valueNode = (FlatRecordTraversalObjectNode) entry.getValue(); + return valueNode.getFieldValueFloat("floatVal"); + }) + .containsExactlyInAnyOrder( + tuple(65, 67, 68L, 69.0f), + tuple(70, 72, 73L, 74.0f)); + } + + @Test + public void testWalkKitchenSinkFlatRecordUsingSchemaHints() { + FlatRecord flatRecord = createKitchenSinkFlatRecord(); + FlatRecordTraversalObjectNode node = new FlatRecordTraversalObjectNode(flatRecord); + + // primitives + assertThat(node.getFieldValueInt("intVal")).isEqualTo(1); + assertThat(node.getFieldValueLong("longVal")).isEqualTo(2L); + assertThat(node.getFieldValueFloat("floatVal")).isEqualTo(3.0f); + assertThat(node.getFieldValueDouble("doubleVal")).isEqualTo(4.0); + assertThat(node.getFieldValueBoolean("booleanVal")).isTrue(); + assertThat(node.getFieldValueInt("byteVal")).isEqualTo((byte) 5); + assertThat(node.getFieldValueInt("shortVal")).isEqualTo((short) 6); + assertThat(node.getFieldValueInt("charVal")).isEqualTo('7'); + assertThat(node.getObjectFieldNode("boxedIntVal").getFieldValueInt("value")).isEqualTo(8); + assertThat(node.getObjectFieldNode("boxedLongVal").getFieldValueLong("value")).isEqualTo(9L); + assertThat(node.getObjectFieldNode("boxedFloatVal").getFieldValueFloat("value")).isEqualTo(10.0f); + assertThat(node.getObjectFieldNode("boxedDoubleVal").getFieldValueDouble("value")).isEqualTo(11.0); + assertThat(node.getObjectFieldNode("boxedBooleanVal").getFieldValueBoolean("value")).isTrue(); + assertThat(node.getObjectFieldNode("boxedByteVal").getFieldValueInt("value")).isEqualTo((byte) 12); + assertThat(node.getObjectFieldNode("boxedShortVal").getFieldValueInt("value")).isEqualTo((short) 13); + assertThat(node.getObjectFieldNode("boxedCharVal").getFieldValueInt("value")).isEqualTo('1'); + assertThat(node.getObjectFieldNode("stringVal").getFieldValueString("value")).isEqualTo("15"); + assertThat(node.getFieldValueInt("inlineIntVal")).isEqualTo(16); + assertThat(node.getFieldValueLong("inlineLongVal")).isEqualTo(17L); + assertThat(node.getFieldValueFloat("inlineFloatVal")).isEqualTo(18.0f); + assertThat(node.getFieldValueDouble("inlineDoubleVal")).isEqualTo(19.0); + assertThat(node.getFieldValueBoolean("inlineBooleanVal")).isTrue(); + assertThat(node.getFieldValueInt("inlineByteVal")).isEqualTo((byte) 20); + assertThat(node.getFieldValueInt("inlineShortVal")).isEqualTo((short) 21); + assertThat(node.getFieldValueInt("inlineCharVal")).isEqualTo('2'); + assertThat(node.getFieldValueString("inlineStringVal")).isEqualTo("23"); + assertThat(node.getFieldValueBytes("bytesVal")).containsExactly((byte) 24, (byte) 25, (byte) 26); + assertThat(node.getObjectFieldNode("customTypeVal").getFieldValueString("value")).isEqualTo("27"); + + // subType + FlatRecordTraversalObjectNode subTypeNode = node.getObjectFieldNode("subType"); + assertThat(subTypeNode.getFieldValueInt("intVal")).isEqualTo(28); + assertThat(subTypeNode.getFieldValueLong("longVal")).isEqualTo(29L); + assertThat(subTypeNode.getFieldValueFloat("floatVal")).isEqualTo(30.0f); + + // subTypeList + FlatRecordTraversalListNode subTypeListNode = node.getListFieldNode("subTypeList"); + assertThat(subTypeListNode) + .extracting( + n -> ((FlatRecordTraversalObjectNode) n).getFieldValueInt("intVal"), + n -> ((FlatRecordTraversalObjectNode) n).getFieldValueLong("longVal"), + n -> ((FlatRecordTraversalObjectNode) n).getFieldValueFloat("floatVal")) + .containsExactlyInAnyOrder( + tuple(31, 32L, 33.0f), + tuple(34, 35L, 36.0f)); + + // subTypeSet + FlatRecordTraversalSetNode subTypeSetNode = node.getSetFieldNode("subTypeSet"); + assertThat(subTypeSetNode) + .extracting( + n -> ((FlatRecordTraversalObjectNode) n).getFieldValueInt("intVal"), + n -> ((FlatRecordTraversalObjectNode) n).getFieldValueLong("longVal"), + n -> ((FlatRecordTraversalObjectNode) n).getFieldValueFloat("floatVal")) + .containsExactlyInAnyOrder( + tuple(37, 38L, 39.0f), + tuple(40, 41L, 42.0f)); + + // subTypeMap + FlatRecordTraversalMapNode subTypeMapNode = node.getMapFieldNode("subTypeMap"); + assertThat(subTypeMapNode).hasSize(2); + assertThat(subTypeMapNode.entrySet()) + .extracting( + entry -> ((FlatRecordTraversalObjectNode) entry.getKey()).getFieldValueInt("value"), + entry -> ((FlatRecordTraversalObjectNode) entry.getValue()).getFieldValueInt("intVal"), + entry -> ((FlatRecordTraversalObjectNode) entry.getValue()).getFieldValueLong("longVal"), + entry -> ((FlatRecordTraversalObjectNode) entry.getValue()).getFieldValueFloat("floatVal")) + .containsExactlyInAnyOrder( + tuple(43, 44, 45L, 46.0f), + tuple(47, 48, 49L, 50.0f)); + + // complexMapKeyMap + FlatRecordTraversalMapNode complexMapKeyMapNode = node.getMapFieldNode("complexMapKeyMap"); + assertThat(complexMapKeyMapNode).hasSize(2); + assertThat(complexMapKeyMapNode.entrySet()) + .extracting( + entry -> { + FlatRecordTraversalObjectNode keyNode = (FlatRecordTraversalObjectNode) entry.getKey(); + return keyNode.getFieldValueInt("value1"); + }, + entry -> { + FlatRecordTraversalObjectNode valueNode = (FlatRecordTraversalObjectNode) entry.getValue(); + return valueNode.getFieldValueInt("intVal"); + }, + entry -> { + FlatRecordTraversalObjectNode valueNode = (FlatRecordTraversalObjectNode) entry.getValue(); + return valueNode.getFieldValueLong("longVal"); + }, + entry -> { + FlatRecordTraversalObjectNode valueNode = (FlatRecordTraversalObjectNode) entry.getValue(); + return valueNode.getFieldValueFloat("floatVal"); + }) + .containsExactlyInAnyOrder( + tuple(51, 53, 54L, 55.0f), + tuple(56, 58, 59L, 60.0f)); + + // hashableSet + FlatRecordTraversalSetNode hashableSetNode = node.getSetFieldNode("hashableSet"); + assertThat(hashableSetNode) + .extracting( + n -> ((FlatRecordTraversalObjectNode) n).getFieldValueInt("value1"), + n -> ((FlatRecordTraversalObjectNode) n).getFieldValueInt("value2")) + .containsExactlyInAnyOrder( + tuple(61, 62), + tuple(63, 64)); + + // hashableMap + FlatRecordTraversalMapNode hashableMapNode = node.getMapFieldNode("hashableMap"); + assertThat(hashableMapNode).hasSize(2); + assertThat(hashableMapNode.entrySet()) + .extracting( + entry -> { + FlatRecordTraversalObjectNode keyNode = (FlatRecordTraversalObjectNode) entry.getKey(); + return keyNode.getFieldValueInt("value1"); + }, + entry -> { + FlatRecordTraversalObjectNode valueNode = (FlatRecordTraversalObjectNode) entry.getValue(); + return valueNode.getFieldValueInt("intVal"); + }, + entry -> { + FlatRecordTraversalObjectNode valueNode = (FlatRecordTraversalObjectNode) entry.getValue(); + return valueNode.getFieldValueLong("longVal"); + }, + entry -> { + FlatRecordTraversalObjectNode valueNode = (FlatRecordTraversalObjectNode) entry.getValue(); + return valueNode.getFieldValueFloat("floatVal"); + }) + .containsExactlyInAnyOrder( + tuple(65, 67, 68L, 69.0f), + tuple(70, 72, 73L, 74.0f)); + } + + + private FlatRecord createMovieFlatRecord() { Movie movie1 = new Movie(); movie1.id = 1; movie1.title = "Movie1"; @@ -212,4 +486,129 @@ private FlatRecord createTestFlatRecord() { objMapper.writeFlat(movie1, flatRecordWriter); return flatRecordWriter.generateFlatRecord(); } + + private FlatRecord createKitchenSinkFlatRecord() { + KitchenSink sink = new KitchenSink(); + sink.intVal = 1; + sink.longVal = 2L; + sink.floatVal = 3.0f; + sink.doubleVal = 4.0; + sink.booleanVal = true; + sink.byteVal = 5; + sink.shortVal = 6; + sink.charVal = '7'; + sink.boxedIntVal = 8; + sink.boxedLongVal = 9L; + sink.boxedFloatVal = 10.0f; + sink.boxedDoubleVal = 11.0; + sink.boxedBooleanVal = true; + sink.boxedByteVal = 12; + sink.boxedShortVal = 13; + sink.boxedCharVal = '1'; + sink.stringVal = "15"; + sink.inlineIntVal = 16; + sink.inlineLongVal = 17L; + sink.inlineFloatVal = 18.0f; + sink.inlineDoubleVal = 19.0; + sink.inlineBooleanVal = true; + sink.inlineByteVal = 20; + sink.inlineShortVal = 21; + sink.inlineCharVal = '2'; + sink.inlineStringVal = "23"; + sink.bytesVal = new byte[]{24, 25, 26}; + sink.customTypeVal = "27"; + sink.subType = new KitchenSink.SubType(); + sink.subType.intVal = 28; + sink.subType.longVal = 29L; + sink.subType.floatVal = 30.0f; + sink.subTypeList = new ArrayList<>(); + KitchenSink.SubType subTypeListElement1 = new KitchenSink.SubType(); + subTypeListElement1.intVal = 31; + subTypeListElement1.longVal = 32L; + subTypeListElement1.floatVal = 33.0f; + KitchenSink.SubType subTypeListElement2 = new KitchenSink.SubType(); + subTypeListElement2.intVal = 34; + subTypeListElement2.longVal = 35L; + subTypeListElement2.floatVal = 36.0f; + sink.subTypeList.add(subTypeListElement1); + sink.subTypeList.add(subTypeListElement2); + sink.subTypeSet = new HashSet<>(); + KitchenSink.SubType subTypeSetElement1 = new KitchenSink.SubType(); + subTypeSetElement1.intVal = 37; + subTypeSetElement1.longVal = 38L; + subTypeSetElement1.floatVal = 39.0f; + KitchenSink.SubType subTypeSetElement2 = new KitchenSink.SubType(); + subTypeSetElement2.intVal = 40; + subTypeSetElement2.longVal = 41L; + subTypeSetElement2.floatVal = 42.0f; + sink.subTypeSet.add(subTypeSetElement1); + sink.subTypeSet.add(subTypeSetElement2); + sink.subTypeMap = new HashMap<>(); + KitchenSink.MapKey mapKey1 = new KitchenSink.MapKey(); + mapKey1.value = 43; + KitchenSink.SubType subTypeMapElement1 = new KitchenSink.SubType(); + subTypeMapElement1.intVal = 44; + subTypeMapElement1.longVal = 45L; + subTypeMapElement1.floatVal = 46.0f; + KitchenSink.MapKey mapKey2 = new KitchenSink.MapKey(); + mapKey2.value = 47; + KitchenSink.SubType subTypeMapElement2 = new KitchenSink.SubType(); + subTypeMapElement2.intVal = 48; + subTypeMapElement2.longVal = 49L; + subTypeMapElement2.floatVal = 50.0f; + sink.subTypeMap.put(mapKey1, subTypeMapElement1); + sink.subTypeMap.put(mapKey2, subTypeMapElement2); + sink.complexMapKeyMap = new HashMap<>(); + KitchenSink.ComplexMapKey complexMapKey1 = new KitchenSink.ComplexMapKey(); + complexMapKey1.value1 = 51; + complexMapKey1.value2 = 52; + KitchenSink.SubType complexMapKeyMapElement1 = new KitchenSink.SubType(); + complexMapKeyMapElement1.intVal = 53; + complexMapKeyMapElement1.longVal = 54L; + complexMapKeyMapElement1.floatVal = 55.0f; + KitchenSink.ComplexMapKey complexMapKey2 = new KitchenSink.ComplexMapKey(); + complexMapKey2.value1 = 56; + complexMapKey2.value2 = 57; + KitchenSink.SubType complexMapKeyMapElement2 = new KitchenSink.SubType(); + complexMapKeyMapElement2.intVal = 58; + complexMapKeyMapElement2.longVal = 59L; + complexMapKeyMapElement2.floatVal = 60.0f; + sink.complexMapKeyMap.put(complexMapKey1, complexMapKeyMapElement1); + sink.complexMapKeyMap.put(complexMapKey2, complexMapKeyMapElement2); + sink.hashableSet = new HashSet<>(); + KitchenSink.HashableKey hashableSetElement1 = new KitchenSink.HashableKey(); + hashableSetElement1.value1 = 61; + hashableSetElement1.value2 = 62; + KitchenSink.HashableKey hashableSetElement2 = new KitchenSink.HashableKey(); + hashableSetElement2.value1 = 63; + hashableSetElement2.value2 = 64; + sink.hashableSet.add(hashableSetElement1); + sink.hashableSet.add(hashableSetElement2); + sink.hashableMap = new HashMap<>(); + KitchenSink.HashableKey hashableMapKey1 = new KitchenSink.HashableKey(); + hashableMapKey1.value1 = 65; + hashableMapKey1.value2 = 66; + KitchenSink.SubType hashableMapElement1 = new KitchenSink.SubType(); + hashableMapElement1.intVal = 67; + hashableMapElement1.longVal = 68L; + hashableMapElement1.floatVal = 69.0f; + KitchenSink.HashableKey hashableMapKey2 = new KitchenSink.HashableKey(); + hashableMapKey2.value1 = 70; + hashableMapKey2.value2 = 71; + KitchenSink.SubType hashableMapElement2 = new KitchenSink.SubType(); + hashableMapElement2.intVal = 72; + hashableMapElement2.longVal = 73L; + hashableMapElement2.floatVal = 74.0f; + sink.hashableMap.put(hashableMapKey1, hashableMapElement1); + sink.hashableMap.put(hashableMapKey2, hashableMapElement2); + + SimpleHollowDataset dataset = SimpleHollowDataset.fromClassDefinitions(KitchenSink.class); + FakeHollowSchemaIdentifierMapper idMapper = new FakeHollowSchemaIdentifierMapper(dataset); + HollowObjectMapper objMapper = new HollowObjectMapper(HollowWriteStateCreator.createWithSchemas(dataset.getSchemas())); + FlatRecordWriter flatRecordWriter = new FlatRecordWriter(dataset, idMapper); + + flatRecordWriter.reset(); + objMapper.writeFlat(sink, flatRecordWriter); + return flatRecordWriter.generateFlatRecord(); + } } diff --git a/hollow/src/test/java/com/netflix/hollow/core/write/objectmapper/flatrecords/traversal/FlatRecordTraversalObjectNodeEqualityTest.java b/hollow/src/test/java/com/netflix/hollow/core/write/objectmapper/flatrecords/traversal/FlatRecordTraversalObjectNodeEqualityTest.java index b88f59a6c..399e2eb4e 100644 --- a/hollow/src/test/java/com/netflix/hollow/core/write/objectmapper/flatrecords/traversal/FlatRecordTraversalObjectNodeEqualityTest.java +++ b/hollow/src/test/java/com/netflix/hollow/core/write/objectmapper/flatrecords/traversal/FlatRecordTraversalObjectNodeEqualityTest.java @@ -13,14 +13,14 @@ import com.netflix.hollow.core.write.objectmapper.flatrecords.FlatRecord; import com.netflix.hollow.core.write.objectmapper.flatrecords.FlatRecordWriter; import com.netflix.hollow.core.write.objectmapper.flatrecords.HollowSchemaIdentifierMapper; -import com.netflix.hollow.test.dto.Award; -import com.netflix.hollow.test.dto.CastMember; -import com.netflix.hollow.test.dto.CastRole; -import com.netflix.hollow.test.dto.Country; -import com.netflix.hollow.test.dto.MaturityRating; -import com.netflix.hollow.test.dto.Movie; -import com.netflix.hollow.test.dto.Tag; -import com.netflix.hollow.test.dto.TagValue; +import com.netflix.hollow.test.dto.movie.Award; +import com.netflix.hollow.test.dto.movie.CastMember; +import com.netflix.hollow.test.dto.movie.CastRole; +import com.netflix.hollow.test.dto.movie.Country; +import com.netflix.hollow.test.dto.movie.MaturityRating; +import com.netflix.hollow.test.dto.movie.Movie; +import com.netflix.hollow.test.dto.movie.Tag; +import com.netflix.hollow.test.dto.movie.TagValue; import org.assertj.core.api.Assertions; import org.junit.Before; import org.junit.Test; diff --git a/hollow/src/test/java/com/netflix/hollow/test/dto/kitchensink/KitchenSink.java b/hollow/src/test/java/com/netflix/hollow/test/dto/kitchensink/KitchenSink.java new file mode 100644 index 000000000..bb71031f5 --- /dev/null +++ b/hollow/src/test/java/com/netflix/hollow/test/dto/kitchensink/KitchenSink.java @@ -0,0 +1,91 @@ +package com.netflix.hollow.test.dto.kitchensink; + + +import com.netflix.hollow.core.write.objectmapper.HollowHashKey; +import com.netflix.hollow.core.write.objectmapper.HollowInline; +import com.netflix.hollow.core.write.objectmapper.HollowPrimaryKey; +import com.netflix.hollow.core.write.objectmapper.HollowTypeName; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +@HollowPrimaryKey(fields = {"intVal"}) +public class KitchenSink { + public int intVal; + public long longVal; + public float floatVal; + public double doubleVal; + public boolean booleanVal; + public byte byteVal; + public short shortVal; + public char charVal; + + public Integer boxedIntVal; + public Long boxedLongVal; + public Float boxedFloatVal; + public Double boxedDoubleVal; + public Boolean boxedBooleanVal; + public Byte boxedByteVal; + public Short boxedShortVal; + public Character boxedCharVal; + public String stringVal; + + @HollowInline + public Integer inlineIntVal; + @HollowInline + public Long inlineLongVal; + @HollowInline + public Float inlineFloatVal; + @HollowInline + public Double inlineDoubleVal; + @HollowInline + public Boolean inlineBooleanVal; + @HollowInline + public Byte inlineByteVal; + @HollowInline + public Short inlineShortVal; + @HollowInline + public Character inlineCharVal; + @HollowInline + public String inlineStringVal; + + public byte[] bytesVal; + + @HollowTypeName(name = "CustomType") + public String customTypeVal; + + public SubType subType; + + public List subTypeList; + public Set subTypeSet; + + public Map subTypeMap; + public Map complexMapKeyMap; + + + @HollowHashKey(fields = {"value1"}) + public Set hashableSet; + @HollowHashKey(fields = {"value1"}) + public Map hashableMap; + + public static class SubType { + public int intVal; + public long longVal; + public float floatVal; + } + + public static class MapKey { + public int value; + } + + public static class ComplexMapKey { + public int value1; + public int value2; + } + + public static class HashableKey { + public int value1; + public int value2; + } +} diff --git a/hollow/src/test/java/com/netflix/hollow/test/dto/Award.java b/hollow/src/test/java/com/netflix/hollow/test/dto/movie/Award.java similarity index 85% rename from hollow/src/test/java/com/netflix/hollow/test/dto/Award.java rename to hollow/src/test/java/com/netflix/hollow/test/dto/movie/Award.java index 7056a1e85..8db76b432 100644 --- a/hollow/src/test/java/com/netflix/hollow/test/dto/Award.java +++ b/hollow/src/test/java/com/netflix/hollow/test/dto/movie/Award.java @@ -1,4 +1,4 @@ -package com.netflix.hollow.test.dto; +package com.netflix.hollow.test.dto.movie; import com.netflix.hollow.core.write.objectmapper.HollowTypeName; diff --git a/hollow/src/test/java/com/netflix/hollow/test/dto/CastMember.java b/hollow/src/test/java/com/netflix/hollow/test/dto/movie/CastMember.java similarity index 87% rename from hollow/src/test/java/com/netflix/hollow/test/dto/CastMember.java rename to hollow/src/test/java/com/netflix/hollow/test/dto/movie/CastMember.java index 876292e96..9fd288af9 100644 --- a/hollow/src/test/java/com/netflix/hollow/test/dto/CastMember.java +++ b/hollow/src/test/java/com/netflix/hollow/test/dto/movie/CastMember.java @@ -1,4 +1,4 @@ -package com.netflix.hollow.test.dto; +package com.netflix.hollow.test.dto.movie; import com.netflix.hollow.core.write.objectmapper.HollowInline; diff --git a/hollow/src/test/java/com/netflix/hollow/test/dto/CastRole.java b/hollow/src/test/java/com/netflix/hollow/test/dto/movie/CastRole.java similarity index 61% rename from hollow/src/test/java/com/netflix/hollow/test/dto/CastRole.java rename to hollow/src/test/java/com/netflix/hollow/test/dto/movie/CastRole.java index 884070fa5..b07448356 100644 --- a/hollow/src/test/java/com/netflix/hollow/test/dto/CastRole.java +++ b/hollow/src/test/java/com/netflix/hollow/test/dto/movie/CastRole.java @@ -1,4 +1,4 @@ -package com.netflix.hollow.test.dto; +package com.netflix.hollow.test.dto.movie; public enum CastRole { DIRECTOR, diff --git a/hollow/src/test/java/com/netflix/hollow/test/dto/Country.java b/hollow/src/test/java/com/netflix/hollow/test/dto/movie/Country.java similarity index 81% rename from hollow/src/test/java/com/netflix/hollow/test/dto/Country.java rename to hollow/src/test/java/com/netflix/hollow/test/dto/movie/Country.java index 78a6542c7..966bbaafe 100644 --- a/hollow/src/test/java/com/netflix/hollow/test/dto/Country.java +++ b/hollow/src/test/java/com/netflix/hollow/test/dto/movie/Country.java @@ -1,4 +1,4 @@ -package com.netflix.hollow.test.dto; +package com.netflix.hollow.test.dto.movie; import com.netflix.hollow.core.write.objectmapper.HollowInline; diff --git a/hollow/src/test/java/com/netflix/hollow/test/dto/MaturityRating.java b/hollow/src/test/java/com/netflix/hollow/test/dto/movie/MaturityRating.java similarity index 93% rename from hollow/src/test/java/com/netflix/hollow/test/dto/MaturityRating.java rename to hollow/src/test/java/com/netflix/hollow/test/dto/movie/MaturityRating.java index f2e6760d0..90b43be5f 100644 --- a/hollow/src/test/java/com/netflix/hollow/test/dto/MaturityRating.java +++ b/hollow/src/test/java/com/netflix/hollow/test/dto/movie/MaturityRating.java @@ -1,4 +1,4 @@ -package com.netflix.hollow.test.dto; +package com.netflix.hollow.test.dto.movie; import com.netflix.hollow.core.write.objectmapper.HollowTypeName; diff --git a/hollow/src/test/java/com/netflix/hollow/test/dto/Movie.java b/hollow/src/test/java/com/netflix/hollow/test/dto/movie/Movie.java similarity index 94% rename from hollow/src/test/java/com/netflix/hollow/test/dto/Movie.java rename to hollow/src/test/java/com/netflix/hollow/test/dto/movie/Movie.java index ec0d60965..f014ae136 100644 --- a/hollow/src/test/java/com/netflix/hollow/test/dto/Movie.java +++ b/hollow/src/test/java/com/netflix/hollow/test/dto/movie/Movie.java @@ -1,4 +1,4 @@ -package com.netflix.hollow.test.dto; +package com.netflix.hollow.test.dto.movie; import com.netflix.hollow.core.write.objectmapper.HollowHashKey; diff --git a/hollow/src/test/java/com/netflix/hollow/test/dto/Tag.java b/hollow/src/test/java/com/netflix/hollow/test/dto/movie/Tag.java similarity index 80% rename from hollow/src/test/java/com/netflix/hollow/test/dto/Tag.java rename to hollow/src/test/java/com/netflix/hollow/test/dto/movie/Tag.java index d9cfa4661..574d4c94d 100644 --- a/hollow/src/test/java/com/netflix/hollow/test/dto/Tag.java +++ b/hollow/src/test/java/com/netflix/hollow/test/dto/movie/Tag.java @@ -1,4 +1,4 @@ -package com.netflix.hollow.test.dto; +package com.netflix.hollow.test.dto.movie; import com.netflix.hollow.core.write.objectmapper.HollowInline; diff --git a/hollow/src/test/java/com/netflix/hollow/test/dto/TagValue.java b/hollow/src/test/java/com/netflix/hollow/test/dto/movie/TagValue.java similarity index 81% rename from hollow/src/test/java/com/netflix/hollow/test/dto/TagValue.java rename to hollow/src/test/java/com/netflix/hollow/test/dto/movie/TagValue.java index a741edf55..af4d64eff 100644 --- a/hollow/src/test/java/com/netflix/hollow/test/dto/TagValue.java +++ b/hollow/src/test/java/com/netflix/hollow/test/dto/movie/TagValue.java @@ -1,4 +1,4 @@ -package com.netflix.hollow.test.dto; +package com.netflix.hollow.test.dto.movie; import com.netflix.hollow.core.write.objectmapper.HollowInline;