summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorEric Hartmann <hartmann.eric@gmail.com>2017-09-05 15:00:44 +0200
committerEric Hartmann <hartmann.eric@gmail.Com>2017-09-14 18:18:20 +0200
commit0cf148c9666a0c293921d391f3fffcc851bf4393 (patch)
tree59eb6ee0b7bc99e346d725253585e3162a574db8 /server
parent9a4c4e50641c73064fef10fa4c2073439bc38651 (diff)
downloadsonarqube-0cf148c9666a0c293921d391f3fffcc851bf4393.tar.gz
sonarqube-0cf148c9666a0c293921d391f3fffcc851bf4393.zip
SONAR-9762 Implement resiliency on startup
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/es/IndexingListener.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/es/FailOnErrorIndexingListenerTest.java52
2 files changed, 53 insertions, 1 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/es/IndexingListener.java b/server/sonar-server/src/main/java/org/sonar/server/es/IndexingListener.java
index d4748a5652a..aa5cd895b2b 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/es/IndexingListener.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/es/IndexingListener.java
@@ -36,7 +36,7 @@ public interface IndexingListener {
@Override
public void onFinish(IndexingResult result) {
if (result.getFailures() > 0) {
- throw new IllegalStateException("Indexation failures");
+ throw new IllegalStateException("Unrecoverable indexation failures");
}
}
};
diff --git a/server/sonar-server/src/test/java/org/sonar/server/es/FailOnErrorIndexingListenerTest.java b/server/sonar-server/src/test/java/org/sonar/server/es/FailOnErrorIndexingListenerTest.java
new file mode 100644
index 00000000000..7753063c63c
--- /dev/null
+++ b/server/sonar-server/src/test/java/org/sonar/server/es/FailOnErrorIndexingListenerTest.java
@@ -0,0 +1,52 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.es;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+public class FailOnErrorIndexingListenerTest {
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ @Test
+ public void onFinish_must_throw_ISE_when_an_error_is_present() {
+ IndexingResult indexingResult = new IndexingResult();
+
+ indexingResult.incrementRequests();
+
+ expectedException.expect(IllegalStateException.class);
+ expectedException.expectMessage("Unrecoverable indexation failures");
+
+ IndexingListener.FAIL_ON_ERROR.onFinish(indexingResult);
+ }
+
+ @Test
+ public void onFinish_must_not_throw_any_exception_if_no_failure() {
+ IndexingResult indexingResult = new IndexingResult();
+
+ indexingResult.incrementRequests();
+ indexingResult.incrementSuccess();
+
+ IndexingListener.FAIL_ON_ERROR.onFinish(indexingResult);
+ }
+}