Skip to content

Commit eff39e5

Browse files
committed
PollerAdviceTests: synchronized list actions
https://build.spring.io/browse/INT-MASTERSPRING40-441 Even if we `stop()` a `SourcePollingChannelAdapter` that doesn't mean that task-in-progress can't deliver its result to the source consumer. * Wrap a list `add()` and iterator operations to avoid a `ConcurrentModificationException` # Conflicts: # spring-integration-core/src/test/java/org/springframework/integration/endpoint/PollerAdviceTests.java
1 parent 11310ff commit eff39e5

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

spring-integration-core/src/test/java/org/springframework/integration/endpoint/PollerAdviceTests.java

+6-8
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,9 @@ public void testActiveIdleAdvice() throws Exception {
279279
final LinkedList<Long> triggerPeriods = new LinkedList<Long>();
280280
final DynamicPeriodicTrigger trigger = new DynamicPeriodicTrigger(10);
281281
adapter.setSource(() -> {
282-
triggerPeriods.add(trigger.getPeriod());
282+
synchronized (triggerPeriods) {
283+
triggerPeriods.add(trigger.getPeriod());
284+
}
283285
Message<Object> m = null;
284286
if (latch.getCount() % 2 == 0) {
285287
m = new GenericMessage<>("foo");
@@ -297,10 +299,9 @@ public void testActiveIdleAdvice() throws Exception {
297299
adapter.start();
298300
assertTrue(latch.await(10, TimeUnit.SECONDS));
299301
adapter.stop();
300-
while (triggerPeriods.size() > 5) {
301-
triggerPeriods.removeLast();
302+
synchronized (triggerPeriods) {
303+
assertThat(triggerPeriods.subList(0, 5), contains(10L, 12L, 11L, 12L, 11L));
302304
}
303-
assertThat(triggerPeriods, contains(10L, 12L, 11L, 12L, 11L));
304305
}
305306

306307
@Test
@@ -330,11 +331,8 @@ public void testCompoundTriggerAdvice() throws Exception {
330331
assertTrue(latch.await(10, TimeUnit.SECONDS));
331332
adapter.stop();
332333
synchronized (overridePresent) {
333-
while (overridePresent.size() > 5) {
334-
overridePresent.removeLast();
335-
}
334+
assertThat(overridePresent.subList(0, 5), contains(null, override, null, override, null));
336335
}
337-
assertThat(overridePresent, contains(null, override, null, override, null));
338336
verify(override, atLeast(2)).nextExecutionTime(any(TriggerContext.class));
339337
}
340338

0 commit comments

Comments
 (0)