GH-3509: Fix regression in TcpNetServerConnectionFactory

Related to https://github.com/spring-projects/spring-integration/issues/3509

* Fix intercepted connection cleanup tests
* Add missing logic to call `setSenders()` on wrapped connection

**Cherry-pick to `5.4.x`**
This commit is contained in:
Mário Dias
2021-05-26 16:28:10 +01:00
committed by Artem Bilan
parent 9bab07d21d
commit ec8a747261
2 changed files with 8 additions and 4 deletions

View File

@@ -35,6 +35,7 @@ import org.springframework.util.Assert;
*
* @author Gary Russell
* @author Artem Bilan
* @author Mário Dias
*
* @since 2.0
*
@@ -180,7 +181,11 @@ public class TcpNetServerConnectionFactory extends AbstractServerConnectionFacto
setSocketAttributes(socket);
TcpConnectionSupport connection = this.tcpNetConnectionSupport.createNewConnection(socket, true,
isLookupHost(), getApplicationEventPublisher(), getComponentName());
connection = wrapConnection(connection);
TcpConnectionSupport wrapped = wrapConnection(connection);
if (!wrapped.equals(connection)) {
connection.setSenders(getSenders());
connection = wrapped;
}
initializeConnection(connection, socket);
getTaskExecutor().execute(connection);
harvestClosedConnections();

View File

@@ -1199,7 +1199,6 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
}
}
@SuppressWarnings("unchecked")
@Test
public void testInterceptedConnection() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
@@ -1229,7 +1228,7 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
socket.close();
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(connection.get()).isInstanceOf(HelloWorldInterceptor.class);
await().untilAsserted(() -> handler.getConnections().isEmpty());
await().untilAsserted(() -> assertThat(handler.getConnections()).isEmpty());
scf.stop();
}
@@ -1258,7 +1257,7 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
Socket socket = SocketFactory.getDefault().createSocket("localhost", port);
socket.close();
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
await().untilAsserted(() -> handler.getConnections().isEmpty());
await().untilAsserted(() -> assertThat(handler.getConnections()).isEmpty());
scf.stop();
}