]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13398 Verify needIssue sync flag at project level
authorJacek <jacek.poreda@sonarsource.com>
Mon, 15 Jun 2020 09:37:14 +0000 (11:37 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 26 Jun 2020 20:04:57 +0000 (20:04 +0000)
server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/component/BranchMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/component/BranchDaoTest.java
server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndexSyncProgressChecker.java
server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSyncProgressCheckerTest.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchAction.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/SearchActionTest.java

index fc7981ccd261d2dbaadd3624cae128475c7586ef..b55ce5a0b75d185f2ab682a308d1966653901fbc 100644 (file)
@@ -156,12 +156,11 @@ public class BranchDao implements Dao {
     return mapper(dbSession).updateNeedIssueSync(branchUuid, needIssueSync, now);
   }
 
-  public boolean doAnyOfComponentsNeedIssueSync(DbSession session, List<String> components, @Nullable String branch,
-      @Nullable String pullRequest) {
+  public boolean doAnyOfComponentsNeedIssueSync(DbSession session, List<String> components) {
     if (!components.isEmpty()) {
       List<Boolean> result = new LinkedList<>();
       return executeLargeInputs(components, input -> {
-        boolean groupNeedIssueSync = mapper(session).doAnyOfComponentsNeedIssueSync(components, branch, pullRequest) > 0;
+        boolean groupNeedIssueSync = mapper(session).doAnyOfComponentsNeedIssueSync(components) > 0;
         result.add(groupNeedIssueSync);
         return result;
       }).stream()
index 62bbfa9955dc7c4038816383c5b36bfde6b531b8..60a017fcac3067e18184e77af5c2ee27c9151d6b 100644 (file)
@@ -66,7 +66,6 @@ public interface BranchMapper {
 
   long updateNeedIssueSync(@Param("uuid") String uuid, @Param("needIssueSync")boolean needIssueSync,@Param("now") long now);
 
-  short doAnyOfComponentsNeedIssueSync(@Param("componentKeys") List<String> components, @Nullable @Param("branch") String branch,
-      @Nullable @Param("pullRequest") String pullRequest);
+  short doAnyOfComponentsNeedIssueSync(@Param("componentKeys") List<String> components);
 
 }
index 982a77009e47d9fd54a477e67e0c173fad532bb9..e94c442cdf2ef0c2e08cec52c809704279bc69ed 100644 (file)
       #{componentKey,jdbcType=VARCHAR}
     </foreach>
     and pb.need_issue_sync = ${_true}
-    <if test="branch != null">
-      and pb.kee = #{branch,jdbcType=VARCHAR}
-    </if>
-    <if test="pullRequest != null">
-      and pb.kee = #{pullRequest,jdbcType=VARCHAR}
-    </if>
     )
     then 1
     else 0
index d7c4051565c78f8f83fb2e9fe909ee9ec71c56e4..42a5b7efb0135741f415486dd93a41812504f315 100644 (file)
@@ -658,10 +658,11 @@ public class BranchDaoTest {
 
   @Test
   public void doAnyOfComponentsNeedIssueSync() {
-    assertThat(underTest.doAnyOfComponentsNeedIssueSync(dbSession, emptyList(), null, null)).isFalse();
+    assertThat(underTest.doAnyOfComponentsNeedIssueSync(dbSession, emptyList())).isFalse();
 
-    ComponentDto project = db.components().insertPrivateProject();
-    ProjectDto projectDto = db.components().getProjectDto(project);
+    ComponentDto project1 = db.components().insertPrivateProject();
+    ComponentDto project2 = db.components().insertPrivateProject();
+    ProjectDto projectDto = db.components().getProjectDto(project1);
     db.components().insertProjectBranch(projectDto, b -> b.setBranchType(BranchType.BRANCH).setNeedIssueSync(true));
     BranchDto projectBranch1 = db.components().insertProjectBranch(projectDto, b -> b.setBranchType(BranchType.BRANCH).setNeedIssueSync(true));
     BranchDto projectBranch2 = db.components().insertProjectBranch(projectDto, b -> b.setBranchType(BranchType.BRANCH).setNeedIssueSync(false));
@@ -670,13 +671,8 @@ public class BranchDaoTest {
     BranchDto pullRequest2 = db.components().insertProjectBranch(projectDto, b -> b.setBranchType(BranchType.PULL_REQUEST).setNeedIssueSync(false));
     db.components().insertProjectBranch(projectDto, b -> b.setBranchType(BranchType.PULL_REQUEST).setNeedIssueSync(true));
 
-    assertThat(underTest.doAnyOfComponentsNeedIssueSync(dbSession, singletonList(project.getKey()), null, null)).isTrue();
-
-    assertThat(underTest.doAnyOfComponentsNeedIssueSync(dbSession, singletonList(project.getKey()), projectBranch1.getKey(), null)).isTrue();
-    assertThat(underTest.doAnyOfComponentsNeedIssueSync(dbSession, singletonList(project.getKey()), projectBranch2.getKey(), null)).isFalse();
-
-    assertThat(underTest.doAnyOfComponentsNeedIssueSync(dbSession, singletonList(project.getKey()), null, pullRequest1.getKey())).isTrue();
-    assertThat(underTest.doAnyOfComponentsNeedIssueSync(dbSession, singletonList(project.getKey()), null, pullRequest2.getKey())).isFalse();
+    assertThat(underTest.doAnyOfComponentsNeedIssueSync(dbSession, singletonList(project1.getKey()))).isTrue();
+    assertThat(underTest.doAnyOfComponentsNeedIssueSync(dbSession, singletonList(project2.getKey()))).isFalse();
   }
 
   @Test
@@ -685,7 +681,7 @@ public class BranchDaoTest {
       .map(ComponentDto::getDbKey)
       .collect(Collectors.toList());
 
-    assertThat(underTest.doAnyOfComponentsNeedIssueSync(dbSession, componentKeys, null, null)).isFalse();
+    assertThat(underTest.doAnyOfComponentsNeedIssueSync(dbSession, componentKeys)).isFalse();
 
     ComponentDto project = db.components().insertPrivateProject();
     ProjectDto projectDto = db.components().getProjectDto(project);
@@ -693,6 +689,6 @@ public class BranchDaoTest {
 
     componentKeys.add(project.getDbKey());
 
-    assertThat(underTest.doAnyOfComponentsNeedIssueSync(dbSession, componentKeys, null, null)).isTrue();
+    assertThat(underTest.doAnyOfComponentsNeedIssueSync(dbSession, componentKeys)).isTrue();
   }
 }
index b638e3ba2cf1a0547dddc36b761ef94712f26234..8af309c34cf48508078230cb684082393bbec601 100644 (file)
@@ -23,7 +23,6 @@ import com.google.common.collect.Sets;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
-import javax.annotation.Nullable;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.server.es.EsIndexSyncInProgressException;
@@ -41,25 +40,16 @@ public class IssueIndexSyncProgressChecker {
     return new IssueSyncProgress(completed, total);
   }
 
-  public void checkIfAnyComponentsNeedIssueSync(DbSession dbSession, List<String> componentKeys, @Nullable String branch,
-    @Nullable String pullRequest) {
-    boolean needIssueSync = dbClient.branchDao().doAnyOfComponentsNeedIssueSync(dbSession, componentKeys, branch, pullRequest);
+  public void checkIfAnyComponentsNeedIssueSync(DbSession dbSession, List<String> componentKeys) {
+    boolean needIssueSync = dbClient.branchDao().doAnyOfComponentsNeedIssueSync(dbSession, componentKeys);
     if (needIssueSync) {
       throw new EsIndexSyncInProgressException(IssueIndexDefinition.TYPE_ISSUE.getMainType(),
           "Results are temporarily unavailable. Indexing of issues is in progress.");
     }
   }
 
-  public void checkIfAnyComponentsNeedIssueSync(DbSession dbSession, List<String> componentKeys) {
-    checkIfAnyComponentsNeedIssueSync(dbSession, componentKeys, null, null);
-  }
-
   public void checkIfComponentNeedIssueSync(DbSession dbSession, String componentKey) {
-    checkIfComponentNeedIssueSync(dbSession, componentKey, null);
-  }
-
-  public void checkIfComponentNeedIssueSync(DbSession dbSession, String componentKey, @Nullable String branchKey) {
-    checkIfAnyComponentsNeedIssueSync(dbSession, Collections.singletonList(componentKey), branchKey, null);
+    checkIfAnyComponentsNeedIssueSync(dbSession, Collections.singletonList(componentKey));
   }
 
   /**
index d41cf3188daadae951437ecf7c876375f38990ec..7ef82fa5ad073dd6cf1e35a58faadc47fdca3fc2 100644 (file)
@@ -121,7 +121,7 @@ public class IssueIndexSyncProgressCheckerTest {
     ProjectDto projectDto2 = insertProjectWithBranches(true, 0);
     DbSession session = db.getSession();
     List<String> projectKeys = Arrays.asList(projectDto1.getKey(), projectDto2.getKey());
-    assertThatThrownBy(() -> underTest.checkIfAnyComponentsNeedIssueSync(session, projectKeys, null, null))
+    assertThatThrownBy(() -> underTest.checkIfAnyComponentsNeedIssueSync(session, projectKeys))
       .isInstanceOf(EsIndexSyncInProgressException.class)
       .hasFieldOrPropertyWithValue("httpCode", 503)
       .hasMessage("Results are temporarily unavailable. Indexing of issues is in progress.");
@@ -129,10 +129,10 @@ public class IssueIndexSyncProgressCheckerTest {
 
   @Test
   public void checkIfAnyComponentsIssueSyncInProgress_does_not_throw_exception_if_all_components_have_need_issue_sync_FALSE() {
-    underTest.checkIfAnyComponentsNeedIssueSync(db.getSession(), Collections.emptyList(), null, null);
+    underTest.checkIfAnyComponentsNeedIssueSync(db.getSession(), Collections.emptyList());
     ProjectDto projectDto1 = insertProjectWithBranches(false, 0);
     ProjectDto projectDto2 = insertProjectWithBranches(false, 0);
-    underTest.checkIfAnyComponentsNeedIssueSync(db.getSession(), Arrays.asList(projectDto1.getKey(), projectDto2.getKey()), null, null);
+    underTest.checkIfAnyComponentsNeedIssueSync(db.getSession(), Arrays.asList(projectDto1.getKey(), projectDto2.getKey()));
   }
 
   @Test
@@ -142,7 +142,7 @@ public class IssueIndexSyncProgressCheckerTest {
 
     DbSession session = db.getSession();
     List<String> projectKeys = Arrays.asList(projectDto1.getKey(), projectDto2.getKey());
-    assertThatThrownBy(() -> underTest.checkIfAnyComponentsNeedIssueSync(session, projectKeys, null, null))
+    assertThatThrownBy(() -> underTest.checkIfAnyComponentsNeedIssueSync(session, projectKeys))
       .isInstanceOf(EsIndexSyncInProgressException.class)
       .hasFieldOrPropertyWithValue("httpCode", 503)
       .hasMessage("Results are temporarily unavailable. Indexing of issues is in progress.");
@@ -156,12 +156,12 @@ public class IssueIndexSyncProgressCheckerTest {
     DbSession session = db.getSession();
     List<String> projectKey1 = singletonList(projectDto2.getKey());
     // do nothing when need issue sync false
-    underTest.checkIfAnyComponentsNeedIssueSync(session, projectKey1, null, null);
+    underTest.checkIfAnyComponentsNeedIssueSync(session, projectKey1);
 
     List<String> projectKey2 = singletonList(projectDto1.getKey());
     // throws if flag set to TRUE
     assertThatThrownBy(() -> underTest.checkIfAnyComponentsNeedIssueSync(session,
-        projectKey2, null, null))
+        projectKey2))
         .isInstanceOf(EsIndexSyncInProgressException.class)
         .hasFieldOrPropertyWithValue("httpCode", 503)
         .hasMessage("Results are temporarily unavailable. Indexing of issues is in progress.");
@@ -179,8 +179,8 @@ public class IssueIndexSyncProgressCheckerTest {
     List<String> appViewOrSubviewKeys = Arrays.asList(projectDto1.getKey(), app.getDbKey(), view.getDbKey(), subview.getDbKey());
 
     // throws if flag set to TRUE
-    assertThatThrownBy(() -> underTest.checkIfAnyComponentsIssueSyncInProgress(session,
-      appViewOrSubviewKeys, null, null))
+    assertThatThrownBy(() -> underTest.checkIfAnyComponentsNeedIssueSync(session,
+      appViewOrSubviewKeys))
         .isInstanceOf(EsIndexSyncInProgressException.class)
         .hasFieldOrPropertyWithValue("httpCode", 503)
         .hasMessage("Results are temporarily unavailable. Indexing of issues is in progress.");
index 4bc64bce33d6ca7440545aec1eb4a335ae1962e8..214184cea9d14cba63e8ab3c0917b7da2a6255e1 100644 (file)
@@ -184,9 +184,7 @@ public class SearchAction implements HotspotsWsAction {
   private void checkIfNeedIssueSync(DbSession dbSession, WsRequest wsRequest) {
     Optional<String> projectKey = wsRequest.getProjectKey();
     if (projectKey.isPresent()) {
-      String branch = wsRequest.getBranch().orElse(null);
-      String pullRequest = wsRequest.getPullRequest().orElse(null);
-      issueIndexSyncProgressChecker.checkIfAnyComponentsNeedIssueSync(dbSession, singletonList(projectKey.get()), branch, pullRequest);
+      issueIndexSyncProgressChecker.checkIfComponentNeedIssueSync(dbSession, projectKey.get());
     } else {
       // component keys not provided - asking for global
       issueIndexSyncProgressChecker.checkIfIssueSyncInProgress(dbSession);
index f6d7cdae71888cb0fe5d1769e6c4460d9f10b7e8..dc1433327961acecb5cb8732f7612be557404fc4 100644 (file)
@@ -544,9 +544,7 @@ public class SearchAction implements IssuesWsAction {
   private void checkIfNeedIssueSync(DbSession dbSession, SearchRequest searchRequest) {
     List<String> components = searchRequest.getComponents();
     if (components != null && !components.isEmpty()) {
-      String branch = searchRequest.getBranch();
-      String pullRequest = searchRequest.getPullRequest();
-      issueIndexSyncProgressChecker.checkIfAnyComponentsNeedIssueSync(dbSession, components, branch, pullRequest);
+      issueIndexSyncProgressChecker.checkIfAnyComponentsNeedIssueSync(dbSession, components);
     } else {
       // component keys not provided - asking for global
       issueIndexSyncProgressChecker.checkIfIssueSyncInProgress(dbSession);
index f41016a90afe163bf783785d775c03b18eda4f7a..fb8d5e05b671ac2e74f35a3adc665865ba9a49e8 100644 (file)
@@ -85,6 +85,7 @@ import static org.mockito.ArgumentMatchers.argThat;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.ArgumentMatchers.isNull;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.sonar.api.issue.Issue.RESOLUTION_FIXED;
 import static org.sonar.api.issue.Issue.RESOLUTION_SAFE;
@@ -671,9 +672,7 @@ public class SearchActionTest {
       .extracting(SearchWsResponse.Hotspot::getKey)
       .containsExactlyInAnyOrder(Arrays.stream(hotspotPR).map(IssueDto::getKey).toArray(String[]::new));
 
-    verify(issueIndexSyncProgressChecker).checkIfAnyComponentsNeedIssueSync(any(), argThat(arg -> arg.contains(project.getKey())), isNull(), isNull());
-    verify(issueIndexSyncProgressChecker).checkIfAnyComponentsNeedIssueSync(any(), argThat(arg -> arg.contains(project.getKey())), eq(branch.getBranch()), isNull());
-    verify(issueIndexSyncProgressChecker).checkIfAnyComponentsNeedIssueSync(any(), argThat(arg -> arg.contains(project.getKey())), isNull(), eq(branch.getPullRequest()));
+    verify(issueIndexSyncProgressChecker, times(3)).checkIfComponentNeedIssueSync(any(), eq(project.getDbKey()));
   }
 
   @Test