From 509b6f99cc2c3a7ddfe3d9d779209be26652fbaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Fri, 20 Oct 2023 23:16:21 +0200 Subject: [PATCH] fixup! Automated tests for Rollover --- .../search/app/indexing/RolloverTest.java | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/test/java/io/quarkus/search/app/indexing/RolloverTest.java b/src/test/java/io/quarkus/search/app/indexing/RolloverTest.java index c07e5da4..87b93d69 100644 --- a/src/test/java/io/quarkus/search/app/indexing/RolloverTest.java +++ b/src/test/java/io/quarkus/search/app/indexing/RolloverTest.java @@ -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; @@ -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; @@ -94,7 +92,7 @@ private void assertSearchWorksAndTargetsIndex(int readIndex) { .containsExactlyInAnyOrder(String.format("guide-%06d", readIndex)); } - @AfterEach + @BeforeEach void recreateIndexes() { Set aliasedIndexes = searchMapping.allIndexedEntities().stream() .map(this::aliased) @@ -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); } }