/** * Populate the provided {@link HollowReadStateEngine} with the dataset currently in the provided {@link HollowWriteStateEngine} * * @param writeEngine the write state engine * @param readEngine the read state engine * @throws IOException if the round trip from write to read state failed */ public static void roundTripSnapshot(HollowWriteStateEngine writeEngine, HollowReadStateEngine readEngine) throws IOException { roundTripSnapshot(writeEngine, readEngine, null); }
/** * @param writeEngine the write state engine * @return a brand-new {@link HollowReadStateEngine} with the dataset populated in the provided {@link HollowWriteStateEngine} * @throws IOException if the round trip from write to read state failed */ public static HollowReadStateEngine roundTripSnapshot(HollowWriteStateEngine writeEngine) throws IOException { HollowReadStateEngine readEngine = new HollowReadStateEngine(); roundTripSnapshot(writeEngine, readEngine); return readEngine; }
protected void roundTripSnapshot() throws IOException { readStateEngine = new HollowReadStateEngine(); StateEngineRoundTripper.roundTripSnapshot(writeStateEngine, readStateEngine, readFilter); }
@Test public void testMovieActorReference_duplicatesInList() throws Exception { List<Actor> actors = Collections.singletonList(new Actor("Keanu Reeves")); int numMovies = 10; IntStream.range(0, numMovies).mapToObj(index -> new MovieActorReference(index, 1999 + index, "The Matrix " + index, actors)) .forEach(objectMapper::add); StateEngineRoundTripper.roundTripSnapshot(writeStateEngine, readStateEngine); HollowPrefixIndex prefixIndex = new HollowPrefixIndex(readStateEngine, "MovieActorReference", "actors.element"); Assert.assertEquals(numMovies, toSet(prefixIndex.findKeysWithPrefix("kea")).size()); }
@Test public void testMovieMapReference() throws Exception { Map<Integer, String> idActorMap = new HashMap<>(); idActorMap.put(1, "Keanu Reeves"); idActorMap.put(2, "Laurence Fishburne"); idActorMap.put(3, "Carrie-Anne Moss"); MovieMapReference movieMapReference = new MovieMapReference(1, 1999, "The Matrix", idActorMap); objectMapper.add(movieMapReference); StateEngineRoundTripper.roundTripSnapshot(writeStateEngine, readStateEngine); HollowPrefixIndex prefixIndex = new HollowPrefixIndex(readStateEngine, "MovieMapReference", "idActorNameMap.value"); Set<Integer> ordinals = toSet(prefixIndex.findKeysWithPrefix("kea")); Assert.assertTrue(ordinals.size() == 1); }
@Test public void testSetReference() throws Exception { MovieSetReference movieSetReference = new MovieSetReference(1, 1999, "The Matrix", new HashSet<String>(Arrays.asList("Keanu Reeves", "Laurence Fishburne", "Carrie-Anne Moss"))); objectMapper.add(movieSetReference); StateEngineRoundTripper.roundTripSnapshot(writeStateEngine, readStateEngine); HollowPrefixIndex prefixIndex = new HollowPrefixIndex(readStateEngine, "MovieSetReference", "actors.element"); Set<Integer> ordinals = toSet(prefixIndex.findKeysWithPrefix("kea")); Assert.assertTrue(ordinals.size() == 1); }
@Test(expected = IllegalArgumentException.class) public void testInvalidType() throws Exception { for (Movie movie : getSimpleList()) { objectMapper.add(movie); } StateEngineRoundTripper.roundTripSnapshot(writeStateEngine, readStateEngine); // random type which does not exists in read state engine. new HollowPrefixIndex(readStateEngine, "randomType", "id"); }
@Test(expected = IllegalArgumentException.class) public void testInvalidFieldPathReference() throws Exception { for (Movie movie : getReferenceList()) { objectMapper.add(movie); } StateEngineRoundTripper.roundTripSnapshot(writeStateEngine, readStateEngine); // test invalid field path, in this case reference type is referring toa field which is not present. // PrimaryKey class helps in catching this. new HollowPrefixIndex(readStateEngine, "MovieWithReferenceName", "name.randomField"); }
private HollowReadStateEngine createStateEngine(TypeAKeyOnly... typeAs) throws IOException { HollowWriteStateEngine writeEngine = new HollowWriteStateEngine(); HollowObjectMapper mapper = new HollowObjectMapper(writeEngine); mapper.initializeTypeState(TypeB.class); for(TypeAKeyOnly a : typeAs) { mapper.add(a); } return StateEngineRoundTripper.roundTripSnapshot(writeEngine); }
@Test public void testListReference() throws Exception { MovieListReference movieListReference = new MovieListReference(1, 1999, "The Matrix", Arrays.asList("Keanu Reeves", "Laurence Fishburne", "Carrie-Anne Moss")); objectMapper.add(movieListReference); StateEngineRoundTripper.roundTripSnapshot(writeStateEngine, readStateEngine); HollowPrefixIndex prefixIndex = new HollowPrefixIndex(readStateEngine, "MovieListReference", "actors.element.value"); Set<Integer> ordinals = toSet(prefixIndex.findKeysWithPrefix("kea")); Assert.assertTrue(ordinals.size() == 1); }
private HollowReadStateEngine createStateEngine(Type0KeyOnly... type0s) throws IOException { HollowWriteStateEngine writeEngine = new HollowWriteStateEngine(); HollowObjectMapper mapper = new HollowObjectMapper(writeEngine); mapper.initializeTypeState(TypeB.class); for(Type0KeyOnly a : type0s) { mapper.add(a); } return StateEngineRoundTripper.roundTripSnapshot(writeEngine); }
@Test(expected = IllegalArgumentException.class) public void testInvalidFieldPath() throws Exception { for (Movie movie : getSimpleList()) { objectMapper.add(movie); } StateEngineRoundTripper.roundTripSnapshot(writeStateEngine, readStateEngine); // test invalid field path, basically field path does not lead to a string value. new HollowPrefixIndex(readStateEngine, "SimpleMovie", "id"); }
private HollowReadStateEngine createStateEngine(boolean addType0, TypeA... typeAs) throws IOException { HollowWriteStateEngine writeEngine = new HollowWriteStateEngine(); HollowObjectMapper mapper = new HollowObjectMapper(writeEngine); for(TypeA a : typeAs) { mapper.add(addType0 ? new Type0(a) : a); } return StateEngineRoundTripper.roundTripSnapshot(writeEngine); }
@Test public void throwsExceptionIfWriteStateIsPopulated() throws IOException { HollowWriteStateEngine writeEngine = new HollowWriteStateEngine(); HollowObjectMapper mapper = new HollowObjectMapper(writeEngine); mapper.add(new Integer(1)); HollowReadStateEngine readEngine = StateEngineRoundTripper.roundTripSnapshot(writeEngine); try { HollowWriteStateCreator.populateUsingReadEngine(writeEngine, readEngine); Assert.fail(); } catch(IllegalStateException expected) { } }
@Test public void testAutoExpandFieldPath() throws Exception { for (Movie movie : getReferenceList()) { objectMapper.add(movie); } StateEngineRoundTripper.roundTripSnapshot(writeStateEngine, readStateEngine); HollowPrefixIndex index = new HollowPrefixIndex(readStateEngine, "MovieWithReferenceName", "name.n");// no.value appended, it should work Set<Integer> ordinals = toSet(index.findKeysWithPrefix("the")); Assert.assertTrue(ordinals.size() == 1); }
@Test public void testMovieActorReference() throws Exception { List<Actor> actors = Arrays.asList(new Actor("Keanu Reeves"), new Actor("Laurence Fishburne"), new Actor("Carrie-Anne Moss")); MovieActorReference movieSetReference = new MovieActorReference(1, 1999, "The Matrix", actors); objectMapper.add(movieSetReference); StateEngineRoundTripper.roundTripSnapshot(writeStateEngine, readStateEngine); HollowPrefixIndex prefixIndex = new HollowPrefixIndex(readStateEngine, "MovieActorReference", "actors.element"); Set<Integer> ordinals = toSet(prefixIndex.findKeysWithPrefix("kea")); Assert.assertTrue(ordinals.size() == 1); }
@Test public void recreatesUsingReadEngine() throws IOException { HollowWriteStateEngine writeEngine = new HollowWriteStateEngine(); HollowObjectMapper mapper = new HollowObjectMapper(writeEngine); mapper.add(new Integer(1)); writeEngine.addHeaderTag("CopyTag", "copied"); HollowReadStateEngine readEngine = StateEngineRoundTripper.roundTripSnapshot(writeEngine); HollowWriteStateEngine recreatedWriteEngine = HollowWriteStateCreator.recreateAndPopulateUsingReadEngine(readEngine); HollowReadStateEngine recreatedReadEngine = StateEngineRoundTripper.roundTripSnapshot(recreatedWriteEngine); Assert.assertEquals(HollowChecksum.forStateEngine(readEngine), HollowChecksum.forStateEngine(recreatedReadEngine)); Assert.assertEquals("copied", recreatedReadEngine.getHeaderTag("CopyTag")); Assert.assertEquals(readEngine.getCurrentRandomizedTag(), recreatedReadEngine.getCurrentRandomizedTag()); }
@Test public void test() throws IOException { HollowWriteStateEngine writeEngine = new HollowWriteStateEngine(); HollowObjectMapper mapper = new HollowObjectMapper(writeEngine); for(int i=0;i<10;i++) { mapper.add(new TypeWithFloat(-200f, i)); } HollowReadStateEngine readEngine = StateEngineRoundTripper.roundTripSnapshot(writeEngine); for(int i=0;i<10;i++) { GenericHollowObject obj = new GenericHollowObject(readEngine, "TypeWithFloat", i); Assert.assertEquals(i, obj.getInt("i")); } }
@Test public void testLookupOfLongKey() throws IOException { HollowWriteStateEngine writeEngine = new HollowWriteStateEngine(); HollowObjectMapper mapper = new HollowObjectMapper(writeEngine); mapper.initializeTypeState(TypeWithLongMap.class); TypeWithLongMap top = new TypeWithLongMap(); long longValue = (long)Integer.MAX_VALUE+1; top.longMap.put(longValue, 100L); mapper.add(top); HollowReadStateEngine readEngine = StateEngineRoundTripper.roundTripSnapshot(writeEngine); GenericHollowMap map = new GenericHollowMap(readEngine, "MapOfLongToLong", 0); GenericHollowObject value = new GenericHollowObject(readEngine, "Long", map.findValue(longValue).getOrdinal()); Assert.assertEquals(100L, value.getLong("value")); }
@Test public void testExplicitlyExcludedButOtherwiseReferencedKeys() throws IOException { HollowPrimaryKeyIndex cIdx3 = new HollowPrimaryKeyIndex(input3, "TypeC", "key"); HollowCombinerExcludePrimaryKeysCopyDirector director = new HollowCombinerExcludePrimaryKeysCopyDirector(); director.excludeKey(cIdx3, 8); HollowCombiner combiner = new HollowCombiner(director, input1, input2, input3); combiner.setPrimaryKeys(new PrimaryKey("TypeB", "key", "c.key"), new PrimaryKey("TypeC", "key")); combiner.combine(); HollowReadStateEngine output = StateEngineRoundTripper.roundTripSnapshot(combiner.getCombinedStateEngine()); assertObject(output, 9, 3, 8, 3, 8, 3); }