From c11605cc614fdf0b7cea5b8ab2d9fcd0f368dc91 Mon Sep 17 00:00:00 2001 From: Adrian Bob Date: Mon, 24 Apr 2023 20:32:49 +0300 Subject: [PATCH] Update bulkhead test (#13836) --- .../ResilientAppControllerIntegrationTest.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/spring-boot-modules/spring-boot-resilience4j/src/test/java/com/baeldung/resilience4j/eventendpoints/ResilientAppControllerIntegrationTest.java b/spring-boot-modules/spring-boot-resilience4j/src/test/java/com/baeldung/resilience4j/eventendpoints/ResilientAppControllerIntegrationTest.java index 3933a02753..d1951218de 100644 --- a/spring-boot-modules/spring-boot-resilience4j/src/test/java/com/baeldung/resilience4j/eventendpoints/ResilientAppControllerIntegrationTest.java +++ b/spring-boot-modules/spring-boot-resilience4j/src/test/java/com/baeldung/resilience4j/eventendpoints/ResilientAppControllerIntegrationTest.java @@ -14,7 +14,6 @@ import com.github.tomakehurst.wiremock.core.WireMockConfiguration; import com.github.tomakehurst.wiremock.junit5.WireMockExtension; import java.net.URI; import java.nio.charset.Charset; -import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.concurrent.*; @@ -210,23 +209,20 @@ class ResilientAppControllerIntegrationTest { EXTERNAL_SERVICE.stubFor(WireMock.get("/api/external").willReturn(ok())); Map responseStatusCount = new ConcurrentHashMap<>(); ExecutorService executorService = Executors.newFixedThreadPool(5); + CountDownLatch latch = new CountDownLatch(5); - List> tasks = new ArrayList<>(); IntStream.rangeClosed(1, 5) .forEach( i -> - tasks.add( + executorService.execute( () -> { ResponseEntity response = restTemplate.getForEntity("/api/bulkhead", String.class); - return response.getStatusCodeValue(); + int statusCode = response.getStatusCodeValue(); + responseStatusCount.merge(statusCode, 1, Integer::sum); + latch.countDown(); })); - - List> futures = executorService.invokeAll(tasks); - for (Future future : futures) { - int statusCode = future.get(); - responseStatusCount.merge(statusCode, 1, Integer::sum); - } + latch.await(); executorService.shutdown(); assertEquals(2, responseStatusCount.keySet().size());