GH-9430: Fix CachingClientCF for collaborating channel adapters (#9431)

Fixes: #9430

When `CachingClientConnectionFactory` is used in combination of
`Tcp.outboundAdapter()` & `Tcp.inboundAdapter()`, the connection is not released
back to the cache because `CachingClientConnectionFactory` does not store
created connections into its `connections` property.
So, when `TcpReceivingChannelAdapter` calls `this.clientConnectionFactory.closeConnection(connectionId);`
it returned immediately because there is nothing to remove from the `this.connections`

* Add `protected removeConnection()` in the `AbstractConnectionFactory`
and override it in the `CachingClientConnectionFactory` with delegation to the `this.targetConnectionFactory`
* Demonstrate the problem in the new `IpIntegrationTests.allRepliesAreReceivedViaLimitedCachingConnectionFactory()` test
and ensure that all 27 letters from English alphabet are sent to the server and received in uppercase
while size of the `CachingClientConnectionFactory` is only `10`

**Auto-cherry-pick to `6.3.x` & `6.2.x`**
This commit is contained in:
Artem Bilan
2024-08-29 20:39:09 -04:00
committed by GitHub
parent f10fbca38b
commit dc02dec4de
3 changed files with 101 additions and 10 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
@@ -977,7 +977,7 @@ public abstract class AbstractConnectionFactory extends IntegrationObjectSupport
this.connectionsMonitor.lock();
try {
boolean closed = false;
TcpConnectionSupport connection = this.connections.remove(connectionId);
TcpConnectionSupport connection = removeConnection(connectionId);
if (connection != null) {
try {
connection.close();
@@ -996,6 +996,11 @@ public abstract class AbstractConnectionFactory extends IntegrationObjectSupport
}
}
@Nullable
protected TcpConnectionSupport removeConnection(String connectionId) {
return this.connections.remove(connectionId);
}
@Override
public String toString() {
return super.toString()

View File

@@ -358,6 +358,11 @@ public class CachingClientConnectionFactory extends AbstractClientConnectionFact
this.targetConnectionFactory.enableManualListenerRegistration();
}
@Override
protected TcpConnectionSupport removeConnection(String connectionId) {
return this.targetConnectionFactory.removeConnection(connectionId.replaceFirst("Cached:", ""));
}
@Override
public void start() {
setActive(true);