Fix timing issue in test for STOMP Server
https://build.spring.io/browse/INT-MASTER-733 The Netty tries to load `netty-transport-native-epoll` too long, more then 10 seconds we expect in the `AbstractStompSessionManager`, therefore we end up having `StompConnectionFailedEvent` as a first event in the queue channel for STOMP events. * Increase connection wait timeout to `30 secs`, like it is in many other places in Spring * Provide some Java 8 style refactoring for the `AbstractStompSessionManager` * Fix `StompServerIntegrationTests` to poll events from queue until `StompSessionConnectedEvent` any way * Upgrade to Gradle 4.0 and `spring-io-plugin-0.0.8` * Bump `org.sonarqube` version to `2.5` - `2.1` isn't compatible with Gradle 4.0
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2016 the original author or authors.
|
||||
* Copyright 2015-2017 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.
|
||||
@@ -198,39 +198,35 @@ public abstract class AbstractStompSessionManager implements StompSessionManager
|
||||
}
|
||||
return;
|
||||
}
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
this.stompSessionListenableFuture.addCallback(new ListenableFutureCallback<StompSession>() {
|
||||
final CountDownLatch connectLatch = new CountDownLatch(1);
|
||||
this.stompSessionListenableFuture.addCallback(
|
||||
stompSession -> {
|
||||
if (AbstractStompSessionManager.this.logger.isDebugEnabled()) {
|
||||
AbstractStompSessionManager.this.logger.debug("onSuccess");
|
||||
}
|
||||
AbstractStompSessionManager.this.connected = true;
|
||||
AbstractStompSessionManager.this.connecting = false;
|
||||
stompSession.setAutoReceipt(isAutoReceiptEnabled());
|
||||
if (AbstractStompSessionManager.this.applicationEventPublisher != null) {
|
||||
AbstractStompSessionManager.this.applicationEventPublisher.publishEvent(
|
||||
new StompSessionConnectedEvent(this));
|
||||
}
|
||||
AbstractStompSessionManager.this.reconnectFuture = null;
|
||||
connectLatch.countDown();
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable e) {
|
||||
if (AbstractStompSessionManager.this.logger.isDebugEnabled()) {
|
||||
AbstractStompSessionManager.this.logger.debug("onFailure", e);
|
||||
}
|
||||
latch.countDown();
|
||||
if (epoch == AbstractStompSessionManager.this.epoch.get()) {
|
||||
scheduleReconnect(e);
|
||||
}
|
||||
}
|
||||
},
|
||||
e -> {
|
||||
if (AbstractStompSessionManager.this.logger.isDebugEnabled()) {
|
||||
AbstractStompSessionManager.this.logger.debug("onFailure", e);
|
||||
}
|
||||
connectLatch.countDown();
|
||||
if (epoch == AbstractStompSessionManager.this.epoch.get()) {
|
||||
scheduleReconnect(e);
|
||||
}
|
||||
});
|
||||
|
||||
@Override
|
||||
public void onSuccess(StompSession stompSession) {
|
||||
if (AbstractStompSessionManager.this.logger.isDebugEnabled()) {
|
||||
AbstractStompSessionManager.this.logger.debug("onSuccess");
|
||||
}
|
||||
AbstractStompSessionManager.this.connected = true;
|
||||
AbstractStompSessionManager.this.connecting = false;
|
||||
stompSession.setAutoReceipt(isAutoReceiptEnabled());
|
||||
if (AbstractStompSessionManager.this.applicationEventPublisher != null) {
|
||||
AbstractStompSessionManager.this.applicationEventPublisher.publishEvent(
|
||||
new StompSessionConnectedEvent(this));
|
||||
}
|
||||
AbstractStompSessionManager.this.reconnectFuture = null;
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
});
|
||||
try {
|
||||
if (!latch.await(10, TimeUnit.SECONDS)) {
|
||||
if (!connectLatch.await(30, TimeUnit.SECONDS)) {
|
||||
this.logger.error("No response to connection attempt");
|
||||
if (epoch == this.epoch.get()) {
|
||||
scheduleReconnect(null);
|
||||
@@ -261,7 +257,7 @@ public abstract class AbstractStompSessionManager implements StompSessionManager
|
||||
|
||||
if (this.stompClient.getTaskScheduler() != null) {
|
||||
this.reconnectFuture = this.stompClient.getTaskScheduler()
|
||||
.schedule((Runnable) () -> connect(), new Date(System.currentTimeMillis() + this.recoveryInterval));
|
||||
.schedule(this::connect, new Date(System.currentTimeMillis() + this.recoveryInterval));
|
||||
}
|
||||
else {
|
||||
this.logger.info("For automatic reconnection the 'stompClient' should be configured with a TaskScheduler.");
|
||||
|
||||
@@ -118,9 +118,13 @@ public class StompServerIntegrationTests extends LogAdjustingTestSupport {
|
||||
MessageChannel stompOutputChannel1 = context1.getBean("stompOutputChannel", MessageChannel.class);
|
||||
MessageChannel stompOutputChannel2 = context2.getBean("stompOutputChannel", MessageChannel.class);
|
||||
|
||||
Message<?> eventMessage = stompEvents1.receive(10000);
|
||||
Message<?> eventMessage;
|
||||
do {
|
||||
eventMessage = stompEvents1.receive(10000);
|
||||
}
|
||||
while (eventMessage != null && !(eventMessage.getPayload() instanceof StompSessionConnectedEvent));
|
||||
|
||||
assertNotNull(eventMessage);
|
||||
assertThat(eventMessage.getPayload(), instanceOf(StompSessionConnectedEvent.class));
|
||||
|
||||
eventMessage = stompEvents1.receive(10000);
|
||||
assertNotNull(eventMessage);
|
||||
|
||||
Reference in New Issue
Block a user