From 8ade7e3a1203301b15e15629ca83137507454630 Mon Sep 17 00:00:00 2001 From: Antoine Vinot Date: Wed, 7 Jun 2023 17:40:43 +0200 Subject: [PATCH] NO-JIRA - Improve flaky tests --- .../java/org/sonar/server/es/EsTester.java | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/server/sonar-server-common/src/testFixtures/java/org/sonar/server/es/EsTester.java b/server/sonar-server-common/src/testFixtures/java/org/sonar/server/es/EsTester.java index 5b304813d71..ca3cbb50ca8 100644 --- a/server/sonar-server-common/src/testFixtures/java/org/sonar/server/es/EsTester.java +++ b/server/sonar-server-common/src/testFixtures/java/org/sonar/server/es/EsTester.java @@ -103,6 +103,7 @@ import static com.google.common.base.Preconditions.checkState; import static com.google.common.collect.Lists.newArrayList; import static java.lang.String.format; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; import static org.sonar.server.es.Index.ALL_INDICES; import static org.sonar.server.es.IndexType.FIELD_INDEX_TYPE; @@ -230,18 +231,14 @@ public class EsTester extends ExternalResource { } public void putDocuments(IndexType indexType, BaseDoc... docs) { - try { - BulkRequest bulk = new BulkRequest() - .setRefreshPolicy(REFRESH_IMMEDIATE); - for (BaseDoc doc : docs) { - bulk.add(doc.toIndexRequest()); - } - BulkResponse bulkResponse = ES_REST_CLIENT.bulk(bulk); - if (bulkResponse.hasFailures()) { - throw new IllegalStateException(bulkResponse.buildFailureMessage()); - } - } catch (Exception e) { - throw Throwables.propagate(e); + BulkRequest bulk = new BulkRequest() + .setRefreshPolicy(REFRESH_IMMEDIATE); + for (BaseDoc doc : docs) { + bulk.add(doc.toIndexRequest()); + } + BulkResponse bulkResponse = ES_REST_CLIENT.bulk(bulk); + if (bulkResponse.hasFailures()) { + fail("Bulk indexing of documents failed: " + bulkResponse.buildFailureMessage()); } } -- 2.39.5