Skip to content

Commit

Permalink
Merge branch '6.1.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbasle committed Sep 17, 2024
2 parents 20bc5ef + de4ff4b commit 06d240b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,13 @@ public static class SpringCoreBlockHoundIntegration implements BlockHoundIntegra
public void applyTo(BlockHound.Builder builder) {
// Avoid hard references potentially anywhere in spring-core (no need for structural dependency)

String className = "org.springframework.util.ConcurrentReferenceHashMap$Segment";
builder.allowBlockingCallsInside(className, "doTask");
builder.allowBlockingCallsInside(className, "clear");
builder.allowBlockingCallsInside(className, "restructure");
String segmentClassName = "org.springframework.util.ConcurrentReferenceHashMap$Segment";
builder.allowBlockingCallsInside(segmentClassName, "doTask");
builder.allowBlockingCallsInside(segmentClassName, "clear");
builder.allowBlockingCallsInside(segmentClassName, "restructure");

String referenceManagerClassName = "org.springframework.util.ConcurrentReferenceHashMap$ReferenceManager";
builder.allowBlockingCallsInside(referenceManagerClassName, "pollForPurge");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void blockHoundIsInstalled() {
}

@Test
void concurrentReferenceHashMap() {
void concurrentReferenceHashMapSegmentDoTask() {
int size = 10000;
Map<String, String> map = new ConcurrentReferenceHashMap<>(size);

Expand All @@ -88,6 +88,29 @@ void concurrentReferenceHashMap() {
assertThat(map).hasSize(size);
}

@Test
void concurrentReferenceHashMapSegmentClear() {
int size = 10000;
Map<String, String> map = new ConcurrentReferenceHashMap<>(size);

CompletableFuture<Object> future1 = new CompletableFuture<>();
testNonBlockingTask(() -> {
for (int i = 0; i < size / 2; i++) {
map.put("a" + i, "bar");
}
}, future1);

CompletableFuture<Object> 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<Object> future = new CompletableFuture<>();
testNonBlockingTask(task, future);
Expand Down

0 comments on commit 06d240b

Please sign in to comment.