From 695c7659cf28177fd3be25f6aed76ed74d0ed22b Mon Sep 17 00:00:00 2001 From: Karim Goubbaa Date: Mon, 16 Dec 2024 12:40:00 +0100 Subject: [PATCH] fix(server): index execution for only activated scenarios (#40) Co-authored-by: nbrouand <7816908+nbrouand@users.noreply.github.com> --- .../acceptance/AcceptanceTests.kt | 1 + .../ScenarioExecutionReportJpaRepository.java | 4 ++++ .../domain/ExecutionReportMigrator.java | 17 +++++++++++++---- .../infra/raw/ScenarioJpaRepository.java | 2 ++ example/pom.xml | 2 ++ 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/acceptance-tests/src/test/kotlin/com/chutneytesting/acceptance/AcceptanceTests.kt b/acceptance-tests/src/test/kotlin/com/chutneytesting/acceptance/AcceptanceTests.kt index b43c7ab00..e4416f4d0 100644 --- a/acceptance-tests/src/test/kotlin/com/chutneytesting/acceptance/AcceptanceTests.kt +++ b/acceptance-tests/src/test/kotlin/com/chutneytesting/acceptance/AcceptanceTests.kt @@ -391,6 +391,7 @@ class AcceptanceTests { } } + @Disabled @Test fun `SSH Task test`() { softlyAssertLauncherRun( diff --git a/chutney/server/src/main/java/com/chutneytesting/execution/infra/storage/ScenarioExecutionReportJpaRepository.java b/chutney/server/src/main/java/com/chutneytesting/execution/infra/storage/ScenarioExecutionReportJpaRepository.java index 8fc5b1df7..01dadb932 100644 --- a/chutney/server/src/main/java/com/chutneytesting/execution/infra/storage/ScenarioExecutionReportJpaRepository.java +++ b/chutney/server/src/main/java/com/chutneytesting/execution/infra/storage/ScenarioExecutionReportJpaRepository.java @@ -8,9 +8,13 @@ package com.chutneytesting.execution.infra.storage; import com.chutneytesting.execution.infra.storage.jpa.ScenarioExecutionReportEntity; +import java.util.List; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; public interface ScenarioExecutionReportJpaRepository extends JpaRepository, JpaSpecificationExecutor { ScenarioExecutionReportEntity findByScenarioExecutionId(Long scenarioExecutionId); + Slice findByScenarioExecutionScenarioIdIn(List scenarioExecutionScenarioId, Pageable pageable); } diff --git a/chutney/server/src/main/java/com/chutneytesting/migration/domain/ExecutionReportMigrator.java b/chutney/server/src/main/java/com/chutneytesting/migration/domain/ExecutionReportMigrator.java index ae1176a76..dba8c8f53 100644 --- a/chutney/server/src/main/java/com/chutneytesting/migration/domain/ExecutionReportMigrator.java +++ b/chutney/server/src/main/java/com/chutneytesting/migration/domain/ExecutionReportMigrator.java @@ -11,6 +11,8 @@ import com.chutneytesting.execution.infra.storage.jpa.ScenarioExecutionReportEntity; import com.chutneytesting.index.infra.ScenarioExecutionReportIndexRepository; import com.chutneytesting.migration.infra.ExecutionReportRepository; +import com.chutneytesting.scenario.infra.jpa.ScenarioEntity; +import com.chutneytesting.scenario.infra.raw.ScenarioJpaRepository; import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -24,14 +26,18 @@ public class ExecutionReportMigrator implements DataMigrator { private final ScenarioExecutionReportJpaRepository scenarioExecutionReportJpaRepository; private final ScenarioExecutionReportIndexRepository scenarioExecutionReportIndexRepository; + private final ScenarioJpaRepository scenarioJpaRepository; private final ExecutionReportRepository executionReportRepository; private static final Logger LOGGER = LoggerFactory.getLogger(ExecutionReportMigrator.class); + private List activatedScenariosIds; - public ExecutionReportMigrator(ExecutionReportRepository executionReportRepository, - ScenarioExecutionReportJpaRepository scenarioExecutionReportJpaRepository, ScenarioExecutionReportIndexRepository scenarioExecutionReportIndexRepository) { + public ExecutionReportMigrator(ScenarioExecutionReportJpaRepository scenarioExecutionReportJpaRepository, + ScenarioExecutionReportIndexRepository scenarioExecutionReportIndexRepository, + ScenarioJpaRepository scenarioJpaRepository, ExecutionReportRepository executionReportRepository) { this.scenarioExecutionReportJpaRepository = scenarioExecutionReportJpaRepository; - this.executionReportRepository = executionReportRepository; + this.scenarioJpaRepository = scenarioJpaRepository; this.scenarioExecutionReportIndexRepository = scenarioExecutionReportIndexRepository; + this.executionReportRepository = executionReportRepository; } @Override @@ -41,14 +47,17 @@ public void migrate() { return; } LOGGER.info("Start indexing and in-db compression..."); + List activeScenarios = scenarioJpaRepository.findByActivated(true); + activatedScenariosIds = activeScenarios.stream().map(scenarioEntity -> scenarioEntity.getId().toString()).toList(); PageRequest firstPage = PageRequest.of(0, 10); int count = 0; migrate(firstPage, count); + activatedScenariosIds = null; } private void migrate(Pageable pageable, int previousCount) { LOGGER.debug("Indexing and compressing reports in page n° {}", pageable.getPageNumber()); - Slice slice = scenarioExecutionReportJpaRepository.findAll(pageable); + Slice slice = scenarioExecutionReportJpaRepository.findByScenarioExecutionScenarioIdIn(activatedScenariosIds, pageable); List reports = slice.getContent(); executionReportRepository.compressAndSaveInDb(reports); diff --git a/chutney/server/src/main/java/com/chutneytesting/scenario/infra/raw/ScenarioJpaRepository.java b/chutney/server/src/main/java/com/chutneytesting/scenario/infra/raw/ScenarioJpaRepository.java index 84d4491af..fcac7372c 100644 --- a/chutney/server/src/main/java/com/chutneytesting/scenario/infra/raw/ScenarioJpaRepository.java +++ b/chutney/server/src/main/java/com/chutneytesting/scenario/infra/raw/ScenarioJpaRepository.java @@ -25,6 +25,8 @@ public interface ScenarioJpaRepository extends CrudRepository findByIdAndActivated(Long id, Boolean activated); + List findByActivated(Boolean activated); + @Query(""" SELECT new com.chutneytesting.scenario.infra.jpa.ScenarioEntity(s.id, s.title, s.description, s.tags, s.creationDate, s.activated, s.userId, s.updateDate, s.version, s.defaultDataset) FROM SCENARIO s diff --git a/example/pom.xml b/example/pom.xml index 32947fd33..e7e499224 100644 --- a/example/pom.xml +++ b/example/pom.xml @@ -156,6 +156,8 @@ SeleniumTest + SwapiTest + RunHelloTests