Skip to content

Commit

Permalink
fix(server): index execution for only activated scenarios (#40)
Browse files Browse the repository at this point in the history
Co-authored-by: nbrouand <[email protected]>
  • Loading branch information
KarimGl and nbrouand authored Dec 16, 2024
1 parent 77220ef commit 695c765
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ class AcceptanceTests {
}
}

@Disabled
@Test
fun `SSH Task test`() {
softlyAssertLauncherRun(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ScenarioExecutionReportEntity, Long>, JpaSpecificationExecutor<ScenarioExecutionReportEntity> {
ScenarioExecutionReportEntity findByScenarioExecutionId(Long scenarioExecutionId);
Slice<ScenarioExecutionReportEntity> findByScenarioExecutionScenarioIdIn(List<String> scenarioExecutionScenarioId, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> 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
Expand All @@ -41,14 +47,17 @@ public void migrate() {
return;
}
LOGGER.info("Start indexing and in-db compression...");
List<ScenarioEntity> 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<ScenarioExecutionReportEntity> slice = scenarioExecutionReportJpaRepository.findAll(pageable);
Slice<ScenarioExecutionReportEntity> slice = scenarioExecutionReportJpaRepository.findByScenarioExecutionScenarioIdIn(activatedScenariosIds, pageable);
List<ScenarioExecutionReportEntity> reports = slice.getContent();

executionReportRepository.compressAndSaveInDb(reports);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public interface ScenarioJpaRepository extends CrudRepository<ScenarioEntity, Lo

Optional<ScenarioEntity> findByIdAndActivated(Long id, Boolean activated);

List<ScenarioEntity> 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
Expand Down
2 changes: 2 additions & 0 deletions example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@
<configuration>
<excludes>
<exclude>SeleniumTest</exclude>
<exclude>SwapiTest</exclude>
<exclude>RunHelloTests</exclude>
</excludes>
</configuration>
</plugin>
Expand Down

0 comments on commit 695c765

Please sign in to comment.