Fixes for Sporadic Test Failures

* `ClientWebSocketContainer`: add some synchronization to avoid race conditions: https://build.spring.io/browse/INT-B41-492
* `TomcatWebSocketTestServer`: convert to `0` port to rely on the OS resolution for `localPort`
* Add `LogAdjustingTestSupport` for STOMP test
* `SftpServerTests`: use `0` port to rely on the OS resolution for `localPort`
* `ImapMailReceiver`, `OutboundGatewayFunctionTests` (JMS), `CachingClientConnectionFactoryTests`,
`AsyncGatewayTests`, `AsyncMessagingTemplateTests`, `GatewayParserTests`, `PriorityChannelTests`, `AggregatorIntegrationTests`: increase timeout
* `EnableIntegrationTests`: use `LogAdjustingTestSupport`
* `FileOutboundChannelAdapterParserTests`: rework `Thread.sleep()` with `CountDownLatch`
* `ConnectionToConnectionTests`: increase timeout and count iteration. Previously with `1sec` we may lose some events. And we can't just rely on the `10sec`,
because the last iteration will be so long
* `TcpOutboundGatewayTests`: `500ms` is so big timeout to wait for the `Exception` that in the high load environment we can yield to other Thread so long.
Like in our case to `server` Thread to send the reply for us. Therefore decrease the Exception timeout to the `50ms` and increase server delay to `2sec`
* `StompInboundChannelAdapterWebSocketIntegrationTests`: remove `@Qualifier("taskScheduler")` as a potential candidate to test against latest SF changes.
We're fine with `SF-4.2.2` and it is just a test-case. So, I don't see reason to wait for their fix here.

STOMP: `session = null` in adapters for any transportError

Polishing
This commit is contained in:
Artem Bilan
2015-11-13 22:39:00 -05:00
committed by Gary Russell
parent e45bb36be2
commit 9d8e2b61f6
23 changed files with 150 additions and 129 deletions

View File

@@ -158,7 +158,7 @@ public class AggregatorIntegrationTests {
Thread.sleep(100);
}
assertTrue("Group did not complete", n < 100);
assertNotNull(this.output.receive(1000));
assertNotNull(this.output.receive(10000));
assertNull(this.discard.receive(0));
}
}
@@ -183,7 +183,7 @@ public class AggregatorIntegrationTests {
}
}
assertTrue("Group did not complete", n < 100);
Message<?> receive = this.output.receive(1000);
Message<?> receive = this.output.receive(10000);
assertNotNull(receive);
assertEquals(Collections.singletonList(1), receive.getPayload());
assertNull(this.discard.receive(0));
@@ -199,7 +199,7 @@ public class AggregatorIntegrationTests {
// As far as 'group.size() >= 2' it will be scheduled to 'forceComplete'
this.groupTimeoutExpressionAggregatorInput.send(new GenericMessage<Integer>(2, stubHeaders(2, 6, 1)));
assertNull(this.output.receive(0));
Message<?> receive = this.output.receive(500);
Message<?> receive = this.output.receive(10000);
assertNotNull(receive);
assertEquals(2, ((Collection<?>) receive.getPayload()).size());
assertNull(this.discard.receive(0));
@@ -215,14 +215,14 @@ public class AggregatorIntegrationTests {
this.groupTimeoutExpressionAggregatorInput.send(new GenericMessage<Integer>(5, stubHeaders(5, 6, 1)));
assertNull(this.output.receive(0));
receive = this.output.receive(500);
receive = this.output.receive(10000);
assertNotNull(receive);
assertEquals(3, ((Collection<?>) receive.getPayload()).size());
assertNull(this.discard.receive(0));
// The last message in the sequence - normal release by provided 'ReleaseStrategy'
this.groupTimeoutExpressionAggregatorInput.send(new GenericMessage<Integer>(6, stubHeaders(6, 6, 1)));
receive = this.output.receive(500);
receive = this.output.receive(10000);
assertNotNull(receive);
assertEquals(1, ((Collection<?>) receive.getPayload()).size());
assertNull(this.discard.receive(0));

View File

@@ -25,6 +25,7 @@ import static org.junit.Assert.assertTrue;
import java.util.Comparator;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -236,22 +237,23 @@ public class PriorityChannelTests {
public void testTimeoutElapses() throws InterruptedException {
final PriorityChannel channel = new PriorityChannel(1);
final AtomicBoolean sentSecondMessage = new AtomicBoolean(false);
final CountDownLatch latch = new CountDownLatch(1);
Executor executor = Executors.newSingleThreadScheduledExecutor();
ExecutorService executor = Executors.newSingleThreadScheduledExecutor();
channel.send(new GenericMessage<String>("test-1"));
executor.execute(new Runnable() {
@Override
public void run() {
sentSecondMessage.set(channel.send(new GenericMessage<String>("test-2"), 10));
latch.countDown();
}
});
assertFalse(sentSecondMessage.get());
Thread.sleep(1000);
Message<?> message1 = channel.receive();
executor.shutdown();
assertTrue(executor.awaitTermination(10, TimeUnit.SECONDS));
Message<?> message1 = channel.receive(10000);
assertNotNull(message1);
assertEquals("test-1", message1.getPayload());
latch.await(10000, TimeUnit.MILLISECONDS);
assertFalse(sentSecondMessage.get());
assertNull(channel.receive(0));
}
@@ -286,22 +288,21 @@ public class PriorityChannelTests {
public void testIndefiniteTimeout() throws InterruptedException {
final PriorityChannel channel = new PriorityChannel(1);
final AtomicBoolean sentSecondMessage = new AtomicBoolean(false);
final CountDownLatch latch = new CountDownLatch(1);
Executor executor = Executors.newSingleThreadScheduledExecutor();
ExecutorService executor = Executors.newSingleThreadScheduledExecutor();
channel.send(new GenericMessage<String>("test-1"));
executor.execute(new Runnable() {
@Override
public void run() {
sentSecondMessage.set(channel.send(new GenericMessage<String>("test-2"), -1));
latch.countDown();
}
});
assertFalse(sentSecondMessage.get());
Thread.sleep(500);
Message<?> message1 = channel.receive();
Message<?> message1 = channel.receive(1000);
assertNotNull(message1);
assertEquals("test-1", message1.getPayload());
latch.await(1000, TimeUnit.MILLISECONDS);
executor.shutdown();
assertTrue(executor.awaitTermination(10, TimeUnit.SECONDS));
assertTrue(sentSecondMessage.get());
Message<?> message2 = channel.receive();
assertNotNull(message2);
@@ -322,9 +323,11 @@ public class PriorityChannelTests {
String s2 = (String) message2.getPayload();
return s1.compareTo(s2);
}
}
public static class FooHeaderComparator implements Comparator<Message<?>> {
@Override
public int compare(Message<?> message1, Message<?> message2) {
Integer foo1 = (Integer) message1.getHeaders().get("foo");
@@ -333,6 +336,7 @@ public class PriorityChannelTests {
foo2 = foo2 != null ? foo2 : 0;
return foo2.compareTo(foo1);
}
}
}

View File

@@ -36,6 +36,7 @@ import java.util.concurrent.atomic.AtomicReference;
import org.apache.commons.logging.Log;
import org.junit.Test;
import org.junit.runner.RunWith;
import reactor.rx.Promise;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.BeanNameAware;
@@ -64,8 +65,6 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import reactor.rx.Promise;
/**
* @author Mark Fisher
* @author Artem Bilan
@@ -196,7 +195,7 @@ public class GatewayParserTests {
this.startResponder(requestChannel, replyChannel);
TestService service = context.getBean("asyncCompletable", TestService.class);
CompletableFuture<String> result = service.completable("foo").thenApply(String::toUpperCase);
String reply = result.get(1, TimeUnit.SECONDS);
String reply = result.get(10, TimeUnit.SECONDS);
assertEquals("FOO", reply);
assertThat(thread.get().getName(), startsWith("testExec-"));
assertNotNull(TestUtils.getPropertyValue(context.getBean("&asyncCompletable"), "asyncExecutor"));

View File

@@ -262,6 +262,10 @@ public class EnableIntegrationTests extends LogAdjustingTestSupport {
@Qualifier("enableIntegrationTests.ContextConfiguration2.sendAsyncHandler.serviceActivator")
private AbstractEndpoint sendAsyncHandler;
public EnableIntegrationTests() {
super("org.springframework.integration", "org.springframework");
}
@Test
public void testAnnotatedServiceActivator() {
assertEquals(10L, TestUtils.getPropertyValue(this.serviceActivatorEndpoint, "maxMessagesPerPoll"));

View File

@@ -58,7 +58,7 @@ public class AsyncMessagingTemplateTests {
template.setDefaultDestination(channel);
Message<?> message = MessageBuilder.withPayload("test").build();
Future<?> future = template.asyncSend(message);
assertNull(future.get(1000, TimeUnit.MILLISECONDS));
assertNull(future.get(10000, TimeUnit.MILLISECONDS));
Message<?> result = channel.receive(0);
assertEquals(message, result);
}
@@ -69,7 +69,7 @@ public class AsyncMessagingTemplateTests {
AsyncMessagingTemplate template = new AsyncMessagingTemplate();
Message<?> message = MessageBuilder.withPayload("test").build();
Future<?> future = template.asyncSend(channel, message);
assertNull(future.get(1000, TimeUnit.MILLISECONDS));
assertNull(future.get(10000, TimeUnit.MILLISECONDS));
Message<?> result = channel.receive(0);
assertEquals(message, result);
}
@@ -84,7 +84,7 @@ public class AsyncMessagingTemplateTests {
template.setBeanFactory(context);
Message<?> message = MessageBuilder.withPayload("test").build();
Future<?> future = template.asyncSend("testChannel", message);
assertNull(future.get(1000, TimeUnit.MILLISECONDS));
assertNull(future.get(10000, TimeUnit.MILLISECONDS));
Message<?> result = channel.receive(0);
assertEquals(message, result);
}
@@ -104,7 +104,7 @@ public class AsyncMessagingTemplateTests {
AsyncMessagingTemplate template = new AsyncMessagingTemplate();
template.setDefaultDestination(channel);
Future<?> future = template.asyncConvertAndSend("test");
assertNull(future.get(1000, TimeUnit.MILLISECONDS));
assertNull(future.get(10000, TimeUnit.MILLISECONDS));
Message<?> result = channel.receive(0);
assertEquals("test", result.getPayload());
}
@@ -114,7 +114,7 @@ public class AsyncMessagingTemplateTests {
QueueChannel channel = new QueueChannel();
AsyncMessagingTemplate template = new AsyncMessagingTemplate();
Future<?> future = template.asyncConvertAndSend(channel, "test");
assertNull(future.get(1000, TimeUnit.MILLISECONDS));
assertNull(future.get(10000, TimeUnit.MILLISECONDS));
Message<?> result = channel.receive(0);
assertEquals("test", result.getPayload());
}
@@ -128,7 +128,7 @@ public class AsyncMessagingTemplateTests {
AsyncMessagingTemplate template = new AsyncMessagingTemplate();
template.setBeanFactory(context);
Future<?> future = template.asyncConvertAndSend("testChannel", "test");
assertNull(future.get(1000, TimeUnit.MILLISECONDS));
assertNull(future.get(10000, TimeUnit.MILLISECONDS));
Message<?> result = channel.receive(0);
assertEquals("test", result.getPayload());
}
@@ -150,7 +150,7 @@ public class AsyncMessagingTemplateTests {
Future<Message<?>> result = template.asyncReceive();
sendMessageAfterDelay(channel, new GenericMessage<String>("test"), 200);
long start = System.currentTimeMillis();
assertNotNull(result.get(10000, TimeUnit.MILLISECONDS));
assertNotNull(result.get(100000, TimeUnit.MILLISECONDS));
long elapsed = System.currentTimeMillis() - start;
assertEquals("test", result.get().getPayload());
assertTrue(elapsed >= 200-safety);
@@ -163,7 +163,7 @@ public class AsyncMessagingTemplateTests {
Future<Message<?>> result = template.asyncReceive(channel);
sendMessageAfterDelay(channel, new GenericMessage<String>("test"), 200);
long start = System.currentTimeMillis();
assertNotNull(result.get(1000, TimeUnit.MILLISECONDS));
assertNotNull(result.get(10000, TimeUnit.MILLISECONDS));
long elapsed = System.currentTimeMillis() - start;
assertEquals("test", result.get().getPayload());
assertTrue(elapsed >= 200-safety);
@@ -348,7 +348,7 @@ public class AsyncMessagingTemplateTests {
AsyncMessagingTemplate template = new AsyncMessagingTemplate();
template.setDefaultDestination(channel);
long start = System.currentTimeMillis();
Future<String> result = template.asyncConvertSendAndReceive(new Integer(123), new TestMessagePostProcessor());
Future<String> result = template.asyncConvertSendAndReceive(123, new TestMessagePostProcessor());
assertNotNull(result.get());
long elapsed = System.currentTimeMillis() - start;
@@ -435,8 +435,10 @@ public class AsyncMessagingTemplateTests {
}
private static void sendMessageAfterDelay(final MessageChannel channel, final GenericMessage<String> message, final int delay) {
private static void sendMessageAfterDelay(final MessageChannel channel, final GenericMessage<String> message,
final int delay) {
Executors.newSingleThreadExecutor().execute(new Runnable() {
public void run() {
try {
Thread.sleep(delay);
@@ -447,6 +449,7 @@ public class AsyncMessagingTemplateTests {
}
channel.send(message);
}
});
}
@@ -480,6 +483,7 @@ public class AsyncMessagingTemplateTests {
String header = requestMessage.getHeaders().get("foo", String.class);
return (header != null) ? result + "-" + header : result;
}
}
@@ -488,6 +492,7 @@ public class AsyncMessagingTemplateTests {
public Message<?> postProcessMessage(Message<?> message) {
return MessageBuilder.fromMessage(message).setHeader("foo", "bar").build();
}
}
}

View File

@@ -33,6 +33,9 @@ import java.util.concurrent.atomic.AtomicReference;
import org.hamcrest.Matchers;
import org.junit.Test;
import reactor.Environment;
import reactor.fn.Consumer;
import reactor.rx.Promise;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.integration.annotation.Gateway;
@@ -47,10 +50,6 @@ import org.springframework.messaging.support.MessageBuilder;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.util.concurrent.ListenableFutureCallback;
import reactor.Environment;
import reactor.rx.Promise;
import reactor.fn.Consumer;
/**
* @author Mark Fisher
* @author Oleg Zhurakousky
@@ -82,7 +81,7 @@ public class AsyncGatewayTests {
TestEchoService service = (TestEchoService) proxyFactory.getObject();
Future<Message<?>> f = service.returnMessage("foo");
long start = System.currentTimeMillis();
Object result = f.get(1000, TimeUnit.MILLISECONDS);
Object result = f.get(10000, TimeUnit.MILLISECONDS);
long elapsed = System.currentTimeMillis() - start;
assertTrue(elapsed >= 200);
assertNotNull(result);
@@ -109,7 +108,7 @@ public class AsyncGatewayTests {
TestEchoService service = (TestEchoService) proxyFactory.getObject();
Future<Message<?>> f = service.returnMessage("foo");
try {
f.get(1000, TimeUnit.MILLISECONDS);
f.get(10000, TimeUnit.MILLISECONDS);
fail("Expected Exception");
}
catch (ExecutionException e) {
@@ -167,7 +166,7 @@ public class AsyncGatewayTests {
proxyFactory.afterPropertiesSet();
TestEchoService service = (TestEchoService) proxyFactory.getObject();
CustomFuture f = service.returnCustomFuture("foo");
String result = f.get(1000, TimeUnit.MILLISECONDS);
String result = f.get(10000, TimeUnit.MILLISECONDS);
assertEquals("foobar", result);
assertEquals(Thread.currentThread(), f.thread);
}
@@ -188,7 +187,7 @@ public class AsyncGatewayTests {
proxyFactory.afterPropertiesSet();
TestEchoService service = (TestEchoService) proxyFactory.getObject();
CustomFuture f = (CustomFuture) service.returnCustomFutureWithTypeFuture("foo");
String result = f.get(1000, TimeUnit.MILLISECONDS);
String result = f.get(10000, TimeUnit.MILLISECONDS);
assertEquals("foobar", result);
assertEquals(Thread.currentThread(), f.thread);
}
@@ -219,7 +218,7 @@ public class AsyncGatewayTests {
TestEchoService service = (TestEchoService) proxyFactory.getObject();
Future<String> f = service.returnString("foo");
long start = System.currentTimeMillis();
Object result = f.get(1000, TimeUnit.MILLISECONDS);
Object result = f.get(10000, TimeUnit.MILLISECONDS);
long elapsed = System.currentTimeMillis() - start;
assertTrue(elapsed >= 200 - safety);
assertNotNull(result);
@@ -239,7 +238,7 @@ public class AsyncGatewayTests {
TestEchoService service = (TestEchoService) proxyFactory.getObject();
Future<?> f = service.returnSomething("foo");
long start = System.currentTimeMillis();
Object result = f.get(1000, TimeUnit.MILLISECONDS);
Object result = f.get(10000, TimeUnit.MILLISECONDS);
long elapsed = System.currentTimeMillis() - start;
assertTrue(elapsed >= 200 - safety);
assertTrue(result instanceof String);
@@ -260,7 +259,7 @@ public class AsyncGatewayTests {
proxyFactory.afterPropertiesSet();
TestEchoService service = (TestEchoService) proxyFactory.getObject();
Promise<Message<?>> promise = service.returnMessagePromise("foo");
Object result = promise.await(1, TimeUnit.SECONDS);
Object result = promise.await(10, TimeUnit.SECONDS);
assertEquals("foobar", ((Message<?>) result).getPayload());
}
@@ -277,7 +276,7 @@ public class AsyncGatewayTests {
proxyFactory.afterPropertiesSet();
TestEchoService service = (TestEchoService) proxyFactory.getObject();
Promise<String> promise = service.returnStringPromise("foo");
Object result = promise.await(1, TimeUnit.SECONDS);
Object result = promise.await(10, TimeUnit.SECONDS);
assertEquals("foobar", result);
}
@@ -294,7 +293,7 @@ public class AsyncGatewayTests {
proxyFactory.afterPropertiesSet();
TestEchoService service = (TestEchoService) proxyFactory.getObject();
Promise<?> promise = service.returnSomethingPromise("foo");
Object result = promise.await(1, TimeUnit.SECONDS);
Object result = promise.await(10, TimeUnit.SECONDS);
assertNotNull(result);
assertEquals("foobar", result);
}
@@ -324,7 +323,7 @@ public class AsyncGatewayTests {
}
});
latch.await(1, TimeUnit.SECONDS);
latch.await(10, TimeUnit.SECONDS);
assertEquals("foobar", result.get());
}