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:
committed by
Gary Russell
parent
e45bb36be2
commit
9d8e2b61f6
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
* Copyright 2014-2015 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.
|
||||
@@ -57,7 +57,7 @@ public final class ClientWebSocketContainer extends IntegrationWebSocketContaine
|
||||
|
||||
private volatile CountDownLatch connectionLatch;
|
||||
|
||||
private WebSocketSession clientSession;
|
||||
private volatile WebSocketSession clientSession;
|
||||
|
||||
private volatile Throwable openConnectionException;
|
||||
|
||||
@@ -106,7 +106,7 @@ public final class ClientWebSocketContainer extends IntegrationWebSocketContaine
|
||||
*/
|
||||
@Override
|
||||
public WebSocketSession getSession(String sessionId) {
|
||||
if (this.isRunning()) {
|
||||
if (isRunning()) {
|
||||
try {
|
||||
this.connectionLatch.await(this.connectionTimeout, TimeUnit.SECONDS);
|
||||
}
|
||||
@@ -146,9 +146,11 @@ public final class ClientWebSocketContainer extends IntegrationWebSocketContaine
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
this.connectionLatch = new CountDownLatch(1);
|
||||
this.connectionManager.start();
|
||||
public synchronized void start() {
|
||||
if (!isRunning()) {
|
||||
this.connectionLatch = new CountDownLatch(1);
|
||||
this.connectionManager.start();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
* Copyright 2014-2015 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.
|
||||
@@ -20,14 +20,11 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.catalina.Context;
|
||||
import org.apache.catalina.connector.Connector;
|
||||
import org.apache.catalina.startup.Tomcat;
|
||||
import org.apache.coyote.http11.Http11NioProtocol;
|
||||
import org.apache.tomcat.websocket.server.WsContextListener;
|
||||
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.util.SocketUtils;
|
||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||
import org.springframework.web.servlet.DispatcherServlet;
|
||||
|
||||
@@ -40,40 +37,29 @@ public class TomcatWebSocketTestServer implements InitializingBean, DisposableBe
|
||||
|
||||
private final Tomcat tomcatServer;
|
||||
|
||||
private final int port;
|
||||
|
||||
private final AnnotationConfigWebApplicationContext serverContext;
|
||||
|
||||
public TomcatWebSocketTestServer(Class<?>... serverConfigs) {
|
||||
this.port = SocketUtils.findAvailableTcpPort();
|
||||
Connector connector = new Connector(Http11NioProtocol.class.getName());
|
||||
connector.setPort(this.port);
|
||||
|
||||
File baseDir = createTempDir("tomcat");
|
||||
String baseDirPath = baseDir.getAbsolutePath();
|
||||
|
||||
this.tomcatServer = new Tomcat();
|
||||
this.tomcatServer.setBaseDir(baseDirPath);
|
||||
this.tomcatServer.setPort(this.port);
|
||||
this.tomcatServer.getService().addConnector(connector);
|
||||
this.tomcatServer.setConnector(connector);
|
||||
|
||||
this.tomcatServer.setPort(0);
|
||||
this.tomcatServer.setBaseDir(createTempDir());
|
||||
this.serverContext = new AnnotationConfigWebApplicationContext();
|
||||
this.serverContext.register(serverConfigs);
|
||||
|
||||
Context context = this.tomcatServer.addContext("", System.getProperty("java.io.tmpdir"));
|
||||
context.addApplicationListener(WsContextListener.class.getName());
|
||||
Tomcat.addServlet(context, "dispatcherServlet", new DispatcherServlet(this.serverContext)).setAsyncSupported(true);
|
||||
Tomcat.addServlet(context, "dispatcherServlet", new DispatcherServlet(this.serverContext))
|
||||
.setAsyncSupported(true);
|
||||
context.addServletMapping("/", "dispatcherServlet");
|
||||
}
|
||||
|
||||
private File createTempDir(String prefix) {
|
||||
private String createTempDir() {
|
||||
try {
|
||||
File tempFolder = File.createTempFile(prefix + ".", "." + this.port);
|
||||
File tempFolder = File.createTempFile("tomcat.", ".workDir");
|
||||
tempFolder.delete();
|
||||
tempFolder.mkdir();
|
||||
tempFolder.deleteOnExit();
|
||||
return tempFolder;
|
||||
return tempFolder.getAbsolutePath();
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new RuntimeException("Unable to create temp directory", ex);
|
||||
@@ -85,7 +71,7 @@ public class TomcatWebSocketTestServer implements InitializingBean, DisposableBe
|
||||
}
|
||||
|
||||
public String getWsBaseUrl() {
|
||||
return "ws://localhost:" + this.port;
|
||||
return "ws://localhost:" + this.tomcatServer.getConnector().getLocalPort();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user