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
This commit is contained in:
Artem Bilan
2018-08-27 12:20:26 -04:00
parent 11310ff1ff
commit eff39e5cb5

View File

@@ -279,7 +279,9 @@ public class PollerAdviceTests {
final LinkedList<Long> triggerPeriods = new LinkedList<Long>();
final DynamicPeriodicTrigger trigger = new DynamicPeriodicTrigger(10);
adapter.setSource(() -> {
triggerPeriods.add(trigger.getPeriod());
synchronized (triggerPeriods) {
triggerPeriods.add(trigger.getPeriod());
}
Message<Object> m = null;
if (latch.getCount() % 2 == 0) {
m = new GenericMessage<>("foo");
@@ -297,10 +299,9 @@ public class PollerAdviceTests {
adapter.start();
assertTrue(latch.await(10, TimeUnit.SECONDS));
adapter.stop();
while (triggerPeriods.size() > 5) {
triggerPeriods.removeLast();
synchronized (triggerPeriods) {
assertThat(triggerPeriods.subList(0, 5), contains(10L, 12L, 11L, 12L, 11L));
}
assertThat(triggerPeriods, contains(10L, 12L, 11L, 12L, 11L));
}
@Test
@@ -330,11 +331,8 @@ public class PollerAdviceTests {
assertTrue(latch.await(10, TimeUnit.SECONDS));
adapter.stop();
synchronized (overridePresent) {
while (overridePresent.size() > 5) {
overridePresent.removeLast();
}
assertThat(overridePresent.subList(0, 5), contains(null, override, null, override, null));
}
assertThat(overridePresent, contains(null, override, null, override, null));
verify(override, atLeast(2)).nextExecutionTime(any(TriggerContext.class));
}