Browse Source

SONAR-19556 Refactor use of DB columns referencing projects or branches for Entities

tags/10.2.0.77647
Duarte Meneses 1 year ago
parent
commit
667618747b
100 changed files with 670 additions and 698 deletions
  1. 50
    51
      server/sonar-ce-common/src/it/java/org/sonar/ce/queue/CeQueueImplIT.java
  2. 2
    2
      server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueue.java
  3. 37
    38
      server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueueImpl.java
  4. 11
    20
      server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeTaskSubmit.java
  5. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/component/BranchPersisterImplIT.java
  6. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/component/ComponentUuidFactoryImplIT.java
  7. 5
    5
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/component/ProjectPersisterIT.java
  8. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/component/ReferenceBranchComponentUuidsIT.java
  9. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/component/SiblingComponentsWithOpenIssuesIT.java
  10. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStepIT.java
  11. 12
    7
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/filemove/PullRequestFileMoveDetectionStepIT.java
  12. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/AdHocRuleCreatorIT.java
  13. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/ComponentIssuesLoaderIT.java
  14. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/DefaultAssigneeIT.java
  15. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/IntegrateIssuesVisitorIT.java
  16. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/ProjectTrackerBaseLazyInputIT.java
  17. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/ScmAccountToUserLoaderIT.java
  18. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssueMergerIT.java
  19. 5
    3
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/SourceBranchComponentUuidsIT.java
  20. 8
    6
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/TargetBranchComponentUuidsIT.java
  21. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/TrackerReferenceBranchInputFactoryIT.java
  22. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/TrackerSourceBranchInputFactoryIT.java
  23. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/TrackerTargetBranchInputFactoryIT.java
  24. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryImplIT.java
  25. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/metric/MetricRepositoryImplIT.java
  26. 8
    7
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/period/NewCodeReferenceBranchComponentUuidsIT.java
  27. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoDbLoaderIT.java
  28. 4
    4
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/source/DbLineHashVersionIT.java
  29. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/source/PersistFileSourcesStepIT.java
  30. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStepIT.java
  31. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/CleanIssueChangesStepIT.java
  32. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/EnableAnalysisStepIT.java
  33. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ExtractReportStepIT.java
  34. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/LoadCrossProjectDuplicationsRepositoryStepIT.java
  35. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/LoadFileHashesAndStatusStepIT.java
  36. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/LoadPeriodsStepIT.java
  37. 13
    11
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStepIT.java
  38. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistAdHocRulesStepIT.java
  39. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisPropertiesStepIT.java
  40. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistCrossProjectDuplicationIndexStepIT.java
  41. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistDuplicationDataStepIT.java
  42. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistEventsStepIT.java
  43. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepIT.java
  44. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStepIT.java
  45. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStepIT.java
  46. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistProjectLinksStepIT.java
  47. 3
    3
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistPushEventsStepIT.java
  48. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistScannerAnalysisCacheStepIT.java
  49. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistScannerContextStepIT.java
  50. 7
    5
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ProjectNclocComputationStepIT.java
  51. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ReportPersistAnalysisStepIT.java
  52. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepIT.java
  53. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStepIT.java
  54. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/UpdateNeedIssueSyncStepIT.java
  55. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/UpdateQualityProfilesLastUsedDateStepIT.java
  56. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStepIT.java
  57. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistAnalysisStepIT.java
  58. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepIT.java
  59. 2
    2
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/taskprocessor/AuditPurgeStepIT.java
  60. 10
    9
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/taskprocessor/IgnoreOrphanBranchStepIT.java
  61. 11
    16
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/taskprocessor/IndexIssuesStepIT.java
  62. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/analysis/ExportAnalysesStepIT.java
  63. 6
    16
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/branches/ExportBranchesStepIT.java
  64. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/component/ExportComponentsStepIT.java
  65. 6
    7
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/file/ExportLineHashesStepIT.java
  66. 18
    17
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/issue/ExportIssuesChangelogStepIT.java
  67. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/issue/ExportIssuesStepIT.java
  68. 21
    32
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/rule/ExportAdHocRulesStepIT.java
  69. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportEventsStepIT.java
  70. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportLinksStepIT.java
  71. 6
    6
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportLiveMeasuresStepIT.java
  72. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportMeasuresStepIT.java
  73. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportMetricsStepIT.java
  74. 13
    17
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportNewCodePeriodsStepIT.java
  75. 5
    5
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportSettingsStepIT.java
  76. 1
    1
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/LoadProjectStepIT.java
  77. 1
    1
      server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutor.java
  78. 4
    4
      server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/PersistFileSourcesStep.java
  79. 8
    9
      server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java
  80. 2
    2
      server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/taskprocessor/IgnoreOrphanBranchStep.java
  81. 2
    3
      server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/issue/ExportIssuesChangelogStep.java
  82. 2
    2
      server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/taskprocessor/ProjectExportTaskProcessor.java
  83. 5
    4
      server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutorTest.java
  84. 10
    10
      server/sonar-ce-task/src/main/java/org/sonar/ce/task/CeTask.java
  85. 11
    11
      server/sonar-ce-task/src/test/java/org/sonar/ce/task/CeTaskTest.java
  86. 64
    65
      server/sonar-ce/src/it/java/org/sonar/ce/queue/InternalCeQueueImplIT.java
  87. 9
    9
      server/sonar-ce/src/it/java/org/sonar/ce/queue/NextPendingTaskPickerIT.java
  88. 3
    2
      server/sonar-ce/src/it/java/org/sonar/ce/taskprocessor/CeWorkerImplIT.java
  89. 1
    1
      server/sonar-ce/src/main/java/org/sonar/ce/monitoring/CEQueueStatusImpl.java
  90. 1
    7
      server/sonar-ce/src/main/java/org/sonar/ce/queue/InternalCeQueueImpl.java
  91. 5
    5
      server/sonar-ce/src/main/java/org/sonar/ce/queue/NextPendingTaskPicker.java
  92. 1
    1
      server/sonar-ce/src/main/java/org/sonar/ce/taskprocessor/CeWorkerImpl.java
  93. 3
    1
      server/sonar-ce/src/test/java/org/sonar/ce/taskprocessor/CeTaskProcessorRepositoryImplTest.java
  94. 61
    61
      server/sonar-db-dao/src/it/java/org/sonar/db/ce/CeActivityDaoIT.java
  95. 74
    74
      server/sonar-db-dao/src/it/java/org/sonar/db/ce/CeQueueDaoIT.java
  96. 72
    67
      server/sonar-db-dao/src/it/java/org/sonar/db/measure/LiveMeasureDaoIT.java
  97. 5
    7
      server/sonar-db-dao/src/it/java/org/sonar/db/measure/MeasureDaoIT.java
  98. 9
    9
      server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeDaoIT.java
  99. 1
    1
      server/sonar-db-dao/src/it/java/org/sonar/db/pushevent/PushEventDaoIT.java
  100. 0
    0
      server/sonar-db-dao/src/it/java/org/sonar/db/qualitygate/ProjectQgateAssociationDaoIT.java

+ 50
- 51
server/sonar-ce-common/src/it/java/org/sonar/ce/queue/CeQueueImplIT.java View File

@@ -39,8 +39,11 @@ import org.sonar.db.DbTester;
import org.sonar.db.ce.CeActivityDto;
import org.sonar.db.ce.CeQueueDto;
import org.sonar.db.ce.CeTaskTypes;
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
import org.sonar.db.component.ProjectData;
import org.sonar.db.entity.EntityDto;
import org.sonar.db.project.ProjectDto;
import org.sonar.db.user.UserDto;
import org.sonar.db.user.UserTesting;
import org.sonar.server.platform.NodeInformation;
@@ -55,7 +58,7 @@ import static org.assertj.core.api.Assertions.catchThrowable;
import static org.assertj.core.api.Assertions.tuple;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.sonar.ce.queue.CeQueue.SubmitOption.UNIQUE_QUEUE_PER_MAIN_COMPONENT;
import static org.sonar.ce.queue.CeQueue.SubmitOption.UNIQUE_QUEUE_PER_ENTITY;
import static org.sonar.ce.queue.CeQueue.SubmitOption.UNIQUE_QUEUE_PER_TASK_TYPE;

public class CeQueueImplIT {
@@ -86,18 +89,18 @@ public class CeQueueImplIT {

CeTask task = underTest.submit(taskSubmit);

verifyCeTask(taskSubmit, task, null, userDto);
verifyCeTask(taskSubmit, task, null, null, userDto);
verifyCeQueueDtoForTaskSubmit(taskSubmit);
}

@Test
public void submit_populates_component_name_and_key_of_CeTask_if_component_exists() {
ComponentDto componentDto = insertComponent(ComponentTesting.newPrivateProjectDto("PROJECT_1"));
CeTaskSubmit taskSubmit = createTaskSubmit(CeTaskTypes.REPORT, Component.fromDto(componentDto.uuid(), componentDto.uuid()), null);
ProjectData projectData = db.components().insertPrivateProject("PROJECT_1");
CeTaskSubmit taskSubmit = createTaskSubmit(CeTaskTypes.REPORT, Component.fromDto(projectData.getMainBranchDto()), null);

CeTask task = underTest.submit(taskSubmit);

verifyCeTask(taskSubmit, task, componentDto, null);
verifyCeTask(taskSubmit, task, projectData.getProjectDto(), projectData.getMainBranchDto(), null);
}

@Test
@@ -106,7 +109,7 @@ public class CeQueueImplIT {

CeTask task = underTest.submit(taskSubmit);

verifyCeTask(taskSubmit, task, null, null);
verifyCeTask(taskSubmit, task, null, null, null);
}

@Test
@@ -116,7 +119,7 @@ public class CeQueueImplIT {

CeTask task = underTest.submit(taskSubmit);

verifyCeTask(taskSubmit, task, null, userDto);
verifyCeTask(taskSubmit, task, null, null, userDto);
}

@Test
@@ -124,7 +127,7 @@ public class CeQueueImplIT {
CeTaskSubmit taskSubmit = createTaskSubmit("no_component");
CeQueueDto dto = insertPendingInQueue(null);

Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_MAIN_COMPONENT);
Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_ENTITY);

assertThat(task).isNotEmpty();
assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession()))
@@ -139,7 +142,7 @@ public class CeQueueImplIT {
CeTaskSubmit taskSubmit = createTaskSubmit("with_component", newComponent(mainComponentUuid), null);
CeQueueDto dto = insertPendingInQueue(newComponent(otherMainComponentUuid));

Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_MAIN_COMPONENT);
Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_ENTITY);

assertThat(task).isNotEmpty();
assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession()))
@@ -153,7 +156,7 @@ public class CeQueueImplIT {
CeTaskSubmit taskSubmit = createTaskSubmit("with_component", newComponent(mainComponentUuid), null);
CeQueueDto dto = insertPendingInQueue(newComponent(mainComponentUuid));

Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_MAIN_COMPONENT);
Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_ENTITY);

assertThat(task).isEmpty();
assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession()))
@@ -170,7 +173,7 @@ public class CeQueueImplIT {
.map(CeQueueDto::getUuid)
.toArray(String[]::new);

Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_MAIN_COMPONENT);
Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_ENTITY);

assertThat(task).isEmpty();
assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession()))
@@ -235,38 +238,38 @@ public class CeQueueImplIT {
List<CeTask> tasks = underTest.massSubmit(asList(taskSubmit1, taskSubmit2));

assertThat(tasks).hasSize(2);
verifyCeTask(taskSubmit1, tasks.get(0), null, userDto1);
verifyCeTask(taskSubmit2, tasks.get(1), null, null);
verifyCeTask(taskSubmit1, tasks.get(0), null, null, userDto1);
verifyCeTask(taskSubmit2, tasks.get(1), null, null, null);
verifyCeQueueDtoForTaskSubmit(taskSubmit1);
verifyCeQueueDtoForTaskSubmit(taskSubmit2);
}

@Test
public void massSubmit_populates_component_name_and_key_of_CeTask_if_project_exists() {
ComponentDto componentDto1 = insertComponent(ComponentTesting.newPrivateProjectDto("PROJECT_1"));
CeTaskSubmit taskSubmit1 = createTaskSubmit(CeTaskTypes.REPORT, Component.fromDto(componentDto1.uuid(), componentDto1.uuid()), null);
ProjectData projectData = db.components().insertPrivateProject("PROJECT_1");
CeTaskSubmit taskSubmit1 = createTaskSubmit(CeTaskTypes.REPORT, Component.fromDto(projectData.getMainBranchDto()), null);
CeTaskSubmit taskSubmit2 = createTaskSubmit("something", newComponent(randomAlphabetic(12)), null);

List<CeTask> tasks = underTest.massSubmit(asList(taskSubmit1, taskSubmit2));

assertThat(tasks).hasSize(2);
verifyCeTask(taskSubmit1, tasks.get(0), componentDto1, null);
verifyCeTask(taskSubmit2, tasks.get(1), null, null);
verifyCeTask(taskSubmit1, tasks.get(0), projectData.getProjectDto(), projectData.getMainBranchDto(), null);
verifyCeTask(taskSubmit2, tasks.get(1), null, null, null);
}

@Test
public void massSubmit_populates_component_name_and_key_of_CeTask_if_project_and_branch_exists() {
ComponentDto project = db.components().insertPublicProject(p -> p.setUuid("PROJECT_1").setBranchUuid("PROJECT_1")).getMainBranchComponent();
ComponentDto branch1 = db.components().insertProjectBranch(project);
ComponentDto branch2 = db.components().insertProjectBranch(project);
CeTaskSubmit taskSubmit1 = createTaskSubmit(CeTaskTypes.REPORT, Component.fromDto(branch1.uuid(), project.uuid()), null);
CeTaskSubmit taskSubmit2 = createTaskSubmit("something", Component.fromDto(branch2.uuid(), project.uuid()), null);
ProjectDto project = db.components().insertPublicProject(p -> p.setUuid("PROJECT_1").setBranchUuid("PROJECT_1")).getProjectDto();
BranchDto branch1 = db.components().insertProjectBranch(project);
BranchDto branch2 = db.components().insertProjectBranch(project);
CeTaskSubmit taskSubmit1 = createTaskSubmit(CeTaskTypes.REPORT, Component.fromDto(branch1.getUuid(), project.getUuid()), null);
CeTaskSubmit taskSubmit2 = createTaskSubmit("something", Component.fromDto(branch2.getUuid(), project.getUuid()), null);

List<CeTask> tasks = underTest.massSubmit(asList(taskSubmit1, taskSubmit2));

assertThat(tasks).hasSize(2);
verifyCeTask(taskSubmit1, tasks.get(0), branch1, project, null);
verifyCeTask(taskSubmit2, tasks.get(1), branch2, project, null);
verifyCeTask(taskSubmit1, tasks.get(0), project, branch1, null);
verifyCeTask(taskSubmit2, tasks.get(1), project, branch2, null);
}

@Test
@@ -274,7 +277,7 @@ public class CeQueueImplIT {
CeTaskSubmit taskSubmit = createTaskSubmit("no_component");
CeQueueDto dto = insertPendingInQueue(null);

List<CeTask> tasks = underTest.massSubmit(of(taskSubmit), UNIQUE_QUEUE_PER_MAIN_COMPONENT);
List<CeTask> tasks = underTest.massSubmit(of(taskSubmit), UNIQUE_QUEUE_PER_ENTITY);

assertThat(tasks).hasSize(1);
assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession()))
@@ -289,7 +292,7 @@ public class CeQueueImplIT {
CeTaskSubmit taskSubmit = createTaskSubmit("with_component", newComponent(mainComponentUuid), null);
CeQueueDto dto = insertPendingInQueue(newComponent(otherMainComponentUuid));

List<CeTask> tasks = underTest.massSubmit(of(taskSubmit), UNIQUE_QUEUE_PER_MAIN_COMPONENT);
List<CeTask> tasks = underTest.massSubmit(of(taskSubmit), UNIQUE_QUEUE_PER_ENTITY);

assertThat(tasks).hasSize(1);
assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession()))
@@ -303,7 +306,7 @@ public class CeQueueImplIT {
CeTaskSubmit taskSubmit = createTaskSubmit("with_component", newComponent(mainComponentUuid), null);
CeQueueDto dto = insertPendingInQueue(newComponent(mainComponentUuid));

List<CeTask> tasks = underTest.massSubmit(of(taskSubmit), UNIQUE_QUEUE_PER_MAIN_COMPONENT);
List<CeTask> tasks = underTest.massSubmit(of(taskSubmit), UNIQUE_QUEUE_PER_ENTITY);

assertThat(tasks).isEmpty();
assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession()))
@@ -320,7 +323,7 @@ public class CeQueueImplIT {
.map(CeQueueDto::getUuid)
.toArray(String[]::new);

List<CeTask> tasks = underTest.massSubmit(of(taskSubmit), UNIQUE_QUEUE_PER_MAIN_COMPONENT);
List<CeTask> tasks = underTest.massSubmit(of(taskSubmit), UNIQUE_QUEUE_PER_ENTITY);

assertThat(tasks).isEmpty();
assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession()))
@@ -382,13 +385,13 @@ public class CeQueueImplIT {
CeTaskSubmit taskSubmit5 = createTaskSubmit("with_pending_2", newComponent(mainComponentUuid5), null);
CeQueueDto dto5 = insertPendingInQueue(newComponent(mainComponentUuid5));

List<CeTask> tasks = underTest.massSubmit(of(taskSubmit1, taskSubmit2, taskSubmit3, taskSubmit4, taskSubmit5), UNIQUE_QUEUE_PER_MAIN_COMPONENT);
List<CeTask> tasks = underTest.massSubmit(of(taskSubmit1, taskSubmit2, taskSubmit3, taskSubmit4, taskSubmit5), UNIQUE_QUEUE_PER_ENTITY);

assertThat(tasks)
.hasSize(2)
.extracting(task -> task.getComponent().get().getUuid(), task -> task.getMainComponent().get().getUuid())
.containsOnly(tuple(componentForMainComponentUuid2.getUuid(), componentForMainComponentUuid2.getMainComponentUuid()),
tuple(componentForMainComponentUuid4.getUuid(), componentForMainComponentUuid4.getMainComponentUuid()));
.extracting(task -> task.getComponent().get().getUuid(), task -> task.getEntity().get().getUuid())
.containsOnly(tuple(componentForMainComponentUuid2.getUuid(), componentForMainComponentUuid2.getEntityUuid()),
tuple(componentForMainComponentUuid4.getUuid(), componentForMainComponentUuid4.getEntityUuid()));
assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession()))
.extracting(CeQueueDto::getUuid)
.hasSize(1 + uuids3.length + 1 + tasks.size())
@@ -565,31 +568,27 @@ public class CeQueueImplIT {
.hasMessage("Task is not in-progress and can't be marked as failed [uuid=" + task.getUuid() + "]");
}

private void verifyCeTask(CeTaskSubmit taskSubmit, CeTask task, @Nullable ComponentDto componentDto, UserDto userDto) {
verifyCeTask(taskSubmit, task, componentDto, componentDto, userDto);
}

private void verifyCeTask(CeTaskSubmit taskSubmit, CeTask task, @Nullable ComponentDto componentDto, @Nullable ComponentDto mainComponentDto, @Nullable UserDto userDto) {
private void verifyCeTask(CeTaskSubmit taskSubmit, CeTask task, @Nullable EntityDto entityDto, @Nullable BranchDto branch, @Nullable UserDto userDto) {
assertThat(task.getUuid()).isEqualTo(taskSubmit.getUuid());
if (componentDto != null) {
if (branch != null) {
CeTask.Component component = task.getComponent().get();
assertThat(component.getUuid()).isEqualTo(componentDto.uuid());
assertThat(component.getKey()).contains(componentDto.getKey());
assertThat(component.getName()).contains(componentDto.name());
assertThat(component.getUuid()).isEqualTo(branch.getUuid());
assertThat(component.getKey()).contains(entityDto.getKey());
assertThat(component.getName()).contains(entityDto.getName());
} else if (taskSubmit.getComponent().isPresent()) {
assertThat(task.getComponent()).contains(new CeTask.Component(taskSubmit.getComponent().get().getUuid(), null, null));
} else {
assertThat(task.getComponent()).isEmpty();
}
if (mainComponentDto != null) {
CeTask.Component component = task.getMainComponent().get();
assertThat(component.getUuid()).isEqualTo(mainComponentDto.uuid());
assertThat(component.getKey()).contains(mainComponentDto.getKey());
assertThat(component.getName()).contains(mainComponentDto.name());
if (entityDto != null) {
CeTask.Component component = task.getEntity().get();
assertThat(component.getUuid()).isEqualTo(entityDto.getUuid());
assertThat(component.getKey()).contains(entityDto.getKey());
assertThat(component.getName()).contains(entityDto.getName());
} else if (taskSubmit.getComponent().isPresent()) {
assertThat(task.getMainComponent()).contains(new CeTask.Component(taskSubmit.getComponent().get().getMainComponentUuid(), null, null));
assertThat(task.getEntity()).contains(new CeTask.Component(taskSubmit.getComponent().get().getEntityUuid(), null, null));
} else {
assertThat(task.getMainComponent()).isEmpty();
assertThat(task.getEntity()).isEmpty();
}
assertThat(task.getType()).isEqualTo(taskSubmit.getType());
if (taskSubmit.getSubmitterUuid() != null) {
@@ -610,7 +609,7 @@ public class CeQueueImplIT {
Optional<Component> component = taskSubmit.getComponent();
if (component.isPresent()) {
assertThat(queueDto.get().getComponentUuid()).isEqualTo(component.get().getUuid());
assertThat(queueDto.get().getMainComponentUuid()).isEqualTo(component.get().getMainComponentUuid());
assertThat(queueDto.get().getEntityUuid()).isEqualTo(component.get().getEntityUuid());
} else {
assertThat(queueDto.get().getComponentUuid()).isNull();
assertThat(queueDto.get().getComponentUuid()).isNull();
@@ -653,7 +652,7 @@ public class CeQueueImplIT {
.setStatus(CeQueueDto.Status.PENDING);
if (component != null) {
dto.setComponentUuid(component.getUuid())
.setMainComponentUuid(component.getMainComponentUuid());
.setEntityUuid(component.getEntityUuid());
}
db.getDbClient().ceQueueDao().insert(db.getSession(), dto);
db.commit();

+ 2
- 2
server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueue.java View File

@@ -59,7 +59,7 @@ public interface CeQueue {
* <p>
* This method is equivalent to calling {@code massSubmit(Collections.singletonList(submission))}.
*
* @return empty if {@code options} contains {@link SubmitOption#UNIQUE_QUEUE_PER_MAIN_COMPONENT UNIQUE_QUEUE_PER_MAIN_COMPONENT}
* @return empty if {@code options} contains {@link SubmitOption#UNIQUE_QUEUE_PER_ENTITY UNIQUE_QUEUE_PER_MAIN_COMPONENT}
* and there's already a queued task, otherwise the created task.
*/
Optional<CeTask> submit(CeTaskSubmit submission, SubmitOption... options);
@@ -124,7 +124,7 @@ public interface CeQueue {
int clear();

enum SubmitOption {
UNIQUE_QUEUE_PER_MAIN_COMPONENT,
UNIQUE_QUEUE_PER_ENTITY,
UNIQUE_QUEUE_PER_TASK_TYPE
}


+ 37
- 38
server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueueImpl.java View File

@@ -32,7 +32,6 @@ import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.api.server.ServerSide;
@@ -49,15 +48,15 @@ import org.sonar.db.ce.CeTaskCharacteristicDto;
import org.sonar.db.ce.CeTaskQuery;
import org.sonar.db.ce.DeleteIf;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.entity.EntityDto;
import org.sonar.db.user.UserDto;
import org.sonar.server.platform.NodeInformation;
import org.sonar.server.property.InternalProperties;

import static com.google.common.base.Preconditions.checkState;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singleton;
import static java.util.Optional.ofNullable;
import static org.sonar.ce.queue.CeQueue.SubmitOption.UNIQUE_QUEUE_PER_MAIN_COMPONENT;
import static org.sonar.ce.queue.CeQueue.SubmitOption.UNIQUE_QUEUE_PER_ENTITY;
import static org.sonar.core.util.stream.MoreCollectors.toEnumSet;
import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
import static org.sonar.db.ce.CeQueueDto.Status.IN_PROGRESS;
@@ -105,14 +104,14 @@ public class CeQueueImpl implements CeQueue {
CeTaskQuery query = new CeTaskQuery();
for (SubmitOption option : submitOptions) {
switch (option) {
case UNIQUE_QUEUE_PER_MAIN_COMPONENT -> submission.getComponent()
.flatMap(component -> Optional.ofNullable(component.getMainComponentUuid()))
.ifPresent(mainComponentUuid -> query.setMainComponentUuid(mainComponentUuid).setStatuses(List.of(PENDING.name())));
case UNIQUE_QUEUE_PER_ENTITY -> submission.getComponent()
.flatMap(component -> Optional.ofNullable(component.getEntityUuid()))
.ifPresent(entityUuid -> query.setEntityUuid(entityUuid).setStatuses(List.of(PENDING.name())));
case UNIQUE_QUEUE_PER_TASK_TYPE -> query.setType(submission.getType());
}
}

boolean queryNonEmpty = query.getMainComponentUuids() != null || query.getStatuses() != null || query.getType() != null;
boolean queryNonEmpty = query.getEntityUuids() != null || query.getStatuses() != null || query.getType() != null;
if (queryNonEmpty && dbClient.ceQueueDao().countByQuery(dbSession, query) > 0) {
return Optional.empty();
}
@@ -121,26 +120,22 @@ public class CeQueueImpl implements CeQueue {
}

private CeTask convertQueueDtoToTask(DbSession dbSession, CeQueueDto queueDto, CeTaskSubmit submission) {
Map<String, ComponentDto> componentsByUuid = loadComponentDtos(dbSession, queueDto);
if (componentsByUuid.isEmpty()) {
return convertToTask(dbSession, queueDto, submission.getCharacteristics(), null, null);
}
return convertToTask(dbSession, queueDto, submission.getCharacteristics(),
ofNullable(queueDto.getComponentUuid()).map(componentsByUuid::get).orElse(null),
ofNullable(queueDto.getMainComponentUuid()).map(componentsByUuid::get).orElse(null));
return convertToTask(dbSession, queueDto, submission.getCharacteristics());
}

Map<String, ComponentDto> loadComponentDtos(DbSession dbSession, CeQueueDto taskDto) {
Set<String> componentUuids = Stream.of(taskDto.getComponentUuid(), taskDto.getMainComponentUuid())
.filter(Objects::nonNull)
.collect(MoreCollectors.toSet(2));
if (componentUuids.isEmpty()) {
return emptyMap();
protected CeTask convertToTask(DbSession dbSession, CeQueueDto queueDto, Map<String, String> characteristicDto) {
ComponentDto component = null;
EntityDto entity = null;

if (queueDto.getComponentUuid() != null) {
component = dbClient.componentDao().selectByUuid(dbSession, queueDto.getComponentUuid()).orElse(null);
}
if (queueDto.getEntityUuid() != null) {
entity = dbClient.entityDao().selectByUuid(dbSession, queueDto.getEntityUuid()).orElse(null);
}

return convertToTask(dbSession, queueDto, characteristicDto, component, entity);

return dbClient.componentDao().selectByUuids(dbSession, componentUuids)
.stream()
.collect(uniqueIndex(ComponentDto::uuid, 2));
}

@Override
@@ -163,12 +158,12 @@ public class CeQueueImpl implements CeQueue {
private Predicate<CeTaskSubmit> filterBySubmitOptions(SubmitOption[] options, Collection<CeTaskSubmit> submissions, DbSession dbSession) {
EnumSet<SubmitOption> submitOptions = toSet(options);

if (submitOptions.contains(UNIQUE_QUEUE_PER_MAIN_COMPONENT)) {
if (submitOptions.contains(UNIQUE_QUEUE_PER_ENTITY)) {
Set<String> mainComponentUuids = submissions.stream()
.map(CeTaskSubmit::getComponent)
.filter(Optional::isPresent)
.map(Optional::get)
.map(CeTaskSubmit.Component::getMainComponentUuid)
.map(CeTaskSubmit.Component::getEntityUuid)
.collect(MoreCollectors.toSet(submissions.size()));
if (mainComponentUuids.isEmpty()) {
return t -> true;
@@ -183,13 +178,13 @@ public class CeQueueImpl implements CeQueue {
private final Map<String, Integer> queuedItemsByMainComponentUuid;

private NoPendingTaskFilter(DbSession dbSession, Set<String> projectUuids) {
queuedItemsByMainComponentUuid = dbClient.ceQueueDao().countByStatusAndMainComponentUuids(dbSession, PENDING, projectUuids);
queuedItemsByMainComponentUuid = dbClient.ceQueueDao().countByStatusAndEntityUuids(dbSession, PENDING, projectUuids);
}

@Override
public boolean test(CeTaskSubmit ceTaskSubmit) {
return ceTaskSubmit.getComponent()
.map(component -> queuedItemsByMainComponentUuid.getOrDefault(component.getMainComponentUuid(), 0) == 0)
.map(component -> queuedItemsByMainComponentUuid.getOrDefault(component.getEntityUuid(), 0) == 0)
.orElse(true);
}
}
@@ -217,7 +212,7 @@ public class CeQueueImpl implements CeQueue {
dto.setTaskType(submission.getType());
submission.getComponent().ifPresent(component -> dto
.setComponentUuid(component.getUuid())
.setMainComponentUuid(component.getMainComponentUuid()));
.setEntityUuid(component.getEntityUuid()));
dto.setStatus(PENDING);
dto.setSubmitterUuid(submission.getSubmitterUuid());
dbClient.ceQueueDao().insert(dbSession, dto);
@@ -228,12 +223,16 @@ public class CeQueueImpl implements CeQueue {
private List<CeTask> loadTasks(DbSession dbSession, List<CeQueueDto> dtos) {
// load components, if defined
Set<String> componentUuids = dtos.stream()
.flatMap(dto -> Stream.of(dto.getComponentUuid(), dto.getMainComponentUuid()))
.map(CeQueueDto::getComponentUuid)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
// these components correspond to a branch or a portfolio (analysis target)
Map<String, ComponentDto> componentsByUuid = dbClient.componentDao()
.selectByUuids(dbSession, componentUuids).stream()
.collect(uniqueIndex(ComponentDto::uuid));
Set<String> entityUuids = dtos.stream().map(CeQueueDto::getEntityUuid).filter(Objects::nonNull).collect(Collectors.toSet());
Map<String, EntityDto> entitiesByUuid = dbClient.entityDao().selectByUuids(dbSession, entityUuids).stream()
.collect(Collectors.toMap(EntityDto::getUuid, e -> e));

// load characteristics
// TODO could be avoided, characteristics are already present in submissions
@@ -247,12 +246,12 @@ public class CeQueueImpl implements CeQueue {
ComponentDto component = ofNullable(dto.getComponentUuid())
.map(componentsByUuid::get)
.orElse(null);
ComponentDto mainComponent = ofNullable(dto.getMainComponentUuid())
.map(componentsByUuid::get)
EntityDto entity = ofNullable(dto.getEntityUuid())
.map(entitiesByUuid::get)
.orElse(null);
Map<String, String> characteristics = characteristicsByTaskUuid.get(dto.getUuid()).stream()
.collect(uniqueIndex(CeTaskCharacteristicDto::getKey, CeTaskCharacteristicDto::getValue));
result.add(convertToTask(dbSession, dto, characteristics, component, mainComponent));
result.add(convertToTask(dbSession, dto, characteristics, component, entity));
}
return result;
}
@@ -366,7 +365,7 @@ public class CeQueueImpl implements CeQueue {
return cancelAll(true);
}

CeTask convertToTask(DbSession dbSession, CeQueueDto taskDto, Map<String, String> characteristics, @Nullable ComponentDto component, @Nullable ComponentDto mainComponent) {
CeTask convertToTask(DbSession dbSession, CeQueueDto taskDto, Map<String, String> characteristics, @Nullable ComponentDto component, @Nullable EntityDto entity) {
CeTask.Builder builder = new CeTask.Builder()
.setUuid(taskDto.getUuid())
.setType(taskDto.getTaskType())
@@ -380,11 +379,11 @@ public class CeQueueImpl implements CeQueue {
builder.setComponent(new CeTask.Component(componentUuid, null, null));
}

String mainComponentUuid = taskDto.getMainComponentUuid();
if (mainComponent != null) {
builder.setMainComponent(new CeTask.Component(mainComponent.uuid(), mainComponent.getKey(), mainComponent.name()));
} else if (mainComponentUuid != null) {
builder.setMainComponent(new CeTask.Component(mainComponentUuid, null, null));
String entityUuid = taskDto.getEntityUuid();
if (entity != null) {
builder.setEntity(new CeTask.Component(entity.getUuid(), entity.getKey(), entity.getName()));
} else if (entityUuid != null) {
builder.setEntity(new CeTask.Component(entityUuid, null, null));
}

return builder.build();

+ 11
- 20
server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeTaskSubmit.java View File

@@ -27,7 +27,6 @@ import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import org.sonar.db.component.BranchDto;
import org.sonar.db.portfolio.PortfolioDto;
import org.sonar.db.project.ProjectDto;

import static com.google.common.base.Strings.emptyToNull;
import static com.google.common.base.Strings.nullToEmpty;
@@ -116,20 +115,16 @@ public final class CeTaskSubmit {
}

public static class Component {
private String uuid;
private String mainComponentUuid;
private final String uuid;
private final String entityUuid;

public Component(String uuid, String mainComponentUuid) {
public Component(String uuid, String entityUuid) {
this.uuid = requireNonNull(nullToEmpty(uuid), "uuid can't be null");
this.mainComponentUuid = requireNonNull(nullToEmpty(mainComponentUuid), "mainComponentUuid can't be null");
}

public static Component fromDto(String componentUuid, String mainComponentUuid) {
return new Component(componentUuid, mainComponentUuid);
this.entityUuid = requireNonNull(nullToEmpty(entityUuid), "mainComponentUuid can't be null");
}

public static Component fromDto(ProjectDto dto) {
return new Component(dto.getUuid(), dto.getUuid());
public static Component fromDto(String componentUuid, String entityUuid) {
return new Component(componentUuid, entityUuid);
}

public static Component fromDto(PortfolioDto dto) {
@@ -140,23 +135,19 @@ public final class CeTaskSubmit {
return new Component(dto.getUuid(), dto.getProjectUuid());
}

public static Component fromProjectUuid(String projectUuid) {
return new Component(projectUuid, projectUuid);
}

public String getUuid() {
return uuid;
}

public String getMainComponentUuid() {
return mainComponentUuid;
public String getEntityUuid() {
return entityUuid;
}

@Override
public String toString() {
return "Component{" +
"uuid='" + uuid + '\'' +
", mainComponentUuid='" + mainComponentUuid + '\'' +
", entityUuid='" + entityUuid + '\'' +
'}';
}

@@ -169,12 +160,12 @@ public final class CeTaskSubmit {
return false;
}
Component component = (Component) o;
return uuid.equals(component.uuid) && mainComponentUuid.equals(component.mainComponentUuid);
return uuid.equals(component.uuid) && entityUuid.equals(component.entityUuid);
}

@Override
public int hashCode() {
return Objects.hash(uuid, mainComponentUuid);
return Objects.hash(uuid, entityUuid);
}
}
}

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/component/BranchPersisterImplIT.java View File

@@ -63,7 +63,7 @@ public class BranchPersisterImplIT {
@Rule
public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();


+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/component/ComponentUuidFactoryImplIT.java View File

@@ -39,7 +39,7 @@ public class ComponentUuidFactoryImplIT {
private final Branch mockedBranch = mock(Branch.class);

@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
public DbTester db = DbTester.create(System2.INSTANCE, true);

@Test
public void getOrCreateForKey_when_existingComponentsInDbForMainBranch_should_load() {

+ 5
- 5
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/component/ProjectPersisterIT.java View File

@@ -48,7 +48,7 @@ public class ProjectPersisterIT {
@Rule
public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
public TestSystem2 system2 = new TestSystem2();
@@ -74,8 +74,8 @@ public class ProjectPersisterIT {

@Test
public void update_description() {
ProjectDto p1 = dbTester.components().insertPublicProject(
c -> c.setUuid("PROJECT_UUID").setKey(ROOT.getKey()).setName(ROOT.getName()).setDescription("OLD_DESC")).getProjectDto();
ProjectDto p1 = dbTester.components().insertPublicProject("PROJECT_UUID",
p -> p.setKey(ROOT.getKey()).setName(ROOT.getName()).setDescription("OLD_DESC")).getProjectDto();

assertProject("OLD_DESC", ROOT.getName(), p1.getUpdatedAt());
underTest.persist(dbTester.getSession());
@@ -84,8 +84,8 @@ public class ProjectPersisterIT {

@Test
public void update_name() {
ProjectDto p1 = dbTester.components().insertPublicProject(
c -> c.setUuid("PROJECT_UUID").setKey(ROOT.getKey()).setName("OLD_NAME").setDescription(ROOT.getDescription())).getProjectDto();
ProjectDto p1 = dbTester.components().insertPublicProject("PROJECT_UUID",
p -> p.setKey(ROOT.getKey()).setName("OLD_NAME").setDescription(ROOT.getDescription())).getProjectDto();

assertProject(ROOT.getDescription(), "OLD_NAME", p1.getUpdatedAt());
underTest.persist(dbTester.getSession());

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/component/ReferenceBranchComponentUuidsIT.java View File

@@ -40,7 +40,7 @@ public class ReferenceBranchComponentUuidsIT {
public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();

@Rule
public DbTester db = DbTester.create();
public DbTester db = DbTester.create(true);

private ReferenceBranchComponentUuids underTest;
private Branch branch = mock(Branch.class);

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/component/SiblingComponentsWithOpenIssuesIT.java View File

@@ -45,7 +45,7 @@ public class SiblingComponentsWithOpenIssuesIT {
public AnalysisMetadataHolderRule metadataHolder = new AnalysisMetadataHolderRule();

@Rule
public DbTester db = DbTester.create();
public DbTester db = DbTester.create(true);

private SiblingComponentsWithOpenIssues underTest;


+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStepIT.java View File

@@ -219,7 +219,7 @@ public class FileMoveDetectionStepIT {
@Rule
public MutableMovedFilesRepositoryRule movedFilesRepository = new MutableMovedFilesRepositoryRule();
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public LogTester logTester = new LogTester();


+ 12
- 7
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/filemove/PullRequestFileMoveDetectionStepIT.java View File

@@ -45,6 +45,8 @@ import org.sonar.db.DbTester;
import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
import org.sonar.db.component.ProjectData;
import org.sonar.db.project.ProjectDto;
import org.sonar.db.source.FileSourceDto;
import org.sonar.server.project.Project;

@@ -84,12 +86,13 @@ public class PullRequestFileMoveDetectionStepIT {
@Rule
public MutableMovedFilesRepositoryRule movedFilesRepository = new MutableMovedFilesRepositoryRule();
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public LogTester logTester = new LogTester();

private ComponentDto branch;
private ComponentDto project;
private ComponentDto mainBranch;
private ProjectDto project;

private final DbClient dbClient = dbTester.getDbClient();
private final AnalysisMetadataHolderRule analysisMetadataHolder = mock(AnalysisMetadataHolderRule.class);
@@ -98,9 +101,11 @@ public class PullRequestFileMoveDetectionStepIT {

@Before
public void setUp() throws Exception {
project = dbTester.components().insertPrivateProject().getMainBranchComponent();
branch = dbTester.components().insertProjectBranch(project, branchDto -> branchDto.setUuid(BRANCH_UUID).setKey(TARGET_BRANCH));
treeRootHolder.setRoot(builder(Component.Type.PROJECT, Integer.parseInt(ROOT_REF)).setUuid(project.uuid()).build());
ProjectData projectData = dbTester.components().insertPrivateProject();
mainBranch = projectData.getMainBranchComponent();
project = projectData.getProjectDto();
branch = dbTester.components().insertProjectBranch(mainBranch, branchDto -> branchDto.setUuid(BRANCH_UUID).setKey(TARGET_BRANCH));
treeRootHolder.setRoot(builder(Component.Type.PROJECT, Integer.parseInt(ROOT_REF)).setUuid(mainBranch.uuid()).build());
}

@Test
@@ -285,7 +290,7 @@ public class PullRequestFileMoveDetectionStepIT {
private void insertFileComponentsInReport(Set<Component> files) {
treeRootHolder
.setRoot(builder(PROJECT, Integer.parseInt(ROOT_REF))
.setUuid(project.uuid())
.setUuid(mainBranch.uuid())
.addChildren(files.toArray(Component[]::new))
.build());
}
@@ -306,7 +311,7 @@ public class PullRequestFileMoveDetectionStepIT {

private ComponentDto composeComponentDto(String uuid) {
return ComponentTesting
.newFileDto(project)
.newFileDto(mainBranch)
.setBranchUuid(branch.uuid())
.setKey("key_" + uuid)
.setUuid(uuid)

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/AdHocRuleCreatorIT.java View File

@@ -39,7 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat;
public class AdHocRuleCreatorIT {

@org.junit.Rule
public DbTester db = DbTester.create(System2.INSTANCE);
public DbTester db = DbTester.create(System2.INSTANCE, true);
@org.junit.Rule
public EsTester es = EsTester.create();


+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/ComponentIssuesLoaderIT.java View File

@@ -69,7 +69,7 @@ public class ComponentIssuesLoaderIT {
private static final Date DATE_LIMIT_30_DAYS_BACK_MIDNIGHT = parseDateTime("2018-07-18T00:00:00+0000");

@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
public DbTester db = DbTester.create(System2.INSTANCE, true);

private final DbClient dbClient = db.getDbClient();
private final System2 system2 = mock(System2.class);

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/DefaultAssigneeIT.java View File

@@ -36,7 +36,7 @@ public class DefaultAssigneeIT {
public static final String PROJECT_KEY = "PROJECT_KEY";

@Rule
public DbTester db = DbTester.create();
public DbTester db = DbTester.create(true);

private final MapSettings settings = new MapSettings();
private final ConfigurationRepository settingsRepository = new TestSettingsRepository(settings.asConfig());

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/IntegrateIssuesVisitorIT.java View File

@@ -103,7 +103,7 @@ public class IntegrateIssuesVisitorIT {
@Rule
public TemporaryFolder temp = new TemporaryFolder();
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
@Rule

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/ProjectTrackerBaseLazyInputIT.java View File

@@ -48,7 +48,7 @@ public class ProjectTrackerBaseLazyInputIT {
@Rule
public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule().setAnalysisDate(ANALYSIS_DATE);
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public ActiveRulesHolderRule activeRulesHolderRule = new ActiveRulesHolderRule();
@Rule

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/ScmAccountToUserLoaderIT.java View File

@@ -36,7 +36,7 @@ import static org.junit.Assert.fail;
public class ScmAccountToUserLoaderIT {

@Rule
public DbTester db = DbTester.create();
public DbTester db = DbTester.create(true);
@Rule
public EsTester es = EsTester.create();
@Rule

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssueMergerIT.java View File

@@ -62,7 +62,7 @@ public class SiblingsIssueMergerIT {
private final Branch branch = mock(Branch.class);

@Rule
public DbTester db = DbTester.create();
public DbTester db = DbTester.create(true);

@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule()

+ 5
- 3
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/SourceBranchComponentUuidsIT.java View File

@@ -28,6 +28,7 @@ import org.sonar.db.DbTester;
import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
import org.sonar.db.component.ProjectData;
import org.sonar.db.protobuf.DbProjectBranches;
import org.sonar.server.project.Project;

@@ -45,7 +46,7 @@ public class SourceBranchComponentUuidsIT {
public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();

@Rule
public DbTester db = DbTester.create();
public DbTester db = DbTester.create(true);

private SourceBranchComponentUuids underTest;
private final Branch branch = mock(Branch.class);
@@ -60,8 +61,9 @@ public class SourceBranchComponentUuidsIT {
analysisMetadataHolder.setProject(project);
analysisMetadataHolder.setBranch(branch);

ComponentDto projectDto = db.components().insertPublicProject().getMainBranchComponent();
when(project.getUuid()).thenReturn(projectDto.uuid());
ProjectData projectData = db.components().insertPublicProject();
ComponentDto projectDto = projectData.getMainBranchComponent();
when(project.getUuid()).thenReturn(projectData.projectUuid());
branch1 = db.components().insertProjectBranch(projectDto, b -> b.setKey(BRANCH_KEY));
ComponentDto pr1branch = db.components().insertProjectBranch(projectDto, b -> b.setKey(PR_KEY)
.setBranchType(BranchType.PULL_REQUEST)

+ 8
- 6
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/TargetBranchComponentUuidsIT.java View File

@@ -28,6 +28,7 @@ import org.sonar.db.DbTester;
import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
import org.sonar.db.component.ProjectData;
import org.sonar.db.protobuf.DbProjectBranches;
import org.sonar.server.project.Project;

@@ -44,7 +45,7 @@ public class TargetBranchComponentUuidsIT {
public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();

@Rule
public DbTester db = DbTester.create();
public DbTester db = DbTester.create(true);

private TargetBranchComponentUuids underTest;
private final Branch branch = mock(Branch.class);
@@ -59,13 +60,14 @@ public class TargetBranchComponentUuidsIT {
analysisMetadataHolder.setProject(project);
analysisMetadataHolder.setBranch(branch);

ComponentDto projectDto = db.components().insertPublicProject().getMainBranchComponent();
when(project.getUuid()).thenReturn(projectDto.uuid());
branch1 = db.components().insertProjectBranch(projectDto, b -> b.setKey(BRANCH_KEY));
ComponentDto pr1branch = db.components().insertProjectBranch(projectDto, b -> b.setKey(PR_KEY)
ProjectData projectData = db.components().insertPublicProject();
ComponentDto mainBranch = projectData.getMainBranchComponent();
when(project.getUuid()).thenReturn(projectData.projectUuid());
branch1 = db.components().insertProjectBranch(mainBranch, b -> b.setKey(BRANCH_KEY));
ComponentDto pr1branch = db.components().insertProjectBranch(mainBranch, b -> b.setKey(PR_KEY)
.setBranchType(BranchType.PULL_REQUEST)
.setPullRequestData(DbProjectBranches.PullRequestData.newBuilder().setTarget(BRANCH_KEY).build())
.setMergeBranchUuid(projectDto.uuid()));
.setMergeBranchUuid(mainBranch.uuid()));
branch1File = ComponentTesting.newFileDto(branch1, null, "file").setUuid("branch1File");
pr1File = ComponentTesting.newFileDto(pr1branch, null, "file").setUuid("file1");
db.components().insertComponents(branch1File, pr1File);

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/TrackerReferenceBranchInputFactoryIT.java View File

@@ -40,7 +40,7 @@ public class TrackerReferenceBranchInputFactoryIT {
private final static String COMPONENT_UUID = "uuid1";

@Rule
public DbTester db = DbTester.create();
public DbTester db = DbTester.create(true);

private ComponentIssuesLoader componentIssuesLoader = mock(ComponentIssuesLoader.class);
private ReferenceBranchComponentUuids referenceBranchComponentUuids = mock(ReferenceBranchComponentUuids.class);

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/TrackerSourceBranchInputFactoryIT.java View File

@@ -39,7 +39,7 @@ public class TrackerSourceBranchInputFactoryIT {
private final static String COMPONENT_UUID = "uuid1";

@Rule
public DbTester db = DbTester.create();
public DbTester db = DbTester.create(true);

private final ComponentIssuesLoader componentIssuesLoader = mock(ComponentIssuesLoader.class);
private final SourceBranchComponentUuids sourceBranchComponentUuids = mock(SourceBranchComponentUuids.class);

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/TrackerTargetBranchInputFactoryIT.java View File

@@ -44,7 +44,7 @@ public class TrackerTargetBranchInputFactoryIT {
private final static String ORIGINAL_COMPONENT_UUID = "uuid2";

@Rule
public DbTester db = DbTester.create();
public DbTester db = DbTester.create(true);

private final ComponentIssuesLoader componentIssuesLoader = mock(ComponentIssuesLoader.class);
private final TargetBranchComponentUuids targetBranchComponentUuids = mock(TargetBranchComponentUuids.class);

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryImplIT.java View File

@@ -67,7 +67,7 @@ public class MeasureRepositoryImplIT {


@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public BatchReportReaderRule reportReader = new BatchReportReaderRule();


+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/metric/MetricRepositoryImplIT.java View File

@@ -38,7 +38,7 @@ public class MetricRepositoryImplIT {
private static final String SOME_UUID = "uuid";

@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
public DbTester dbTester = DbTester.create(System2.INSTANCE, true);

private DbClient dbClient = dbTester.getDbClient();
private MetricRepositoryImpl underTest = new MetricRepositoryImpl(dbClient);

+ 8
- 7
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/period/NewCodeReferenceBranchComponentUuidsIT.java View File

@@ -27,6 +27,7 @@ import org.sonar.db.DbTester;
import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
import org.sonar.db.component.ProjectData;
import org.sonar.db.newcodeperiod.NewCodePeriodType;
import org.sonar.server.project.Project;

@@ -43,7 +44,7 @@ public class NewCodeReferenceBranchComponentUuidsIT {
@Rule
public PeriodHolderRule periodHolder = new PeriodHolderRule();
@Rule
public DbTester db = DbTester.create();
public DbTester db = DbTester.create(true);

private NewCodeReferenceBranchComponentUuids underTest = new NewCodeReferenceBranchComponentUuids(analysisMetadataHolder, periodHolder, db.getDbClient());

@@ -61,12 +62,12 @@ public class NewCodeReferenceBranchComponentUuidsIT {
public void setUp() {
analysisMetadataHolder.setProject(project);

ComponentDto projectDto = db.components().insertPublicProject().getMainBranchComponent();
when(project.getUuid()).thenReturn(projectDto.uuid());
branch1 = db.components().insertProjectBranch(projectDto, b -> b.setKey("branch1"));
branch2 = db.components().insertProjectBranch(projectDto, b -> b.setKey("branch2"));
pr1 = db.components().insertProjectBranch(projectDto, b -> b.setKey("pr1").setBranchType(BranchType.PULL_REQUEST).setMergeBranchUuid(branch1.uuid()));
pr2 = db.components().insertProjectBranch(projectDto, b -> b.setKey("pr2").setBranchType(BranchType.PULL_REQUEST).setMergeBranchUuid(branch1.uuid()));
ProjectData projectData = db.components().insertPublicProject();
when(project.getUuid()).thenReturn(projectData.projectUuid());
branch1 = db.components().insertProjectBranch(projectData.getMainBranchComponent(), b -> b.setKey("branch1"));
branch2 = db.components().insertProjectBranch(projectData.getMainBranchComponent(), b -> b.setKey("branch2"));
pr1 = db.components().insertProjectBranch(projectData.getMainBranchComponent(), b -> b.setKey("pr1").setBranchType(BranchType.PULL_REQUEST).setMergeBranchUuid(branch1.uuid()));
pr2 = db.components().insertProjectBranch(projectData.getMainBranchComponent(), b -> b.setKey("pr2").setBranchType(BranchType.PULL_REQUEST).setMergeBranchUuid(branch1.uuid()));
branch1File = ComponentTesting.newFileDto(branch1, null, "file").setUuid("branch1File");
branch2File = ComponentTesting.newFileDto(branch2, null, "file").setUuid("branch2File");
pr1File = ComponentTesting.newFileDto(pr1, null, "file").setUuid("file1");

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoDbLoaderIT.java View File

@@ -69,7 +69,7 @@ public class ScmInfoDbLoaderIT {
@Rule
public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public BatchReportReaderRule reportReader = new BatchReportReaderRule();
@Rule

+ 4
- 4
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/source/DbLineHashVersionIT.java View File

@@ -37,11 +37,11 @@ import static org.mockito.Mockito.when;

public class DbLineHashVersionIT {
@Rule
public DbTester db = DbTester.create();
public DbTester db = DbTester.create(true);

private AnalysisMetadataHolder analysisMetadataHolder = mock(AnalysisMetadataHolder.class);
private ReferenceBranchComponentUuids referenceBranchComponentUuids = mock(ReferenceBranchComponentUuids.class);
private DbLineHashVersion underTest = new DbLineHashVersion(db.getDbClient(), analysisMetadataHolder, referenceBranchComponentUuids);
private final AnalysisMetadataHolder analysisMetadataHolder = mock(AnalysisMetadataHolder.class);
private final ReferenceBranchComponentUuids referenceBranchComponentUuids = mock(ReferenceBranchComponentUuids.class);
private final DbLineHashVersion underTest = new DbLineHashVersion(db.getDbClient(), analysisMetadataHolder, referenceBranchComponentUuids);

@Test
public void hasLineHashWithSignificantCode_should_return_true() {

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/source/PersistFileSourcesStepIT.java View File

@@ -66,7 +66,7 @@ public class PersistFileSourcesStepIT extends BaseStepTest {
private final System2 system2 = mock(System2.class);

@Rule
public DbTester dbTester = DbTester.create(system2);
public DbTester dbTester = DbTester.create(system2, true);
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();


+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStepIT.java View File

@@ -86,7 +86,7 @@ public class BuildComponentTreeStepIT {
private static final long ANALYSIS_DATE = 123456789L;

@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public BatchReportReaderRule reportReader = new BatchReportReaderRule().setMetadata(createReportMetadata(NO_SCANNER_PROJECT_VERSION, NO_SCANNER_BUILD_STRING));
@Rule

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/CleanIssueChangesStepIT.java View File

@@ -32,7 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat;

public class CleanIssueChangesStepIT {
@Rule
public DbTester db = DbTester.create();
public DbTester db = DbTester.create(true);
private final IssueChangesToDeleteRepository repository = new IssueChangesToDeleteRepository();
private final CleanIssueChangesStep cleanIssueChangesStep = new CleanIssueChangesStep(repository, db.getDbClient());
private final TestComputationStepContext context = new TestComputationStepContext();

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/EnableAnalysisStepIT.java View File

@@ -43,7 +43,7 @@ public class EnableAnalysisStepIT {
private static final String CURRENT_ANALYSIS_UUID = "ANALYSIS_2";

@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
public DbTester db = DbTester.create(System2.INSTANCE, true);

@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ExtractReportStepIT.java View File

@@ -55,7 +55,7 @@ public class ExtractReportStepIT {


@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
public DbTester dbTester = DbTester.create(System2.INSTANCE, true);

private MutableBatchReportDirectoryHolder reportDirectoryHolder = new BatchReportDirectoryHolderImpl();
private CeTask ceTask = new CeTask.Builder()

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/LoadCrossProjectDuplicationsRepositoryStepIT.java View File

@@ -89,7 +89,7 @@ public class LoadCrossProjectDuplicationsRepositoryStepIT {
private CrossProjectDuplicationStatusHolder crossProjectDuplicationStatusHolder = mock(CrossProjectDuplicationStatusHolder.class);

@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
public DbTester dbTester = DbTester.create(System2.INSTANCE, true);

private DbClient dbClient = dbTester.getDbClient();
private DbSession dbSession = dbTester.getSession();

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/LoadFileHashesAndStatusStepIT.java View File

@@ -43,7 +43,7 @@ import static org.mockito.Mockito.when;

public class LoadFileHashesAndStatusStepIT {
@Rule
public DbTester db = DbTester.create();
public DbTester db = DbTester.create(true);
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
public PreviousSourceHashRepositoryImpl previousFileHashesRepository = new PreviousSourceHashRepositoryImpl();

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/LoadPeriodsStepIT.java View File

@@ -76,7 +76,7 @@ import static org.sonar.db.event.EventTesting.newEvent;
@RunWith(DataProviderRunner.class)
public class LoadPeriodsStepIT extends BaseStepTest {
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
@Rule

+ 13
- 11
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStepIT.java View File

@@ -44,6 +44,7 @@ import org.sonar.core.platform.PluginRepository;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.project.ProjectDto;
import org.sonar.scanner.protocol.output.ScannerReport;
import org.sonar.server.project.DefaultBranchNameResolver;
import org.sonar.server.project.Project;
@@ -62,7 +63,7 @@ public class LoadReportAnalysisMetadataHolderStepIT {
private static final long ANALYSIS_DATE = 123456789L;

@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
public DbTester db = DbTester.create(System2.INSTANCE, true);
@Rule
public BatchReportReaderRule reportReader = new BatchReportReaderRule();
@Rule
@@ -70,14 +71,14 @@ public class LoadReportAnalysisMetadataHolderStepIT {

private final DbClient dbClient = db.getDbClient();
private final TestPluginRepository pluginRepository = new TestPluginRepository();
private ComponentDto project;
private ProjectDto project;
private ComputationStep underTest;

@Before
public void setUp() {
CeTask defaultOrgCeTask = createCeTask(PROJECT_KEY);
underTest = createStep(defaultOrgCeTask);
project = db.components().insertPublicProject(p -> p.setKey(PROJECT_KEY)).getMainBranchComponent();
project = db.components().insertPublicProject(p -> p.setKey(PROJECT_KEY)).getProjectDto();
}

@Test
@@ -127,10 +128,10 @@ public class LoadReportAnalysisMetadataHolderStepIT {
underTest.execute(new TestComputationStepContext());

Project project = analysisMetadataHolder.getProject();
assertThat(project.getUuid()).isEqualTo(this.project.uuid());
assertThat(project.getUuid()).isEqualTo(this.project.getUuid());
assertThat(project.getKey()).isEqualTo(this.project.getKey());
assertThat(project.getName()).isEqualTo(this.project.name());
assertThat(project.getDescription()).isEqualTo(this.project.description());
assertThat(project.getName()).isEqualTo(this.project.getName());
assertThat(project.getDescription()).isEqualTo(this.project.getDescription());
}

@Test
@@ -186,14 +187,14 @@ public class LoadReportAnalysisMetadataHolderStepIT {
CeTask res = mock(CeTask.class);
Optional<CeTask.Component> component = Optional.of(new CeTask.Component("main_prj_uuid", null, null));
when(res.getComponent()).thenReturn(component);
when(res.getMainComponent()).thenReturn(component);
when(res.getEntity()).thenReturn(component);
reportReader.setMetadata(ScannerReport.Metadata.newBuilder().build());

ComputationStep underTest = createStep(res);

assertThatThrownBy(() -> underTest.execute(new TestComputationStepContext()))
.isInstanceOf(MessageException.class)
.hasMessage("Compute Engine task main component key is null. Project with UUID main_prj_uuid must have been deleted since report was uploaded. Can not proceed.");
.hasMessage("Compute Engine task entity key is null. Project with UUID main_prj_uuid must have been deleted since report was uploaded. Can not proceed.");
}

@Test
@@ -201,7 +202,7 @@ public class LoadReportAnalysisMetadataHolderStepIT {
CeTask res = mock(CeTask.class);
Optional<CeTask.Component> component = Optional.of(new CeTask.Component("prj_uuid", null, null));
when(res.getComponent()).thenReturn(component);
when(res.getMainComponent()).thenReturn(Optional.of(new CeTask.Component("main_prj_uuid", "main_prj_key", null)));
when(res.getEntity()).thenReturn(Optional.of(new CeTask.Component("main_prj_uuid", "main_prj_key", null)));
reportReader.setMetadata(ScannerReport.Metadata.newBuilder().build());

ComputationStep underTest = createStep(res);
@@ -308,9 +309,10 @@ public class LoadReportAnalysisMetadataHolderStepIT {

private CeTask createCeTask(String projectKey) {
CeTask res = mock(CeTask.class);
Optional<CeTask.Component> component = Optional.of(new CeTask.Component(projectKey + "_uuid", projectKey, projectKey + "_name"));
Optional<CeTask.Component> entity = Optional.of(new CeTask.Component(projectKey + "_uuid", projectKey, projectKey + "_name"));
Optional<CeTask.Component> component = Optional.of(new CeTask.Component(projectKey + "branch_uuid", projectKey, projectKey + "_name"));
when(res.getComponent()).thenReturn(component);
when(res.getMainComponent()).thenReturn(component);
when(res.getEntity()).thenReturn(entity);
return res;
}


+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistAdHocRulesStepIT.java View File

@@ -45,7 +45,7 @@ import static org.assertj.core.api.Assertions.assertThat;
public class PersistAdHocRulesStepIT extends BaseStepTest {

@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
public DbTester db = DbTester.create(System2.INSTANCE, true);

private DbClient dbClient = db.getDbClient();


+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisPropertiesStepIT.java View File

@@ -64,7 +64,7 @@ public class PersistAnalysisPropertiesStepIT {
private static final String SCM_REV_ID = "sha1";

@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
public DbTester dbTester = DbTester.create(System2.INSTANCE, true);

private BatchReportReader batchReportReader = mock(BatchReportReader.class);
private AnalysisMetadataHolder analysisMetadataHolder = mock(AnalysisMetadataHolder.class);

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistCrossProjectDuplicationIndexStepIT.java View File

@@ -69,7 +69,7 @@ public class PersistCrossProjectDuplicationIndexStepIT {
private static final String BASE_ANALYSIS_UUID = "base analysis uuid";

@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public BatchReportReaderRule reportReader = new BatchReportReaderRule();
@Rule

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistDuplicationDataStepIT.java View File

@@ -59,7 +59,7 @@ public class PersistDuplicationDataStepIT extends BaseStepTest {
private static final String FILE_2_UUID = "u3";

@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
public DbTester db = DbTester.create(System2.INSTANCE, true);
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule()
.setRoot(

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistEventsStepIT.java View File

@@ -77,7 +77,7 @@ public class PersistEventsStepIT extends BaseStepTest {
System2 system2 = mock(System2.class);

@Rule
public DbTester dbTester = DbTester.create(system2);
public DbTester dbTester = DbTester.create(system2, true);
@Rule
public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
@Rule

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepIT.java View File

@@ -80,7 +80,7 @@ public class PersistIssuesStepIT extends BaseStepTest {
@Rule
public TemporaryFolder temp = new TemporaryFolder();
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
public DbTester db = DbTester.create(System2.INSTANCE, true);
@Rule
public BatchReportReaderRule reportReader = new BatchReportReaderRule();
@Rule

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStepIT.java View File

@@ -73,7 +73,7 @@ public class PersistLiveMeasuresStepIT extends BaseStepTest {
private static final int REF_4 = 4;

@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
public DbTester db = DbTester.create(System2.INSTANCE, true);
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
@Rule

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStepIT.java View File

@@ -64,7 +64,7 @@ public class PersistMeasuresStepIT extends BaseStepTest {
private static final int REF_4 = 4;

@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
public DbTester db = DbTester.create(System2.INSTANCE, true);
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
@Rule

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistProjectLinksStepIT.java View File

@@ -58,7 +58,7 @@ public class PersistProjectLinksStepIT extends BaseStepTest {
@Rule
public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
public DbTester db = DbTester.create(System2.INSTANCE, true);
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
@Rule

+ 3
- 3
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistPushEventsStepIT.java View File

@@ -55,7 +55,7 @@ public class PersistPushEventsStepIT {
private final TestSystem2 system2 = new TestSystem2().setNow(1L);

@Rule
public DbTester db = DbTester.create(system2);
public DbTester db = DbTester.create(system2, true);

public final PushEventFactory pushEventFactory = mock(PushEventFactory.class);
@Rule
@@ -143,7 +143,7 @@ public class PersistPushEventsStepIT {

@Test
public void store_push_events_for_branch() {
var project = db.components().insertPrivateProject().getMainBranchComponent();
var project = db.components().insertPrivateProject().getProjectDto();
db.components().insertProjectBranch(project, b -> b.setUuid("uuid_1"));

protoIssueCache.newAppender()
@@ -155,7 +155,7 @@ public class PersistPushEventsStepIT {
.setComponentKey("ck2"))
.close();

when(pushEventFactory.raiseEventOnIssue(eq(project.uuid()), any(DefaultIssue.class))).thenReturn(
when(pushEventFactory.raiseEventOnIssue(eq(project.getUuid()), any(DefaultIssue.class))).thenReturn(
Optional.of(createPushEvent()),
Optional.of(createPushEvent()));


+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistScannerAnalysisCacheStepIT.java View File

@@ -41,7 +41,7 @@ public class PersistScannerAnalysisCacheStepIT {
@Rule
public BatchReportReaderRule reader = new BatchReportReaderRule();
@Rule
public DbTester dbTester = DbTester.create();
public DbTester dbTester = DbTester.create(true);
private final DbClient client = dbTester.getDbClient();
private final TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
private final PersistScannerAnalysisCacheStep step = new PersistScannerAnalysisCacheStep(reader, dbTester.getDbClient(), treeRootHolder);

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistScannerContextStepIT.java View File

@@ -42,7 +42,7 @@ public class PersistScannerContextStepIT {
private static final String ANALYSIS_UUID = "UUID";

@ClassRule
public static final DbTester dbTester = DbTester.create(System2.INSTANCE);
public static final DbTester dbTester = DbTester.create(System2.INSTANCE, true);

@Rule
public BatchReportReaderRule reportReader = new BatchReportReaderRule();

+ 7
- 5
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ProjectNclocComputationStepIT.java View File

@@ -25,9 +25,11 @@ import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule;
import org.sonar.ce.task.step.TestComputationStepContext;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.metric.MetricDto;
import org.sonar.db.project.ProjectDto;
import org.sonar.server.project.Project;

import static java.util.Collections.emptyList;
@@ -36,7 +38,7 @@ import static org.sonar.api.measures.Metric.ValueType.INT;

public class ProjectNclocComputationStepIT {
@Rule
public DbTester db = DbTester.create();
public DbTester db = DbTester.create(true);
private final DbClient dbClient = db.getDbClient();

@Rule
@@ -47,12 +49,12 @@ public class ProjectNclocComputationStepIT {
@Test
public void test_computing_branch_ncloc() {
MetricDto ncloc = db.measures().insertMetric(m -> m.setKey("ncloc").setValueType(INT.toString()));
ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
ComponentDto branch1 = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH));
ProjectDto project = db.components().insertPublicProject().getProjectDto();
BranchDto branch1 = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH));
db.measures().insertLiveMeasure(branch1, ncloc, m -> m.setValue(200d));
ComponentDto branch2 = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH));
BranchDto branch2 = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH));
db.measures().insertLiveMeasure(branch2, ncloc, m -> m.setValue(10d));
analysisMetadataHolder.setProject(new Project(project.uuid(), project.getKey(), project.name(), project.description(), emptyList()));
analysisMetadataHolder.setProject(new Project(project.getUuid(), project.getKey(), project.getName(), project.getDescription(), emptyList()));
step.execute(TestComputationStepContext.TestStatistics::new);

assertThat(dbClient.projectDao().getNclocSum(db.getSession())).isEqualTo(200L);

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ReportPersistAnalysisStepIT.java View File

@@ -54,7 +54,7 @@ public class ReportPersistAnalysisStepIT extends BaseStepTest {
private static final String REVISION_ID = "5f6432a1";

@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
@Rule

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepIT.java View File

@@ -67,7 +67,7 @@ public class ReportPersistComponentsStepIT extends BaseStepTest {
private static final String PROJECT_KEY = "PROJECT_KEY";

@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
public DbTester db = DbTester.create(System2.INSTANCE, true);
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
@Rule

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStepIT.java View File

@@ -134,7 +134,7 @@ public class SendIssueNotificationsStepIT extends BaseStepTest {
@Rule
public TemporaryFolder temp = new TemporaryFolder();
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
public DbTester db = DbTester.create(System2.INSTANCE, true);

private final Random random = new Random();
private final RuleType[] RULE_TYPES_EXCEPT_HOTSPOTS = Stream.of(RuleType.values()).filter(r -> r != SECURITY_HOTSPOT).toArray(RuleType[]::new);

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/UpdateNeedIssueSyncStepIT.java View File

@@ -37,7 +37,7 @@ public class UpdateNeedIssueSyncStepIT {
private static final Component PROJECT = ReportComponent.DUMB_PROJECT;

@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
public DbTester db = DbTester.create(System2.INSTANCE, true);

@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule().setRoot(PROJECT);

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/UpdateQualityProfilesLastUsedDateStepIT.java View File

@@ -58,7 +58,7 @@ public class UpdateQualityProfilesLastUsedDateStepIT {


@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
public DbTester db = DbTester.create(System2.INSTANCE, true);

@Rule
public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule().setAnalysisDate(ANALYSIS_DATE);

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStepIT.java View File

@@ -52,7 +52,7 @@ public class ValidateProjectStepIT {
static final Branch DEFAULT_BRANCH = new DefaultBranchImpl(DEFAULT_MAIN_BRANCH_NAME);

@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
public DbTester db = DbTester.create(System2.INSTANCE, true);
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
@Rule

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistAnalysisStepIT.java View File

@@ -53,7 +53,7 @@ public class ViewsPersistAnalysisStepIT extends BaseStepTest {
private static final String ANALYSIS_UUID = "U1";

@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
@Rule

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepIT.java View File

@@ -80,7 +80,7 @@ public class ViewsPersistComponentsStepIT extends BaseStepTest {
private static final String PROJECT_VIEW_1_UUID = "PV1_UUID";

@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
public DbTester dbTester = DbTester.create(System2.INSTANCE, true);

@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();

+ 2
- 2
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/taskprocessor/AuditPurgeStepIT.java View File

@@ -51,14 +51,14 @@ public class AuditPurgeStepIT {
.setValue(MONTHLY.name());

@Rule
public final DbTester dbTester = DbTester.create(System2.INSTANCE);
public final DbTester dbTester = DbTester.create(System2.INSTANCE, true);

private final DbClient dbClient = dbTester.getDbClient();

private final System2 system2 = new System2();

@Rule
public final DbTester db = DbTester.create(system2);
public final DbTester db = DbTester.create(system2, true);

private final AuditHousekeepingFrequencyHelper auditHousekeepingFrequencyHelper = mock(AuditHousekeepingFrequencyHelper.class);


+ 10
- 9
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/taskprocessor/IgnoreOrphanBranchStepIT.java View File

@@ -33,22 +33,23 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.sonar.db.component.BranchType.BRANCH;

public class IgnoreOrphanBranchStepIT {
private String BRANCH_UUID = "branch_uuid";
private final String ENTITY_UUID = "entity_uuid";
private final String BRANCH_UUID = "branch_uuid";

@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE, true);

private CeTask.Component component = new CeTask.Component(BRANCH_UUID, "component key", "component name");
private CeTask ceTask = new CeTask.Builder()
private final CeTask.Component entity = new CeTask.Component(ENTITY_UUID, "component key", "component name");
private final CeTask.Component component = new CeTask.Component(BRANCH_UUID, "component key", "component name");
private final CeTask ceTask = new CeTask.Builder()
.setType("type")
.setUuid("uuid")
.setComponent(component)
.setMainComponent(component)
.setEntity(entity)
.build();

private DbClient dbClient = dbTester.getDbClient();
private IgnoreOrphanBranchStep underTest = new IgnoreOrphanBranchStep(ceTask, dbClient);
private final DbClient dbClient = dbTester.getDbClient();
private final IgnoreOrphanBranchStep underTest = new IgnoreOrphanBranchStep(ceTask, dbClient);

@Test
public void execute() {
@@ -94,13 +95,13 @@ public class IgnoreOrphanBranchStepIT {
.setType("type")
.setUuid("uuid")
.setComponent(null)
.setMainComponent(null)
.setEntity(null)
.build();
IgnoreOrphanBranchStep underTest = new IgnoreOrphanBranchStep(ceTask, dbClient);

assertThatThrownBy(() -> underTest.execute(() -> null))
.isInstanceOf(UnsupportedOperationException.class)
.hasMessage("main component not found in task");
.hasMessage("entity not found in task");
}

@Test

+ 11
- 16
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/taskprocessor/IndexIssuesStepIT.java View File

@@ -38,32 +38,27 @@ import static org.mockito.Mockito.verify;
import static org.sonar.db.component.BranchType.BRANCH;

public class IndexIssuesStepIT {

private String BRANCH_UUID = "branch_uuid";

private final String ENTITY_UUID = "entity_uuid";
private final String BRANCH_UUID = "branch_uuid";

@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);

private DbClient dbClient = dbTester.getDbClient();
public DbTester dbTester = DbTester.create(System2.INSTANCE, true);

private CeTask.Component component = new CeTask.Component(BRANCH_UUID, "component key", "component name");
private CeTask ceTask = new CeTask.Builder()
private final DbClient dbClient = dbTester.getDbClient();
private final CeTask.Component entity = new CeTask.Component(ENTITY_UUID, "component key", "component name");
private final CeTask.Component component = new CeTask.Component(BRANCH_UUID, "component key", "component name");
private final CeTask ceTask = new CeTask.Builder()
.setType("type")
.setUuid("uuid")
.setComponent(component)
.setMainComponent(component)
.setEntity(entity)
.build();

@Rule
public EsTester es = EsTester.create();
private System2 system2 = new System2();
@Rule
public DbTester db = DbTester.create(system2);

private IssueIndexer issueIndexer = mock(IssueIndexer.class);

private IndexIssuesStep underTest = new IndexIssuesStep(ceTask, dbClient, issueIndexer);
private final IssueIndexer issueIndexer = mock(IssueIndexer.class);
private final IndexIssuesStep underTest = new IndexIssuesStep(ceTask, dbClient, issueIndexer);

@Test
public void execute() {
@@ -107,7 +102,7 @@ public class IndexIssuesStepIT {
.setType("type")
.setUuid("uuid")
.setComponent(null)
.setMainComponent(null)
.setEntity(null)
.build();
IndexIssuesStep underTest = new IndexIssuesStep(ceTask, dbClient, issueIndexer);


+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/analysis/ExportAnalysesStepIT.java View File

@@ -96,7 +96,7 @@ public class ExportAnalysesStepIT {
.setBranchUuid(PROJECT_UUID);

@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public LogTester logTester = new LogTester();


+ 6
- 16
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/branches/ExportBranchesStepIT.java View File

@@ -42,6 +42,7 @@ import org.sonar.db.DbTester;
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ProjectData;
import org.sonar.db.project.ProjectExportMapper;

import static java.util.stream.Collectors.toMap;
@@ -53,20 +54,9 @@ import static org.sonar.db.component.ComponentDto.UUID_PATH_OF_ROOT;

public class ExportBranchesStepIT {
private static final String PROJECT_UUID = "PROJECT_UUID";
private static final ComponentDto PROJECT = new ComponentDto()
// no id yet
.setScope(Scopes.PROJECT)
.setQualifier(Qualifiers.PROJECT)
.setKey("the_project")
.setName("The Project")
.setDescription("The project description")
.setEnabled(true)
.setUuid(PROJECT_UUID)
.setUuidPath(UUID_PATH_OF_ROOT)
.setBranchUuid(PROJECT_UUID);

@Rule
public DbTester dbTester = DbTester.createWithExtensionMappers(System2.INSTANCE, ProjectExportMapper.class);
public DbTester dbTester = DbTester.createWithExtensionMappers(System2.INSTANCE, true, ProjectExportMapper.class);
@Rule
public LogTester logTester = new LogTester();

@@ -109,13 +99,13 @@ public class ExportBranchesStepIT {
public void setUp() {
logTester.setLevel(Level.DEBUG);
Date createdAt = new Date();
ComponentDto projectDto = dbTester.components().insertPublicProject(PROJECT).getMainBranchComponent().setCreatedAt(createdAt);
ProjectData projectData = dbTester.components().insertPublicProject(PROJECT_UUID);
for (BranchDto branch : branches) {
createdAt = DateUtils.addMinutes(createdAt, 10);
dbTester.components().insertProjectBranch(PROJECT, branch).setCreatedAt(createdAt);
dbTester.components().insertProjectBranch(projectData.getProjectDto(), branch).setCreatedAt(createdAt);
}
dbTester.commit();
when(projectHolder.projectDto()).thenReturn(dbTester.components().getProjectDtoByMainBranch(projectDto));
when(projectHolder.projectDto()).thenReturn(projectData.getProjectDto());
}

@Test
@@ -127,7 +117,7 @@ public class ExportBranchesStepIT {
.stream()
.collect(toMap(ProjectDump.Branch::getUuid, Function.identity()));
assertThat(branches).hasSize(3);
ProjectDump.Branch mainBranch = branches.get(PROJECT_UUID);
ProjectDump.Branch mainBranch = branches.values().stream().filter(ProjectDump.Branch::getIsMain).findFirst().get();
assertThat(mainBranch).isNotNull();
assertThat(mainBranch.getKee()).isEqualTo(BranchDto.DEFAULT_MAIN_BRANCH_NAME);
assertThat(mainBranch.getProjectUuid()).isEqualTo(PROJECT_UUID);

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/component/ExportComponentsStepIT.java View File

@@ -78,7 +78,7 @@ public class ExportComponentsStepIT {
.setBranchUuid(PROJECT_UUID);

@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public LogTester logTester = new LogTester();


+ 6
- 7
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/file/ExportLineHashesStepIT.java View File

@@ -55,16 +55,15 @@ public class ExportLineHashesStepIT {
private static final String FILE_UUID_2 = "file-2-uuid";

@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public LogTester logTester = new LogTester();

private DbClient dbClient = dbTester.getDbClient();
private DbSession dbSession = dbClient.openSession(false);
private FakeDumpWriter dumpWriter = new FakeDumpWriter();
private MutableComponentRepository componentRepository = new ComponentRepositoryImpl();

private ExportLineHashesStep underTest = new ExportLineHashesStep(dbClient, dumpWriter, componentRepository);
private final DbClient dbClient = dbTester.getDbClient();
private final DbSession dbSession = dbClient.openSession(false);
private final FakeDumpWriter dumpWriter = new FakeDumpWriter();
private final MutableComponentRepository componentRepository = new ComponentRepositoryImpl();
private final ExportLineHashesStep underTest = new ExportLineHashesStep(dbClient, dumpWriter, componentRepository);

@Before
public void before() {

+ 18
- 17
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/issue/ExportIssuesChangelogStepIT.java View File

@@ -39,11 +39,11 @@ import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ProjectData;
import org.sonar.db.issue.IssueChangeDto;
import org.sonar.db.issue.IssueDto;
import org.sonar.db.project.ProjectDto;

import static com.google.common.collect.Lists.newArrayList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;
@@ -63,7 +63,7 @@ public class ExportIssuesChangelogStepIT {
private static final String ISSUE_CLOSED_UUID = "issue closed uuid";

@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public LogTester logTester = new LogTester();

@@ -73,21 +73,22 @@ public class ExportIssuesChangelogStepIT {
private final FakeDumpWriter dumpWriter = new FakeDumpWriter();
private final ExportIssuesChangelogStep underTest = new ExportIssuesChangelogStep(dbClient, projectHolder, dumpWriter);

private BranchDto mainBranch;
private int issueChangeUuidGenerator = 0;

@Before
public void setUp() {
logTester.setLevel(Level.DEBUG);
ComponentDto projectDto = dbTester.components().insertPublicProject(p -> p.setUuid(PROJECT_UUID)).getMainBranchComponent();
when(projectHolder.projectDto()).thenReturn(dbTester.components().getProjectDtoByMainBranch(projectDto));
when(projectHolder.branches()).thenReturn(newArrayList(
new BranchDto().setBranchType(BranchType.BRANCH).setKey("master").setProjectUuid(PROJECT_UUID).setUuid(PROJECT_UUID)));
insertIssue(PROJECT_UUID, ISSUE_OPEN_UUID, STATUS_OPEN);
insertIssue(PROJECT_UUID, ISSUE_CONFIRMED_UUID, STATUS_CONFIRMED);
insertIssue(PROJECT_UUID, ISSUE_REOPENED_UUID, STATUS_REOPENED);
insertIssue(PROJECT_UUID, ISSUE_RESOLVED_UUID, STATUS_RESOLVED);
insertIssue(PROJECT_UUID, ISSUE_CLOSED_UUID, STATUS_CLOSED);
ProjectData projectData = dbTester.components().insertPublicProject(PROJECT_UUID);
mainBranch = projectData.getMainBranchDto();
when(projectHolder.projectDto()).thenReturn(projectData.getProjectDto());
when(projectHolder.branches()).thenReturn(List.of(mainBranch));
insertIssue(mainBranch.getUuid(), ISSUE_OPEN_UUID, STATUS_OPEN);
insertIssue(mainBranch.getUuid(), ISSUE_CONFIRMED_UUID, STATUS_CONFIRMED);
insertIssue(mainBranch.getUuid(), ISSUE_REOPENED_UUID, STATUS_REOPENED);
insertIssue(mainBranch.getUuid(), ISSUE_RESOLVED_UUID, STATUS_RESOLVED);
insertIssue(mainBranch.getUuid(), ISSUE_CLOSED_UUID, STATUS_CLOSED);
}

@After
@@ -145,7 +146,7 @@ public class ExportIssuesChangelogStepIT {
.setChangeType("change type")
.setUserUuid("user_uuid")
.setIssueChangeCreationDate(454135L)
.setProjectUuid(PROJECT_UUID);
.setProjectUuid(mainBranch.getUuid());
insertIssueChange(issueChangeDto);

underTest.execute(new TestComputationStepContext());
@@ -193,7 +194,7 @@ public class ExportIssuesChangelogStepIT {

@Test
public void execute_sets_createAt_to_zero_if_both_createdAt_and_issueChangeDate_are_null() {
insertIssueChange(new IssueChangeDto().setUuid(Uuids.createFast()).setIssueKey(ISSUE_REOPENED_UUID).setProjectUuid(PROJECT_UUID));
insertIssueChange(new IssueChangeDto().setUuid(Uuids.createFast()).setIssueKey(ISSUE_REOPENED_UUID).setProjectUuid(mainBranch.getUuid()));

underTest.execute(new TestComputationStepContext());

@@ -262,10 +263,10 @@ public class ExportIssuesChangelogStepIT {
return dto;
}

private void insertIssue(String projectUuid, String uuid, String status) {
private void insertIssue(String branchUuid, String uuid, String status) {
IssueDto dto = new IssueDto()
.setKee(uuid)
.setProjectUuid(projectUuid)
.setProjectUuid(branchUuid)
.setStatus(status);
dbClient.issueDao().insert(dbSession, dto);
dbSession.commit();

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/issue/ExportIssuesStepIT.java View File

@@ -83,7 +83,7 @@ public class ExportIssuesStepIT {
public static final DbIssues.MessageFormatting MESSAGE_FORMATTING = DbIssues.MessageFormatting.newBuilder().setStart(0).setEnd(4).setType(MessageFormattingType.CODE).build();

@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public LogTester logTester = new LogTester();


+ 21
- 32
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/rule/ExportAdHocRulesStepIT.java View File

@@ -44,6 +44,7 @@ import org.sonar.db.DbTester;
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ProjectData;
import org.sonar.db.issue.IssueDto;
import org.sonar.db.project.ProjectDto;
import org.sonar.db.rule.RuleDto;
@@ -56,19 +57,6 @@ import static org.sonar.db.component.ComponentDto.UUID_PATH_OF_ROOT;

public class ExportAdHocRulesStepIT {
private static final String PROJECT_UUID = "some-uuid";

private static final ComponentDto PROJECT = new ComponentDto()
// no id yet
.setScope(Scopes.PROJECT)
.setQualifier(Qualifiers.PROJECT)
.setKey("the_project")
.setName("The Project")
.setDescription("The project description")
.setEnabled(true)
.setUuid(PROJECT_UUID)
.setUuidPath(UUID_PATH_OF_ROOT)
.setBranchUuid(PROJECT_UUID);

private static final List<BranchDto> BRANCHES = ImmutableList.of(
new BranchDto().setBranchType(BranchType.PULL_REQUEST).setProjectUuid(PROJECT_UUID).setKey("pr-1").setUuid("pr-1-uuid").setMergeBranchUuid("master").setIsMain(false),
new BranchDto().setBranchType(BranchType.BRANCH).setProjectUuid(PROJECT_UUID).setKey("branch-2").setUuid("branch-2-uuid").setMergeBranchUuid("master")
@@ -78,14 +66,14 @@ public class ExportAdHocRulesStepIT {

@Rule
public LogTester logTester = new LogTester();

@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
public DbTester dbTester = DbTester.create(System2.INSTANCE, true);

private int issueUuidGenerator = 1;
private FakeDumpWriter dumpWriter = new FakeDumpWriter();
private ProjectHolder projectHolder = mock(ProjectHolder.class);
private ExportAdHocRulesStep underTest = new ExportAdHocRulesStep(dbTester.getDbClient(), projectHolder, dumpWriter);
private ComponentDto mainBranch;
private final FakeDumpWriter dumpWriter = new FakeDumpWriter();
private final ProjectHolder projectHolder = mock(ProjectHolder.class);
private final ExportAdHocRulesStep underTest = new ExportAdHocRulesStep(dbTester.getDbClient(), projectHolder, dumpWriter);

@Before
public void setup() {
@@ -110,7 +98,7 @@ public class ExportAdHocRulesStepIT {
RuleDto rule2 = insertAddHocRule( "rule-2");
insertAddHocRule( "rule-3");
insertIssue(rule1, differentProject, differentProject);
insertIssue(rule2, PROJECT_UUID, PROJECT_UUID);
insertIssue(rule2, mainBranch.uuid(), mainBranch.uuid());

underTest.execute(new TestComputationStepContext());

@@ -125,9 +113,9 @@ public class ExportAdHocRulesStepIT {
RuleDto rule1 = insertStandardRule("rule-1");
RuleDto rule2 = insertExternalRule("rule-2");
RuleDto rule3 = insertAddHocRule("rule-3");
insertIssue(rule1, PROJECT_UUID, PROJECT_UUID);
insertIssue(rule2, PROJECT_UUID, PROJECT_UUID);
insertIssue(rule3, PROJECT_UUID, PROJECT_UUID);
insertIssue(rule1, mainBranch.uuid(), mainBranch.uuid());
insertIssue(rule2, mainBranch.uuid(), mainBranch.uuid());
insertIssue(rule3, mainBranch.uuid(), mainBranch.uuid());

underTest.execute(new TestComputationStepContext());

@@ -160,9 +148,9 @@ public class ExportAdHocRulesStepIT {
RuleDto rule1 = insertAddHocRule("rule-1");
RuleDto rule2 = insertAddHocRule("rule-2");
RuleDto rule3 = insertAddHocRule("rule-3");
insertIssue(rule1, PROJECT_UUID, PROJECT_UUID);
insertIssue(rule2, PROJECT_UUID, PROJECT_UUID);
insertIssue(rule3, PROJECT_UUID, PROJECT_UUID);
insertIssue(rule1, mainBranch.uuid(), mainBranch.uuid());
insertIssue(rule2, mainBranch.uuid(), mainBranch.uuid());
insertIssue(rule3, mainBranch.uuid(), mainBranch.uuid());
dumpWriter.failIfMoreThan(2, DumpElement.AD_HOC_RULES);

assertThatThrownBy(() -> underTest.execute(new TestComputationStepContext()))
@@ -177,14 +165,15 @@ public class ExportAdHocRulesStepIT {

private ProjectDto createProject() {
Date createdAt = new Date();
ComponentDto projectDto = dbTester.components().insertPublicProject(PROJECT).getMainBranchComponent();
BRANCHES.forEach(branch -> dbTester.components().insertProjectBranch(projectDto, branch).setCreatedAt(createdAt));
ProjectData projectData = dbTester.components().insertPublicProject(PROJECT_UUID);
mainBranch = projectData.getMainBranchComponent();
BRANCHES.forEach(branch -> dbTester.components().insertProjectBranch(projectData.getProjectDto(), branch).setCreatedAt(createdAt));
dbTester.commit();
return dbTester.components().getProjectDtoByMainBranch(projectDto);
return projectData.getProjectDto();
}

private void insertIssue(RuleDto ruleDto, String projectUuid, String componentUuid) {
IssueDto dto = createBaseIssueDto(ruleDto, projectUuid, componentUuid);
private void insertIssue(RuleDto ruleDto, String branchUuid, String componentUuid) {
IssueDto dto = createBaseIssueDto(ruleDto, branchUuid, componentUuid);
insertIssue(dto);
}

@@ -193,11 +182,11 @@ public class ExportAdHocRulesStepIT {
dbTester.commit();
}

private IssueDto createBaseIssueDto(RuleDto ruleDto, String projectUuid, String componentUuid) {
private IssueDto createBaseIssueDto(RuleDto ruleDto, String branchUuid, String componentUuid) {
return new IssueDto()
.setKee("issue_uuid_" + issueUuidGenerator++)
.setComponentUuid(componentUuid)
.setProjectUuid(projectUuid)
.setProjectUuid(branchUuid)
.setRuleUuid(ruleDto.getUuid())
.setStatus("OPEN");
}

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportEventsStepIT.java View File

@@ -58,7 +58,7 @@ public class ExportEventsStepIT {


@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
public DbTester dbTester = DbTester.create(System2.INSTANCE, true);

@Rule
public LogTester logTester = new LogTester();

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportLinksStepIT.java View File

@@ -58,7 +58,7 @@ public class ExportLinksStepIT {
.setBranchUuid(PROJECT_UUID);

@Rule
public DbTester db = DbTester.createWithExtensionMappers(System2.INSTANCE, ProjectExportMapper.class);
public DbTester db = DbTester.createWithExtensionMappers(System2.INSTANCE, true, ProjectExportMapper.class);


@Rule

+ 6
- 6
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportLiveMeasuresStepIT.java View File

@@ -47,13 +47,13 @@ public class ExportLiveMeasuresStepIT {
@Rule
public LogTester logTester = new LogTester();
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
public DbTester dbTester = DbTester.create(System2.INSTANCE, true);

private ComponentRepositoryImpl componentRepository = new ComponentRepositoryImpl();
private MutableMetricRepository metricRepository = new MutableMetricRepositoryImpl();
private ProjectHolder projectHolder = mock(ProjectHolder.class);
private FakeDumpWriter dumpWriter = new FakeDumpWriter();
private ExportLiveMeasuresStep underTest = new ExportLiveMeasuresStep(dbTester.getDbClient(), projectHolder, componentRepository, metricRepository, dumpWriter);
private final ComponentRepositoryImpl componentRepository = new ComponentRepositoryImpl();
private final MutableMetricRepository metricRepository = new MutableMetricRepositoryImpl();
private final ProjectHolder projectHolder = mock(ProjectHolder.class);
private final FakeDumpWriter dumpWriter = new FakeDumpWriter();
private final ExportLiveMeasuresStep underTest = new ExportLiveMeasuresStep(dbTester.getDbClient(), projectHolder, componentRepository, metricRepository, dumpWriter);

@Before
public void before() {

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportMeasuresStepIT.java View File

@@ -97,7 +97,7 @@ public class ExportMeasuresStepIT {
public LogTester logTester = new LogTester();

@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
public DbTester dbTester = DbTester.create(System2.INSTANCE, true);

private ComponentRepositoryImpl componentRepository = new ComponentRepositoryImpl();
private MutableMetricRepository metricRepository = new MutableMetricRepositoryImpl();

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportMetricsStepIT.java View File

@@ -52,7 +52,7 @@ public class ExportMetricsStepIT {
public LogTester logTester = new LogTester();

@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
public DbTester dbTester = DbTester.create(System2.INSTANCE, true);

MutableMetricRepository metricsHolder = new MutableMetricRepositoryImpl();
FakeDumpWriter dumpWriter = new FakeDumpWriter();

+ 13
- 17
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportNewCodePeriodsStepIT.java View File

@@ -38,6 +38,7 @@ import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.newcodeperiod.NewCodePeriodDto;
import org.sonar.db.newcodeperiod.NewCodePeriodType;
import org.sonar.db.project.ProjectDto;
import org.sonar.db.project.ProjectExportMapper;

import static org.assertj.core.api.Assertions.assertThat;
@@ -50,13 +51,6 @@ public class ExportNewCodePeriodsStepIT {

private static final String PROJECT_UUID = "project_uuid";
private static final String ANOTHER_PROJECT_UUID = "another_project_uuid";
private static final ComponentDto PROJECT = new ComponentDto()
.setUuid(PROJECT_UUID)
.setUuidPath(UUID_PATH_OF_ROOT)
.setBranchUuid(PROJECT_UUID)
.setQualifier(Qualifiers.PROJECT)
.setName("project")
.setKey("the_project");
private static final ComponentDto ANOTHER_PROJECT = new ComponentDto()
.setUuid(ANOTHER_PROJECT_UUID)
.setUuidPath(UUID_PATH_OF_ROOT)
@@ -76,10 +70,12 @@ public class ExportNewCodePeriodsStepIT {
new BranchDto().setBranchType(BranchType.BRANCH).setProjectUuid(ANOTHER_PROJECT_UUID).setKey("branch-3").setUuid("branch-uuid-3").setMergeBranchUuid("master")
.setExcludeFromPurge(true).setIsMain(false));

private ProjectDto project;

@Rule
public LogTester logTester = new LogTester();
@Rule
public DbTester dbTester = DbTester.createWithExtensionMappers(System2.INSTANCE, ProjectExportMapper.class);
public DbTester dbTester = DbTester.createWithExtensionMappers(System2.INSTANCE, true, ProjectExportMapper.class);

private MutableProjectHolder projectHolder = new MutableProjectHolderImpl();
private FakeDumpWriter dumpWriter = new FakeDumpWriter();
@@ -89,14 +85,14 @@ public class ExportNewCodePeriodsStepIT {
public void setUp() {
logTester.setLevel(Level.DEBUG);
Date createdAt = new Date();
ComponentDto projectDto = dbTester.components().insertPublicProject(PROJECT).getMainBranchComponent();
PROJECT_BRANCHES.forEach(branch -> dbTester.components().insertProjectBranch(projectDto, branch).setCreatedAt(createdAt));
project = dbTester.components().insertPrivateProject(PROJECT_UUID).getProjectDto();
PROJECT_BRANCHES.forEach(branch -> dbTester.components().insertProjectBranch(project, branch).setCreatedAt(createdAt));

ComponentDto anotherProjectDto = dbTester.components().insertPublicProject(ANOTHER_PROJECT).getMainBranchComponent();
ANOTHER_PROJECT_BRANCHES.forEach(branch -> dbTester.components().insertProjectBranch(anotherProjectDto, branch).setCreatedAt(createdAt));

dbTester.commit();
projectHolder.setProjectDto(dbTester.components().getProjectDtoByMainBranch(PROJECT));
projectHolder.setProjectDto(project);
}

@Test
@@ -109,10 +105,10 @@ public class ExportNewCodePeriodsStepIT {

@Test
public void export_only_project_new_code_periods_on_branches_excluded_from_purge() {
NewCodePeriodDto newCodePeriod1 = newDto("uuid1", PROJECT.uuid(), null, SPECIFIC_ANALYSIS, "analysis-uuid");
NewCodePeriodDto newCodePeriod2 = newDto("uuid2", PROJECT.uuid(), "branch-uuid-1", SPECIFIC_ANALYSIS, "analysis-uuid");
NewCodePeriodDto newCodePeriod1 = newDto("uuid1", project.getUuid(), null, SPECIFIC_ANALYSIS, "analysis-uuid");
NewCodePeriodDto newCodePeriod2 = newDto("uuid2", project.getUuid(), "branch-uuid-1", SPECIFIC_ANALYSIS, "analysis-uuid");
// the following new code periods are not exported
NewCodePeriodDto newCodePeriod3 = newDto("uuid3", PROJECT.uuid(), "branch-uuid-2", SPECIFIC_ANALYSIS, "analysis-uuid");
NewCodePeriodDto newCodePeriod3 = newDto("uuid3", project.getUuid(), "branch-uuid-2", SPECIFIC_ANALYSIS, "analysis-uuid");
NewCodePeriodDto anotherProjectNewCodePeriods = newDto("uuid4", ANOTHER_PROJECT.uuid(), "branch-uuid-3", SPECIFIC_ANALYSIS, "analysis-uuid");
NewCodePeriodDto globalNewCodePeriod = newDto("uuid5", null, null, PREVIOUS_VERSION, null);
insertNewCodePeriods(newCodePeriod1, newCodePeriod2, newCodePeriod3, anotherProjectNewCodePeriods, globalNewCodePeriod);
@@ -127,7 +123,7 @@ public class ExportNewCodePeriodsStepIT {

@Test
public void test_exported_fields() {
NewCodePeriodDto dto = newDto("uuid1", PROJECT.uuid(), "branch-uuid-1", SPECIFIC_ANALYSIS, "analysis-uuid");
NewCodePeriodDto dto = newDto("uuid1", project.getUuid(), "branch-uuid-1", SPECIFIC_ANALYSIS, "analysis-uuid");
insertNewCodePeriods(dto);

underTest.execute(new TestComputationStepContext());
@@ -144,8 +140,8 @@ public class ExportNewCodePeriodsStepIT {
public void throws_ISE_if_error() {
dumpWriter.failIfMoreThan(1, DumpElement.NEW_CODE_PERIODS);
insertNewCodePeriods(
newDto("uuid1", PROJECT.uuid(), null, SPECIFIC_ANALYSIS, "analysis-uuid"),
newDto("uuid2", PROJECT.uuid(), "branch-uuid-1", SPECIFIC_ANALYSIS, "analysis-uuid"));
newDto("uuid1", project.getUuid(), null, SPECIFIC_ANALYSIS, "analysis-uuid"),
newDto("uuid2", project.getUuid(), "branch-uuid-1", SPECIFIC_ANALYSIS, "analysis-uuid"));

assertThatThrownBy(() -> underTest.execute(new TestComputationStepContext()))
.isInstanceOf(IllegalStateException.class)

+ 5
- 5
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportSettingsStepIT.java View File

@@ -58,11 +58,11 @@ public class ExportSettingsStepIT {
@Rule
public LogTester logTester = new LogTester();
@Rule
public DbTester dbTester = DbTester.createWithExtensionMappers(System2.INSTANCE, ProjectExportMapper.class);
private MutableComponentRepository componentRepository = new ComponentRepositoryImpl();
private MutableProjectHolder projectHolder = new MutableProjectHolderImpl();
private FakeDumpWriter dumpWriter = new FakeDumpWriter();
private ExportSettingsStep underTest = new ExportSettingsStep(dbTester.getDbClient(), projectHolder, componentRepository, dumpWriter);
public DbTester dbTester = DbTester.createWithExtensionMappers(System2.INSTANCE, true, ProjectExportMapper.class);
private final MutableComponentRepository componentRepository = new ComponentRepositoryImpl();
private final MutableProjectHolder projectHolder = new MutableProjectHolderImpl();
private final FakeDumpWriter dumpWriter = new FakeDumpWriter();
private final ExportSettingsStep underTest = new ExportSettingsStep(dbTester.getDbClient(), projectHolder, componentRepository, dumpWriter);

@Before
public void setUp() {

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/LoadProjectStepIT.java View File

@@ -37,7 +37,7 @@ public class LoadProjectStepIT {
private static final String PROJECT_KEY = "project_key";

@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
public DbTester dbTester = DbTester.create(System2.INSTANCE, true);

private final ProjectDescriptor descriptor = new ProjectDescriptor("project_uuid", PROJECT_KEY, "Project Name");
private final MutableProjectHolder definitionHolder = new MutableProjectHolderImpl();

+ 1
- 1
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutor.java View File

@@ -167,7 +167,7 @@ public class PostProjectAnalysisTasksExecutor implements ComputationStepExecutor
}

private static Project createProject(org.sonar.ce.task.CeTask ceTask) {
return ceTask.getMainComponent()
return ceTask.getEntity()
.map(c -> new ProjectImpl(
c.getUuid(),
c.getKey().orElseThrow(() -> new IllegalStateException("Missing project key")),

+ 4
- 4
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/PersistFileSourcesStep.java View File

@@ -78,7 +78,7 @@ public class PersistFileSourcesStep implements ComputationStep {

private class FileSourceVisitor extends TypeAwareVisitorAdapter {
private final DbSession session;
private String projectUuid;
private String branchUuid;

private FileSourceVisitor(DbSession session) {
super(CrawlerDepthLimit.FILE, PRE_ORDER);
@@ -86,8 +86,8 @@ public class PersistFileSourcesStep implements ComputationStep {
}

@Override
public void visitProject(Component project) {
this.projectUuid = project.getUuid();
public void visitProject(Component branch) {
this.branchUuid = branch.getUuid();
}

@Override
@@ -113,7 +113,7 @@ public class PersistFileSourcesStep implements ComputationStep {
if (previousDto == null) {
FileSourceDto dto = new FileSourceDto()
.setUuid(uuidFactory.create())
.setProjectUuid(projectUuid)
.setProjectUuid(branchUuid)
.setFileUuid(file.getUuid())
.setBinaryData(binaryData)
.setSrcHash(srcHash)

+ 8
- 9
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java View File

@@ -87,11 +87,11 @@ public class LoadReportAnalysisMetadataHolderStep implements ComputationStep {
* @return a {@link Runnable} to execute some checks on the project at the end of the step
*/
private Runnable loadProject(ScannerReport.Metadata reportMetadata) {
CeTask.Component mainComponent = mandatoryComponent(ceTask.getMainComponent());
String mainComponentKey = mainComponent.getKey()
CeTask.Component entity = mandatoryComponent(ceTask.getEntity());
String entityKey = entity.getKey()
.orElseThrow(() -> MessageException.of(format(
"Compute Engine task main component key is null. Project with UUID %s must have been deleted since report was uploaded. Can not proceed.",
mainComponent.getUuid())));
"Compute Engine task entity key is null. Project with UUID %s must have been deleted since report was uploaded. Can not proceed.",
entity.getUuid())));
CeTask.Component component = mandatoryComponent(ceTask.getComponent());
if (!component.getKey().isPresent()) {
throw MessageException.of(format(
@@ -102,18 +102,17 @@ public class LoadReportAnalysisMetadataHolderStep implements ComputationStep {
ProjectDto dto = toProject(reportMetadata.getProjectKey());
analysisMetadata.setProject(Project.fromProjectDtoWithTags(dto));
return () -> {
if (!mainComponentKey.equals(reportMetadata.getProjectKey())) {
if (!entityKey.equals(reportMetadata.getProjectKey())) {
throw MessageException.of(format(
"ProjectKey in report (%s) is not consistent with projectKey under which the report has been submitted (%s)",
reportMetadata.getProjectKey(),
mainComponentKey));
entityKey));
}
};
}

private static CeTask.Component mandatoryComponent(Optional<CeTask.Component> mainComponent) {
return mainComponent
.orElseThrow(() -> new IllegalStateException("component missing on ce task"));
private static CeTask.Component mandatoryComponent(Optional<CeTask.Component> entity) {
return entity.orElseThrow(() -> new IllegalStateException("component missing on ce task"));
}

private void loadQualityProfiles(ScannerReport.Metadata reportMetadata) {

+ 2
- 2
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/taskprocessor/IgnoreOrphanBranchStep.java View File

@@ -40,11 +40,11 @@ public final class IgnoreOrphanBranchStep implements ComputationStep {

@Override
public void execute(Context context) {
String mainComponentUuid = ceTask.getMainComponent().orElseThrow(() -> new UnsupportedOperationException("main component not found in task")).getUuid();
String entityUuid = ceTask.getEntity().orElseThrow(() -> new UnsupportedOperationException("entity not found in task")).getUuid();
String componentUuid = ceTask.getComponent().orElseThrow(() -> new UnsupportedOperationException("component not found in task")).getUuid();

try (DbSession dbSession = dbClient.openSession(false)) {
Optional<ComponentDto> componentDto = dbClient.componentDao().selectByUuid(dbSession, mainComponentUuid);
Optional<ComponentDto> componentDto = dbClient.componentDao().selectByUuid(dbSession, entityUuid);
if(!componentDto.isPresent()){
LOG.info("reindexation task has been trigger on an orphan branch. removing any exclude_from_purge flag, and skip the indexation");
dbClient.branchDao().updateExcludeFromPurge(dbSession, componentUuid, false);

+ 2
- 3
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/issue/ExportIssuesChangelogStep.java View File

@@ -41,11 +41,10 @@ public class ExportIssuesChangelogStep implements ComputationStep {
private static final String STATUS_CLOSED = "CLOSED";
private static final String QUERY = "select" +
" ic.kee, ic.issue_key, ic.change_type, ic.change_data, ic.user_login," +
" ic.issue_change_creation_date, ic.created_at, p.uuid" +
" ic.issue_change_creation_date, ic.created_at, pb.uuid" +
" from issue_changes ic" +
" join issues i on i.kee = ic.issue_key" +
" join projects p on p.uuid = i.project_uuid" +
" join project_branches pb on pb.uuid = p.uuid" +
" join project_branches pb on pb.uuid = i.project_uuid" +
" where pb.project_uuid = ? and pb.branch_type = 'BRANCH' and pb.exclude_from_purge = ? " +
" and i.status <> ?" +
" order by ic.created_at asc";

+ 2
- 2
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/taskprocessor/ProjectExportTaskProcessor.java View File

@@ -65,8 +65,8 @@ public class ProjectExportTaskProcessor implements CeTaskProcessor {
}

private static void failIfNotMain(CeTask.Component exportComponent, CeTask task) {
task.getMainComponent().filter(mainComponent -> mainComponent.equals(exportComponent))
.orElseThrow(() -> new IllegalStateException("Component of task must be the same as main component"));
task.getEntity().filter(entity -> entity.equals(exportComponent))
.orElseThrow(() -> new IllegalStateException("Component of task must be the same as entity"));
}

private static CeTask.Component mandatoryComponent(CeTask task, String type) {

+ 5
- 4
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutorTest.java View File

@@ -88,11 +88,12 @@ public class PostProjectAnalysisTasksExecutorTest {

private final ArgumentCaptor<PostProjectAnalysisTask.Context> taskContextCaptor = ArgumentCaptor.forClass(PostProjectAnalysisTask.Context.class);
private final CeTask.Component component = new CeTask.Component("component uuid", "component key", "component name");
private final CeTask.Component entity = new CeTask.Component("entity uuid", "component key", "component name");
private final CeTask ceTask = new CeTask.Builder()
.setType("type")
.setUuid("uuid")
.setComponent(component)
.setMainComponent(component)
.setEntity(entity)
.build();
private final PostProjectAnalysisTask postProjectAnalysisTask = newPostProjectAnalysisTask("PT1");
private final PostProjectAnalysisTasksExecutor underTest = new PostProjectAnalysisTasksExecutor(
@@ -189,9 +190,9 @@ public class PostProjectAnalysisTasksExecutorTest {
verify(postProjectAnalysisTask).finished(taskContextCaptor.capture());

Project project = taskContextCaptor.getValue().getProjectAnalysis().getProject();
assertThat(project.getUuid()).isEqualTo(ceTask.getComponent().get().getUuid());
assertThat(project.getKey()).isEqualTo(ceTask.getComponent().get().getKey().get());
assertThat(project.getName()).isEqualTo(ceTask.getComponent().get().getName().get());
assertThat(project.getUuid()).isEqualTo(ceTask.getEntity().get().getUuid());
assertThat(project.getKey()).isEqualTo(ceTask.getEntity().get().getKey().get());
assertThat(project.getName()).isEqualTo(ceTask.getEntity().get().getName().get());
}

@Test

+ 10
- 10
server/sonar-ce-task/src/main/java/org/sonar/ce/task/CeTask.java View File

@@ -40,17 +40,17 @@ public class CeTask {
private final String type;
private final String uuid;
private final Component component;
private final Component mainComponent;
private final Component entity;
private final User submitter;
private final Map<String, String> characteristics;

private CeTask(Builder builder) {
this.uuid = requireNonNull(emptyToNull(builder.uuid), "uuid can't be null nor empty");
this.type = requireNonNull(emptyToNull(builder.type), "type can't be null nor empty");
checkArgument((builder.component == null) == (builder.mainComponent == null),
"None or both component and main component must be non null");
checkArgument((builder.component == null) == (builder.entity == null),
"None or both component and entity must be non null");
this.component = builder.component;
this.mainComponent = builder.mainComponent;
this.entity = builder.entity;
this.submitter = builder.submitter;
if (builder.characteristics == null) {
this.characteristics = emptyMap();
@@ -103,8 +103,8 @@ public class CeTask {
return Optional.ofNullable(component);
}

public Optional<Component> getMainComponent() {
return Optional.ofNullable(mainComponent);
public Optional<Component> getEntity() {
return Optional.ofNullable(entity);
}

@CheckForNull
@@ -122,7 +122,7 @@ public class CeTask {
.add("type", type)
.add("uuid", uuid)
.add("component", component)
.add("mainComponent", mainComponent)
.add("entity", entity)
.add("submitter", submitter)
.toString();
}
@@ -148,7 +148,7 @@ public class CeTask {
private String uuid;
private String type;
private Component component;
private Component mainComponent;
private Component entity;
private User submitter;
private Map<String, String> characteristics;

@@ -167,8 +167,8 @@ public class CeTask {
return this;
}

public Builder setMainComponent(@Nullable Component mainComponent) {
this.mainComponent = mainComponent;
public Builder setEntity(@Nullable Component entity) {
this.entity = entity;
return this;
}


+ 11
- 11
server/sonar-ce-task/src/test/java/org/sonar/ce/task/CeTaskTest.java View File

@@ -35,20 +35,20 @@ public class CeTaskTest {
private CeTask.Builder underTest = new CeTask.Builder();

@Test
@UseDataProvider("oneAndOnlyOneOfComponentAndMainComponent")
public void build_fails_with_IAE_if_only_one_of_component_and_main_component_is_non_null(CeTask.Component component, CeTask.Component mainComponent) {
@UseDataProvider("oneAndOnlyOneOfComponentAndEntity")
public void build_fails_with_IAE_if_only_one_of_component_and_main_component_is_non_null(CeTask.Component component, CeTask.Component entity) {
underTest.setType("TYPE_1");
underTest.setUuid("UUID_1");
underTest.setComponent(component);
underTest.setMainComponent(mainComponent);
underTest.setEntity(entity);

assertThatThrownBy(() -> underTest.build())
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("None or both component and main component must be non null");
.hasMessage("None or both component and entity must be non null");
}

@DataProvider
public static Object[][] oneAndOnlyOneOfComponentAndMainComponent() {
public static Object[][] oneAndOnlyOneOfComponentAndEntity() {
CeTask.Component component = new CeTask.Component("COMPONENT_UUID_1", "COMPONENT_KEY_1", "The component");
return new Object[][] {
{component, null},
@@ -59,13 +59,13 @@ public class CeTaskTest {
@Test
public void verify_getters() {
CeTask.Component component = new CeTask.Component("COMPONENT_UUID_1", "COMPONENT_KEY_1", "The component");
CeTask.Component mainComponent = new CeTask.Component("MAIN_COMPONENT_UUID_1", "MAIN_COMPONENT_KEY_1", "The main component");
CeTask.Component entity = new CeTask.Component("ENTITY_UUID_1", "ENTITY_KEY_1", "The entity");
CeTask.User submitter = new CeTask.User("UUID_USER_1", "LOGIN_1");
underTest.setType("TYPE_1");
underTest.setUuid("UUID_1");
underTest.setSubmitter(submitter);
underTest.setComponent(component);
underTest.setMainComponent(mainComponent);
underTest.setEntity(entity);
underTest.setCharacteristics(ImmutableMap.of("k1", "v1", "k2", "v2"));

CeTask task = underTest.build();
@@ -74,7 +74,7 @@ public class CeTaskTest {
assertThat(task.getType()).isEqualTo("TYPE_1");
assertThat(task.getSubmitter()).isEqualTo(submitter);
assertThat(task.getComponent()).contains(component);
assertThat(task.getMainComponent()).contains(mainComponent);
assertThat(task.getEntity()).contains(entity);
assertThat(task.getCharacteristics())
.hasSize(2)
.containsEntry("k1", "v1")
@@ -84,11 +84,11 @@ public class CeTaskTest {
@Test
public void verify_toString() {
CeTask.Component component = new CeTask.Component("COMPONENT_UUID_1", "COMPONENT_KEY_1", "The component");
CeTask.Component mainComponent = new CeTask.Component("MAIN_COMPONENT_UUID_1", "MAIN_COMPONENT_KEY_1", "The main component");
CeTask.Component entity = new CeTask.Component("ENTITY_UUID_1", "ENTITY_KEY_1", "The entity");
underTest.setType("TYPE_1");
underTest.setUuid("UUID_1");
underTest.setComponent(component);
underTest.setMainComponent(mainComponent);
underTest.setEntity(entity);
underTest.setSubmitter(new CeTask.User("UUID_USER_1", "LOGIN_1"));
underTest.setCharacteristics(ImmutableMap.of("k1", "v1", "k2", "v2"));

@@ -99,7 +99,7 @@ public class CeTaskTest {
"type=TYPE_1, " +
"uuid=UUID_1, " +
"component=Component{uuid='COMPONENT_UUID_1', key='COMPONENT_KEY_1', name='The component'}, " +
"mainComponent=Component{uuid='MAIN_COMPONENT_UUID_1', key='MAIN_COMPONENT_KEY_1', name='The main component'}, " +
"entity=Component{uuid='ENTITY_UUID_1', key='ENTITY_KEY_1', name='The entity'}, " +
"submitter=User{uuid='UUID_USER_1', login='LOGIN_1'}" +
"}");
}

+ 64
- 65
server/sonar-ce/src/it/java/org/sonar/ce/queue/InternalCeQueueImplIT.java View File

@@ -45,8 +45,10 @@ import org.sonar.db.ce.CeActivityDto;
import org.sonar.db.ce.CeQueueDto;
import org.sonar.db.ce.CeQueueTesting;
import org.sonar.db.ce.CeTaskTypes;
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
import org.sonar.db.component.ProjectData;
import org.sonar.db.project.ProjectDto;
import org.sonar.db.user.UserDto;
import org.sonar.server.platform.NodeInformation;

@@ -71,20 +73,19 @@ public class InternalCeQueueImplIT {
private static final String WORKER_UUID_2 = "worker uuid 2";
private static final String NODE_NAME = "nodeName1";

private System2 system2 = new AlwaysIncreasingSystem2();
private final System2 system2 = new AlwaysIncreasingSystem2();

@Rule
public DbTester db = DbTester.create(system2);

private DbSession session = db.getSession();

private UuidFactory uuidFactory = UuidFactoryImpl.INSTANCE;
private CEQueueStatus queueStatus = new CEQueueStatusImpl(db.getDbClient(), mock(System2.class));
private ComputeEngineStatus computeEngineStatus = mock(ComputeEngineStatus.class);
private Configuration config = mock(Configuration.class);
private NextPendingTaskPicker nextPendingTaskPicker = new NextPendingTaskPicker(config, db.getDbClient());
private NodeInformation nodeInformation = mock(NodeInformation.class);
private InternalCeQueue underTest = new InternalCeQueueImpl(system2, db.getDbClient(), uuidFactory, queueStatus,
private final DbSession session = db.getSession();
private final UuidFactory uuidFactory = UuidFactoryImpl.INSTANCE;
private final CEQueueStatus queueStatus = new CEQueueStatusImpl(db.getDbClient(), mock(System2.class));
private final ComputeEngineStatus computeEngineStatus = mock(ComputeEngineStatus.class);
private final Configuration config = mock(Configuration.class);
private final NextPendingTaskPicker nextPendingTaskPicker = new NextPendingTaskPicker(config, db.getDbClient());
private final NodeInformation nodeInformation = mock(NodeInformation.class);
private final InternalCeQueue underTest = new InternalCeQueueImpl(system2, db.getDbClient(), uuidFactory, queueStatus,
computeEngineStatus, nextPendingTaskPicker, nodeInformation);

@Before
@@ -96,8 +97,7 @@ public class InternalCeQueueImplIT {

@Test
public void submit_returns_task_populated_from_CeTaskSubmit_and_creates_CeQueue_row() {
ComponentDto project1 = newProjectDto("PROJECT_1");
CeTaskSubmit taskSubmit = createTaskSubmit(CeTaskTypes.REPORT, project1, project1, "rob");
CeTaskSubmit taskSubmit = createTaskSubmit(CeTaskTypes.REPORT, "entity", "component", "rob");
CeTask task = underTest.submit(taskSubmit);
UserDto userDto = db.getDbClient().userDao().selectByUuid(db.getSession(), taskSubmit.getSubmitterUuid());
verifyCeTask(taskSubmit, task, null, userDto);
@@ -106,12 +106,12 @@ public class InternalCeQueueImplIT {

@Test
public void submit_populates_component_name_and_key_of_CeTask_if_component_exists() {
ComponentDto componentDto = insertComponent(newProjectDto("PROJECT_1"));
CeTaskSubmit taskSubmit = createTaskSubmit(CeTaskTypes.REPORT, componentDto, componentDto, null);
ProjectData projectData = newProject("PROJECT_1");
CeTaskSubmit taskSubmit = createTaskSubmit(CeTaskTypes.REPORT, projectData, null);

CeTask task = underTest.submit(taskSubmit);

verifyCeTask(taskSubmit, task, componentDto, null);
verifyCeTask(taskSubmit, task, projectData.getMainBranchComponent(), null);
}

@Test
@@ -125,8 +125,7 @@ public class InternalCeQueueImplIT {

@Test
public void massSubmit_returns_tasks_for_each_CeTaskSubmit_populated_from_CeTaskSubmit_and_creates_CeQueue_row_for_each() {
ComponentDto project1 = newProjectDto("PROJECT_1");
CeTaskSubmit taskSubmit1 = createTaskSubmit(CeTaskTypes.REPORT, project1, project1, "rob");
CeTaskSubmit taskSubmit1 = createTaskSubmit(CeTaskTypes.REPORT, "entity", "component", "rob");
CeTaskSubmit taskSubmit2 = createTaskSubmit("some type");

List<CeTask> tasks = underTest.massSubmit(asList(taskSubmit1, taskSubmit2));
@@ -141,15 +140,14 @@ public class InternalCeQueueImplIT {

@Test
public void massSubmit_populates_component_name_and_key_of_CeTask_if_component_exists() {
ComponentDto componentDto1 = insertComponent(newProjectDto("PROJECT_1"));
CeTaskSubmit taskSubmit1 = createTaskSubmit(CeTaskTypes.REPORT, componentDto1, componentDto1, null);
ComponentDto nonExistingComponent = newProjectDto("non existing component uuid");
CeTaskSubmit taskSubmit2 = createTaskSubmit("something", nonExistingComponent, nonExistingComponent, null);
ProjectData project = newProject("PROJECT_1");
CeTaskSubmit taskSubmit1 = createTaskSubmit(CeTaskTypes.REPORT, project, null);
CeTaskSubmit taskSubmit2 = createTaskSubmit("something", project.projectUuid(), "non-existing", null);

List<CeTask> tasks = underTest.massSubmit(asList(taskSubmit1, taskSubmit2));

assertThat(tasks).hasSize(2);
verifyCeTask(taskSubmit1, tasks.get(0), componentDto1, null);
verifyCeTask(taskSubmit1, tasks.get(0), project.getMainBranchComponent(), null);
verifyCeTask(taskSubmit2, tasks.get(1), null, null);
}

@@ -162,7 +160,7 @@ public class InternalCeQueueImplIT {

@Test
public void test_remove() {
CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
Optional<CeTask> peek = underTest.peek(WORKER_UUID_1, true);
underTest.remove(peek.get(), CeActivityDto.Status.SUCCESS, null, null);

@@ -194,7 +192,7 @@ public class InternalCeQueueImplIT {

@Test
public void remove_does_not_set_analysisUuid_in_CeActivity_when_CeTaskResult_has_no_analysis_uuid() {
CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
Optional<CeTask> peek = underTest.peek(WORKER_UUID_1, true);
underTest.remove(peek.get(), CeActivityDto.Status.SUCCESS, newTaskResult(null), null);

@@ -206,7 +204,7 @@ public class InternalCeQueueImplIT {

@Test
public void remove_sets_analysisUuid_in_CeActivity_when_CeTaskResult_has_analysis_uuid() {
CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));

Optional<CeTask> peek = underTest.peek(WORKER_UUID_2, true);
underTest.remove(peek.get(), CeActivityDto.Status.SUCCESS, newTaskResult(AN_ANALYSIS_UUID), null);
@@ -220,7 +218,7 @@ public class InternalCeQueueImplIT {
@Test
public void remove_sets_nodeName_in_CeActivity_when_nodeInformation_defines_node_name() {
when(nodeInformation.getNodeName()).thenReturn(Optional.of(NODE_NAME));
CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));

Optional<CeTask> peek = underTest.peek(WORKER_UUID_2, true);
underTest.remove(peek.get(), CeActivityDto.Status.SUCCESS, newTaskResult(AN_ANALYSIS_UUID), null);
@@ -233,7 +231,7 @@ public class InternalCeQueueImplIT {
@Test
public void remove_do_not_set_nodeName_in_CeActivity_when_nodeInformation_does_not_define_node_name() {
when(nodeInformation.getNodeName()).thenReturn(Optional.empty());
CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));

Optional<CeTask> peek = underTest.peek(WORKER_UUID_2, true);
underTest.remove(peek.get(), CeActivityDto.Status.SUCCESS, newTaskResult(AN_ANALYSIS_UUID), null);
@@ -247,7 +245,7 @@ public class InternalCeQueueImplIT {
public void remove_saves_error_message_and_stacktrace_when_exception_is_provided() {
Throwable error = new NullPointerException("Fake NPE to test persistence to DB");

CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
Optional<CeTask> peek = underTest.peek(WORKER_UUID_1, true);
underTest.remove(peek.get(), CeActivityDto.Status.FAILED, null, error);

@@ -263,7 +261,7 @@ public class InternalCeQueueImplIT {
public void remove_saves_error_when_TypedMessageException_is_provided() {
Throwable error = new TypedExceptionImpl("aType", "aMessage");

CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
Optional<CeTask> peek = underTest.peek(WORKER_UUID_1, true);
underTest.remove(peek.get(), CeActivityDto.Status.FAILED, null, error);

@@ -277,7 +275,7 @@ public class InternalCeQueueImplIT {
public void remove_updates_queueStatus_success_even_if_task_does_not_exist_in_DB() {
CEQueueStatus queueStatus = mock(CEQueueStatus.class);

CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
db.getDbClient().ceQueueDao().deleteByUuid(db.getSession(), task.getUuid());
db.commit();

@@ -295,7 +293,7 @@ public class InternalCeQueueImplIT {
public void remove_updates_queueStatus_failure_even_if_task_does_not_exist_in_DB() {
CEQueueStatus queueStatusMock = mock(CEQueueStatus.class);

CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
db.getDbClient().ceQueueDao().deleteByUuid(db.getSession(), task.getUuid());
db.commit();
InternalCeQueueImpl underTest = new InternalCeQueueImpl(system2, db.getDbClient(), null, queueStatusMock, null, null, nodeInformation);
@@ -313,7 +311,7 @@ public class InternalCeQueueImplIT {

CEQueueStatus queueStatusMock = mock(CEQueueStatus.class);

CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
db.executeUpdateSql("update ce_queue set status = 'PENDING', started_at = 123 where uuid = '" + task.getUuid() + "'");
db.commit();
InternalCeQueueImpl underTest = new InternalCeQueueImpl(system2, db.getDbClient(), null, queueStatusMock, null, null, nodeInformation);
@@ -360,7 +358,7 @@ public class InternalCeQueueImplIT {

@Test
public void fail_to_remove_if_not_in_queue() {
CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
underTest.remove(task, CeActivityDto.Status.SUCCESS, null, null);

assertThatThrownBy(() -> underTest.remove(task, CeActivityDto.Status.SUCCESS, null, null))
@@ -369,14 +367,16 @@ public class InternalCeQueueImplIT {

@Test
public void test_peek() {
CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
ProjectData projectData = newProject("PROJECT_1");
ComponentDto mainBranchComponent = projectData.getMainBranchComponent();
CeTask task = submit(CeTaskTypes.REPORT, projectData);

Optional<CeTask> peek = underTest.peek(WORKER_UUID_1, true);
assertThat(peek).isPresent();
assertThat(peek.get().getUuid()).isEqualTo(task.getUuid());
assertThat(peek.get().getType()).isEqualTo(CeTaskTypes.REPORT);
assertThat(peek.get().getComponent()).contains(new CeTask.Component("PROJECT_1", null, null));
assertThat(peek.get().getMainComponent()).contains(peek.get().getComponent().get());
assertThat(peek.get().getComponent()).contains(new CeTask.Component(mainBranchComponent.uuid(), mainBranchComponent.getKey(), mainBranchComponent.name()));
assertThat(peek.get().getEntity()).contains(peek.get().getComponent().get());

// no more pending tasks
peek = underTest.peek(WORKER_UUID_2, true);
@@ -385,16 +385,16 @@ public class InternalCeQueueImplIT {

@Test
public void peek_populates_name_and_key_for_existing_component_and_main_component() {
ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
ComponentDto branch = db.components().insertProjectBranch(project);
CeTask task = submit(CeTaskTypes.REPORT, project, branch);
ProjectDto project = db.components().insertPrivateProject().getProjectDto();
BranchDto branch = db.components().insertProjectBranch(project);
CeTask task = submit(CeTaskTypes.REPORT, branch);

Optional<CeTask> peek = underTest.peek(WORKER_UUID_1, true);
assertThat(peek).isPresent();
assertThat(peek.get().getUuid()).isEqualTo(task.getUuid());
assertThat(peek.get().getType()).isEqualTo(CeTaskTypes.REPORT);
assertThat(peek.get().getComponent()).contains(new CeTask.Component(branch.uuid(), branch.getKey(), branch.name()));
assertThat(peek.get().getMainComponent()).contains(new CeTask.Component(project.uuid(), project.getKey(), project.name()));
assertThat(peek.get().getComponent()).contains(new CeTask.Component(branch.getUuid(), project.getKey(), project.getName()));
assertThat(peek.get().getEntity()).contains(new CeTask.Component(project.getUuid(), project.getKey(), project.getName()));

// no more pending tasks
peek = underTest.peek(WORKER_UUID_2, true);
@@ -403,7 +403,7 @@ public class InternalCeQueueImplIT {

@Test
public void peek_is_paused_then_resumed() {
CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
underTest.pauseWorkers();

Optional<CeTask> peek = underTest.peek(WORKER_UUID_1, true);
@@ -429,7 +429,7 @@ public class InternalCeQueueImplIT {

@Test
public void peek_nothing_if_application_status_stopping() {
submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
when(computeEngineStatus.getStatus()).thenReturn(STOPPING);

Optional<CeTask> peek = underTest.peek(WORKER_UUID_1, true);
@@ -512,7 +512,7 @@ public class InternalCeQueueImplIT {

@Test
public void cancel_pending() {
CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
CeQueueDto queueDto = db.getDbClient().ceQueueDao().selectByUuid(db.getSession(), task.getUuid()).get();

underTest.cancel(db.getSession(), queueDto);
@@ -524,7 +524,7 @@ public class InternalCeQueueImplIT {

@Test
public void fail_to_cancel_if_in_progress() {
CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
underTest.peek(WORKER_UUID_2, true);
CeQueueDto queueDto = db.getDbClient().ceQueueDao().selectByUuid(db.getSession(), task.getUuid()).get();

@@ -535,9 +535,9 @@ public class InternalCeQueueImplIT {

@Test
public void cancelAll_pendings_but_not_in_progress() {
CeTask inProgressTask = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
CeTask pendingTask1 = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_2"));
CeTask pendingTask2 = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_3"));
CeTask inProgressTask = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
CeTask pendingTask1 = submit(CeTaskTypes.REPORT, newProject("PROJECT_2"));
CeTask pendingTask2 = submit(CeTaskTypes.REPORT, newProject("PROJECT_3"));
underTest.peek(WORKER_UUID_2, true);

int canceledCount = underTest.cancelAll();
@@ -675,40 +675,43 @@ public class InternalCeQueueImplIT {
assertThat(dto.getTaskType()).isEqualTo(taskSubmit.getType());
Optional<CeTaskSubmit.Component> component = taskSubmit.getComponent();
if (component.isPresent()) {
assertThat(dto.getMainComponentUuid()).isEqualTo(component.get().getMainComponentUuid());
assertThat(dto.getEntityUuid()).isEqualTo(component.get().getEntityUuid());
assertThat(dto.getComponentUuid()).isEqualTo(component.get().getUuid());
} else {
assertThat(dto.getMainComponentUuid()).isNull();
assertThat(dto.getEntityUuid()).isNull();
assertThat(dto.getComponentUuid()).isNull();
}
assertThat(dto.getSubmitterUuid()).isEqualTo(taskSubmit.getSubmitterUuid());
assertThat(dto.getCreatedAt()).isEqualTo(dto.getUpdatedAt());
}

private ComponentDto newProjectDto(String uuid) {
return ComponentTesting.newPublicProjectDto(uuid).setName("name_" + uuid).setKey("key_" + uuid);
private ProjectData newProject(String uuid) {
return db.components().insertPublicProject(uuid);
}

private CeTask submit(String reportType, ComponentDto mainBranchComponent) {
return underTest.submit(createTaskSubmit(reportType, mainBranchComponent, mainBranchComponent, null));
private CeTask submit(String reportType, BranchDto branchDto) {
return underTest.submit(createTaskSubmit(reportType, branchDto.getProjectUuid(), branchDto.getUuid(), null));
}

private CeTask submit(String reportType, ComponentDto mainBranchComponent, ComponentDto branchComponent) {
return underTest.submit(createTaskSubmit(reportType, mainBranchComponent, branchComponent, null));
private CeTask submit(String reportType, ProjectData projectData) {
return underTest.submit(createTaskSubmit(reportType, projectData.getProjectDto().getUuid(), projectData.getMainBranchDto().getUuid(), null));
}

private CeTaskSubmit createTaskSubmit(String type) {
return createTaskSubmit(type, null, null, null);
}

private CeTaskSubmit createTaskSubmit(String type, @Nullable ComponentDto mainBranchComponentDto, @Nullable ComponentDto componentDto,
@Nullable String submitterUuid) {
private CeTaskSubmit createTaskSubmit(String type, ProjectData projectData, @Nullable String submitterUuid) {
return createTaskSubmit(type, projectData.projectUuid(), projectData.getMainBranchDto().getUuid(), submitterUuid);
}

private CeTaskSubmit createTaskSubmit(String type, @Nullable String entityUuid, @Nullable String componentUuid, @Nullable String submitterUuid) {
CeTaskSubmit.Builder builder = underTest.prepareSubmit()
.setType(type)
.setSubmitterUuid(submitterUuid)
.setCharacteristics(emptyMap());
if (componentDto != null && mainBranchComponentDto != null) {
builder.setComponent(CeTaskSubmit.Component.fromDto(componentDto.uuid(), mainBranchComponentDto.uuid()));
if (componentUuid != null && entityUuid != null) {
builder.setComponent(CeTaskSubmit.Component.fromDto(componentUuid, entityUuid));
}
return builder.build();
}
@@ -719,10 +722,6 @@ public class InternalCeQueueImplIT {
return taskResult;
}

private ComponentDto insertComponent(ComponentDto componentDto) {
return db.components().insertComponent(componentDto);
}

private CeQueueDto makeInProgress(CeQueueDto ceQueueDto, String workerUuid) {
CeQueueTesting.makeInProgress(session, workerUuid, system2.now(), ceQueueDto);
return db.getDbClient().ceQueueDao().selectByUuid(session, ceQueueDto.getUuid()).get();

+ 9
- 9
server/sonar-ce/src/it/java/org/sonar/ce/queue/NextPendingTaskPickerIT.java View File

@@ -205,7 +205,7 @@ public class NextPendingTaskPickerIT {
// we have branch task in progress.
insertInProgress("1");
// The PR can run in parallel, but needs to wait for this other project to finish. We dont allow PRs to jump ahead
insertPending("2", c -> c.setMainComponentUuid("different project"));
insertPending("2", c -> c.setEntityUuid("different project"));
insertPendingPullRequest("3");

Optional<CeQueueDto> ceQueueDto = underTest.findPendingTask("workerUuid", db.getSession(), true);
@@ -220,7 +220,7 @@ public class NextPendingTaskPickerIT {
insertInProgress("1");
// The PR can run in parallel and is ahead of the other project
insertPendingPullRequest("2");
insertPending("3", c -> c.setMainComponentUuid("different project"));
insertPending("3", c -> c.setEntityUuid("different project"));

Optional<CeQueueDto> ceQueueDto = underTest.findPendingTask("workerUuid", db.getSession(), true);

@@ -247,7 +247,7 @@ public class NextPendingTaskPickerIT {
public void findPendingTask_excludingViewPickUpOrphanBranches() {
insertPending("1", dto -> dto
.setComponentUuid("1")
.setMainComponentUuid("non-existing-uuid")
.setEntityUuid("non-existing-uuid")
.setStatus(PENDING)
.setTaskType(CeTaskTypes.BRANCH_ISSUE_SYNC)
.setCreatedAt(100_000L));
@@ -260,11 +260,11 @@ public class NextPendingTaskPickerIT {
@Test
public void exclude_portfolios_computation_when_indexing_issues() {
String taskUuid1 = "1", taskUuid2 = "2";
String mainComponentUuid = "1";
insertBranch(mainComponentUuid);
String branchUuid = "1";
insertBranch(branchUuid);
insertPending(taskUuid1, dto -> dto
.setComponentUuid(mainComponentUuid)
.setMainComponentUuid(mainComponentUuid)
.setComponentUuid(branchUuid)
.setEntityUuid("entity_uuid")
.setStatus(PENDING)
.setTaskType(CeTaskTypes.BRANCH_ISSUE_SYNC)
.setCreatedAt(100_000L));
@@ -273,7 +273,7 @@ public class NextPendingTaskPickerIT {
insertView(view_uuid);
insertPending(taskUuid2, dto -> dto
.setComponentUuid(view_uuid)
.setMainComponentUuid(view_uuid)
.setEntityUuid(view_uuid)
.setStatus(PENDING)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(100_000L));
@@ -351,7 +351,7 @@ public class NextPendingTaskPickerIT {
dto.setStatus(status);
dto.setSubmitterUuid("henri");
dto.setComponentUuid(UUID.randomUUID().toString());
dto.setMainComponentUuid("1");
dto.setEntityUuid("1");
if (ceQueueDtoConsumer != null) {
ceQueueDtoConsumer.accept(dto);
}

+ 3
- 2
server/sonar-ce/src/it/java/org/sonar/ce/taskprocessor/CeWorkerImplIT.java View File

@@ -743,11 +743,12 @@ public class CeWorkerImplIT {
for (int i = 0; i < characteristics.length; i += 2) {
characteristicMap.put(characteristics[i], characteristics[i + 1]);
}
CeTask.Component component = new CeTask.Component("PROJECT_1", null, null);
CeTask.Component entity = new CeTask.Component("PROJECT_1", null, null);
CeTask.Component component = new CeTask.Component("BRANCH_1", null, null);
return new CeTask.Builder()
.setUuid("TASK_1").setType(CeTaskTypes.REPORT)
.setComponent(component)
.setMainComponent(component)
.setEntity(entity)
.setSubmitter(submitter)
.setCharacteristics(characteristicMap)
.build();

+ 1
- 1
server/sonar-ce/src/main/java/org/sonar/ce/monitoring/CEQueueStatusImpl.java View File

@@ -77,7 +77,7 @@ public class CEQueueStatusImpl implements CEQueueStatus {
@Override
public Optional<Long> getLongestTimePending() {
try (DbSession dbSession = dbClient.openSession(false)) {
return dbClient.ceQueueDao().selectCreationDateOfOldestPendingByMainComponentUuid(dbSession, null)
return dbClient.ceQueueDao().selectCreationDateOfOldestPendingByEntityUuid(dbSession, null)
.map(creationDate -> system.now() - creationDate);
}
}

+ 1
- 7
server/sonar-ce/src/main/java/org/sonar/ce/queue/InternalCeQueueImpl.java View File

@@ -29,7 +29,6 @@ import java.util.Optional;
import java.util.Set;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;

import org.sonar.api.ce.ComputeEngineSide;
import org.sonar.api.utils.System2;
import org.slf4j.Logger;
@@ -46,14 +45,12 @@ import org.sonar.db.DbSession;
import org.sonar.db.ce.CeActivityDto;
import org.sonar.db.ce.CeQueueDto;
import org.sonar.db.ce.CeTaskCharacteristicDto;
import org.sonar.db.component.ComponentDto;
import org.sonar.server.platform.NodeInformation;

import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.String.format;
import static java.util.Collections.singletonList;
import static java.util.Objects.requireNonNull;
import static java.util.Optional.ofNullable;
import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;

@ComputeEngineSide
@@ -88,13 +85,10 @@ public class InternalCeQueueImpl extends CeQueueImpl implements InternalCeQueue
return Optional.empty();
}
CeQueueDto taskDto = opt.get();
Map<String, ComponentDto> componentsByUuid = loadComponentDtos(dbSession, taskDto);
Map<String, String> characteristics = dbClient.ceTaskCharacteristicsDao().selectByTaskUuids(dbSession, singletonList(taskDto.getUuid())).stream()
.collect(uniqueIndex(CeTaskCharacteristicDto::getKey, CeTaskCharacteristicDto::getValue));

CeTask task = convertToTask(dbSession, taskDto, characteristics,
ofNullable(taskDto.getComponentUuid()).map(componentsByUuid::get).orElse(null),
ofNullable(taskDto.getMainComponentUuid()).map(componentsByUuid::get).orElse(null));
CeTask task = convertToTask(dbSession, taskDto, characteristics);
queueStatus.addInProgress();
return Optional.of(task);
}

+ 5
- 5
server/sonar-ce/src/main/java/org/sonar/ce/queue/NextPendingTaskPicker.java View File

@@ -108,8 +108,8 @@ public class NextPendingTaskPicker {
}

private static List<PrOrBranchTask> filterOldestPerProject(List<PrOrBranchTask> queuedPrOrBranches) {
Set<String> mainComponentUuidsSeen = new HashSet<>();
return queuedPrOrBranches.stream().filter(t -> mainComponentUuidsSeen.add(t.getMainComponentUuid())).toList();
Set<String> entityUuidsSeen = new HashSet<>();
return queuedPrOrBranches.stream().filter(t -> entityUuidsSeen.add(t.getEntityUuid())).toList();
}

/**
@@ -120,9 +120,9 @@ public class NextPendingTaskPicker {
* This method returns the longest waiting branch in the queue which can be scheduled concurrently with pull requests.
*/
private static boolean canRunBranch(PrOrBranchTask task, List<PrOrBranchTask> inProgress) {
String mainComponentUuid = task.getMainComponentUuid();
String entityUuid = task.getEntityUuid();
List<PrOrBranchTask> sameComponentTasks = inProgress.stream()
.filter(t -> t.getMainComponentUuid().equals(mainComponentUuid))
.filter(t -> t.getEntityUuid().equals(entityUuid))
.toList();
//we can peek branch analysis task only if all the other in progress tasks for this component uuid are pull requests
return sameComponentTasks.stream().map(PrOrBranchTask::getBranchType).allMatch(s -> Objects.equals(s, PULL_REQUEST));
@@ -135,7 +135,7 @@ public class NextPendingTaskPicker {
private static boolean canRunPr(PrOrBranchTask task, List<PrOrBranchTask> inProgress) {
// return true unless the same PR is already in progress
return inProgress.stream()
.noneMatch(pr -> pr.getMainComponentUuid().equals(task.getMainComponentUuid()) && Objects.equals(pr.getBranchType(), PULL_REQUEST) &&
.noneMatch(pr -> pr.getEntityUuid().equals(task.getEntityUuid()) && Objects.equals(pr.getBranchType(), PULL_REQUEST) &&
Objects.equals(pr.getComponentUuid(), (task.getComponentUuid())));
}
}

+ 1
- 1
server/sonar-ce/src/main/java/org/sonar/ce/taskprocessor/CeWorkerImpl.java View File

@@ -270,7 +270,7 @@ public class CeWorkerImpl implements CeWorker {
private static Profiler startLogProfiler(CeTask task) {
Profiler profiler = Profiler.create(LOG)
.logTimeLast(true)
.addContext("project", task.getMainComponent().flatMap(CeTask.Component::getKey).orElse(null))
.addContext("project", task.getEntity().flatMap(CeTask.Component::getKey).orElse(null))
.addContext("type", task.getType());
for (Map.Entry<String, String> characteristic : task.getCharacteristics().entrySet()) {
profiler.addContext(characteristic.getKey(), characteristic.getValue());

+ 3
- 1
server/sonar-ce/src/test/java/org/sonar/ce/taskprocessor/CeTaskProcessorRepositoryImplTest.java View File

@@ -105,11 +105,13 @@ public class CeTaskProcessorRepositoryImplTest {

private static CeTask createCeTask(String ceTaskType, String key) {
CeTask.Component component = new CeTask.Component("uuid_" + key, key, "name_" + key);
CeTask.Component entity = new CeTask.Component("uuid_entity_" + key, key, "name_" + key);

return new CeTask.Builder()
.setType(ceTaskType)
.setUuid("task_uuid_" + key)
.setComponent(component)
.setMainComponent(component)
.setEntity(entity)
.build();
}


+ 61
- 61
server/sonar-db-dao/src/it/java/org/sonar/db/ce/CeActivityDaoIT.java View File

@@ -67,7 +67,7 @@ import static org.sonar.db.ce.CeTaskTypes.REPORT;
@RunWith(DataProviderRunner.class)
public class CeActivityDaoIT {

private static final String MAINCOMPONENT_1 = randomAlphabetic(12);
private static final String ENTITY_1 = randomAlphabetic(12);
private static final String MAINCOMPONENT_2 = randomAlphabetic(13);
private static final String COMPONENT_1 = randomAlphabetic(14);

@@ -89,14 +89,14 @@ public class CeActivityDaoIT {

@Test
public void test_insert() {
CeActivityDto inserted = insert("TASK_1", REPORT, COMPONENT_1, MAINCOMPONENT_1, SUCCESS);
CeActivityDto inserted = insert("TASK_1", REPORT, COMPONENT_1, ENTITY_1, SUCCESS);

Optional<CeActivityDto> saved = underTest.selectByUuid(db.getSession(), "TASK_1");
assertThat(saved).isPresent();
CeActivityDto dto = saved.get();
assertThat(dto.getUuid()).isEqualTo("TASK_1");
assertThat(dto.getNodeName()).isEqualTo(NODE_NAME);
assertThat(dto.getMainComponentUuid()).isEqualTo(MAINCOMPONENT_1);
assertThat(dto.getEntityUuid()).isEqualTo(ENTITY_1);
assertThat(dto.getComponentUuid()).isEqualTo(COMPONENT_1);
assertThat(dto.getStatus()).isEqualTo(SUCCESS);
assertThat(dto.getSubmitterUuid()).isEqualTo("submitter uuid");
@@ -105,7 +105,7 @@ public class CeActivityDaoIT {
assertThat(dto.getIsLast()).isTrue();
assertThat(dto.getMainIsLast()).isTrue();
assertThat(dto.getIsLastKey()).isEqualTo("REPORT" + COMPONENT_1);
assertThat(dto.getMainIsLastKey()).isEqualTo("REPORT" + MAINCOMPONENT_1);
assertThat(dto.getMainIsLastKey()).isEqualTo("REPORT" + ENTITY_1);
assertThat(dto.getCreatedAt()).isEqualTo(INITIAL_TIME + 1);
assertThat(dto.getStartedAt()).isEqualTo(1_500_000_000_000L);
assertThat(dto.getExecutedAt()).isEqualTo(1_500_000_000_500L);
@@ -362,7 +362,7 @@ public class CeActivityDaoIT {

@Test
public void test_insert_of_errorMessage_of_1_000_chars() {
CeActivityDto dto = createActivityDto("TASK_1", REPORT, COMPONENT_1, MAINCOMPONENT_1, FAILED)
CeActivityDto dto = createActivityDto("TASK_1", REPORT, COMPONENT_1, ENTITY_1, FAILED)
.setErrorMessage(Strings.repeat("x", 1_000));
underTest.insert(db.getSession(), dto);

@@ -373,7 +373,7 @@ public class CeActivityDaoIT {
@Test
public void test_insert_of_errorMessage_of_1_001_chars_is_truncated_to_1000() {
String expected = Strings.repeat("x", 1_000);
CeActivityDto dto = createActivityDto("TASK_1", REPORT, COMPONENT_1, MAINCOMPONENT_1, FAILED)
CeActivityDto dto = createActivityDto("TASK_1", REPORT, COMPONENT_1, ENTITY_1, FAILED)
.setErrorMessage(expected + "y");
underTest.insert(db.getSession(), dto);

@@ -383,7 +383,7 @@ public class CeActivityDaoIT {

@Test
public void test_insert_error_message_and_stacktrace() {
CeActivityDto dto = createActivityDto("TASK_1", REPORT, COMPONENT_1, MAINCOMPONENT_1, FAILED)
CeActivityDto dto = createActivityDto("TASK_1", REPORT, COMPONENT_1, ENTITY_1, FAILED)
.setErrorStacktrace("error stack");
underTest.insert(db.getSession(), dto);

@@ -396,7 +396,7 @@ public class CeActivityDaoIT {

@Test
public void test_insert_error_message_only() {
CeActivityDto dto = createActivityDto("TASK_1", REPORT, COMPONENT_1, MAINCOMPONENT_1, FAILED);
CeActivityDto dto = createActivityDto("TASK_1", REPORT, COMPONENT_1, ENTITY_1, FAILED);
underTest.insert(db.getSession(), dto);

Optional<CeActivityDto> saved = underTest.selectByUuid(db.getSession(), "TASK_1");
@@ -408,7 +408,7 @@ public class CeActivityDaoIT {
@Test
public void insert_must_set_relevant_is_last_field() {
// only a single task on MAINCOMPONENT_1 -> is_last=true
insert("TASK_1", REPORT, MAINCOMPONENT_1, SUCCESS);
insert("TASK_1", REPORT, ENTITY_1, SUCCESS);
assertThat(underTest.selectByUuid(db.getSession(), "TASK_1").get().getIsLast()).isTrue();

// only a single task on MAINCOMPONENT_2 -> is_last=true
@@ -416,13 +416,13 @@ public class CeActivityDaoIT {
assertThat(underTest.selectByUuid(db.getSession(), "TASK_2").get().getIsLast()).isTrue();

// two tasks on MAINCOMPONENT_1, the most recent one is TASK_3
insert("TASK_3", REPORT, MAINCOMPONENT_1, FAILED);
insert("TASK_3", REPORT, ENTITY_1, FAILED);
assertThat(underTest.selectByUuid(db.getSession(), "TASK_1").get().getIsLast()).isFalse();
assertThat(underTest.selectByUuid(db.getSession(), "TASK_2").get().getIsLast()).isTrue();
assertThat(underTest.selectByUuid(db.getSession(), "TASK_3").get().getIsLast()).isTrue();

// inserting a cancelled task does not change the last task
insert("TASK_4", REPORT, MAINCOMPONENT_1, CANCELED);
insert("TASK_4", REPORT, ENTITY_1, CANCELED);
assertThat(underTest.selectByUuid(db.getSession(), "TASK_1").get().getIsLast()).isFalse();
assertThat(underTest.selectByUuid(db.getSession(), "TASK_2").get().getIsLast()).isTrue();
assertThat(underTest.selectByUuid(db.getSession(), "TASK_3").get().getIsLast()).isTrue();
@@ -431,8 +431,8 @@ public class CeActivityDaoIT {

@Test
public void test_selectByQuery() {
insert("TASK_1", REPORT, MAINCOMPONENT_1, SUCCESS);
insert("TASK_2", REPORT, MAINCOMPONENT_1, FAILED);
insert("TASK_1", REPORT, ENTITY_1, SUCCESS);
insert("TASK_2", REPORT, ENTITY_1, FAILED);
insert("TASK_3", REPORT, MAINCOMPONENT_2, SUCCESS);
insert("TASK_4", "views", null, SUCCESS);

@@ -442,7 +442,7 @@ public class CeActivityDaoIT {
assertThat(dtos).extracting("uuid").containsExactly("TASK_4", "TASK_3", "TASK_2", "TASK_1");

// select by component uuid
query = new CeTaskQuery().setMainComponentUuid(MAINCOMPONENT_1);
query = new CeTaskQuery().setEntityUuid(ENTITY_1);
dtos = underTest.selectByQuery(db.getSession(), query, forPage(1).andSize(100));
assertThat(dtos).extracting("uuid").containsExactly("TASK_2", "TASK_1");

@@ -460,7 +460,7 @@ public class CeActivityDaoIT {
assertThat(dtos).extracting("uuid").containsExactly("TASK_4");

// select by multiple conditions
query = new CeTaskQuery().setType(REPORT).setOnlyCurrents(true).setMainComponentUuid(MAINCOMPONENT_1);
query = new CeTaskQuery().setType(REPORT).setOnlyCurrents(true).setEntityUuid(ENTITY_1);
dtos = underTest.selectByQuery(db.getSession(), query, forPage(1).andSize(100));
assertThat(dtos).extracting("uuid").containsExactly("TASK_2");
}
@@ -468,9 +468,9 @@ public class CeActivityDaoIT {
@Test
public void test_selectByQuery_verify_order_if_same_date() {
system2.setNow(INITIAL_TIME);
insert("TASK_1", REPORT, MAINCOMPONENT_1, SUCCESS);
insert("TASK_1", REPORT, ENTITY_1, SUCCESS);
system2.setNow(INITIAL_TIME);
insert("TASK_2", REPORT, MAINCOMPONENT_1, FAILED);
insert("TASK_2", REPORT, ENTITY_1, FAILED);
system2.setNow(INITIAL_TIME);
insert("TASK_3", REPORT, MAINCOMPONENT_2, SUCCESS);
system2.setNow(INITIAL_TIME);
@@ -482,7 +482,7 @@ public class CeActivityDaoIT {
assertThat(dtos).extracting("uuid").containsExactly("TASK_4", "TASK_3", "TASK_2", "TASK_1");

// select by component uuid
query = new CeTaskQuery().setMainComponentUuid(MAINCOMPONENT_1);
query = new CeTaskQuery().setEntityUuid(ENTITY_1);
dtos = underTest.selectByQuery(db.getSession(), query, forPage(1).andSize(100));
assertThat(dtos).extracting("uuid").containsExactly("TASK_2", "TASK_1");

@@ -500,17 +500,17 @@ public class CeActivityDaoIT {
assertThat(dtos).extracting("uuid").containsExactly("TASK_4");

// select by multiple conditions
query = new CeTaskQuery().setType(REPORT).setOnlyCurrents(true).setMainComponentUuid(MAINCOMPONENT_1);
query = new CeTaskQuery().setType(REPORT).setOnlyCurrents(true).setEntityUuid(ENTITY_1);
dtos = underTest.selectByQuery(db.getSession(), query, forPage(1).andSize(100));
assertThat(dtos).extracting("uuid").containsExactly("TASK_2");
}

@Test
public void selectByQuery_does_not_populate_errorStacktrace_field() {
insert("TASK_1", REPORT, MAINCOMPONENT_1, FAILED);
underTest.insert(db.getSession(), createActivityDto("TASK_2", REPORT, COMPONENT_1, MAINCOMPONENT_1, FAILED).setErrorStacktrace("some stack"));
insert("TASK_1", REPORT, ENTITY_1, FAILED);
underTest.insert(db.getSession(), createActivityDto("TASK_2", REPORT, COMPONENT_1, ENTITY_1, FAILED).setErrorStacktrace("some stack"));

List<CeActivityDto> dtos = underTest.selectByQuery(db.getSession(), new CeTaskQuery().setMainComponentUuid(MAINCOMPONENT_1), forPage(1).andSize(100));
List<CeActivityDto> dtos = underTest.selectByQuery(db.getSession(), new CeTaskQuery().setEntityUuid(ENTITY_1), forPage(1).andSize(100));

assertThat(dtos)
.hasSize(2)
@@ -519,13 +519,13 @@ public class CeActivityDaoIT {

@Test
public void selectByQuery_populates_hasScannerContext_flag() {
insert("TASK_1", REPORT, MAINCOMPONENT_1, SUCCESS);
insert("TASK_1", REPORT, ENTITY_1, SUCCESS);
CeActivityDto dto2 = insert("TASK_2", REPORT, MAINCOMPONENT_2, SUCCESS);
insertScannerContext(dto2.getUuid());

CeActivityDto dto = underTest.selectByQuery(db.getSession(), new CeTaskQuery().setMainComponentUuid(MAINCOMPONENT_1), forPage(1).andSize(100)).iterator().next();
CeActivityDto dto = underTest.selectByQuery(db.getSession(), new CeTaskQuery().setEntityUuid(ENTITY_1), forPage(1).andSize(100)).iterator().next();
assertThat(dto.isHasScannerContext()).isFalse();
dto = underTest.selectByQuery(db.getSession(), new CeTaskQuery().setMainComponentUuid(MAINCOMPONENT_2), forPage(1).andSize(100)).iterator().next();
dto = underTest.selectByQuery(db.getSession(), new CeTaskQuery().setEntityUuid(MAINCOMPONENT_2), forPage(1).andSize(100)).iterator().next();
assertThat(dto.isHasScannerContext()).isTrue();
}

@@ -550,7 +550,7 @@ public class CeActivityDaoIT {
.containsExactly(tuple("TASK_4", 60), tuple("TASK_3", 10), tuple("TASK_2", 30), tuple("TASK_1", moreThan1));

// select by component uuid
query = new CeTaskQuery().setMainComponentUuid("PROJECT_1");
query = new CeTaskQuery().setEntityUuid("PROJECT_1");
assertThat(underTest.selectByQuery(db.getSession(), query, forPage(1).andSize(100)))
.extracting(CeActivityDto::getUuid, ceActivityDto -> ceActivityDto.getCeTaskMessageDtos().size())
.containsExactly(tuple("TASK_2", 30), tuple("TASK_1", moreThan1));
@@ -572,7 +572,7 @@ public class CeActivityDaoIT {
.containsExactly(tuple("TASK_4", 60));

// select by multiple conditions
query = new CeTaskQuery().setType(REPORT).setOnlyCurrents(true).setMainComponentUuid("PROJECT_1");
query = new CeTaskQuery().setType(REPORT).setOnlyCurrents(true).setEntityUuid("PROJECT_1");
assertThat(underTest.selectByQuery(db.getSession(), query, forPage(1).andSize(100)))
.extracting(CeActivityDto::getUuid, ceActivityDto -> ceActivityDto.getCeTaskMessageDtos().size())
.containsExactly(tuple("TASK_2", 30));
@@ -593,8 +593,8 @@ public class CeActivityDaoIT {

@Test
public void selectByQuery_is_paginated_and_return_results_sorted_from_last_to_first() {
insert("TASK_1", REPORT, MAINCOMPONENT_1, SUCCESS);
insert("TASK_2", REPORT, MAINCOMPONENT_1, FAILED);
insert("TASK_1", REPORT, ENTITY_1, SUCCESS);
insert("TASK_2", REPORT, ENTITY_1, FAILED);
insert("TASK_3", REPORT, MAINCOMPONENT_2, SUCCESS);
insert("TASK_4", "views", null, SUCCESS);

@@ -609,10 +609,10 @@ public class CeActivityDaoIT {

@Test
public void selectByQuery_no_results_if_shortcircuited_by_component_uuids() {
insert("TASK_1", REPORT, MAINCOMPONENT_1, SUCCESS);
insert("TASK_1", REPORT, ENTITY_1, SUCCESS);

CeTaskQuery query = new CeTaskQuery();
query.setMainComponentUuids(Collections.emptyList());
query.setEntityUuids(Collections.emptyList());
assertThat(underTest.selectByQuery(db.getSession(), query, forPage(1).andSize(1))).isEmpty();
}

@@ -695,8 +695,8 @@ public class CeActivityDaoIT {

@Test
public void selectOlderThan_does_not_populate_errorStacktrace() {
insert("TASK_1", REPORT, MAINCOMPONENT_1, FAILED);
underTest.insert(db.getSession(), createActivityDto("TASK_2", REPORT, COMPONENT_1, MAINCOMPONENT_1, FAILED).setErrorStacktrace("some stack"));
insert("TASK_1", REPORT, ENTITY_1, FAILED);
underTest.insert(db.getSession(), createActivityDto("TASK_2", REPORT, COMPONENT_1, ENTITY_1, FAILED).setErrorStacktrace("some stack"));

List<CeActivityDto> dtos = underTest.selectOlderThan(db.getSession(), system2.now() + 1_000_000L);

@@ -722,9 +722,9 @@ public class CeActivityDaoIT {

@Test
public void deleteByUuids() {
insert("TASK_1", "REPORT", MAINCOMPONENT_1, SUCCESS);
insert("TASK_2", "REPORT", MAINCOMPONENT_1, SUCCESS);
insert("TASK_3", "REPORT", MAINCOMPONENT_1, SUCCESS);
insert("TASK_1", "REPORT", ENTITY_1, SUCCESS);
insert("TASK_2", "REPORT", ENTITY_1, SUCCESS);
insert("TASK_3", "REPORT", ENTITY_1, SUCCESS);

underTest.deleteByUuids(db.getSession(), ImmutableSet.of("TASK_1", "TASK_3"));
assertThat(underTest.selectByUuid(db.getSession(), "TASK_1")).isEmpty();
@@ -734,7 +734,7 @@ public class CeActivityDaoIT {

@Test
public void deleteByUuids_does_nothing_if_uuid_does_not_exist() {
insert("TASK_1", "REPORT", MAINCOMPONENT_1, SUCCESS);
insert("TASK_1", "REPORT", ENTITY_1, SUCCESS);

// must not fail
underTest.deleteByUuids(db.getSession(), singleton("TASK_2"));
@@ -743,48 +743,48 @@ public class CeActivityDaoIT {
}

@Test
public void count_last_by_status_and_main_component_uuid() {
insert("TASK_1", CeTaskTypes.REPORT, MAINCOMPONENT_1, SUCCESS);
public void count_last_by_status_and_entity_uuid() {
insert("TASK_1", CeTaskTypes.REPORT, ENTITY_1, SUCCESS);
// component 2
insert("TASK_2", CeTaskTypes.REPORT, MAINCOMPONENT_2, SUCCESS);
// status failed
insert("TASK_3", CeTaskTypes.REPORT, MAINCOMPONENT_1, FAILED);
insert("TASK_3", CeTaskTypes.REPORT, ENTITY_1, FAILED);
// status canceled
insert("TASK_4", CeTaskTypes.REPORT, MAINCOMPONENT_1, CANCELED);
insert("TASK_5", CeTaskTypes.REPORT, MAINCOMPONENT_1, SUCCESS);
insert("TASK_4", CeTaskTypes.REPORT, ENTITY_1, CANCELED);
insert("TASK_5", CeTaskTypes.REPORT, ENTITY_1, SUCCESS);
db.commit();

assertThat(underTest.countLastByStatusAndMainComponentUuid(dbSession, SUCCESS, MAINCOMPONENT_1)).isOne();
assertThat(underTest.countLastByStatusAndMainComponentUuid(dbSession, SUCCESS, null)).isEqualTo(2);
assertThat(underTest.countLastByStatusAndEntityUuid(dbSession, SUCCESS, ENTITY_1)).isOne();
assertThat(underTest.countLastByStatusAndEntityUuid(dbSession, SUCCESS, null)).isEqualTo(2);
}

@Test
public void selectLastByComponentUuidAndTaskType_returns_task_of_given_type() {
insert("TASK_1", "VIEW_REFRESH", MAINCOMPONENT_1, MAINCOMPONENT_1, SUCCESS);
insert("TASK_2", CeTaskTypes.REPORT, MAINCOMPONENT_1, MAINCOMPONENT_1, SUCCESS);
insert("TASK_3", "PROJECT_EXPORT", MAINCOMPONENT_1, MAINCOMPONENT_1, SUCCESS);
insert("TASK_4", "PROJECT_IMPORT", MAINCOMPONENT_1, MAINCOMPONENT_1, SUCCESS);
insert("TASK_1", "VIEW_REFRESH", ENTITY_1, ENTITY_1, SUCCESS);
insert("TASK_2", CeTaskTypes.REPORT, ENTITY_1, ENTITY_1, SUCCESS);
insert("TASK_3", "PROJECT_EXPORT", ENTITY_1, ENTITY_1, SUCCESS);
insert("TASK_4", "PROJECT_IMPORT", ENTITY_1, ENTITY_1, SUCCESS);
db.commit();

Optional<CeActivityDto> result = underTest.selectLastByComponentUuidAndTaskType(db.getSession(), MAINCOMPONENT_1, "PROJECT_EXPORT");
Optional<CeActivityDto> result = underTest.selectLastByComponentUuidAndTaskType(db.getSession(), ENTITY_1, "PROJECT_EXPORT");

assertThat(result).hasValueSatisfying(value -> assertThat(value.getUuid()).isEqualTo("TASK_3"));
}

@Test
public void selectLastByComponentUuidAndTaskType_returns_empty_if_task_of_given_type_does_not_exist() {
insert("TASK_1", CeTaskTypes.REPORT, MAINCOMPONENT_1, SUCCESS);
insert("TASK_1", CeTaskTypes.REPORT, ENTITY_1, SUCCESS);
db.commit();

Optional<CeActivityDto> result = underTest.selectLastByComponentUuidAndTaskType(db.getSession(), MAINCOMPONENT_1, "PROJECT_EXPORT");
Optional<CeActivityDto> result = underTest.selectLastByComponentUuidAndTaskType(db.getSession(), ENTITY_1, "PROJECT_EXPORT");

assertThat(result).isEmpty();
}

@Test
public void selectByTaskType() {
insert("TASK_1", CeTaskTypes.REPORT, MAINCOMPONENT_1, SUCCESS);
insert("TASK_2", CeTaskTypes.BRANCH_ISSUE_SYNC, MAINCOMPONENT_1, SUCCESS);
insert("TASK_1", CeTaskTypes.REPORT, ENTITY_1, SUCCESS);
insert("TASK_2", CeTaskTypes.BRANCH_ISSUE_SYNC, ENTITY_1, SUCCESS);
db.commit();

assertThat(underTest.selectByTaskType(db.getSession(), CeTaskTypes.REPORT))
@@ -801,8 +801,8 @@ public class CeActivityDaoIT {
public void hasAnyFailedOrCancelledIssueSyncTask() {
assertThat(underTest.hasAnyFailedOrCancelledIssueSyncTask(db.getSession())).isFalse();

insert("TASK_1", REPORT, MAINCOMPONENT_1, SUCCESS);
insert("TASK_2", REPORT, MAINCOMPONENT_1, FAILED);
insert("TASK_1", REPORT, ENTITY_1, SUCCESS);
insert("TASK_2", REPORT, ENTITY_1, FAILED);

ProjectDto projectDto1 = db.components().insertPrivateProject(
branchDto -> branchDto.setNeedIssueSync(false), c -> {
@@ -855,26 +855,26 @@ public class CeActivityDaoIT {
return insert(uuid, type, mainComponentUuid, mainComponentUuid, status);
}

private CeActivityDto insertAndCommit(String uuid, String type, @Nullable String componentUuid, @Nullable String mainComponentUuid, CeActivityDto.Status status) {
CeActivityDto res = insert(uuid, type, componentUuid, mainComponentUuid, status);
private CeActivityDto insertAndCommit(String uuid, String type, @Nullable String componentUuid, @Nullable String entityUuid, CeActivityDto.Status status) {
CeActivityDto res = insert(uuid, type, componentUuid, entityUuid, status);
db.commit();
return res;
}

private CeActivityDto insert(String uuid, String type, @Nullable String componentUuid, @Nullable String mainComponentUuid, CeActivityDto.Status status) {
CeActivityDto dto = createActivityDto(uuid, type, componentUuid, mainComponentUuid, status);
private CeActivityDto insert(String uuid, String type, @Nullable String componentUuid, @Nullable String entityUuid, CeActivityDto.Status status) {
CeActivityDto dto = createActivityDto(uuid, type, componentUuid, entityUuid, status);
system2.tick();
underTest.insert(db.getSession(), dto);
return dto;
}

private CeActivityDto createActivityDto(String uuid, String type, @Nullable String componentUuid, @Nullable String mainComponentUuid, CeActivityDto.Status status) {
private CeActivityDto createActivityDto(String uuid, String type, @Nullable String componentUuid, @Nullable String entityUuid, CeActivityDto.Status status) {
CeQueueDto creating = new CeQueueDto();
creating.setUuid(uuid);
creating.setStatus(PENDING);
creating.setTaskType(type);
creating.setComponentUuid(componentUuid);
creating.setMainComponentUuid(mainComponentUuid);
creating.setEntityUuid(entityUuid);
creating.setSubmitterUuid("submitter uuid");
creating.setCreatedAt(system2.now());


+ 74
- 74
server/sonar-db-dao/src/it/java/org/sonar/db/ce/CeQueueDaoIT.java View File

@@ -58,8 +58,8 @@ public class CeQueueDaoIT {
private static final long INIT_TIME = 1_450_000_000_000L;
private static final String TASK_UUID_1 = "TASK_1";
private static final String TASK_UUID_2 = "TASK_2";
private static final String MAIN_COMPONENT_UUID_1 = "PROJECT_1";
private static final String MAIN_COMPONENT_UUID_2 = "PROJECT_2";
private static final String ENTITY_UUID_1 = "PROJECT_1";
private static final String ENTITY_UUID_2 = "PROJECT_2";
private static final String COMPONENT_UUID_1 = "BRANCH_1";
private static final String TASK_UUID_3 = "TASK_3";
private static final String SELECT_QUEUE_UUID_AND_STATUS_QUERY = "select uuid,status from ce_queue";
@@ -84,7 +84,7 @@ public class CeQueueDaoIT {
long now = 1_334_333L;
CeQueueDto dto = new CeQueueDto()
.setTaskType(CeTaskTypes.REPORT)
.setComponentUuid(MAIN_COMPONENT_UUID_1)
.setComponentUuid(ENTITY_UUID_1)
.setStatus(PENDING)
.setSubmitterUuid(SUBMITTER_LOGIN);

@@ -104,7 +104,7 @@ public class CeQueueDaoIT {
CeQueueDto saved = underTest.selectByUuid(db.getSession(), uuid).get();
assertThat(saved.getUuid()).isEqualTo(uuid);
assertThat(saved.getTaskType()).isEqualTo(CeTaskTypes.REPORT);
assertThat(saved.getComponentUuid()).isEqualTo(MAIN_COMPONENT_UUID_1);
assertThat(saved.getComponentUuid()).isEqualTo(ENTITY_UUID_1);
assertThat(saved.getStatus()).isEqualTo(PENDING);
assertThat(saved.getSubmitterUuid()).isEqualTo(SUBMITTER_LOGIN);
assertThat(saved.getWorkerUuid()).isNull();
@@ -115,7 +115,7 @@ public class CeQueueDaoIT {
CeQueueDto saved = underTest.selectByUuid(db.getSession(), uuid4).get();
assertThat(saved.getUuid()).isEqualTo(uuid4);
assertThat(saved.getTaskType()).isEqualTo(CeTaskTypes.REPORT);
assertThat(saved.getComponentUuid()).isEqualTo(MAIN_COMPONENT_UUID_1);
assertThat(saved.getComponentUuid()).isEqualTo(ENTITY_UUID_1);
assertThat(saved.getStatus()).isEqualTo(PENDING);
assertThat(saved.getSubmitterUuid()).isEqualTo(SUBMITTER_LOGIN);
assertThat(saved.getWorkerUuid()).isNull();
@@ -126,13 +126,13 @@ public class CeQueueDaoIT {

@Test
public void test_selectByUuid() {
CeQueueDto ceQueueDto = insertPending(TASK_UUID_1, MAIN_COMPONENT_UUID_1);
CeQueueDto ceQueueDto = insertPending(TASK_UUID_1, ENTITY_UUID_1);

assertThat(underTest.selectByUuid(db.getSession(), "TASK_UNKNOWN")).isEmpty();
CeQueueDto saved = underTest.selectByUuid(db.getSession(), TASK_UUID_1).get();
assertThat(saved.getUuid()).isEqualTo(TASK_UUID_1);
assertThat(saved.getTaskType()).isEqualTo(CeTaskTypes.REPORT);
assertThat(saved.getMainComponentUuid()).isEqualTo(MAIN_COMPONENT_UUID_1);
assertThat(saved.getEntityUuid()).isEqualTo(ENTITY_UUID_1);
assertThat(saved.getComponentUuid()).isEqualTo(ceQueueDto.getComponentUuid());
assertThat(saved.getStatus()).isEqualTo(PENDING);
assertThat(saved.getSubmitterUuid()).isEqualTo("henri");
@@ -144,19 +144,19 @@ public class CeQueueDaoIT {

@Test
public void test_selectByMainComponentUuid() {
insertPending(TASK_UUID_1, MAIN_COMPONENT_UUID_1);
insertPending(TASK_UUID_2, MAIN_COMPONENT_UUID_1);
insertPending(TASK_UUID_1, ENTITY_UUID_1);
insertPending(TASK_UUID_2, ENTITY_UUID_1);
insertPending(TASK_UUID_3, "PROJECT_2");

assertThat(underTest.selectByMainComponentUuid(db.getSession(), "UNKNOWN")).isEmpty();
assertThat(underTest.selectByMainComponentUuid(db.getSession(), MAIN_COMPONENT_UUID_1)).extracting("uuid").containsOnly(TASK_UUID_1, TASK_UUID_2);
assertThat(underTest.selectByMainComponentUuid(db.getSession(), "PROJECT_2")).extracting("uuid").containsOnly(TASK_UUID_3);
assertThat(underTest.selectByEntityUuid(db.getSession(), "UNKNOWN")).isEmpty();
assertThat(underTest.selectByEntityUuid(db.getSession(), ENTITY_UUID_1)).extracting("uuid").containsOnly(TASK_UUID_1, TASK_UUID_2);
assertThat(underTest.selectByEntityUuid(db.getSession(), "PROJECT_2")).extracting("uuid").containsOnly(TASK_UUID_3);
}

@Test
public void test_selectAllInAscOrder() {
insertPending(TASK_UUID_1, MAIN_COMPONENT_UUID_1);
insertPending(TASK_UUID_2, MAIN_COMPONENT_UUID_1);
insertPending(TASK_UUID_1, ENTITY_UUID_1);
insertPending(TASK_UUID_2, ENTITY_UUID_1);
insertPending(TASK_UUID_3, "PROJECT_2");

assertThat(underTest.selectAllInAscOrder(db.getSession())).extracting("uuid").containsOnly(TASK_UUID_1, TASK_UUID_2, TASK_UUID_3);
@@ -182,17 +182,17 @@ public class CeQueueDaoIT {
insertPending("p1", dto -> {
dto.setCreatedAt(time);
dto.setUpdatedAt(time + 500);
dto.setMainComponentUuid("c1");
dto.setEntityUuid("c1");
});
insertPending("p2", dto -> {
dto.setCreatedAt(time + 1000);
dto.setUpdatedAt(time + 2000);
dto.setMainComponentUuid("c2");
dto.setEntityUuid("c2");
});

makeInProgress("w1", alwaysIncreasingSystem2.now(), insertPending("i1", dto -> dto.setMainComponentUuid("c3")));
makeInProgress("w1", alwaysIncreasingSystem2.now(), insertPending("i1", dto -> dto.setEntityUuid("c3")));

assertThat(underTest.selectCreationDateOfOldestPendingByMainComponentUuid(db.getSession(), null))
assertThat(underTest.selectCreationDateOfOldestPendingByEntityUuid(db.getSession(), null))
.isEqualTo(Optional.of(time));
}

@@ -202,29 +202,29 @@ public class CeQueueDaoIT {
insertPending("p1", dto -> {
dto.setCreatedAt(time);
dto.setUpdatedAt(time + 500);
dto.setMainComponentUuid("c2");
dto.setEntityUuid("c2");
});
insertPending("p2", dto -> {
dto.setCreatedAt(time + 2000);
dto.setUpdatedAt(time + 3000);
dto.setMainComponentUuid("c1");
dto.setEntityUuid("c1");
});
insertPending("p3", dto -> {
dto.setCreatedAt(time + 4000);
dto.setUpdatedAt(time + 5000);
dto.setMainComponentUuid("c1");
dto.setEntityUuid("c1");
});

makeInProgress("w1", alwaysIncreasingSystem2.now(), insertPending("i1", dto -> dto.setMainComponentUuid("c1")));
makeInProgress("w1", alwaysIncreasingSystem2.now(), insertPending("i1", dto -> dto.setEntityUuid("c1")));

assertThat(underTest.selectCreationDateOfOldestPendingByMainComponentUuid(db.getSession(), "c1"))
assertThat(underTest.selectCreationDateOfOldestPendingByEntityUuid(db.getSession(), "c1"))
.isEqualTo(Optional.of(time + 2000));
}

@Test
public void selectCreationDateOfOldestPendingByMainComponentUuid_returns_empty_when_no_pending_tasks() {
makeInProgress("w1", alwaysIncreasingSystem2.now(), insertPending("i1"));
assertThat(underTest.selectCreationDateOfOldestPendingByMainComponentUuid(db.getSession(), null))
assertThat(underTest.selectCreationDateOfOldestPendingByEntityUuid(db.getSession(), null))
.isEmpty();
}

@@ -244,8 +244,8 @@ public class CeQueueDaoIT {

@Test
public void test_delete() {
insertPending(TASK_UUID_1, MAIN_COMPONENT_UUID_1);
insertPending(TASK_UUID_2, MAIN_COMPONENT_UUID_1);
insertPending(TASK_UUID_1, ENTITY_UUID_1);
insertPending(TASK_UUID_2, ENTITY_UUID_1);

int deletedCount = underTest.deleteByUuid(db.getSession(), "UNKNOWN");
assertThat(deletedCount).isZero();
@@ -262,7 +262,7 @@ public class CeQueueDaoIT {

@Test
public void test_delete_with_expected_status() {
insertPending(TASK_UUID_1, MAIN_COMPONENT_UUID_1);
insertPending(TASK_UUID_1, ENTITY_UUID_1);
insertInProgress(TASK_UUID_2, "workerUuid", System2.INSTANCE.now());

int deletedCount = underTest.deleteByUuid(db.getSession(), "UNKNOWN", null);
@@ -425,42 +425,42 @@ public class CeQueueDaoIT {
public void select_by_query() {
// task status not in query
insertPending(newCeQueueDto(TASK_UUID_1)
.setMainComponentUuid(MAIN_COMPONENT_UUID_1)
.setEntityUuid(ENTITY_UUID_1)
.setStatus(IN_PROGRESS)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(100_000L));

// too early
insertPending(newCeQueueDto(TASK_UUID_3)
.setMainComponentUuid(MAIN_COMPONENT_UUID_1)
.setEntityUuid(ENTITY_UUID_1)
.setStatus(PENDING)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(90_000L));

// task type not in query
insertPending(newCeQueueDto("TASK_4")
.setMainComponentUuid("PROJECT_2")
.setEntityUuid("PROJECT_2")
.setStatus(PENDING)
.setTaskType("ANOTHER_TYPE")
.setCreatedAt(100_000L));

// correct
insertPending(newCeQueueDto(TASK_UUID_2)
.setMainComponentUuid(MAIN_COMPONENT_UUID_1)
.setEntityUuid(ENTITY_UUID_1)
.setStatus(PENDING)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(100_000L));

// correct submitted later
insertPending(newCeQueueDto("TASK_5")
.setMainComponentUuid(MAIN_COMPONENT_UUID_1)
.setEntityUuid(ENTITY_UUID_1)
.setStatus(PENDING)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(120_000L));

// select by component uuid, status, task type and minimum submitted at
CeTaskQuery query = new CeTaskQuery()
.setMainComponentUuids(newArrayList(MAIN_COMPONENT_UUID_1, "PROJECT_2"))
.setEntityUuids(newArrayList(ENTITY_UUID_1, "PROJECT_2"))
.setStatuses(singletonList(PENDING.name()))
.setType(CeTaskTypes.REPORT)
.setMinSubmittedAt(100_000L);
@@ -475,7 +475,7 @@ public class CeQueueDaoIT {
@Test
public void select_by_query_returns_empty_list_when_only_current() {
insertPending(newCeQueueDto(TASK_UUID_1)
.setComponentUuid(MAIN_COMPONENT_UUID_1)
.setComponentUuid(ENTITY_UUID_1)
.setStatus(IN_PROGRESS)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(100_000L));
@@ -492,7 +492,7 @@ public class CeQueueDaoIT {
@Test
public void select_by_query_returns_empty_list_when_max_submitted_at() {
insertPending(newCeQueueDto(TASK_UUID_1)
.setComponentUuid(MAIN_COMPONENT_UUID_1)
.setComponentUuid(ENTITY_UUID_1)
.setStatus(IN_PROGRESS)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(100_000L));
@@ -507,14 +507,14 @@ public class CeQueueDaoIT {
}

@Test
public void select_by_query_returns_empty_list_when_empty_list_of_main_component_uuid() {
public void select_by_query_returns_empty_list_when_empty_list_of_entity_uuid() {
insertPending(newCeQueueDto(TASK_UUID_1)
.setComponentUuid(MAIN_COMPONENT_UUID_1)
.setComponentUuid(ENTITY_UUID_1)
.setStatus(IN_PROGRESS)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(100_000L));

CeTaskQuery query = new CeTaskQuery().setMainComponentUuids(Collections.emptyList());
CeTaskQuery query = new CeTaskQuery().setEntityUuids(Collections.emptyList());

List<CeQueueDto> result = underTest.selectByQueryInDescOrder(db.getSession(), query, 1_000);
int total = underTest.countByQuery(db.getSession(), query);
@@ -524,57 +524,57 @@ public class CeQueueDaoIT {
}

@Test
public void count_by_status_and_main_component_uuid() {
public void count_by_status_and_entity_uuid() {
// task retrieved in the queue
insertPending(newCeQueueDto(TASK_UUID_1)
.setMainComponentUuid(MAIN_COMPONENT_UUID_1)
.setEntityUuid(ENTITY_UUID_1)
.setStatus(IN_PROGRESS)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(100_000L));
// on component uuid 2, not returned
insertPending(newCeQueueDto(TASK_UUID_2)
.setMainComponentUuid(MAIN_COMPONENT_UUID_2)
.setEntityUuid(ENTITY_UUID_2)
.setStatus(IN_PROGRESS)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(100_000L));
// pending status, not returned
insertPending(newCeQueueDto(TASK_UUID_3)
.setMainComponentUuid(MAIN_COMPONENT_UUID_1)
.setEntityUuid(ENTITY_UUID_1)
.setStatus(PENDING)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(100_000L));

assertThat(underTest.countByStatusAndMainComponentUuid(db.getSession(), IN_PROGRESS, MAIN_COMPONENT_UUID_1)).isOne();
assertThat(underTest.countByStatusAndEntityUuid(db.getSession(), IN_PROGRESS, ENTITY_UUID_1)).isOne();
assertThat(underTest.countByStatus(db.getSession(), IN_PROGRESS)).isEqualTo(2);
}

@Test
public void count_by_status_and_main_component_uuids() {
public void count_by_status_and_entity_uuids() {
// task retrieved in the queue
insertPending(newCeQueueDto(TASK_UUID_1)
.setMainComponentUuid(MAIN_COMPONENT_UUID_1)
.setEntityUuid(ENTITY_UUID_1)
.setStatus(IN_PROGRESS)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(100_000L));
// on component uuid 2, not returned
insertPending(newCeQueueDto(TASK_UUID_2)
.setMainComponentUuid(MAIN_COMPONENT_UUID_2)
.setEntityUuid(ENTITY_UUID_2)
.setStatus(IN_PROGRESS)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(100_000L));
// pending status, not returned
insertPending(newCeQueueDto(TASK_UUID_3)
.setMainComponentUuid(MAIN_COMPONENT_UUID_1)
.setEntityUuid(ENTITY_UUID_1)
.setStatus(PENDING)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(100_000L));

assertThat(underTest.countByStatusAndMainComponentUuids(db.getSession(), IN_PROGRESS, ImmutableSet.of())).isEmpty();
assertThat(underTest.countByStatusAndMainComponentUuids(db.getSession(), IN_PROGRESS, ImmutableSet.of("non existing component uuid"))).isEmpty();
assertThat(underTest.countByStatusAndMainComponentUuids(db.getSession(), IN_PROGRESS, ImmutableSet.of(MAIN_COMPONENT_UUID_1, MAIN_COMPONENT_UUID_2)))
.containsOnly(entry(MAIN_COMPONENT_UUID_1, 1), entry(MAIN_COMPONENT_UUID_2, 1));
assertThat(underTest.countByStatusAndMainComponentUuids(db.getSession(), PENDING, ImmutableSet.of(MAIN_COMPONENT_UUID_1, MAIN_COMPONENT_UUID_2)))
.containsOnly(entry(MAIN_COMPONENT_UUID_1, 1));
assertThat(underTest.countByStatusAndEntityUuids(db.getSession(), IN_PROGRESS, ImmutableSet.of())).isEmpty();
assertThat(underTest.countByStatusAndEntityUuids(db.getSession(), IN_PROGRESS, ImmutableSet.of("non existing component uuid"))).isEmpty();
assertThat(underTest.countByStatusAndEntityUuids(db.getSession(), IN_PROGRESS, ImmutableSet.of(ENTITY_UUID_1, ENTITY_UUID_2)))
.containsOnly(entry(ENTITY_UUID_1, 1), entry(ENTITY_UUID_2, 1));
assertThat(underTest.countByStatusAndEntityUuids(db.getSession(), PENDING, ImmutableSet.of(ENTITY_UUID_1, ENTITY_UUID_2)))
.containsOnly(entry(ENTITY_UUID_1, 1));
assertThat(underTest.countByStatus(db.getSession(), IN_PROGRESS)).isEqualTo(2);
}

@@ -603,7 +603,7 @@ public class CeQueueDaoIT {
assertThat(underTest.hasAnyIssueSyncTaskPendingOrInProgress(db.getSession())).isFalse();

insertPending(newCeQueueDto(TASK_UUID_1)
.setComponentUuid(MAIN_COMPONENT_UUID_1)
.setComponentUuid(ENTITY_UUID_1)
.setStatus(PENDING)
.setTaskType(CeTaskTypes.BRANCH_ISSUE_SYNC)
.setCreatedAt(100_000L));
@@ -616,7 +616,7 @@ public class CeQueueDaoIT {
assertThat(underTest.hasAnyIssueSyncTaskPendingOrInProgress(db.getSession())).isFalse();

insertPending(newCeQueueDto(TASK_UUID_1)
.setComponentUuid(MAIN_COMPONENT_UUID_1)
.setComponentUuid(ENTITY_UUID_1)
.setStatus(IN_PROGRESS)
.setTaskType(CeTaskTypes.BRANCH_ISSUE_SYNC)
.setCreatedAt(100_000L));
@@ -628,13 +628,13 @@ public class CeQueueDaoIT {
public void selectOldestPendingPrOrBranch_returns_oldest_100_pr_or_branch_tasks() {
for (int i = 1; i < 110; i++) {
insertPending(newCeQueueDto("task" + i)
.setComponentUuid(MAIN_COMPONENT_UUID_1).setStatus(PENDING).setTaskType(CeTaskTypes.REPORT).setCreatedAt(i));
.setComponentUuid(ENTITY_UUID_1).setStatus(PENDING).setTaskType(CeTaskTypes.REPORT).setCreatedAt(i));
}
for (int i = 1; i < 10; i++) {
insertPending(newCeQueueDto("progress" + i)
.setComponentUuid(MAIN_COMPONENT_UUID_1).setStatus(IN_PROGRESS).setTaskType(CeTaskTypes.REPORT).setCreatedAt(i));
.setComponentUuid(ENTITY_UUID_1).setStatus(IN_PROGRESS).setTaskType(CeTaskTypes.REPORT).setCreatedAt(i));
insertPending(newCeQueueDto("sync" + i)
.setComponentUuid(MAIN_COMPONENT_UUID_1).setStatus(PENDING).setTaskType(CeTaskTypes.BRANCH_ISSUE_SYNC).setCreatedAt(i));
.setComponentUuid(ENTITY_UUID_1).setStatus(PENDING).setTaskType(CeTaskTypes.BRANCH_ISSUE_SYNC).setCreatedAt(i));
}

List<PrOrBranchTask> prOrBranchTasks = underTest.selectOldestPendingPrOrBranch(db.getSession());
@@ -647,7 +647,7 @@ public class CeQueueDaoIT {
public void selectOldestPendingPrOrBranch_returns_branch_branch_type_if_no_characteristics() {
insertPending(newCeQueueDto(TASK_UUID_1)
.setComponentUuid(COMPONENT_UUID_1)
.setMainComponentUuid(MAIN_COMPONENT_UUID_1)
.setEntityUuid(ENTITY_UUID_1)
.setStatus(PENDING)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(123L));
@@ -655,15 +655,15 @@ public class CeQueueDaoIT {

assertThat(prOrBranchTasks).hasSize(1);
assertThat(prOrBranchTasks.get(0))
.extracting(PrOrBranchTask::getBranchType, PrOrBranchTask::getComponentUuid, PrOrBranchTask::getMainComponentUuid, PrOrBranchTask::getTaskType)
.containsExactly(BRANCH_KEY, COMPONENT_UUID_1, MAIN_COMPONENT_UUID_1, CeTaskTypes.REPORT);
.extracting(PrOrBranchTask::getBranchType, PrOrBranchTask::getComponentUuid, PrOrBranchTask::getEntityUuid, PrOrBranchTask::getTaskType)
.containsExactly(BRANCH_KEY, COMPONENT_UUID_1, ENTITY_UUID_1, CeTaskTypes.REPORT);
}

@Test
public void selectOldestPendingPrOrBranch_returns_branch_branch_type_if_unrelated_characteristics() {
insertPending(newCeQueueDto(TASK_UUID_1)
.setComponentUuid(COMPONENT_UUID_1)
.setMainComponentUuid(MAIN_COMPONENT_UUID_1)
.setEntityUuid(ENTITY_UUID_1)
.setStatus(PENDING)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(123L));
@@ -672,15 +672,15 @@ public class CeQueueDaoIT {

assertThat(prOrBranchTasks).hasSize(1);
assertThat(prOrBranchTasks.get(0))
.extracting(PrOrBranchTask::getBranchType, PrOrBranchTask::getComponentUuid, PrOrBranchTask::getMainComponentUuid, PrOrBranchTask::getTaskType)
.containsExactly(BRANCH_KEY, COMPONENT_UUID_1, MAIN_COMPONENT_UUID_1, CeTaskTypes.REPORT);
.extracting(PrOrBranchTask::getBranchType, PrOrBranchTask::getComponentUuid, PrOrBranchTask::getEntityUuid, PrOrBranchTask::getTaskType)
.containsExactly(BRANCH_KEY, COMPONENT_UUID_1, ENTITY_UUID_1, CeTaskTypes.REPORT);
}

@Test
public void selectOldestPendingPrOrBranch_returns_all_fields() {
insertPending(newCeQueueDto(TASK_UUID_1)
.setComponentUuid(COMPONENT_UUID_1)
.setMainComponentUuid(MAIN_COMPONENT_UUID_1)
.setEntityUuid(ENTITY_UUID_1)
.setStatus(PENDING)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(123L));
@@ -690,15 +690,15 @@ public class CeQueueDaoIT {

assertThat(prOrBranchTasks).hasSize(1);
assertThat(prOrBranchTasks.get(0))
.extracting(PrOrBranchTask::getBranchType, PrOrBranchTask::getComponentUuid, PrOrBranchTask::getMainComponentUuid, PrOrBranchTask::getTaskType)
.containsExactly(PULL_REQUEST, COMPONENT_UUID_1, MAIN_COMPONENT_UUID_1, CeTaskTypes.REPORT);
.extracting(PrOrBranchTask::getBranchType, PrOrBranchTask::getComponentUuid, PrOrBranchTask::getEntityUuid, PrOrBranchTask::getTaskType)
.containsExactly(PULL_REQUEST, COMPONENT_UUID_1, ENTITY_UUID_1, CeTaskTypes.REPORT);
}

@Test
public void selectInProgressWithCharacteristics_returns_all_fields() {
insertPending(newCeQueueDto(TASK_UUID_1)
.setComponentUuid(COMPONENT_UUID_1)
.setMainComponentUuid(MAIN_COMPONENT_UUID_1)
.setEntityUuid(ENTITY_UUID_1)
.setStatus(IN_PROGRESS)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(123L));
@@ -708,15 +708,15 @@ public class CeQueueDaoIT {

assertThat(prOrBranchTasks).hasSize(1);
assertThat(prOrBranchTasks.get(0))
.extracting(PrOrBranchTask::getBranchType, PrOrBranchTask::getComponentUuid, PrOrBranchTask::getMainComponentUuid, PrOrBranchTask::getTaskType)
.containsExactly(PULL_REQUEST, COMPONENT_UUID_1, MAIN_COMPONENT_UUID_1, CeTaskTypes.REPORT);
.extracting(PrOrBranchTask::getBranchType, PrOrBranchTask::getComponentUuid, PrOrBranchTask::getEntityUuid, PrOrBranchTask::getTaskType)
.containsExactly(PULL_REQUEST, COMPONENT_UUID_1, ENTITY_UUID_1, CeTaskTypes.REPORT);
}

@Test
public void selectInProgressWithCharacteristics_returns_branch_branch_type_if_no_characteristics() {
insertPending(newCeQueueDto(TASK_UUID_1)
.setComponentUuid(COMPONENT_UUID_1)
.setMainComponentUuid(MAIN_COMPONENT_UUID_1)
.setEntityUuid(ENTITY_UUID_1)
.setStatus(IN_PROGRESS)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(123L));
@@ -725,8 +725,8 @@ public class CeQueueDaoIT {

assertThat(prOrBranchTasks).hasSize(1);
assertThat(prOrBranchTasks.get(0))
.extracting(PrOrBranchTask::getBranchType, PrOrBranchTask::getComponentUuid, PrOrBranchTask::getMainComponentUuid, PrOrBranchTask::getTaskType)
.containsExactly(BRANCH_KEY, COMPONENT_UUID_1, MAIN_COMPONENT_UUID_1, CeTaskTypes.REPORT);
.extracting(PrOrBranchTask::getBranchType, PrOrBranchTask::getComponentUuid, PrOrBranchTask::getEntityUuid, PrOrBranchTask::getTaskType)
.containsExactly(BRANCH_KEY, COMPONENT_UUID_1, ENTITY_UUID_1, CeTaskTypes.REPORT);
}

private void insertPending(CeQueueDto dto) {
@@ -758,7 +758,7 @@ public class CeQueueDaoIT {
CeQueueDto dto = new CeQueueDto();
dto.setUuid(uuid);
dto.setTaskType(CeTaskTypes.REPORT);
dto.setMainComponentUuid(mainComponentUuid);
dto.setEntityUuid(mainComponentUuid);
dto.setComponentUuid("uuid_" + pendingComponentUuidGenerator++);
dto.setStatus(PENDING);
dto.setSubmitterUuid("henri");

+ 72
- 67
server/sonar-db-dao/src/it/java/org/sonar/db/measure/LiveMeasureDaoIT.java View File

@@ -34,6 +34,7 @@ import org.junit.Test;
import org.mockito.internal.util.collections.Sets;
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ProjectData;
@@ -55,7 +56,7 @@ import static org.sonar.db.measure.MeasureTesting.newLiveMeasure;
public class LiveMeasureDaoIT {

@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
public DbTester db = DbTester.create(System2.INSTANCE, true);

private final LiveMeasureDao underTest = db.getDbClient().liveMeasureDao();
private MetricDto metric;
@@ -148,26 +149,27 @@ public class LiveMeasureDaoIT {
public void selectForProjectsByMetricUuids() {
MetricDto metric = db.measures().insertMetric();
MetricDto metric2 = db.measures().insertMetric();
ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent();
underTest.insert(db.getSession(), newLiveMeasure(project, metric).setValue(3.14).setData((String) null));
underTest.insert(db.getSession(), newLiveMeasure(project, metric2).setValue(4.54).setData((String) null));
underTest.insert(db.getSession(), newLiveMeasure(project2, metric).setValue(99.99).setData((String) null));
BranchDto projectBranch = db.components().insertPrivateProject().getMainBranchDto();
BranchDto project2Branch = db.components().insertPrivateProject().getMainBranchDto();
underTest.insert(db.getSession(), newLiveMeasure(projectBranch, metric).setValue(3.14).setData((String) null));
underTest.insert(db.getSession(), newLiveMeasure(projectBranch, metric2).setValue(4.54).setData((String) null));
underTest.insert(db.getSession(), newLiveMeasure(project2Branch, metric).setValue(99.99).setData((String) null));

List<LiveMeasureDto> selected = underTest.selectForProjectsByMetricUuids(db.getSession(), List.of(metric.getUuid(), metric2.getUuid()));
List<ProjectMainBranchLiveMeasureDto> selected = underTest.selectForProjectMainBranchesByMetricUuids(db.getSession(), List.of(metric.getUuid(), metric2.getUuid()));
assertThat(selected)
.extracting(LiveMeasureDto::getComponentUuid, LiveMeasureDto::getProjectUuid, LiveMeasureDto::getMetricUuid, LiveMeasureDto::getValue, LiveMeasureDto::getDataAsString)
.extracting(ProjectMainBranchLiveMeasureDto::getProjectUuid, ProjectMainBranchLiveMeasureDto::getMetricUuid,
ProjectMainBranchLiveMeasureDto::getValue, ProjectMainBranchLiveMeasureDto::getTextValue)
.containsExactlyInAnyOrder(
tuple(project.uuid(), project.uuid(), metric.getUuid(), 3.14, null),
tuple(project.uuid(), project.uuid(), metric2.getUuid(), 4.54, null),
tuple(project2.uuid(), project2.uuid(), metric.getUuid(), 99.99, null));
tuple(projectBranch.getProjectUuid(), metric.getUuid(), 3.14, null),
tuple(projectBranch.getProjectUuid(), metric2.getUuid(), 4.54, null),
tuple(project2Branch.getProjectUuid(), metric.getUuid(), 99.99, null));
}

@Test
public void selectForProjectsByMetricUuids_whenMetricDoesNotMatch_shouldReturnEmptyList() {
ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
underTest.insert(db.getSession(), newLiveMeasure(project, metric).setValue(3.14).setData((String) null));
List<LiveMeasureDto> selected = underTest.selectForProjectsByMetricUuids(db.getSession(), singletonList("_other_"));
List<ProjectMainBranchLiveMeasureDto> selected = underTest.selectForProjectMainBranchesByMetricUuids(db.getSession(), singletonList("_other_"));
assertThat(selected).isEmpty();
}

@@ -182,10 +184,10 @@ public class LiveMeasureDaoIT {
underTest.insert(db.getSession(), newLiveMeasure(project.getMainBranchComponent(), metric).setValue(4.54).setData((String) null));
underTest.insert(db.getSession(), newLiveMeasure(project2.getMainBranchComponent(), metric).setValue(5.56).setData((String) null));

List<LiveMeasureDto> selected = underTest.selectForProjectsByMetricUuids(db.getSession(), List.of(metric.getUuid()));
List<ProjectMainBranchLiveMeasureDto> selected = underTest.selectForProjectMainBranchesByMetricUuids(db.getSession(), List.of(metric.getUuid()));

assertThat(selected)
.extracting(LiveMeasureDto::getProjectUuid)
.extracting(ProjectMainBranchLiveMeasureDto::getProjectUuid)
.containsExactlyInAnyOrder(project.projectUuid(), project2.projectUuid());
}

@@ -344,8 +346,8 @@ public class LiveMeasureDaoIT {
LiveMeasureDto result = underTest.selectMeasure(db.getSession(), file.uuid(), metric.getKey()).orElseThrow(() -> new IllegalArgumentException("Measure not found"));

assertThat(result).as("Fail to map fields of %s", result.toString()).extracting(
LiveMeasureDto::getProjectUuid, LiveMeasureDto::getComponentUuid, LiveMeasureDto::getMetricUuid, LiveMeasureDto::getValue,
LiveMeasureDto::getDataAsString, LiveMeasureDto::getTextValue)
LiveMeasureDto::getProjectUuid, LiveMeasureDto::getComponentUuid, LiveMeasureDto::getMetricUuid, LiveMeasureDto::getValue,
LiveMeasureDto::getDataAsString, LiveMeasureDto::getTextValue)
.contains(project.uuid(), file.uuid(), metric.getUuid(), 3.14, "text_value", "text_value");
}

@@ -354,21 +356,21 @@ public class LiveMeasureDaoIT {
MetricDto ncloc = db.measures().insertMetric(m -> m.setKey("ncloc").setValueType(INT.toString()));
MetricDto lines = db.measures().insertMetric(m -> m.setKey("lines").setValueType(INT.toString()));

ComponentDto simpleProject = db.components().insertPublicProject().getMainBranchComponent();
ProjectData simpleProject = db.components().insertPublicProject();
db.measures().insertLiveMeasure(simpleProject, ncloc, m -> m.setValue(10d));

ComponentDto projectWithBiggerBranch = db.components().insertPublicProject().getMainBranchComponent();
ComponentDto bigBranch = db.components().insertProjectBranch(projectWithBiggerBranch, b -> b.setBranchType(BranchType.BRANCH));
ProjectData projectWithBiggerBranch = db.components().insertPublicProject();
BranchDto bigBranch = db.components().insertProjectBranch(projectWithBiggerBranch.getProjectDto(), b -> b.setBranchType(BranchType.BRANCH));
db.measures().insertLiveMeasure(projectWithBiggerBranch, ncloc, m -> m.setValue(100d));
db.measures().insertLiveMeasure(bigBranch, ncloc, m -> m.setValue(200d));

ComponentDto projectWithLinesButNoLoc = db.components().insertPublicProject().getMainBranchComponent();
ProjectData projectWithLinesButNoLoc = db.components().insertPublicProject();
db.measures().insertLiveMeasure(projectWithLinesButNoLoc, lines, m -> m.setValue(365d));
db.measures().insertLiveMeasure(projectWithLinesButNoLoc, ncloc, m -> m.setValue(0d));

assertThat(underTest.sumNclocOfBiggestBranchForProject(db.getSession(), simpleProject.uuid())).isEqualTo(10L);
assertThat(underTest.sumNclocOfBiggestBranchForProject(db.getSession(), projectWithBiggerBranch.uuid())).isEqualTo(200L);
assertThat(underTest.sumNclocOfBiggestBranchForProject(db.getSession(), projectWithLinesButNoLoc.uuid())).isZero();
assertThat(underTest.sumNclocOfBiggestBranchForProject(db.getSession(), simpleProject.projectUuid())).isEqualTo(10L);
assertThat(underTest.sumNclocOfBiggestBranchForProject(db.getSession(), projectWithBiggerBranch.projectUuid())).isEqualTo(200L);
assertThat(underTest.sumNclocOfBiggestBranchForProject(db.getSession(), projectWithLinesButNoLoc.projectUuid())).isZero();
}

@Test
@@ -392,17 +394,25 @@ public class LiveMeasureDaoIT {
Map<String, MetricDto> metrics = setupMetrics();
MetricDto ncloc = metrics.get("ncloc");
MetricDto nclocLanguageDistribution = metrics.get("ncloc_language_distribution");
Map<String, ComponentDto> components = setupProjectsWithLoc(ncloc, nclocLanguageDistribution, metrics.get("lines"));
setupProjectsWithLoc(ncloc, nclocLanguageDistribution, metrics.get("lines"));

List<ProjectLocDistributionDto> results = underTest.selectLargestBranchesLocDistribution(db.getSession(), ncloc.getUuid(), nclocLanguageDistribution.getUuid());

assertThat(results)
.containsExactlyInAnyOrder(
new ProjectLocDistributionDto(components.get("projectWithTieOnBranchSize").uuid(), components.get("projectWithTieOnBranchSize").uuid(), "java=250;js=0"),
new ProjectLocDistributionDto(components.get("projectWithTieOnOtherBranches").uuid(), components.get("tieBranch1").uuid(), "java=230;js=0"),
new ProjectLocDistributionDto(components.get("projectWithBranchBiggerThanMaster").uuid(), components.get("notMasterBranch").uuid(), "java=100;js=100"),
new ProjectLocDistributionDto(components.get("simpleProject").uuid(), components.get("simpleProject").uuid(), "java=10;js=0"),
new ProjectLocDistributionDto(components.get("projectWithLinesButNoLoc").uuid(), components.get("projectWithLinesButNoLoc").uuid(), "java=0;js=0"));
new ProjectLocDistributionDto("projectWithTieOnBranchSize", getMainBranchUuid("projectWithTieOnBranchSize"), "java=250;js=0"),
new ProjectLocDistributionDto("projectWithTieOnOtherBranches", getBranchUuid("projectWithTieOnOtherBranches", "tieBranch1"), "java=230;js=0"),
new ProjectLocDistributionDto("projectWithBranchBiggerThanMaster", getBranchUuid("projectWithBranchBiggerThanMaster", "notMasterBranch"), "java=100;js=100"),
new ProjectLocDistributionDto("simpleProject", getMainBranchUuid("simpleProject"), "java=10;js=0"),
new ProjectLocDistributionDto("projectWithLinesButNoLoc", getMainBranchUuid("projectWithLinesButNoLoc"), "java=0;js=0"));
}

private String getBranchUuid(String projectUuid, String branchKey) {
return db.getDbClient().branchDao().selectByBranchKey(db.getSession(), projectUuid, branchKey).get().getUuid();
}

private String getMainBranchUuid(String projectUuid) {
return db.getDbClient().branchDao().selectMainBranchByProjectUuid(db.getSession(), projectUuid).get().getUuid();
}

@Test
@@ -696,63 +706,58 @@ public class LiveMeasureDaoIT {
"lines", lines);
}

private Map<String, ComponentDto> setupProjectsWithLoc(MetricDto ncloc, MetricDto nclocDistribution, MetricDto lines) {
ComponentDto simpleProject = addProjectWithMeasure("simpleProject", ncloc, 10d);
addMeasureToComponent(simpleProject, nclocDistribution, "java=10;js=0");

ComponentDto projectWithBranchBiggerThanMaster = addProjectWithMeasure("projectWithBranchBiggerThanMaster", ncloc, 100d);
addMeasureToComponent(projectWithBranchBiggerThanMaster, nclocDistribution, "java=100;js=0");
private void setupProjectsWithLoc(MetricDto ncloc, MetricDto nclocDistribution, MetricDto lines) {
ProjectData simpleProject = addProjectWithMeasure("simpleProject", ncloc, 10d);
addMeasureToMainBranch(simpleProject, nclocDistribution, "java=10;js=0");

ComponentDto notMasterBranch = addBranchToProjectWithMeasure(projectWithBranchBiggerThanMaster, "notMasterBranch", ncloc, 200d);
addMeasureToComponent(notMasterBranch, nclocDistribution, "java=100;js=100");
ProjectData projectWithBranchBiggerThanMaster = addProjectWithMeasure("projectWithBranchBiggerThanMaster", ncloc, 100d);
addMeasureToMainBranch(projectWithBranchBiggerThanMaster, nclocDistribution, "java=100;js=0");

ComponentDto projectWithLinesButNoLoc = addProjectWithMeasure("projectWithLinesButNoLoc", lines, 365d);
addMeasureToComponent(projectWithLinesButNoLoc, nclocDistribution, "java=0;js=0");
addMeasureToComponent(projectWithLinesButNoLoc, ncloc, 0d, false);
BranchDto notMasterBranch = addBranchToProjectWithMeasure(projectWithBranchBiggerThanMaster, "notMasterBranch", ncloc, 200d);
addMeasureToBranch(notMasterBranch, nclocDistribution, "java=100;js=100");

ComponentDto projectWithTieOnBranchSize = addProjectWithMeasure("projectWithTieOnBranchSize", ncloc, 250d);
addMeasureToComponent(projectWithTieOnBranchSize, nclocDistribution, "java=250;js=0");
ComponentDto tieBranch = addBranchToProjectWithMeasure(projectWithTieOnBranchSize, "tieBranch", ncloc, 250d);
addMeasureToComponent(tieBranch, nclocDistribution, "java=250;js=0");
ProjectData projectWithLinesButNoLoc = addProjectWithMeasure("projectWithLinesButNoLoc", lines, 365d);
addMeasureToMainBranch(projectWithLinesButNoLoc, nclocDistribution, "java=0;js=0");
addMeasureToBranch(projectWithLinesButNoLoc.getMainBranchDto(), ncloc, 0d, false);

ComponentDto projectWithTieOnOtherBranches = addProjectWithMeasure("projectWithTieOnOtherBranches", ncloc, 220d);
addMeasureToComponent(projectWithTieOnOtherBranches, nclocDistribution, "java=220;js=0");
ComponentDto tieBranch1 = addBranchToProjectWithMeasure(projectWithTieOnOtherBranches, "tieBranch1", ncloc, 230d);
addMeasureToComponent(tieBranch1, nclocDistribution, "java=230;js=0");
ComponentDto tieBranch2 = addBranchToProjectWithMeasure(projectWithTieOnOtherBranches, "tieBranch2", ncloc, 230d);
addMeasureToComponent(tieBranch2, nclocDistribution, "java=230;js=0");
ProjectData projectWithTieOnBranchSize = addProjectWithMeasure("projectWithTieOnBranchSize", ncloc, 250d);
addMeasureToMainBranch(projectWithTieOnBranchSize, nclocDistribution, "java=250;js=0");
BranchDto tieBranch = addBranchToProjectWithMeasure(projectWithTieOnBranchSize, "tieBranch", ncloc, 250d);
addMeasureToBranch(tieBranch, nclocDistribution, "java=250;js=0");

return Map.of("simpleProject", simpleProject,
"projectWithBranchBiggerThanMaster", projectWithBranchBiggerThanMaster,
"notMasterBranch", notMasterBranch,
"projectWithLinesButNoLoc", projectWithLinesButNoLoc,
"projectWithTieOnBranchSize", projectWithTieOnBranchSize,
"tieBranch", tieBranch,
"projectWithTieOnOtherBranches", projectWithTieOnOtherBranches,
"tieBranch1", tieBranch1,
"tieBranch2", tieBranch2);
ProjectData projectWithTieOnOtherBranches = addProjectWithMeasure("projectWithTieOnOtherBranches", ncloc, 220d);
addMeasureToMainBranch(projectWithTieOnOtherBranches, nclocDistribution, "java=220;js=0");
BranchDto tieBranch1 = addBranchToProjectWithMeasure(projectWithTieOnOtherBranches, "tieBranch1", ncloc, 230d);
addMeasureToBranch(tieBranch1, nclocDistribution, "java=230;js=0");
BranchDto tieBranch2 = addBranchToProjectWithMeasure(projectWithTieOnOtherBranches, "tieBranch2", ncloc, 230d);
addMeasureToBranch(tieBranch2, nclocDistribution, "java=230;js=0");
}

private ComponentDto addProjectWithMeasure(String projectKey, MetricDto metric, double metricValue) {
ComponentDto project = db.components().insertPublicProject(p -> p.setKey(projectKey)).getMainBranchComponent();
addMeasureToComponent(project, metric, metricValue, true);
private ProjectData addProjectWithMeasure(String projectKey, MetricDto metric, double metricValue) {
ProjectData project = db.components().insertPublicProject(projectKey, p -> p.setKey(projectKey));
addMeasureToBranch(project.getMainBranchDto(), metric, metricValue, true);
return project;
}

private void addMeasureToComponent(ComponentDto component, MetricDto metric, double metricValue, boolean addSnapshot) {
private void addMeasureToBranch(BranchDto component, MetricDto metric, double metricValue, boolean addSnapshot) {
db.measures().insertLiveMeasure(component, metric, m -> m.setValue(metricValue));
if (addSnapshot) {
db.components().insertSnapshot(component, t -> t.setLast(true));
}
}

private void addMeasureToComponent(ComponentDto component, MetricDto metric, String metricValue) {
private void addMeasureToMainBranch(ProjectData projectData, MetricDto metric, String metricValue) {
addMeasureToBranch(projectData.getMainBranchDto(), metric, metricValue);
}

private void addMeasureToBranch(BranchDto component, MetricDto metric, String metricValue) {
db.measures().insertLiveMeasure(component, metric, m -> m.setData(metricValue));
}

private ComponentDto addBranchToProjectWithMeasure(ComponentDto project, String branchKey, MetricDto metric, double metricValue) {
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH).setKey(branchKey));
addMeasureToComponent(branch, metric, metricValue, true);
private BranchDto addBranchToProjectWithMeasure(ProjectData project, String branchKey, MetricDto metric, double metricValue) {
BranchDto branch = db.components()
.insertProjectBranch(project.getProjectDto(), b -> b.setBranchType(BranchType.BRANCH).setKey(branchKey));
addMeasureToBranch(branch, metric, metricValue, true);
return branch;
}


+ 5
- 7
server/sonar-db-dao/src/it/java/org/sonar/db/measure/MeasureDaoIT.java View File

@@ -46,21 +46,19 @@ public class MeasureDaoIT {
private MetricDto coverage;
private MetricDto complexity;
private MetricDto ncloc;
private MetricDto nclocDistribution;

@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
private DbClient dbClient = db.getDbClient();
private DbSession dbSession = db.getSession();

private MeasureDao underTest = db.getDbClient().measureDao();
public DbTester db = DbTester.create(System2.INSTANCE, true);
private final DbClient dbClient = db.getDbClient();
private final DbSession dbSession = db.getSession();
private final MeasureDao underTest = db.getDbClient().measureDao();

@Before
public void before() {
coverage = db.measures().insertMetric(m -> m.setKey("coverage"));
complexity = db.measures().insertMetric(m -> m.setKey("complexity"));
ncloc = db.measures().insertMetric(m -> m.setKey("ncloc"));
nclocDistribution = db.measures().insertMetric(m -> m.setKey("ncloc_language_distribution"));
db.measures().insertMetric(m -> m.setKey("ncloc_language_distribution"));
}

@Test

+ 9
- 9
server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeDaoIT.java View File

@@ -904,7 +904,7 @@ public class PurgeDaoIT {
dbSession.commit();

assertThat(db.countRowsOfTable("ce_queue")).isOne();
assertThat(db.countSql("select count(*) from ce_queue where main_component_uuid='" + projectToBeDeleted.uuid() + "'")).isZero();
assertThat(db.countSql("select count(*) from ce_queue where entity_uuid='" + projectToBeDeleted.uuid() + "'")).isZero();
}

@Test
@@ -1273,9 +1273,9 @@ public class PurgeDaoIT {
public void delete_ce_analysis_older_than_180_and_scanner_context_older_than_40_days_of_specified_project_when_purging_project() {
LocalDateTime now = LocalDateTime.now();
ComponentDto project1 = db.components().insertPublicProject().getMainBranchComponent();
Consumer<CeQueueDto> belongsToProject1 = t -> t.setMainComponentUuid(project1.uuid()).setComponentUuid(project1.uuid());
Consumer<CeQueueDto> belongsToProject1 = t -> t.setEntityUuid(project1.uuid()).setComponentUuid(project1.uuid());
ComponentDto project2 = db.components().insertPublicProject().getMainBranchComponent();
Consumer<CeQueueDto> belongsToProject2 = t -> t.setMainComponentUuid(project2.uuid()).setComponentUuid(project2.uuid());
Consumer<CeQueueDto> belongsToProject2 = t -> t.setEntityUuid(project2.uuid()).setComponentUuid(project2.uuid());

insertCeActivityAndChildDataWithDate("VERY_OLD_1", now.minusDays(180).minusMonths(10), belongsToProject1);
insertCeActivityAndChildDataWithDate("JUST_OLD_ENOUGH_1", now.minusDays(180).minusDays(1), belongsToProject1);
@@ -1332,8 +1332,8 @@ public class PurgeDaoIT {
LocalDateTime now = LocalDateTime.now();
ComponentDto project1 = db.components().insertPublicProject().getMainBranchComponent();
ComponentDto branch1 = db.components().insertProjectBranch(project1, b -> b.setExcludeFromPurge(true));
Consumer<CeQueueDto> belongsToProject1 = t -> t.setMainComponentUuid(project1.uuid()).setComponentUuid(project1.uuid());
Consumer<CeQueueDto> belongsToBranch1 = t -> t.setMainComponentUuid(project1.uuid()).setComponentUuid(branch1.uuid());
Consumer<CeQueueDto> belongsToProject1 = t -> t.setEntityUuid(project1.uuid()).setComponentUuid(project1.uuid());
Consumer<CeQueueDto> belongsToBranch1 = t -> t.setEntityUuid(project1.uuid()).setComponentUuid(branch1.uuid());

insertCeActivityAndChildDataWithDate("VERY_OLD_1", now.minusDays(180).minusMonths(10), belongsToProject1);
insertCeActivityAndChildDataWithDate("JUST_OLD_ENOUGH_1", now.minusDays(180).minusDays(1), belongsToProject1);
@@ -1390,8 +1390,8 @@ public class PurgeDaoIT {
LocalDateTime now = LocalDateTime.now();
ComponentDto project1 = db.components().insertPublicProject().getMainBranchComponent();
ComponentDto branch1 = db.components().insertProjectBranch(project1);
Consumer<CeQueueDto> belongsToProject1 = t -> t.setMainComponentUuid(project1.uuid()).setComponentUuid(project1.uuid());
Consumer<CeQueueDto> belongsToBranch1 = t -> t.setMainComponentUuid(project1.uuid()).setComponentUuid(branch1.uuid());
Consumer<CeQueueDto> belongsToProject1 = t -> t.setEntityUuid(project1.uuid()).setComponentUuid(project1.uuid());
Consumer<CeQueueDto> belongsToBranch1 = t -> t.setEntityUuid(project1.uuid()).setComponentUuid(branch1.uuid());

insertCeActivityAndChildDataWithDate("VERY_OLD_1", now.minusDays(180).minusMonths(10), belongsToProject1);
insertCeActivityAndChildDataWithDate("JUST_OLD_ENOUGH_1", now.minusDays(180).minusDays(1), belongsToProject1);
@@ -1873,7 +1873,7 @@ public class PurgeDaoIT {
queueDto.setUuid(Uuids.create());
queueDto.setTaskType(REPORT);
queueDto.setComponentUuid(component.uuid());
queueDto.setMainComponentUuid(mainBranch);
queueDto.setEntityUuid(mainBranch);
queueDto.setSubmitterUuid("submitter uuid");
queueDto.setCreatedAt(1_300_000_000_000L);
queueDto.setStatus(status);
@@ -1898,7 +1898,7 @@ public class PurgeDaoIT {
.setUuid(UuidFactoryFast.getInstance().create())
.setTaskType("foo")
.setComponentUuid(component.uuid())
.setMainComponentUuid(mainBranch)
.setEntityUuid(mainBranch)
.setStatus(Status.PENDING)
.setCreatedAt(1_2323_222L)
.setUpdatedAt(1_2323_222L);

+ 1
- 1
server/sonar-db-dao/src/it/java/org/sonar/db/pushevent/PushEventDaoIT.java View File

@@ -36,7 +36,7 @@ public class PushEventDaoIT {
private final TestSystem2 system2 = new TestSystem2().setNow(1L);

@Rule
public DbTester db = DbTester.create(system2);
public DbTester db = DbTester.create(system2, true);

private final DbSession session = db.getSession();
private final PushEventDao underTest = db.getDbClient().pushEventDao();

+ 0
- 0
server/sonar-db-dao/src/it/java/org/sonar/db/qualitygate/ProjectQgateAssociationDaoIT.java View File


Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save