From 4dcfadc14b3edfffb0ad0e489cb081eb07729a17 Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Wed, 25 Oct 2023 08:03:54 +0000 Subject: [PATCH] feat: fix sonar issue --- .../test/java/com/example/mongoes/TestApplication.java | 2 +- .../RestaurantESRepositoryIntegrationTest.java | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/boot-mongodb-elasticsearch/src/test/java/com/example/mongoes/TestApplication.java b/boot-mongodb-elasticsearch/src/test/java/com/example/mongoes/TestApplication.java index 0fa55f768..e01fc7324 100644 --- a/boot-mongodb-elasticsearch/src/test/java/com/example/mongoes/TestApplication.java +++ b/boot-mongodb-elasticsearch/src/test/java/com/example/mongoes/TestApplication.java @@ -17,7 +17,7 @@ public class TestApplication { @Bean @RestartScope ElasticsearchContainer elasticsearchContainer() { - return new ElasticsearchContainer("docker.elastic.co/elasticsearch/elasticsearch:8.10.3") + return new ElasticsearchContainer("docker.elastic.co/elasticsearch/elasticsearch:8.10.4") .withEnv(Map.of("xpack.security.enabled", "false")); } diff --git a/boot-mongodb-elasticsearch/src/test/java/com/example/mongoes/elasticsearch/repository/RestaurantESRepositoryIntegrationTest.java b/boot-mongodb-elasticsearch/src/test/java/com/example/mongoes/elasticsearch/repository/RestaurantESRepositoryIntegrationTest.java index 83cda7ddd..77f28ec5f 100644 --- a/boot-mongodb-elasticsearch/src/test/java/com/example/mongoes/elasticsearch/repository/RestaurantESRepositoryIntegrationTest.java +++ b/boot-mongodb-elasticsearch/src/test/java/com/example/mongoes/elasticsearch/repository/RestaurantESRepositoryIntegrationTest.java @@ -1,15 +1,16 @@ package com.example.mongoes.elasticsearch.repository; import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; import com.example.mongoes.common.AbstractIntegrationTest; import com.example.mongoes.document.Address; import com.example.mongoes.document.Grades; import com.example.mongoes.document.Restaurant; +import java.time.Duration; import java.time.LocalDateTime; import java.util.List; import java.util.Map; -import java.util.concurrent.TimeUnit; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -36,7 +37,7 @@ class RestaurantESRepositoryIntegrationTest extends AbstractIntegrationTest { @Autowired private RestaurantESRepository restaurantESRepository; @BeforeAll - void setUpData() throws InterruptedException { + void setUpData() { Restaurant restaurant = new Restaurant(); restaurant.setRestaurantId(2L); restaurant.setName(RESTAURANT_NAME); @@ -61,7 +62,10 @@ void setUpData() throws InterruptedException { .log("saving restaurant") .subscribe(); - TimeUnit.SECONDS.sleep(5); + await().atMost(Duration.ofSeconds(10)) + .pollInterval(Duration.ofSeconds(1)) + .untilAsserted( + () -> assertThat(this.restaurantESRepository.count().block()).isEqualTo(2)); } @Test