SolveMessageInconsistenciesService { public Mono<Task.Result> fixMessageInconsistencies(Context context, RunningOptions runningOptions) { return Flux.concat( fixInconsistenciesInMessageId(context, runningOptions), fixInconsistenciesInImapUid(context, runningOptions)) .reduce(Task.Result.COMPLETED, Task::combine); } @Inject  SolveMessageInconsistenciesService(CassandraMessageIdToImapUidDAO messageIdToImapUidDAO, CassandraMessageIdDAO messageIdDAO); Mono<Task.Result> fixMessageInconsistencies(Context context, RunningOptions runningOptions);  }
@Test void fixMessageInconsistenciesShouldReturnCompletedWhenNoData() { assertThat(testee.fixMessageInconsistencies(new Context(), RunningOptions.DEFAULT).block()) .isEqualTo(Task.Result.COMPLETED); }
@Test void fixMessageInconsistenciesShouldReturnCompletedWhenConsistentData() { imapUidDAO.insert(MESSAGE_1).block(); messageIdDAO.insert(MESSAGE_1).block(); assertThat(testee.fixMessageInconsistencies(new Context(), RunningOptions.DEFAULT).block()) .isEqualTo(Task.Result.COMPLETED); }
@Test void fixMailboxInconsistenciesShouldNotAlterStateWhenEmpty() { testee.fixMessageInconsistencies(new Context(), RunningOptions.DEFAULT).block(); SoftAssertions.assertSoftly(softly -> { softly.assertThat(imapUidDAO.retrieveAllMessages().collectList().block()).isEmpty(); softly.assertThat(messageIdDAO.retrieveAllMessages().collectList().block()).isEmpty(); }); }
@Test void fixMailboxInconsistenciesShouldNotAlterStateWhenConsistent() { imapUidDAO.insert(MESSAGE_1).block(); messageIdDAO.insert(MESSAGE_1).block(); testee.fixMessageInconsistencies(new Context(), RunningOptions.DEFAULT).block(); SoftAssertions.assertSoftly(softly -> { softly.assertThat(imapUidDAO.retrieveAllMessages().collectList().block()) .containsExactlyInAnyOrder(MESSAGE_1); softly.assertThat(messageIdDAO.retrieveAllMessages().collectList().block()) .containsExactlyInAnyOrder(MESSAGE_1); }); }
@Test void fixMailboxInconsistenciesShouldNotUpdateContextWhenNoData() { Context context = new Context(); testee.fixMessageInconsistencies(context, RunningOptions.DEFAULT).block(); assertThat(context.snapshot()).isEqualToComparingFieldByFieldRecursively(new Context().snapshot()); }
@Test void fixMessageInconsistenciesShouldUpdateContextWhenConsistentData() { Context context = new Context(); imapUidDAO.insert(MESSAGE_1).block(); messageIdDAO.insert(MESSAGE_1).block(); testee.fixMessageInconsistencies(context, RunningOptions.DEFAULT).block(); assertThat(context.snapshot()) .isEqualTo(Context.Snapshot.builder() .processedImapUidEntries(1) .processedMessageIdEntries(1) .build()); }
@Test void fixMessageInconsistenciesShouldUpdateContextWhenOrphanImapUidMessage() { Context context = new Context(); imapUidDAO.insert(MESSAGE_1).block(); testee.fixMessageInconsistencies(context, RunningOptions.DEFAULT).block(); assertThat(context.snapshot()) .isEqualTo(Context.Snapshot.builder() .processedImapUidEntries(1) .addedMessageIdEntries(1) .addFixedInconsistencies(MESSAGE_1.getComposedMessageId()) .build()); }
@Test void fixMailboxInconsistenciesShouldUpdateContextWhenInconsistentModSeq() { Context context = new Context(); imapUidDAO.insert(MESSAGE_1).block(); messageIdDAO.insert(MESSAGE_1_WITH_MOD_SEQ_2).block(); testee.fixMessageInconsistencies(context, RunningOptions.DEFAULT).block(); assertThat(context.snapshot()) .isEqualTo(Context.Snapshot.builder() .processedImapUidEntries(1) .processedMessageIdEntries(1) .updatedMessageIdEntries(1) .addFixedInconsistencies(MESSAGE_1.getComposedMessageId()) .build()); }
@Test void fixMailboxInconsistenciesShouldUpdateContextWhenInconsistentFlags() { Context context = new Context(); imapUidDAO.insert(MESSAGE_1).block(); messageIdDAO.insert(MESSAGE_1_WITH_SEEN_FLAG).block(); testee.fixMessageInconsistencies(context, RunningOptions.DEFAULT).block(); assertThat(context.snapshot()) .isEqualTo(Context.Snapshot.builder() .processedImapUidEntries(1) .processedMessageIdEntries(1) .updatedMessageIdEntries(1) .addFixedInconsistencies(MESSAGE_1.getComposedMessageId()) .build()); }
@Test void fixMailboxInconsistenciesShouldUpdateContextWhenOrphanMessageIdMessage() { Context context = new Context(); messageIdDAO.insert(MESSAGE_1).block(); testee.fixMessageInconsistencies(context, RunningOptions.DEFAULT).block(); assertThat(context.snapshot()) .isEqualTo(Context.Snapshot.builder() .processedMessageIdEntries(1) .removedMessageIdEntries(1) .addFixedInconsistencies(MESSAGE_1.getComposedMessageId()) .build()); }
@Test void fixMailboxInconsistenciesShouldUpdateContextWhenDeleteError(CassandraCluster cassandra) { Context context = new Context(); messageIdDAO.insert(MESSAGE_1).block(); cassandra.getConf() .registerScenario(fail() .times(1) .whenQueryStartsWith("DELETE FROM messageIdTable WHERE mailboxId=:mailboxId AND uid=:uid;")); testee.fixMessageInconsistencies(context, RunningOptions.DEFAULT).block(); assertThat(context.snapshot()) .isEqualTo(Context.Snapshot.builder() .processedMessageIdEntries(1) .errors(MESSAGE_1.getComposedMessageId()) .build()); }