diff --git a/spring-core/src/test/java/org/springframework/core/SpringCoreBlockHoundIntegrationTests.java b/spring-core/src/test/java/org/springframework/core/SpringCoreBlockHoundIntegrationTests.java index a6872f168b..1b88dc2147 100644 --- a/spring-core/src/test/java/org/springframework/core/SpringCoreBlockHoundIntegrationTests.java +++ b/spring-core/src/test/java/org/springframework/core/SpringCoreBlockHoundIntegrationTests.java @@ -66,7 +66,7 @@ class SpringCoreBlockHoundIntegrationTests { } @Test - void concurrentReferenceHashMap() { + void concurrentReferenceHashMapSegmentDoTask() { int size = 10000; Map map = new ConcurrentReferenceHashMap<>(size); @@ -88,6 +88,29 @@ class SpringCoreBlockHoundIntegrationTests { assertThat(map).hasSize(size); } + @Test + void concurrentReferenceHashMapSegmentClear() { + int size = 10000; + Map map = new ConcurrentReferenceHashMap<>(size); + + CompletableFuture future1 = new CompletableFuture<>(); + testNonBlockingTask(() -> { + for (int i = 0; i < size / 2; i++) { + map.put("a" + i, "bar"); + } + }, future1); + + CompletableFuture future2 = new CompletableFuture<>(); + testNonBlockingTask(() -> { + for (int i = 0; i < size; i++) { + map.clear(); + } + }, future2); + + CompletableFuture.allOf(future1, future2).join(); + assertThat(map).isEmpty(); + } + private void testNonBlockingTask(NonBlockingTask task) { CompletableFuture future = new CompletableFuture<>(); testNonBlockingTask(task, future);