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)); Trigger override = spy(new PeriodicTrigger(5));
final CompoundTriggerAdvice advice = new CompoundTriggerAdvice(compoundTrigger, override); final CompoundTriggerAdvice advice = new CompoundTriggerAdvice(compoundTrigger, override);
adapter.setSource(() -> { adapter.setSource(() -> {
overridePresent.add(TestUtils.getPropertyValue(compoundTrigger, "override")); synchronized (overridePresent) {
overridePresent.add(TestUtils.getPropertyValue(compoundTrigger, "override"));
}
Message<Object> m = null; Message<Object> m = null;
if (latch.getCount() % 2 == 0) { if (latch.getCount() % 2 == 0) {
m = new GenericMessage<>("foo"); m = new GenericMessage<>("foo");
@@ -305,8 +307,10 @@ public class PollerAdviceTests {
adapter.start(); adapter.start();
assertTrue(latch.await(10, TimeUnit.SECONDS)); assertTrue(latch.await(10, TimeUnit.SECONDS));
adapter.stop(); adapter.stop();
while (overridePresent.size() > 5) { synchronized (overridePresent) {
overridePresent.removeLast(); while (overridePresent.size() > 5) {
overridePresent.removeLast();
}
} }
assertThat(overridePresent, contains(null, override, null, override, null)); assertThat(overridePresent, contains(null, override, null, override, null));
verify(override, atLeast(2)).nextExecutionTime(any(TriggerContext.class)); 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 Gary Russell
* @author Artem Bilan
*
* @since 4.3 * @since 4.3
* *
*/ */
@@ -86,7 +88,7 @@ public class AsyncHandlerTests {
@Override @Override
protected Object handleRequestMessage(Message<?> requestMessage) { protected Object handleRequestMessage(Message<?> requestMessage) {
final SettableListenableFuture<String> future = new SettableListenableFuture<String>(); final SettableListenableFuture<String> future = new SettableListenableFuture<>();
AsyncHandlerTests.this.executor.execute(() -> { AsyncHandlerTests.this.executor.execute(() -> {
try { try {
latch.await(10, TimeUnit.SECONDS); latch.await(10, TimeUnit.SECONDS);
@@ -131,7 +133,7 @@ public class AsyncHandlerTests {
@Test @Test
public void testGoodResult() { public void testGoodResult() {
this.whichTest = 0; this.whichTest = 0;
this.handler.handleMessage(new GenericMessage<String>("foo")); this.handler.handleMessage(new GenericMessage<>("foo"));
assertNull(this.output.receive(0)); assertNull(this.output.receive(0));
this.latch.countDown(); this.latch.countDown();
Message<?> received = this.output.receive(10000); Message<?> received = this.output.receive(10000);
@@ -158,7 +160,7 @@ public class AsyncHandlerTests {
} }
@Test @Test
public void testGoodResultWithNoReplyChannelHeaderNoOutput() throws Exception { public void testGoodResultWithNoReplyChannelHeaderNoOutput() {
this.whichTest = 0; this.whichTest = 0;
this.handler.setOutputChannel(null); this.handler.setOutputChannel(null);
QueueChannel errorChannel = new QueueChannel(); QueueChannel errorChannel = new QueueChannel();
@@ -166,7 +168,7 @@ public class AsyncHandlerTests {
this.handler.handleMessage(message); this.handler.handleMessage(message);
assertNull(this.output.receive(0)); assertNull(this.output.receive(0));
this.latch.countDown(); this.latch.countDown();
Message<?> errorMessage = errorChannel.receive(1000); Message<?> errorMessage = errorChannel.receive(10000);
assertNotNull(errorMessage); assertNotNull(errorMessage);
assertThat(errorMessage.getPayload(), instanceOf(DestinationResolutionException.class)); assertThat(errorMessage.getPayload(), instanceOf(DestinationResolutionException.class));
assertEquals("no output-channel or replyChannel header available", assertEquals("no output-channel or replyChannel header available",

View File

@@ -20,7 +20,7 @@
<bean id="testTrigger" class="org.springframework.integration.test.util.OnlyOnceTrigger"/> <bean id="testTrigger" class="org.springframework.integration.test.util.OnlyOnceTrigger"/>
<int:bridge input-channel="input" output-channel="next"> <int:bridge input-channel="input" output-channel="next">
<int:poller trigger="testTrigger" receive-timeout="10000" /> <int:poller trigger="testTrigger" receive-timeout="100000" />
</int:bridge> </int:bridge>
<int:service-activator input-channel="next"> <int:service-activator input-channel="next">
@@ -29,7 +29,7 @@
<int:inbound-channel-adapter channel="pubsub"> <int:inbound-channel-adapter channel="pubsub">
<bean class="org.springframework.integration.monitor.MonitorTests$TestSource" /> <bean class="org.springframework.integration.monitor.MonitorTests$TestSource" />
<int:poller fixed-delay="500" /> <int:poller fixed-delay="50" />
</int:inbound-channel-adapter> </int:inbound-channel-adapter>
<int:publish-subscribe-channel id="pubsub" /> <int:publish-subscribe-channel id="pubsub" />

View File

@@ -98,7 +98,7 @@ public class MonitorTests {
new DirectFieldAccessor(this.next).setPropertyValue("channelMetrics", channelMetrics); new DirectFieldAccessor(this.next).setPropertyValue("channelMetrics", channelMetrics);
MessagingTemplate messagingTemplate = new MessagingTemplate(this.input); MessagingTemplate messagingTemplate = new MessagingTemplate(this.input);
messagingTemplate.setReceiveTimeout(10000); messagingTemplate.setReceiveTimeout(100000);
Integer active = messagingTemplate.convertSendAndReceive("foo", Integer.class); Integer active = messagingTemplate.convertSendAndReceive("foo", Integer.class);
assertEquals(1, active.intValue()); assertEquals(1, active.intValue());
assertTrue(afterSendLatch.await(10, TimeUnit.SECONDS)); assertTrue(afterSendLatch.await(10, TimeUnit.SECONDS));
@@ -111,7 +111,7 @@ public class MonitorTests {
assertEquals(1, this.next.getSendCount()); assertEquals(1, this.next.getSendCount());
assertThat(this.next.getSendDuration().getMax(), greaterThan(99.0)); assertThat(this.next.getSendDuration().getMax(), greaterThan(99.0));
assertThat(this.next.getSendDuration().getMax(), lessThan(10000.0)); assertThat(this.next.getSendDuration().getMax(), lessThan(10000.0));
Message<?> fromInbound = this.output.receive(10000); Message<?> fromInbound = this.output.receive(100000);
assertNotNull(fromInbound); assertNotNull(fromInbound);
assertEquals(0, fromInbound.getPayload()); assertEquals(0, fromInbound.getPayload());
fromInbound = this.output.receive(10000); fromInbound = this.output.receive(10000);