diff options
author | Jacek <jacek.poreda@sonarsource.com> | 2020-06-09 11:32:36 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2020-06-26 20:04:57 +0000 |
commit | 94ae3b76e8e25adb3d7f266de45bce298e971a1f (patch) | |
tree | 8cd812482c45b965573f00efa1512ec21bc042e8 /server/sonar-webserver-es | |
parent | 67b7694f63106219f9c0c15d91aeb3eb8c0f626d (diff) | |
download | sonarqube-94ae3b76e8e25adb3d7f266de45bce298e971a1f.tar.gz sonarqube-94ae3b76e8e25adb3d7f266de45bce298e971a1f.zip |
SONAR-13398 fail with 503 api/issues/tags WS if needIssueSync is set to true
Diffstat (limited to 'server/sonar-webserver-es')
2 files changed, 12 insertions, 7 deletions
diff --git a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndexSyncProgressChecker.java b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndexSyncProgressChecker.java index 6e9ea790226..5c6aefe3a90 100644 --- a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndexSyncProgressChecker.java +++ b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndexSyncProgressChecker.java @@ -21,6 +21,7 @@ package org.sonar.server.issue.index; 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; @@ -40,7 +41,7 @@ public class IssueIndexSyncProgressChecker { return new IssueSyncProgress(completed, total); } - public void checkIfAnyComponentsIssueSyncInProgress(DbSession dbSession, List<String> componentKeys, @Nullable String branch, + public void checkIfAnyComponentsNeedIssueSync(DbSession dbSession, List<String> componentKeys, @Nullable String branch, @Nullable String pullRequest) { boolean needIssueSync = dbClient.branchDao().doAnyOfComponentsNeedIssueSync(dbSession, componentKeys, branch, pullRequest); if (needIssueSync) { @@ -49,6 +50,10 @@ public class IssueIndexSyncProgressChecker { } } + public void checkIfComponentNeedIssueSync(DbSession dbSession, String componentKey) { + checkIfAnyComponentsNeedIssueSync(dbSession, Collections.singletonList(componentKey), null, null); + } + /** * Checks if issue index sync is in progress, if it is, method throws exception org.sonar.server.es.EsIndexSyncInProgressException */ diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSyncProgressCheckerTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSyncProgressCheckerTest.java index d036d47eea0..d41cf3188da 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSyncProgressCheckerTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSyncProgressCheckerTest.java @@ -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.checkIfAnyComponentsIssueSyncInProgress(session, projectKeys, null, null)) + assertThatThrownBy(() -> underTest.checkIfAnyComponentsNeedIssueSync(session, projectKeys, null, null)) .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.checkIfAnyComponentsIssueSyncInProgress(db.getSession(), Collections.emptyList(), null, null); + underTest.checkIfAnyComponentsNeedIssueSync(db.getSession(), Collections.emptyList(), null, null); ProjectDto projectDto1 = insertProjectWithBranches(false, 0); ProjectDto projectDto2 = insertProjectWithBranches(false, 0); - underTest.checkIfAnyComponentsIssueSyncInProgress(db.getSession(), Arrays.asList(projectDto1.getKey(), projectDto2.getKey()), null, null); + underTest.checkIfAnyComponentsNeedIssueSync(db.getSession(), Arrays.asList(projectDto1.getKey(), projectDto2.getKey()), null, null); } @Test @@ -142,7 +142,7 @@ public class IssueIndexSyncProgressCheckerTest { DbSession session = db.getSession(); List<String> projectKeys = Arrays.asList(projectDto1.getKey(), projectDto2.getKey()); - assertThatThrownBy(() -> underTest.checkIfAnyComponentsIssueSyncInProgress(session, projectKeys, null, null)) + assertThatThrownBy(() -> underTest.checkIfAnyComponentsNeedIssueSync(session, projectKeys, null, null)) .isInstanceOf(EsIndexSyncInProgressException.class) .hasFieldOrPropertyWithValue("httpCode", 503) .hasMessage("Results are temporarily unavailable. Indexing of issues is in progress."); @@ -156,11 +156,11 @@ public class IssueIndexSyncProgressCheckerTest { DbSession session = db.getSession(); List<String> projectKey1 = singletonList(projectDto2.getKey()); // do nothing when need issue sync false - underTest.checkIfAnyComponentsIssueSyncInProgress(session, projectKey1, null, null); + underTest.checkIfAnyComponentsNeedIssueSync(session, projectKey1, null, null); List<String> projectKey2 = singletonList(projectDto1.getKey()); // throws if flag set to TRUE - assertThatThrownBy(() -> underTest.checkIfAnyComponentsIssueSyncInProgress(session, + assertThatThrownBy(() -> underTest.checkIfAnyComponentsNeedIssueSync(session, projectKey2, null, null)) .isInstanceOf(EsIndexSyncInProgressException.class) .hasFieldOrPropertyWithValue("httpCode", 503) |