SolveMailboxInconsistenciesService { public Mono<Result> fixMailboxInconsistencies(Context context) { assertValidVersion(); return Flux.concat( processMailboxDaoInconsistencies(context), processMailboxPathDaoInconsistencies(context)) .reduce(Result.COMPLETED, Task::combine); } @Inject  SolveMailboxInconsistenciesService(CassandraMailboxDAO mailboxDAO, CassandraMailboxPathV2DAO mailboxPathV2DAO, CassandraSchemaVersionManager versionManager); Mono<Result> fixMailboxInconsistencies(Context context); static final Logger LOGGER; }
@Test void fixMailboxInconsistenciesShouldFailWhenIsBelowMailboxPathV2Migration() { versionDAO.truncateVersion().block(); versionDAO.updateVersion(new SchemaVersion(5)).block(); assertThatThrownBy(() -> testee.fixMailboxInconsistencies(new Context()).block()) .isInstanceOf(IllegalStateException.class) .hasMessage("Schema version 6 is required in order to ensure mailboxPathV2DAO to be correctly populated, got 5"); }
@Test void fixMailboxInconsistenciesShouldFailWhenVersionIsMissing() { versionDAO.truncateVersion().block(); assertThatThrownBy(() -> testee.fixMailboxInconsistencies(new Context()).block()) .isInstanceOf(IllegalStateException.class) .hasMessage("Schema version 6 is required in order to ensure mailboxPathV2DAO to be correctly populated, got 5"); }
@Test void fixMailboxInconsistenciesShouldNotFailWhenIsEqualToMailboxPathV2Migration() { versionDAO.truncateVersion().block(); versionDAO.updateVersion(new SchemaVersion(6)).block(); assertThatCode(() -> testee.fixMailboxInconsistencies(new Context()).block()) .doesNotThrowAnyException(); }
@Test void fixMailboxInconsistenciesShouldNotFailWhenIsAboveMailboxPathV2Migration() { versionDAO.truncateVersion().block(); versionDAO.updateVersion(new SchemaVersion(7)).block(); assertThatCode(() -> testee.fixMailboxInconsistencies(new Context()).block()) .doesNotThrowAnyException(); }
@Test void fixMailboxInconsistenciesShouldReturnCompletedWhenNoData() { assertThat(testee.fixMailboxInconsistencies(new Context()).block()) .isEqualTo(Result.COMPLETED); }
@Test void fixMailboxInconsistenciesShouldReturnCompletedWhenConsistentData() { mailboxDAO.save(MAILBOX).block(); mailboxPathV2DAO.save(MAILBOX_PATH, CASSANDRA_ID_1).block(); assertThat(testee.fixMailboxInconsistencies(new Context()).block()) .isEqualTo(Result.COMPLETED); }
@Test void fixMailboxInconsistenciesShouldReturnCompletedWhenOrphanMailboxData() { mailboxDAO.save(MAILBOX).block(); assertThat(testee.fixMailboxInconsistencies(new Context()).block()) .isEqualTo(Result.COMPLETED); }
@Test void fixMailboxInconsistenciesShouldReturnCompletedWhenOrphanPathData() { mailboxPathV2DAO.save(MAILBOX_PATH, CASSANDRA_ID_1).block(); assertThat(testee.fixMailboxInconsistencies(new Context()).block()) .isEqualTo(Result.COMPLETED); }
@Test void fixMailboxInconsistenciesShouldReturnPartialWhenDAOMisMatchOnId() { mailboxDAO.save(MAILBOX).block(); mailboxPathV2DAO.save(MAILBOX_PATH, CASSANDRA_ID_2).block(); assertThat(testee.fixMailboxInconsistencies(new Context()).block()) .isEqualTo(Result.PARTIAL); }
@Test void fixMailboxInconsistenciesShouldReturnPartialWhenDAOMisMatchOnPath() { mailboxDAO.save(MAILBOX).block(); mailboxPathV2DAO.save(NEW_MAILBOX_PATH, CASSANDRA_ID_1).block(); assertThat(testee.fixMailboxInconsistencies(new Context()).block()) .isEqualTo(Result.PARTIAL); }
@Test void fixMailboxInconsistenciesShouldNotUpdateContextWhenNoData() { Context context = new Context(); testee.fixMailboxInconsistencies(context).block(); assertThat(context.snapshot()).isEqualToComparingFieldByFieldRecursively(new Context().snapshot()); }
@Test void fixMailboxInconsistenciesShouldUpdateContextWhenConsistentData() { Context context = new Context(); mailboxDAO.save(MAILBOX).block(); mailboxPathV2DAO.save(MAILBOX_PATH, CASSANDRA_ID_1).block(); testee.fixMailboxInconsistencies(context).block(); assertThat(context.snapshot()) .isEqualTo(Context.builder() .processedMailboxEntries(1) .processedMailboxPathEntries(1) .build() .snapshot()); }
@Test void fixMailboxInconsistenciesShouldUpdateContextWhenOrphanMailboxData() { Context context = new Context(); mailboxDAO.save(MAILBOX).block(); testee.fixMailboxInconsistencies(context).block(); assertThat(context.snapshot()) .isEqualTo(Context.builder() .processedMailboxEntries(1) .processedMailboxPathEntries(1) .addFixedInconsistencies(MAILBOX.getMailboxId()) .build() .snapshot()); }
@Test void fixMailboxInconsistenciesShouldUpdateContextWhenOrphanPathData() { Context context = new Context(); mailboxPathV2DAO.save(MAILBOX_PATH, CASSANDRA_ID_1).block(); testee.fixMailboxInconsistencies(context).block(); assertThat(context.snapshot()) .isEqualTo(Context.builder() .processedMailboxPathEntries(1) .addFixedInconsistencies(CASSANDRA_ID_1) .build() .snapshot()); }
@Test void fixMailboxInconsistenciesShouldUpdateContextWhenDAOMisMatchOnId() { Context context = new Context(); mailboxDAO.save(MAILBOX).block(); mailboxPathV2DAO.save(MAILBOX_PATH, CASSANDRA_ID_2).block(); mailboxDAO.save(new Mailbox(MAILBOX_PATH, UID_VALIDITY_2, CASSANDRA_ID_2)).block(); testee.fixMailboxInconsistencies(context).block(); assertThat(context.snapshot()) .isEqualTo(Context.builder() .processedMailboxEntries(2) .processedMailboxPathEntries(1) .addConflictingEntry(ConflictingEntry.builder() .mailboxDaoEntry(MAILBOX) .mailboxPathDaoEntry(MAILBOX_PATH, CASSANDRA_ID_2)) .build() .snapshot()); }
@Test void fixMailboxInconsistenciesShouldUpdateContextWhenDAOMisMatchOnPath() { Context context = new Context(); mailboxDAO.save(MAILBOX).block(); mailboxPathV2DAO.save(NEW_MAILBOX_PATH, CASSANDRA_ID_1).block(); testee.fixMailboxInconsistencies(context).block(); assertThat(context.snapshot()) .isEqualTo(Context.builder() .processedMailboxEntries(1) .processedMailboxPathEntries(2) .addFixedInconsistencies(CASSANDRA_ID_1) .addConflictingEntry(ConflictingEntry.builder() .mailboxDaoEntry(MAILBOX) .mailboxPathDaoEntry(NEW_MAILBOX_PATH, CASSANDRA_ID_1)) .build() .snapshot()); }
@Test void fixMailboxInconsistenciesShouldNotAlterStateWhenEmpty() { testee.fixMailboxInconsistencies(new Context()).block(); SoftAssertions.assertSoftly(softly -> { softly.assertThat(mailboxDAO.retrieveAllMailboxes().collectList().block()).isEmpty(); softly.assertThat(mailboxPathV2DAO.listAll().collectList().block()).isEmpty(); }); }
@Test void fixMailboxInconsistenciesShouldNotAlterStateWhenConsistent() { mailboxDAO.save(MAILBOX).block(); mailboxPathV2DAO.save(MAILBOX_PATH, CASSANDRA_ID_1).block(); testee.fixMailboxInconsistencies(new Context()).block(); SoftAssertions.assertSoftly(softly -> { softly.assertThat(mailboxDAO.retrieveAllMailboxes().collectList().block()) .containsExactlyInAnyOrder(MAILBOX); softly.assertThat(mailboxPathV2DAO.listAll().collectList().block()) .containsExactlyInAnyOrder(new CassandraIdAndPath(CASSANDRA_ID_1, MAILBOX_PATH)); }); }
@Test void fixMailboxInconsistenciesShouldAlterStateWhenOrphanMailbox() { mailboxDAO.save(MAILBOX).block(); testee.fixMailboxInconsistencies(new Context()).block(); SoftAssertions.assertSoftly(softly -> { softly.assertThat(mailboxDAO.retrieveAllMailboxes().collectList().block()) .containsExactlyInAnyOrder(MAILBOX); softly.assertThat(mailboxPathV2DAO.listAll().collectList().block()) .containsExactlyInAnyOrder(new CassandraIdAndPath(CASSANDRA_ID_1, MAILBOX_PATH)); }); }
@Test void fixMailboxInconsistenciesShouldAlterStateWhenOrphanMailboxPath() { mailboxPathV2DAO.save(MAILBOX_PATH, CASSANDRA_ID_1).block(); testee.fixMailboxInconsistencies(new Context()).block(); SoftAssertions.assertSoftly(softly -> { softly.assertThat(mailboxDAO.retrieveAllMailboxes().collectList().block()) .isEmpty(); softly.assertThat(mailboxPathV2DAO.listAll().collectList().block()) .isEmpty(); }); }
@Test void fixMailboxInconsistenciesShouldNotAlterStateWhenLoop() { mailboxDAO.save(MAILBOX).block(); Mailbox mailbox2 = new Mailbox(NEW_MAILBOX_PATH, UID_VALIDITY_2, CASSANDRA_ID_2); mailboxDAO.save(mailbox2).block(); mailboxPathV2DAO.save(MAILBOX_PATH, CASSANDRA_ID_2).block(); mailboxPathV2DAO.save(NEW_MAILBOX_PATH, CASSANDRA_ID_1).block(); testee.fixMailboxInconsistencies(new Context()).block(); SoftAssertions.assertSoftly(softly -> { softly.assertThat(mailboxDAO.retrieveAllMailboxes().collectList().block()) .containsExactlyInAnyOrder(MAILBOX, mailbox2); softly.assertThat(mailboxPathV2DAO.listAll().collectList().block()) .containsExactlyInAnyOrder( new CassandraIdAndPath(CASSANDRA_ID_1, NEW_MAILBOX_PATH), new CassandraIdAndPath(CASSANDRA_ID_2, MAILBOX_PATH)); }); }
@Test void fixMailboxInconsistenciesShouldAlterStateWhenDaoMisMatchOnPath() { mailboxDAO.save(MAILBOX).block(); mailboxPathV2DAO.save(NEW_MAILBOX_PATH, CASSANDRA_ID_1).block(); testee.fixMailboxInconsistencies(new Context()).block(); SoftAssertions.assertSoftly(softly -> { softly.assertThat(mailboxDAO.retrieveAllMailboxes().collectList().block()) .containsExactlyInAnyOrder(MAILBOX); softly.assertThat(mailboxPathV2DAO.listAll().collectList().block()) .containsExactlyInAnyOrder( new CassandraIdAndPath(CASSANDRA_ID_1, NEW_MAILBOX_PATH), new CassandraIdAndPath(CASSANDRA_ID_1, MAILBOX_PATH)); }); }
@Test void fixMailboxInconsistenciesShouldAlterStateWhenDaoMisMatchOnId() { mailboxDAO.save(MAILBOX).block(); mailboxPathV2DAO.save(MAILBOX_PATH, CASSANDRA_ID_2).block(); testee.fixMailboxInconsistencies(new Context()).block(); SoftAssertions.assertSoftly(softly -> { softly.assertThat(mailboxDAO.retrieveAllMailboxes().collectList().block()) .containsExactlyInAnyOrder(MAILBOX); softly.assertThat(mailboxPathV2DAO.listAll().collectList().block()) .isEmpty(); }); }
@Test void multipleRunShouldDaoMisMatchOnId() { mailboxDAO.save(MAILBOX).block(); mailboxPathV2DAO.save(MAILBOX_PATH, CASSANDRA_ID_2).block(); testee.fixMailboxInconsistencies(new Context()).block(); testee.fixMailboxInconsistencies(new Context()).block(); SoftAssertions.assertSoftly(softly -> { softly.assertThat(mailboxDAO.retrieveAllMailboxes().collectList().block()) .containsExactlyInAnyOrder(MAILBOX); softly.assertThat(mailboxPathV2DAO.listAll().collectList().block()) .containsExactlyInAnyOrder(new CassandraIdAndPath(CASSANDRA_ID_1, MAILBOX_PATH)); }); }
@Test void fixMailboxInconsistenciesShouldNotAlterStateWhenTwoEntriesWithSamePath() { Mailbox mailbox2 = new Mailbox(MAILBOX_PATH, UID_VALIDITY_2, CASSANDRA_ID_2); mailboxDAO.save(MAILBOX).block(); mailboxPathV2DAO.save(MAILBOX_PATH, CASSANDRA_ID_2).block(); mailboxDAO.save(mailbox2).block(); testee.fixMailboxInconsistencies(new Context()).block(); SoftAssertions.assertSoftly(softly -> { softly.assertThat(mailboxDAO.retrieveAllMailboxes().collectList().block()) .containsExactlyInAnyOrder(MAILBOX, mailbox2); softly.assertThat(mailboxPathV2DAO.listAll().collectList().block()) .containsExactlyInAnyOrder( new CassandraIdAndPath(CASSANDRA_ID_2, MAILBOX_PATH)); }); }