Skip to content

Commit

Permalink
fixup! Automated tests for Rollover
Browse files Browse the repository at this point in the history
  • Loading branch information
yrodiere committed Oct 20, 2023
1 parent 614cfe2 commit 509b6f9
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/test/java/io/quarkus/search/app/indexing/RolloverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
import static org.assertj.core.api.Assertions.assertThatCode;

import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import io.quarkus.narayana.jta.QuarkusTransaction;
import jakarta.annotation.PostConstruct;
import jakarta.inject.Inject;

Expand All @@ -24,13 +22,13 @@
import org.hibernate.search.mapper.orm.mapping.SearchMapping;
import org.hibernate.search.mapper.orm.session.SearchSession;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;

import com.google.gson.Gson;

import io.quarkus.narayana.jta.QuarkusTransaction;
import io.quarkus.search.app.entity.Guide;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.QuarkusTestProfile;
Expand Down Expand Up @@ -94,7 +92,7 @@ private void assertSearchWorksAndTargetsIndex(int readIndex) {
.containsExactlyInAnyOrder(String.format("guide-%06d", readIndex));
}

@AfterEach
@BeforeEach
void recreateIndexes() {
Set<String> aliasedIndexes = searchMapping.allIndexedEntities().stream()
.map(this::aliased)
Expand Down Expand Up @@ -156,26 +154,23 @@ void recover() {
// Simulate a JVM crash: the rollover does not get closed
// We restart... and try to recover
assertThat(Rollover.recoverInconsistentAliases(searchMapping)).isTrue();
// After recovery and throughout indexing, search must continue to work
assertSearchWorksAndTargetsIndex(1);
// Immediately after recovery, search may not work, but write will
assertWriteTargetsIndex(2);

// Then we will reindex, triggering another rollover...
searchMapping.scope(Guide.class).schemaManager().createIfMissing();
assertSearchWorksAndTargetsIndex(1);
assertWriteTargetsIndex(2);

try (Rollover rollover = Rollover.start(searchMapping)) {
assertSearchWorksAndTargetsIndex(1);
assertWriteTargetsIndex(2);
assertWriteTargetsIndex(3);

rollover.commit();
assertSearchWorksAndTargetsIndex(2);
assertWriteTargetsIndex(2);
assertSearchWorksAndTargetsIndex(3);
assertWriteTargetsIndex(3);
}
// And all is good in the end!
assertSearchWorksAndTargetsIndex(2);
assertWriteTargetsIndex(2);
assertSearchWorksAndTargetsIndex(3);
assertWriteTargetsIndex(3);
}

}

0 comments on commit 509b6f9

Please sign in to comment.