diff --git a/bosk-mongo/src/test/java/io/vena/bosk/drivers/mongo/SchemaEvolutionTest.java b/bosk-mongo/src/test/java/io/vena/bosk/drivers/mongo/SchemaEvolutionTest.java index 1b260484..dc0b035a 100644 --- a/bosk-mongo/src/test/java/io/vena/bosk/drivers/mongo/SchemaEvolutionTest.java +++ b/bosk-mongo/src/test/java/io/vena/bosk/drivers/mongo/SchemaEvolutionTest.java @@ -9,6 +9,7 @@ import io.vena.bosk.drivers.mongo.MongoDriverSettings.ManifestMode; import io.vena.bosk.drivers.state.TestEntity; import io.vena.bosk.junit.ParametersByName; +import java.io.IOException; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Stream; import org.junit.jupiter.api.AfterEach; @@ -123,27 +124,7 @@ void pairwise_writeCompatible() throws Exception { LOGGER.debug("Refurbish toBosk ({})", toBosk.name()); ((MongoDriver)toBosk.driver()).refurbish(); - if (fromHelper.driverSettings.preferredDatabaseFormat() == SEQUOIA - && toHelper.driverSettings.preferredDatabaseFormat() != SEQUOIA) { - // When switching format classes, the old format's state documents - // disappear. - // Sequoia, being a fundamentally single-document format that does not - // use transactions, is not able to handle the time window between - // when that document disappears and when the corresponding change - // event arrives. We could add complexity to Sequoia to cope with - // this situation, but the point of Sequoia is its simplicity. - // - // Instead, we have a documented limitation that refurbishing from - // Sequoia to another format has a risk that updates occurring during - // a certain window could be ignored, and recommend that refurbish - // operation occur during a period of quiescence. - // - // Performing a flush causes Sequoia to "notice" its document is gone - // and correctly reinitialize itself. - - LOGGER.debug("Flush so fromBosk notices the refurbish ({})", fromBosk.name()); - fromBosk.driver().flush(); - } + flushIfLiveRefurbishIsNotSupported(fromBosk, fromHelper, toHelper); LOGGER.debug("Set distinctive string using fromBosk ({})", fromBosk.name()); fromBosk.driver().submitReplacement(fromRefs.string(), "Distinctive String"); @@ -163,6 +144,40 @@ void pairwise_writeCompatible() throws Exception { // System.out.println("Status: " + ((MongoDriver)toBosk.driver()).readStatus()); } + /** + * @param boskForUpdate {@link Bosk} that is about to submit an update + * @param helperForUpdate {@link Helper} for the bosk that is about to submit an update + * @param helperForRefurbish {@link Helper} for the bosk that performed the {@link MongoDriver#flush()} operation + */ + private static void flushIfLiveRefurbishIsNotSupported( + Bosk boskForUpdate, + Helper helperForUpdate, + Helper helperForRefurbish + ) throws IOException, InterruptedException { + if (helperForUpdate.driverSettings.preferredDatabaseFormat() == SEQUOIA + && helperForRefurbish.driverSettings.preferredDatabaseFormat() != SEQUOIA) { + // When switching format classes, the old format's state documents + // disappear. + // + // Sequoia, being a fundamentally single-document format that does not + // use transactions, is not able to handle the time window between + // when that document disappears and when the corresponding change + // event arrives. We could add complexity to Sequoia to cope with + // this situation, but the point of Sequoia is its simplicity. + // + // Instead, we have a documented limitation that refurbishing from + // Sequoia to another format has a risk that updates occurring during + // a certain window could be ignored, and recommend that refurbish + // operation occur during a period of quiescence. + // + // Performing a flush causes Sequoia to "notice" its document is gone + // and correctly reinitialize itself. + + LOGGER.debug("Flush so boskForUpdate notices the refurbish ({})", boskForUpdate.name()); + boskForUpdate.driver().flush(); + } + } + private static Bosk newBosk(Helper helper) { return new Bosk("bosk" + boskCounter.incrementAndGet(), TestEntity.class, helper::initialRoot, helper.driverFactory); }