Skip to content

Commit f408490

Browse files
committed
Fix Race In Test
- use `BlockingQueue` instead of `ArrayList`.
1 parent 7cc4524 commit f408490

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

spring-kafka/src/test/java/org/springframework/kafka/listener/ConcurrentMessageListenerContainerTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,16 @@
2727
import java.util.Arrays;
2828
import java.util.BitSet;
2929
import java.util.Collection;
30-
import java.util.Collections;
3130
import java.util.HashSet;
3231
import java.util.Iterator;
3332
import java.util.List;
3433
import java.util.Map;
3534
import java.util.Properties;
3635
import java.util.Set;
36+
import java.util.concurrent.BlockingQueue;
3737
import java.util.concurrent.ConcurrentSkipListSet;
3838
import java.util.concurrent.CountDownLatch;
39+
import java.util.concurrent.LinkedBlockingQueue;
3940
import java.util.concurrent.TimeUnit;
4041
import java.util.concurrent.atomic.AtomicBoolean;
4142
import java.util.concurrent.atomic.AtomicReference;
@@ -151,7 +152,7 @@ protected Consumer<Integer, String> createKafkaConsumer(String groupId, String c
151152
new ConcurrentMessageListenerContainer<>(cf, containerProps);
152153
container.setConcurrency(2);
153154
container.setBeanName("testAuto");
154-
List<KafkaEvent> events = Collections.synchronizedList(new ArrayList<>());
155+
BlockingQueue<KafkaEvent> events = new LinkedBlockingQueue<>();
155156
CountDownLatch stopLatch = new CountDownLatch(4);
156157
container.setApplicationEventPublisher(e -> {
157158
events.add((KafkaEvent) e);

0 commit comments

Comments
 (0)