import java.util.List;
+import static java.lang.String.format;
+
public interface IndexingListener {
void onSuccess(List<DocId> docIds);
@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()));
}
}
};
*/
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() {
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
indexingResult.incrementRequests();
indexingResult.incrementSuccess();
- IndexingListener.FAIL_ON_ERROR.onFinish(indexingResult);
+ assertThatCode(() -> FAIL_ON_ERROR.onFinish(indexingResult))
+ .doesNotThrowAnyException();
}
}