File tree 2 files changed +31
-5
lines changed
main/java/org/springframework/core
test/java/org/springframework/core
2 files changed +31
-5
lines changed Original file line number Diff line number Diff line change @@ -441,10 +441,13 @@ public static class SpringCoreBlockHoundIntegration implements BlockHoundIntegra
441
441
public void applyTo (BlockHound .Builder builder ) {
442
442
// Avoid hard references potentially anywhere in spring-core (no need for structural dependency)
443
443
444
- String className = "org.springframework.util.ConcurrentReferenceHashMap$Segment" ;
445
- builder .allowBlockingCallsInside (className , "doTask" );
446
- builder .allowBlockingCallsInside (className , "clear" );
447
- builder .allowBlockingCallsInside (className , "restructure" );
444
+ String segmentClassName = "org.springframework.util.ConcurrentReferenceHashMap$Segment" ;
445
+ builder .allowBlockingCallsInside (segmentClassName , "doTask" );
446
+ builder .allowBlockingCallsInside (segmentClassName , "clear" );
447
+ builder .allowBlockingCallsInside (segmentClassName , "restructure" );
448
+
449
+ String referenceManagerClassName = "org.springframework.util.ConcurrentReferenceHashMap$ReferenceManager" ;
450
+ builder .allowBlockingCallsInside (referenceManagerClassName , "pollForPurge" );
448
451
}
449
452
}
450
453
Original file line number Diff line number Diff line change @@ -66,7 +66,7 @@ void blockHoundIsInstalled() {
66
66
}
67
67
68
68
@ Test
69
- void concurrentReferenceHashMap () {
69
+ void concurrentReferenceHashMapSegmentDoTask () {
70
70
int size = 10000 ;
71
71
Map <String , String > map = new ConcurrentReferenceHashMap <>(size );
72
72
@@ -88,6 +88,29 @@ void concurrentReferenceHashMap() {
88
88
assertThat (map ).hasSize (size );
89
89
}
90
90
91
+ @ Test
92
+ void concurrentReferenceHashMapSegmentClear () {
93
+ int size = 10000 ;
94
+ Map <String , String > map = new ConcurrentReferenceHashMap <>(size );
95
+
96
+ CompletableFuture <Object > future1 = new CompletableFuture <>();
97
+ testNonBlockingTask (() -> {
98
+ for (int i = 0 ; i < size / 2 ; i ++) {
99
+ map .put ("a" + i , "bar" );
100
+ }
101
+ }, future1 );
102
+
103
+ CompletableFuture <Object > future2 = new CompletableFuture <>();
104
+ testNonBlockingTask (() -> {
105
+ for (int i = 0 ; i < size ; i ++) {
106
+ map .clear ();
107
+ }
108
+ }, future2 );
109
+
110
+ CompletableFuture .allOf (future1 , future2 ).join ();
111
+ assertThat (map ).isEmpty ();
112
+ }
113
+
91
114
private void testNonBlockingTask (NonBlockingTask task ) {
92
115
CompletableFuture <Object > future = new CompletableFuture <>();
93
116
testNonBlockingTask (task , future );
You can’t perform that action at this time.
0 commit comments