-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow max connection pool setting to be used (#1431)
* Split ConnectionPoolValidator for sqlserver and postgresql * Move validation of connection pooling to the initialize phase --------- Co-authored-by: Jo Palac <[email protected]>
- Loading branch information
1 parent
3f053a3
commit 9d7ff39
Showing
15 changed files
with
134 additions
and
81 deletions.
There are no files selected for viewing
3 changes: 0 additions & 3 deletions
3
...viceBus.Transport.PostgreSql.TransportTests/ConfigurePostgreSqlTransportInfrastructure.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/NServiceBus.Transport.PostgreSql.UnitTests/ConnectionPoolValidatorTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
namespace NServiceBus.Transport.PostgreSql.UnitTests | ||
{ | ||
using NUnit.Framework; | ||
|
||
[TestFixture] | ||
public class ConnectionPoolValidatorTests | ||
{ | ||
[Test] | ||
public void Is_not_validated_when_connection_pooling_not_specified() | ||
{ | ||
var result = ConnectionPoolValidator.Validate("Database = xxx"); | ||
|
||
Assert.That(result.IsValid, Is.False); | ||
} | ||
|
||
[Test] | ||
public void Is_validated_when_both_min_and_max_pool_size_is_specified() | ||
{ | ||
var result = ConnectionPoolValidator.Validate("Database = xxx; minimum pool size = 20; maximum pool size=120"); | ||
|
||
Assert.That(result.IsValid, Is.True); | ||
} | ||
|
||
[Test] | ||
public void Is_not_validated_when_only_min_pool_size_is_specified() | ||
{ | ||
var result = ConnectionPoolValidator.Validate("Database = xxx; Minimum Pool Size = 20;"); | ||
|
||
Assert.That(result.IsValid, Is.False); | ||
} | ||
|
||
[Test] | ||
public void Is_not_validated_when_pooling_is_enabled_and_no_min_and_max_is_set() | ||
{ | ||
var result = ConnectionPoolValidator.Validate("Database = xxx; Pooling = true"); | ||
|
||
Assert.That(result.IsValid, Is.False); | ||
} | ||
|
||
[Test] | ||
public void Is_validated_when_pooling_is_disabled() | ||
{ | ||
var result = ConnectionPoolValidator.Validate("Database = xxx; Pooling = false"); | ||
|
||
Assert.That(result.IsValid, Is.True); | ||
} | ||
|
||
[Test] | ||
public void Parses_pool_disable_values_with_yes_or_no() | ||
{ | ||
var result = ConnectionPoolValidator.Validate("Database = xxx; Pooling = no"); | ||
|
||
Assert.That(result.IsValid, Is.True); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/NServiceBus.Transport.PostgreSql/Configuration/ConnectionPoolValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
namespace NServiceBus.Transport.PostgreSql; | ||
|
||
using System; | ||
using System.Data.Common; | ||
using Sql.Shared; | ||
|
||
static class ConnectionPoolValidator | ||
{ | ||
public static ValidationCheckResult Validate(string connectionString) | ||
{ | ||
var keys = new DbConnectionStringBuilder { ConnectionString = connectionString }; | ||
var hasPoolingValue = keys.TryGetValue("Pooling", out object poolingValue); | ||
if (hasPoolingValue && !string.Equals(poolingValue.ToString(), "true", StringComparison.InvariantCultureIgnoreCase)) | ||
{ | ||
return ValidationCheckResult.Valid(); | ||
} | ||
if (keys.ContainsKey("Maximum Pool Size")) | ||
{ | ||
return ValidationCheckResult.Valid(); | ||
} | ||
return ValidationCheckResult.Invalid(ConnectionPoolSizeNotSet); | ||
} | ||
|
||
const string ConnectionPoolSizeNotSet = | ||
"Maximum connection pooling value (Maximum Pool Size=N) is not " + | ||
"configured on the provided connection string. The default value (100) will be used."; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 0 additions & 28 deletions
28
src/NServiceBus.Transport.Sql.Shared/Configuration/ConnectionPoolValidator.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
src/NServiceBus.Transport.SqlServer.UnitTests/ConnectionPoolValidatorTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/NServiceBus.Transport.SqlServer/Configuration/ConnectionPoolValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
namespace NServiceBus.Transport.SqlServer; | ||
|
||
using System; | ||
using System.Data.Common; | ||
using Sql.Shared; | ||
|
||
static class ConnectionPoolValidator | ||
{ | ||
public static ValidationCheckResult Validate(string connectionString) | ||
{ | ||
var keys = new DbConnectionStringBuilder { ConnectionString = connectionString }; | ||
var hasPoolingValue = keys.TryGetValue("Pooling", out object poolingValue); | ||
if (hasPoolingValue && !string.Equals(poolingValue.ToString(), "true", StringComparison.InvariantCultureIgnoreCase)) | ||
{ | ||
return ValidationCheckResult.Valid(); | ||
} | ||
if (keys.ContainsKey("Max Pool Size")) | ||
{ | ||
return ValidationCheckResult.Valid(); | ||
} | ||
return ValidationCheckResult.Invalid(ConnectionPoolSizeNotSet); | ||
} | ||
|
||
const string ConnectionPoolSizeNotSet = | ||
"Maximum connection pooling value (Max Pool Size=N) is not " + | ||
"configured on the provided connection string. The default value (100) will be used."; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters