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
@@ -18,6 +18,7 @@ package org.springframework.integration.stomp;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
|
||||
@@ -190,26 +191,27 @@ public abstract class AbstractStompSessionManager implements StompSessionManager
|
||||
}
|
||||
|
||||
private void scheduleReconnect(Throwable e) {
|
||||
if (this.reconnectFuture != null) {
|
||||
this.reconnectFuture.cancel(true);
|
||||
this.reconnectFuture = null;
|
||||
}
|
||||
this.connecting = this.connected = false;
|
||||
logger.error("STOMP connect error.", e);
|
||||
if (this.applicationEventPublisher != null) {
|
||||
this.applicationEventPublisher.publishEvent(
|
||||
new StompConnectionFailedEvent(this, e));
|
||||
}
|
||||
// cancel() after the publish in case we are on that thread; a send to a QueueChannel would fail.
|
||||
if (this.reconnectFuture != null) {
|
||||
this.reconnectFuture.cancel(true);
|
||||
this.reconnectFuture = null;
|
||||
}
|
||||
|
||||
this.reconnectFuture = this.stompClient.getTaskScheduler()
|
||||
.scheduleWithFixedDelay(new Runnable() {
|
||||
.schedule(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
connect();
|
||||
}
|
||||
|
||||
}, this.recoveryInterval);
|
||||
}, new Date(System.currentTimeMillis() + this.recoveryInterval));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -349,6 +351,7 @@ public abstract class AbstractStompSessionManager implements StompSessionManager
|
||||
|
||||
@Override
|
||||
public void handleTransportError(StompSession session, Throwable exception) {
|
||||
logger.error("STOMP transport error for session: [" + session + "]", exception);
|
||||
if (exception instanceof ConnectionLostException) {
|
||||
this.session = null;
|
||||
scheduleReconnect(exception);
|
||||
|
||||
@@ -39,7 +39,6 @@ import org.springframework.jmx.export.annotation.ManagedResource;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.MessageHandlingException;
|
||||
import org.springframework.messaging.simp.stomp.ConnectionLostException;
|
||||
import org.springframework.messaging.simp.stomp.StompCommand;
|
||||
import org.springframework.messaging.simp.stomp.StompFrameHandler;
|
||||
import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
|
||||
@@ -304,10 +303,7 @@ public class StompInboundChannelAdapter extends MessageProducerSupport implement
|
||||
|
||||
@Override
|
||||
public void handleTransportError(StompSession session, Throwable exception) {
|
||||
if (exception instanceof ConnectionLostException) {
|
||||
StompInboundChannelAdapter.this.stompSession = null;
|
||||
}
|
||||
logger.error("STOMP transport error for session: [" + session + "]", exception);
|
||||
StompInboundChannelAdapter.this.stompSession = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -261,12 +261,7 @@ public class StompMessageHandler extends AbstractMessageHandler implements Appli
|
||||
@Override
|
||||
public synchronized void handleTransportError(StompSession session, Throwable exception) {
|
||||
StompMessageHandler.this.transportError = exception;
|
||||
if (exception instanceof ConnectionLostException) {
|
||||
StompMessageHandler.this.stompSession = null;
|
||||
}
|
||||
else {
|
||||
logger.error("STOMP transport error for session: [" + session + "]", exception);
|
||||
}
|
||||
StompMessageHandler.this.stompSession = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ import org.springframework.integration.stomp.event.StompIntegrationEvent;
|
||||
import org.springframework.integration.stomp.event.StompReceiptEvent;
|
||||
import org.springframework.integration.stomp.event.StompSessionConnectedEvent;
|
||||
import org.springframework.integration.test.rule.Log4jLevelAdjuster;
|
||||
import org.springframework.integration.test.support.LogAdjustingTestSupport;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.integration.websocket.TomcatWebSocketTestServer;
|
||||
import org.springframework.messaging.Message;
|
||||
@@ -92,10 +93,7 @@ import org.springframework.web.socket.sockjs.client.WebSocketTransport;
|
||||
@ContextConfiguration(classes = StompInboundChannelAdapterWebSocketIntegrationTests.ContextConfiguration.class)
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@DirtiesContext
|
||||
public class StompInboundChannelAdapterWebSocketIntegrationTests {
|
||||
|
||||
@Rule
|
||||
public Log4jLevelAdjuster adjuster = new Log4jLevelAdjuster(Level.TRACE, "org.springframework");
|
||||
public class StompInboundChannelAdapterWebSocketIntegrationTests extends LogAdjustingTestSupport {
|
||||
|
||||
@Value("#{server.serverContext}")
|
||||
private ConfigurableApplicationContext serverContext;
|
||||
@@ -115,6 +113,10 @@ public class StompInboundChannelAdapterWebSocketIntegrationTests {
|
||||
@Autowired
|
||||
private StompInboundChannelAdapter stompInboundChannelAdapter;
|
||||
|
||||
public StompInboundChannelAdapterWebSocketIntegrationTests() {
|
||||
super("org.springframework", "org.springframework.integration.stomp");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWebSocketStompClient() throws Exception {
|
||||
Message<?> eventMessage = this.stompEvents.receive(10000);
|
||||
@@ -240,7 +242,7 @@ public class StompInboundChannelAdapterWebSocketIntegrationTests {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WebSocketStompClient stompClient(@Qualifier("taskScheduler") TaskScheduler taskScheduler) {
|
||||
public WebSocketStompClient stompClient(TaskScheduler taskScheduler) {
|
||||
WebSocketStompClient webSocketStompClient = new WebSocketStompClient(webSocketClient());
|
||||
webSocketStompClient.setMessageConverter(new MappingJackson2MessageConverter());
|
||||
webSocketStompClient.setTaskScheduler(taskScheduler);
|
||||
|
||||
@@ -55,6 +55,7 @@ import org.springframework.integration.stomp.event.StompExceptionEvent;
|
||||
import org.springframework.integration.stomp.event.StompIntegrationEvent;
|
||||
import org.springframework.integration.stomp.event.StompReceiptEvent;
|
||||
import org.springframework.integration.stomp.event.StompSessionConnectedEvent;
|
||||
import org.springframework.integration.test.support.LogAdjustingTestSupport;
|
||||
import org.springframework.integration.test.support.LongRunningIntegrationTest;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.integration.websocket.TomcatWebSocketTestServer;
|
||||
@@ -96,7 +97,7 @@ import org.springframework.web.socket.sockjs.client.WebSocketTransport;
|
||||
@ContextConfiguration(classes = StompMessageHandlerWebSocketIntegrationTests.ContextConfiguration.class)
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@DirtiesContext
|
||||
public class StompMessageHandlerWebSocketIntegrationTests {
|
||||
public class StompMessageHandlerWebSocketIntegrationTests extends LogAdjustingTestSupport {
|
||||
|
||||
@ClassRule
|
||||
public static LongRunningIntegrationTest longTests = new LongRunningIntegrationTest();
|
||||
@@ -112,6 +113,10 @@ public class StompMessageHandlerWebSocketIntegrationTests {
|
||||
@Qualifier("stompEvents")
|
||||
private PollableChannel stompEvents;
|
||||
|
||||
public StompMessageHandlerWebSocketIntegrationTests() {
|
||||
super("org.springframework", "org.springframework.integration.stomp");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStompMessageHandler() throws InterruptedException {
|
||||
StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SEND);
|
||||
|
||||
Reference in New Issue
Block a user