Skip to content

Commit

Permalink
Update bulkhead test (eugenp#13836)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianbob authored Apr 24, 2023
1 parent 113c62e commit 91d1cdf
Showing 1 changed file with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
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.*;
Expand Down Expand Up @@ -210,23 +209,20 @@ void testBulkheadEvents() throws Exception {
EXTERNAL_SERVICE.stubFor(WireMock.get("/api/external").willReturn(ok()));
Map<Integer, Integer> responseStatusCount = new ConcurrentHashMap<>();
ExecutorService executorService = Executors.newFixedThreadPool(5);
CountDownLatch latch = new CountDownLatch(5);

List<Callable<Integer>> tasks = new ArrayList<>();
IntStream.rangeClosed(1, 5)
.forEach(
i ->
tasks.add(
executorService.execute(
() -> {
ResponseEntity<String> response =
restTemplate.getForEntity("/api/bulkhead", String.class);
return response.getStatusCodeValue();
int statusCode = response.getStatusCodeValue();
responseStatusCount.merge(statusCode, 1, Integer::sum);
latch.countDown();
}));

List<Future<Integer>> futures = executorService.invokeAll(tasks);
for (Future<Integer> future : futures) {
int statusCode = future.get();
responseStatusCount.merge(statusCode, 1, Integer::sum);
}
latch.await();
executorService.shutdown();

assertEquals(2, responseStatusCount.keySet().size());
Expand Down

0 comments on commit 91d1cdf

Please sign in to comment.