Fix some sporadic tests failures

https://build.spring.io/browse/INT-MASTER-1004/
This commit is contained in:
Artem Bilan
2018-04-19 17:35:50 -04:00
parent 82cbafaaa4
commit 1f6f70b4ef
4 changed files with 18 additions and 12 deletions

View File

@@ -290,7 +290,9 @@ public class PollerAdviceTests {
Trigger override = spy(new PeriodicTrigger(5));
final CompoundTriggerAdvice advice = new CompoundTriggerAdvice(compoundTrigger, override);
adapter.setSource(() -> {
overridePresent.add(TestUtils.getPropertyValue(compoundTrigger, "override"));
synchronized (overridePresent) {
overridePresent.add(TestUtils.getPropertyValue(compoundTrigger, "override"));
}
Message<Object> m = null;
if (latch.getCount() % 2 == 0) {
m = new GenericMessage<>("foo");
@@ -305,8 +307,10 @@ public class PollerAdviceTests {
adapter.start();
assertTrue(latch.await(10, TimeUnit.SECONDS));
adapter.stop();
while (overridePresent.size() > 5) {
overridePresent.removeLast();
synchronized (overridePresent) {
while (overridePresent.size() > 5) {
overridePresent.removeLast();
}
}
assertThat(overridePresent, contains(null, override, null, override, null));
verify(override, atLeast(2)).nextExecutionTime(any(TriggerContext.class));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 the original author or authors.
* Copyright 2016-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -58,6 +58,8 @@ import org.springframework.util.concurrent.SettableListenableFuture;
/**
* @author Gary Russell
* @author Artem Bilan
*
* @since 4.3
*
*/
@@ -86,7 +88,7 @@ public class AsyncHandlerTests {
@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
final SettableListenableFuture<String> future = new SettableListenableFuture<String>();
final SettableListenableFuture<String> future = new SettableListenableFuture<>();
AsyncHandlerTests.this.executor.execute(() -> {
try {
latch.await(10, TimeUnit.SECONDS);
@@ -131,7 +133,7 @@ public class AsyncHandlerTests {
@Test
public void testGoodResult() {
this.whichTest = 0;
this.handler.handleMessage(new GenericMessage<String>("foo"));
this.handler.handleMessage(new GenericMessage<>("foo"));
assertNull(this.output.receive(0));
this.latch.countDown();
Message<?> received = this.output.receive(10000);
@@ -158,7 +160,7 @@ public class AsyncHandlerTests {
}
@Test
public void testGoodResultWithNoReplyChannelHeaderNoOutput() throws Exception {
public void testGoodResultWithNoReplyChannelHeaderNoOutput() {
this.whichTest = 0;
this.handler.setOutputChannel(null);
QueueChannel errorChannel = new QueueChannel();
@@ -166,7 +168,7 @@ public class AsyncHandlerTests {
this.handler.handleMessage(message);
assertNull(this.output.receive(0));
this.latch.countDown();
Message<?> errorMessage = errorChannel.receive(1000);
Message<?> errorMessage = errorChannel.receive(10000);
assertNotNull(errorMessage);
assertThat(errorMessage.getPayload(), instanceOf(DestinationResolutionException.class));
assertEquals("no output-channel or replyChannel header available",