HollowProducer.ReadState hardRestore(long versionDesired, HollowConsumer.BlobRetriever blobRetriever) { return restore(versionDesired, blobRetriever, (restoreFrom, restoreTo) -> HollowWriteStateCreator.populateUsingReadEngine(restoreTo, restoreFrom)); }
/** * Recreate a {@link HollowWriteStateEngine} which can be used to write a snapshot of or continue * a delta chain from the supplied {@link HollowReadStateEngine}. * <p> * The returned state engine will be ready to write a snapshot which will exactly recreate the data in the supplied {@link HollowReadStateEngine}. * A delta chain may be continued from this state by calling {@link HollowWriteStateEngine#prepareForNextCycle()}. * * @param readEngine the read state engine * @return the write state engine */ public static HollowWriteStateEngine recreateAndPopulateUsingReadEngine(final HollowReadStateEngine readEngine) { final HollowWriteStateEngine writeEngine = new HollowWriteStateEngine(); populateStateEngineWithTypeWriteStates(writeEngine, readEngine.getSchemas()); populateUsingReadEngine(writeEngine, readEngine); return 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 repopulationFailsIfShardsAreIncorrectlyPreconfigured() throws IOException { HollowWriteStateEngine writeEngine = new HollowWriteStateEngine(); HollowObjectMapper mapper = new HollowObjectMapper(writeEngine); mapper.add(new Integer(1)); mapper.add(new Integer(2)); HollowReadStateEngine readEngine = StateEngineRoundTripper.roundTripSnapshot(writeEngine); HollowWriteStateEngine repopulatedWriteStateEngine = new HollowWriteStateEngine(); new HollowObjectMapper(repopulatedWriteStateEngine).initializeTypeState(IntegerWithWrongShardConfiguration.class); try { HollowWriteStateCreator.populateUsingReadEngine(repopulatedWriteStateEngine, readEngine); Assert.fail(); } catch(Exception expected) { } }
new HollowObjectMapper(repopulatedWriteStateEngine).initializeTypeState(IntegerWithMoreThanOneField.class); HollowWriteStateCreator.populateUsingReadEngine(repopulatedWriteStateEngine, readEngine);
new HollowObjectMapper(repopulatedWriteStateEngine).initializeTypeState(Integer.class); HollowWriteStateCreator.populateUsingReadEngine(repopulatedWriteStateEngine, readEngine);