Search in sources :

Example 1 with CeQueue

use of org.sonar.ce.queue.CeQueue in project sonarqube by SonarSource.

the class AsyncIssueIndexingImplTest method characteristics_are_defined.

@Test
public void characteristics_are_defined() {
    BranchDto dto = new BranchDto().setBranchType(BRANCH).setKey("branch_1").setUuid("branch_uuid1").setProjectUuid("project_uuid1");
    dbClient.branchDao().insert(dbTester.getSession(), dto);
    dbTester.commit();
    insertSnapshot("analysis_1", "project_uuid1", 1);
    BranchDto dto2 = new BranchDto().setBranchType(PULL_REQUEST).setKey("pr_1").setUuid("pr_uuid_1").setProjectUuid("project_uuid2");
    dbClient.branchDao().insert(dbTester.getSession(), dto2);
    dbTester.commit();
    insertSnapshot("analysis_2", "project_uuid2", 2);
    underTest.triggerOnIndexCreation();
    ArgumentCaptor<Collection<CeTaskSubmit>> captor = ArgumentCaptor.forClass(Collection.class);
    verify(ceQueue, times(1)).massSubmit(captor.capture());
    List<Collection<CeTaskSubmit>> captures = captor.getAllValues();
    assertThat(captures).hasSize(1);
    Collection<CeTaskSubmit> tasks = captures.get(0);
    assertThat(tasks).hasSize(2);
    assertThat(tasks).extracting(p -> p.getCharacteristics().get(BRANCH_TYPE_KEY), p -> p.getCharacteristics().get(CeTaskCharacteristicDto.BRANCH_KEY), p -> p.getCharacteristics().get(CeTaskCharacteristicDto.PULL_REQUEST)).containsExactlyInAnyOrder(tuple("BRANCH", "branch_1", null), tuple("PULL_REQUEST", null, "pr_1"));
}
Also used : BranchDto(org.sonar.db.component.BranchDto) Arrays(java.util.Arrays) BRANCH_TYPE_KEY(org.sonar.db.ce.CeTaskCharacteristicDto.BRANCH_TYPE_KEY) STATUS_PROCESSED(org.sonar.db.component.SnapshotDto.STATUS_PROCESSED) REPORT(org.sonar.db.ce.CeTaskTypes.REPORT) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) PULL_REQUEST(org.sonar.db.component.BranchType.PULL_REQUEST) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) CeActivityDto(org.sonar.db.ce.CeActivityDto) ArgumentCaptor(org.mockito.ArgumentCaptor) Map(java.util.Map) BRANCH_ISSUE_SYNC(org.sonar.db.ce.CeTaskTypes.BRANCH_ISSUE_SYNC) CeTaskCharacteristicDto(org.sonar.db.ce.CeTaskCharacteristicDto) Before(org.junit.Before) DbTester(org.sonar.db.DbTester) System2(org.sonar.api.utils.System2) Assertions.tuple(org.assertj.core.api.Assertions.tuple) Collection(java.util.Collection) UuidFactory(org.sonar.core.util.UuidFactory) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) BRANCH(org.sonar.db.component.BranchType.BRANCH) SequenceUuidFactory(org.sonar.core.util.SequenceUuidFactory) Mockito.verify(org.mockito.Mockito.verify) DbClient(org.sonar.db.DbClient) ArgumentMatchers.anyCollection(org.mockito.ArgumentMatchers.anyCollection) List(java.util.List) Rule(org.junit.Rule) LogTester(org.sonar.api.utils.log.LogTester) CeTaskSubmit(org.sonar.ce.queue.CeTaskSubmit) CeQueueDto(org.sonar.db.ce.CeQueueDto) Optional(java.util.Optional) Status(org.sonar.db.ce.CeActivityDto.Status) SnapshotDto(org.sonar.db.component.SnapshotDto) Assertions.assertThatCode(org.assertj.core.api.Assertions.assertThatCode) LoggerLevel(org.sonar.api.utils.log.LoggerLevel) CeQueue(org.sonar.ce.queue.CeQueue) Mockito.mock(org.mockito.Mockito.mock) BranchDto(org.sonar.db.component.BranchDto) Collection(java.util.Collection) ArgumentMatchers.anyCollection(org.mockito.ArgumentMatchers.anyCollection) CeTaskSubmit(org.sonar.ce.queue.CeTaskSubmit) Test(org.junit.Test)

Example 2 with CeQueue

use of org.sonar.ce.queue.CeQueue in project sonarqube by SonarSource.

the class AsyncIssueIndexingImplTest method order_by_last_analysis_date.

@Test
public void order_by_last_analysis_date() {
    BranchDto dto = new BranchDto().setBranchType(BRANCH).setKey("branch_1").setUuid("branch_uuid1").setProjectUuid("project_uuid1");
    dbClient.branchDao().insert(dbTester.getSession(), dto);
    dbTester.commit();
    insertSnapshot("analysis_1", "project_uuid1", 1);
    BranchDto dto2 = new BranchDto().setBranchType(BRANCH).setKey("branch_2").setUuid("branch_uuid2").setProjectUuid("project_uuid2");
    dbClient.branchDao().insert(dbTester.getSession(), dto2);
    dbTester.commit();
    insertSnapshot("analysis_2", "project_uuid2", 2);
    underTest.triggerOnIndexCreation();
    verify(ceQueue, times(2)).prepareSubmit();
    ArgumentCaptor<Collection<CeTaskSubmit>> captor = ArgumentCaptor.forClass(Collection.class);
    verify(ceQueue, times(1)).massSubmit(captor.capture());
    List<Collection<CeTaskSubmit>> captures = captor.getAllValues();
    assertThat(captures).hasSize(1);
    Collection<CeTaskSubmit> tasks = captures.get(0);
    assertThat(tasks).hasSize(2);
    assertThat(tasks).extracting(p -> p.getComponent().get().getUuid()).containsExactly("branch_uuid2", "branch_uuid1");
    assertThat(logTester.logs(LoggerLevel.INFO)).contains("2 projects found in need of issue sync.");
}
Also used : BranchDto(org.sonar.db.component.BranchDto) Arrays(java.util.Arrays) BRANCH_TYPE_KEY(org.sonar.db.ce.CeTaskCharacteristicDto.BRANCH_TYPE_KEY) STATUS_PROCESSED(org.sonar.db.component.SnapshotDto.STATUS_PROCESSED) REPORT(org.sonar.db.ce.CeTaskTypes.REPORT) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) PULL_REQUEST(org.sonar.db.component.BranchType.PULL_REQUEST) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) CeActivityDto(org.sonar.db.ce.CeActivityDto) ArgumentCaptor(org.mockito.ArgumentCaptor) Map(java.util.Map) BRANCH_ISSUE_SYNC(org.sonar.db.ce.CeTaskTypes.BRANCH_ISSUE_SYNC) CeTaskCharacteristicDto(org.sonar.db.ce.CeTaskCharacteristicDto) Before(org.junit.Before) DbTester(org.sonar.db.DbTester) System2(org.sonar.api.utils.System2) Assertions.tuple(org.assertj.core.api.Assertions.tuple) Collection(java.util.Collection) UuidFactory(org.sonar.core.util.UuidFactory) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) BRANCH(org.sonar.db.component.BranchType.BRANCH) SequenceUuidFactory(org.sonar.core.util.SequenceUuidFactory) Mockito.verify(org.mockito.Mockito.verify) DbClient(org.sonar.db.DbClient) ArgumentMatchers.anyCollection(org.mockito.ArgumentMatchers.anyCollection) List(java.util.List) Rule(org.junit.Rule) LogTester(org.sonar.api.utils.log.LogTester) CeTaskSubmit(org.sonar.ce.queue.CeTaskSubmit) CeQueueDto(org.sonar.db.ce.CeQueueDto) Optional(java.util.Optional) Status(org.sonar.db.ce.CeActivityDto.Status) SnapshotDto(org.sonar.db.component.SnapshotDto) Assertions.assertThatCode(org.assertj.core.api.Assertions.assertThatCode) LoggerLevel(org.sonar.api.utils.log.LoggerLevel) CeQueue(org.sonar.ce.queue.CeQueue) Mockito.mock(org.mockito.Mockito.mock) BranchDto(org.sonar.db.component.BranchDto) Collection(java.util.Collection) ArgumentMatchers.anyCollection(org.mockito.ArgumentMatchers.anyCollection) CeTaskSubmit(org.sonar.ce.queue.CeTaskSubmit) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.assertThatCode (org.assertj.core.api.Assertions.assertThatCode)2 Assertions.tuple (org.assertj.core.api.Assertions.tuple)2 Before (org.junit.Before)2 Rule (org.junit.Rule)2 Test (org.junit.Test)2 ArgumentCaptor (org.mockito.ArgumentCaptor)2 ArgumentMatchers.anyCollection (org.mockito.ArgumentMatchers.anyCollection)2 Mockito.mock (org.mockito.Mockito.mock)2 Mockito.times (org.mockito.Mockito.times)2 Mockito.verify (org.mockito.Mockito.verify)2 Mockito.when (org.mockito.Mockito.when)2