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

View File

@@ -257,7 +257,9 @@ public class PollerAdviceTests {
final LinkedList<Long> triggerPeriods = new LinkedList<>();
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");
@@ -275,10 +277,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
@@ -308,10 +309,7 @@ public class PollerAdviceTests {
assertTrue(latch.await(10, TimeUnit.SECONDS));
adapter.stop();
synchronized (overridePresent) {
while (overridePresent.size() > 5) {
overridePresent.removeLast();
}
assertThat(overridePresent, contains(null, override, null, override, null));
assertThat(overridePresent.subList(0, 5), contains(null, override, null, override, null));
}
verify(override, atLeast(2)).nextExecutionTime(any(TriggerContext.class));
}