]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13337 Improve ES error message in batch requests to guide user to check ES...
authorJacek <jacek.poreda@sonarsource.com>
Thu, 16 Sep 2021 09:56:38 +0000 (11:56 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 16 Sep 2021 20:03:30 +0000 (20:03 +0000)
server/sonar-server-common/src/main/java/org/sonar/server/es/IndexingListener.java
server/sonar-server-common/src/test/java/org/sonar/server/es/FailOnErrorIndexingListenerTest.java

index 095451c7f7d58debe18d3060f481361510dd9d8e..6d9b7972a075aa2ee5b585f01817a5fa642b8cb4 100644 (file)
@@ -21,6 +21,8 @@ package org.sonar.server.es;
 
 import java.util.List;
 
+import static java.lang.String.format;
+
 public interface IndexingListener {
 
   void onSuccess(List<DocId> docIds);
@@ -36,7 +38,10 @@ public interface IndexingListener {
     @Override
     public void onFinish(IndexingResult result) {
       if (result.getFailures() > 0) {
-        throw new IllegalStateException(String.format("Unrecoverable indexation failures: %d errors among %d requests", result.getFailures(), result.getTotal()));
+        throw new IllegalStateException(
+          format("Unrecoverable indexation failures: %d errors among %d requests. Check Elasticsearch logs for further details.",
+            result.getFailures(),
+            result.getTotal()));
       }
     }
   };
index a693f0bb17859828e1a1e873796c41fec05a6aa4..631ba9df6c3c44c9a038ca96783ac1648246de2f 100644 (file)
  */
 package org.sonar.server.es;
 
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 
-public class FailOnErrorIndexingListenerTest {
+import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.sonar.server.es.IndexingListener.FAIL_ON_ERROR;
 
-  @Rule
-  public ExpectedException expectedException = ExpectedException.none();
+public class FailOnErrorIndexingListenerTest {
 
   @Test
   public void onFinish_must_throw_ISE_when_an_error_is_present() {
@@ -34,10 +33,10 @@ public class FailOnErrorIndexingListenerTest {
 
     indexingResult.incrementRequests();
 
-    expectedException.expect(IllegalStateException.class);
-    expectedException.expectMessage("Unrecoverable indexation failures");
-
-    IndexingListener.FAIL_ON_ERROR.onFinish(indexingResult);
+    assertThatThrownBy(() -> FAIL_ON_ERROR.onFinish(indexingResult))
+      .isInstanceOf(IllegalStateException.class)
+      .hasMessage("Unrecoverable indexation failures: 1 errors among 1 requests. "
+        + "Check Elasticsearch logs for further details.");
   }
 
   @Test
@@ -47,6 +46,7 @@ public class FailOnErrorIndexingListenerTest {
     indexingResult.incrementRequests();
     indexingResult.incrementSuccess();
 
-    IndexingListener.FAIL_ON_ERROR.onFinish(indexingResult);
+    assertThatCode(() -> FAIL_ON_ERROR.onFinish(indexingResult))
+      .doesNotThrowAnyException();
   }
 }