}
private void removeExistingIndexationTasks(DbSession dbSession) {
- removeIndexationTasks(dbSession, dbClient.ceQueueDao().selectAllInAscOrder(dbSession));
+ Set<String> ceQueueUuids = dbClient.ceQueueDao().selectAllInAscOrder(dbSession)
+ .stream().filter(p -> p.getTaskType().equals(BRANCH_ISSUE_SYNC))
+ .map(CeQueueDto::getUuid).collect(Collectors.toSet());
+ Set<String> ceActivityUuids = dbClient.ceActivityDao().selectByTaskType(dbSession, BRANCH_ISSUE_SYNC)
+ .stream().map(CeActivityDto::getUuid).collect(Collectors.toSet());
+ removeIndexationTasks(dbSession, ceQueueUuids, ceActivityUuids);
}
private void removeExistingIndexationTasksForProject(DbSession dbSession, String projectUuid) {
- removeIndexationTasks(dbSession, dbClient.ceQueueDao().selectByMainComponentUuid(dbSession, projectUuid));
+ Set<String> ceQueueUuidsForProject = dbClient.ceQueueDao().selectByMainComponentUuid(dbSession, projectUuid)
+ .stream().filter(p -> p.getTaskType().equals(BRANCH_ISSUE_SYNC))
+ .map(CeQueueDto::getUuid).collect(Collectors.toSet());
+ Set<String> ceActivityUuidsForProject = dbClient.ceActivityDao().selectByTaskType(dbSession, BRANCH_ISSUE_SYNC)
+ .stream()
+ .filter(ceActivityDto -> projectUuid.equals(ceActivityDto.getMainComponentUuid()))
+ .map(CeActivityDto::getUuid).collect(Collectors.toSet());
+ removeIndexationTasks(dbSession, ceQueueUuidsForProject, ceActivityUuidsForProject);
}
- private void removeIndexationTasks(DbSession dbSession, List<CeQueueDto> ceQueueDtos) {
- List<String> uuids = ceQueueDtos.stream()
- .filter(p -> p.getTaskType().equals(BRANCH_ISSUE_SYNC))
- .map(CeQueueDto::getUuid)
- .toList();
-
- LOG.info(String.format("%s pending indexation task found to be deleted...", uuids.size()));
- for (String uuid : uuids) {
+ private void removeIndexationTasks(DbSession dbSession, Set<String> ceQueueUuids, Set<String> ceActivityUuids) {
+ LOG.info(String.format("%s pending indexation task found to be deleted...", ceQueueUuids.size()));
+ for (String uuid : ceQueueUuids) {
dbClient.ceQueueDao().deleteByUuid(dbSession, uuid);
}
- dbSession.commit();
- Set<String> ceUuids = dbClient.ceActivityDao().selectByTaskType(dbSession, BRANCH_ISSUE_SYNC).stream()
- .map(CeActivityDto::getUuid)
- .collect(Collectors.toSet());
- LOG.info(String.format("%s completed indexation task found to be deleted...", uuids.size()));
- dbClient.ceActivityDao().deleteByUuids(dbSession, ceUuids);
- dbSession.commit();
+ LOG.info(String.format("%s completed indexation task found to be deleted...", ceQueueUuids.size()));
+ dbClient.ceActivityDao().deleteByUuids(dbSession, ceActivityUuids);
LOG.info("Indexation task deletion complete.");
LOG.info("Deleting tasks characteristics...");
- Set<String> tasksUuid = Stream.concat(uuids.stream(), ceUuids.stream()).collect(Collectors.toSet());
+ Set<String> tasksUuid = Stream.concat(ceQueueUuids.stream(), ceActivityUuids.stream()).collect(Collectors.toSet());
dbClient.ceTaskCharacteristicsDao().deleteByTaskUuids(dbSession, tasksUuid);
- dbSession.commit();
LOG.info("Tasks characteristics deletion complete.");
+
+ dbSession.commit();
}
private CeTaskSubmit buildTaskSubmit(BranchDto branch) {
underTest.triggerOnIndexCreation();
- assertCeTasks(reportTaskUuid);
+ assertThat(dbClient.ceQueueDao().selectAllInAscOrder(dbTester.getSession())).extracting("uuid").containsExactly(reportTaskUuid);
+ assertThat(dbClient.ceActivityDao().selectByTaskType(dbTester.getSession(), BRANCH_ISSUE_SYNC)).isEmpty();
+ assertThat(dbClient.ceActivityDao().selectByTaskType(dbTester.getSession(), REPORT)).hasSize(1);
+ assertThat(dbClient.ceTaskCharacteristicsDao().selectByTaskUuids(dbTester.getSession(), new HashSet<>(List.of("uuid_2")))).isEmpty();
+
assertThat(logTester.logs(LoggerLevel.INFO))
.contains(
"1 pending indexation task found to be deleted...",
ProjectDto projectDto = dbTester.components().insertPrivateProjectDto();
String branchUuid = "branch_uuid";
dbTester.components().insertProjectBranch(projectDto, b -> b.setBranchType(BRANCH).setUuid(branchUuid));
+
CeQueueDto mainBranchTask = new CeQueueDto().setUuid("uuid_2").setTaskType(BRANCH_ISSUE_SYNC)
.setMainComponentUuid(projectDto.getUuid()).setComponentUuid(projectDto.getUuid());
+ dbClient.ceQueueDao().insert(dbTester.getSession(), mainBranchTask);
+
CeQueueDto branchTask = new CeQueueDto().setUuid("uuid_3").setTaskType(BRANCH_ISSUE_SYNC)
.setMainComponentUuid(projectDto.getUuid()).setComponentUuid(branchUuid);
- dbClient.ceQueueDao().insert(dbTester.getSession(), mainBranchTask);
dbClient.ceQueueDao().insert(dbTester.getSession(), branchTask);
+
+ ProjectDto anotherProjectDto = dbTester.components().insertPrivateProjectDto();
+ CeQueueDto taskOnAnotherProject = new CeQueueDto().setUuid("uuid_4").setTaskType(BRANCH_ISSUE_SYNC)
+ .setMainComponentUuid(anotherProjectDto.getUuid()).setComponentUuid("another-branchUuid");
+ CeActivityDto canceledTaskOnAnotherProject = new CeActivityDto(taskOnAnotherProject).setStatus(Status.CANCELED);
+ dbClient.ceActivityDao().insert(dbTester.getSession(), canceledTaskOnAnotherProject);
+
dbTester.commit();
underTest.triggerForProject(projectDto.getUuid());
- assertCeTasks(reportTaskUuid);
+ assertThat(dbClient.ceQueueDao().selectAllInAscOrder(dbTester.getSession())).extracting("uuid")
+ .containsExactly(reportTaskUuid);
+ assertThat(dbClient.ceActivityDao().selectByTaskType(dbTester.getSession(), REPORT)).hasSize(1);
+ assertThat(dbClient.ceTaskCharacteristicsDao().selectByTaskUuids(dbTester.getSession(), new HashSet<>(List.of("uuid_2")))).isEmpty();
+
+ // verify that the canceled tasks on anotherProject is still here, and was not removed by the project reindexation
+ assertThat(dbClient.ceActivityDao().selectByTaskType(dbTester.getSession(), BRANCH_ISSUE_SYNC))
+ .hasSize(1)
+ .extracting(CeActivityDto::getMainComponentUuid)
+ .containsExactly(anotherProjectDto.getUuid());
+
assertThat(logTester.logs(LoggerLevel.INFO))
.contains(
"2 pending indexation task found to be deleted...",
return reportTask.getUuid();
}
- private void assertCeTasks(String reportTaskUuid) {
- assertThat(dbClient.ceQueueDao().selectAllInAscOrder(dbTester.getSession())).extracting("uuid")
- .containsExactly(reportTaskUuid);
- assertThat(dbClient.ceActivityDao().selectByTaskType(dbTester.getSession(), BRANCH_ISSUE_SYNC)).isEmpty();
- assertThat(dbClient.ceActivityDao().selectByTaskType(dbTester.getSession(), REPORT)).hasSize(1);
- assertThat(dbClient.ceTaskCharacteristicsDao().selectByTaskUuids(dbTester.getSession(), new HashSet<>(List.of("uuid_2")))).isEmpty();
- }
-
}