Addresses a shortcoming of the Universal Connection Pool pool creation logic in certain test scenarios #8642
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is quite specialized.
This PR addresses a shortcoming in the Universal Connection Pool API when named connection pools are involved.
In the UCP API, when you call
poolDataSource.getConnection()
, a backingUniversalConnectionPool
is created just-in-time, configured indirectly by a subset of configuration present on thePoolDataSource
object. One part of that configuration is a Java Beans property calledconnectionPoolName
.Apparently
UniversalConnectionPool
instances are stored by name in aUniversalConnectionPoolManager
singleton.If you do not call
setConnectionPoolName(String)
on aPoolDataSource
, a (hopefully guaranteed to be truly?) random name for the connection pool is generated internally by UCP, and yourPoolDataSource
'ssetConnectionPoolName(String)
method is called with the new random name (none of this is documented, but unit tests show it to be true). In versions of Helidon prior to 4.0.6 this could result, in unit test scenarios, in dozens if not hundreds ofUniversalConnectionPool
instances all backing what is for all intents and purposes the same data source.Helidon 4.0.6 tried to help this situation by checking to see if the
connectionPoolName
property was not set in configuration. If it was not, then the name defaulted to the data source name (so if you had a data source namedfred
, its backing connection pool would also be namedfred
, and you'd see that information in UCP logs and so on).The problem is that it turns out there is no way to associate a
PoolDataSource
with a givenconnectionPoolName
with an already-existingUniversalConnectionPool
instance that has the same name (!). That is, whenpoolDataSource.getConnection()
is called, a blind attempt at creating the backing connection pool is attempted (and fails), even if such a pool already exists, rather than an association operation. This scenario can crop up in certain user unit tests, apparently.(It is a corollary of this that a user using only the
PoolDataSource
API, as instructed by the UCP documentation, has no way of knowing in advance whether the name she has selected for theconnectionPoolName
property is going to result in aSQLException
or not.)Prior to this change, the user has a couple of choices:
connectionPoolName
she selects for a given unit test is unique in all of her tests, resulting in possibly dozens if not hundreds ofUniversalConnectionPool
instances in her test suite (see above).Neither option is particularly friendly.
This PR therefore amends the Helidon 4.0.7 behavior as follows:
PoolDataSource
configuration contains a value forconnectionPoolName
, no further magic behavior results. If that pool name happens to exist, tough luck. The UCP will fail in whatever way it fails, good or bad, right or wrong.PoolDataSource
configuration does not contain a value forconnectionPoolName
:UCPBackedDataSourceExtension
will now check to see if the data source name can be used as a pool name. This will only be the case if an equivalently-named connection pool does not already exist.connectionPoolName
property to the value of the data source name (as is currently done in 4.0.7).connectionPoolName
property. This will result, as in 4.0.5, in at least two connection pools backing "the same" data source: the pre-existing named one, and the new one with a randomly generated name.This description is approximately 35x longer than the actual PR so have a look.