From 12c7aa87443c64df6a4988896cf44c8d93a0e999 Mon Sep 17 00:00:00 2001 From: Malcolm Daigle Date: Thu, 5 Jun 2025 13:52:07 -0700 Subject: [PATCH] Add ChannelDbConnectionPool and unit tests. --- .../src/Microsoft.Data.SqlClient.csproj | 3 + .../netfx/src/Microsoft.Data.SqlClient.csproj | 3 + .../ConnectionPool/ChannelDbConnectionPool.cs | 120 ++++++++++++++ .../Microsoft.Data.SqlClient.UnitTests.csproj | 1 + .../ChannelDbConnectionPoolTest.cs | 155 ++++++++++++++++++ 5 files changed, 282 insertions(+) create mode 100644 src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/ChannelDbConnectionPool.cs create mode 100644 src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/ConnectionPool/ChannelDbConnectionPoolTest.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj index 96b600e194..1e5ea23f79 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -102,6 +102,9 @@ Microsoft\Data\ProviderBase\DbConnectionFactory.cs + + Microsoft\Data\SqlClient\ConnectionPool\ChannelDbConnectionPool.cs + Microsoft\Data\SqlClient\ConnectionPool\DbConnectionPoolAuthenticationContext.cs diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj index 1e736ee960..ea4950329e 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj @@ -288,6 +288,9 @@ Microsoft\Data\ProviderBase\DbConnectionInternal.cs + + Microsoft\Data\SqlClient\ConnectionPool\ChannelDbConnectionPool.cs + Microsoft\Data\SqlClient\ConnectionPool\DbConnectionPoolAuthenticationContext.cs diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/ChannelDbConnectionPool.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/ChannelDbConnectionPool.cs new file mode 100644 index 0000000000..c4772bb736 --- /dev/null +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/ChannelDbConnectionPool.cs @@ -0,0 +1,120 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. +using System; +using System.Collections.Concurrent; +using System.Data.Common; +using System.Threading.Tasks; +using System.Transactions; +using Microsoft.Data.Common; +using Microsoft.Data.Common.ConnectionString; +using Microsoft.Data.ProviderBase; + +#nullable enable + +namespace Microsoft.Data.SqlClient.ConnectionPool +{ + /// + /// A connection pool implementation based on the channel data structure. + /// Provides methods to manage the pool of connections, including acquiring and releasing connections. + /// + internal sealed class ChannelDbConnectionPool : IDbConnectionPool + { + #region Properties + /// + public ConcurrentDictionary AuthenticationContexts => throw new NotImplementedException(); + + /// + public DbConnectionFactory ConnectionFactory => throw new NotImplementedException(); + + /// + public int Count => throw new NotImplementedException(); + + /// + public bool ErrorOccurred => throw new NotImplementedException(); + + /// + public int Id => throw new NotImplementedException(); + + /// + public DbConnectionPoolIdentity Identity => throw new NotImplementedException(); + + /// + public bool IsRunning => throw new NotImplementedException(); + + /// + public TimeSpan LoadBalanceTimeout => throw new NotImplementedException(); + + /// + public DbConnectionPoolGroup PoolGroup => throw new NotImplementedException(); + + /// + public DbConnectionPoolGroupOptions PoolGroupOptions => throw new NotImplementedException(); + + /// + public DbConnectionPoolProviderInfo ProviderInfo => throw new NotImplementedException(); + + /// + public DbConnectionPoolState State + { + get => throw new NotImplementedException(); + set => throw new NotImplementedException(); + } + + /// + public bool UseLoadBalancing => throw new NotImplementedException(); + #endregion + + + + #region Methods + /// + public void Clear() + { + throw new NotImplementedException(); + } + + /// + public void PutObjectFromTransactedPool(DbConnectionInternal obj) + { + throw new NotImplementedException(); + } + + /// + public DbConnectionInternal ReplaceConnection(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) + { + throw new NotImplementedException(); + } + + /// + public void ReturnInternalConnection(DbConnectionInternal obj, object owningObject) + { + throw new NotImplementedException(); + } + + /// + public void Shutdown() + { + throw new NotImplementedException(); + } + + /// + public void Startup() + { + throw new NotImplementedException(); + } + + /// + public void TransactionEnded(Transaction transaction, DbConnectionInternal transactedObject) + { + throw new NotImplementedException(); + } + + /// + public bool TryGetConnection(DbConnection owningObject, TaskCompletionSource taskCompletionSource, DbConnectionOptions userOptions, out DbConnectionInternal connection) + { + throw new NotImplementedException(); + } + #endregion + } +} diff --git a/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft.Data.SqlClient.UnitTests.csproj b/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft.Data.SqlClient.UnitTests.csproj index af7c11b6b0..8f0489c292 100644 --- a/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft.Data.SqlClient.UnitTests.csproj +++ b/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft.Data.SqlClient.UnitTests.csproj @@ -30,6 +30,7 @@ + diff --git a/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/ConnectionPool/ChannelDbConnectionPoolTest.cs b/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/ConnectionPool/ChannelDbConnectionPoolTest.cs new file mode 100644 index 0000000000..2dcfe476fe --- /dev/null +++ b/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/ConnectionPool/ChannelDbConnectionPoolTest.cs @@ -0,0 +1,155 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Data.Common; +using System.Threading.Tasks; +using System.Transactions; +using Microsoft.Data.SqlClient.ConnectionPool; +using Xunit; + +namespace Microsoft.Data.SqlClient.UnitTests +{ + public class ChannelDbConnectionPoolTest + { + private readonly ChannelDbConnectionPool _pool; + + public ChannelDbConnectionPoolTest() + { + _pool = new ChannelDbConnectionPool(); + } + + [Fact] + public void TestAuthenticationContexts() + { + Assert.Throws(() => _ = _pool.AuthenticationContexts); + } + + [Fact] + public void TestConnectionFactory() + { + Assert.Throws(() => _ = _pool.ConnectionFactory); + } + + [Fact] + public void TestCount() + { + Assert.Throws(() => _ = _pool.Count); + } + + [Fact] + public void TestErrorOccurred() + { + Assert.Throws(() => _ = _pool.ErrorOccurred); + } + + [Fact] + public void TestId() + { + Assert.Throws(() => _ = _pool.Id); + } + + [Fact] + public void TestIdentity() + { + Assert.Throws(() => _ = _pool.Identity); + } + + [Fact] + public void TestIsRunning() + { + Assert.Throws(() => _ = _pool.IsRunning); + } + + [Fact] + public void TestLoadBalanceTimeout() + { + Assert.Throws(() => _ = _pool.LoadBalanceTimeout); + } + + [Fact] + public void TestPoolGroup() + { + Assert.Throws(() => _ = _pool.PoolGroup); + } + + [Fact] + public void TestPoolGroupOptions() + { + Assert.Throws(() => _ = _pool.PoolGroupOptions); + } + + [Fact] + public void TestProviderInfo() + { + Assert.Throws(() => _ = _pool.ProviderInfo); + } + + [Fact] + public void TestStateGetter() + { + Assert.Throws(() => _ = _pool.State); + } + + [Fact] + public void TestStateSetter() + { + Assert.Throws(() => _pool.State = DbConnectionPoolState.Running); + } + + [Fact] + public void TestUseLoadBalancing() + { + Assert.Throws(() => _ = _pool.UseLoadBalancing); + } + + [Fact] + public void TestClear() + { + Assert.Throws(() => _pool.Clear()); + } + + [Fact] + public void TestPutObjectFromTransactedPool() + { + Assert.Throws(() => _pool.PutObjectFromTransactedPool(null!)); + } + + [Fact] + public void TestReplaceConnection() + { + Assert.Throws(() => _pool.ReplaceConnection(null!, null!, null!)); + } + + [Fact] + public void TestReturnInternalConnection() + { + Assert.Throws(() => _pool.ReturnInternalConnection(null!, null!)); + } + + [Fact] + public void TestShutdown() + { + Assert.Throws(() => _pool.Shutdown()); + } + + [Fact] + public void TestStartup() + { + Assert.Throws(() => _pool.Startup()); + } + + [Fact] + public void TestTransactionEnded() + { + Assert.Throws(() => _pool.TransactionEnded(null!, null!)); + } + + [Fact] + public void TestTryGetConnection() + { + Assert.Throws(() => _pool.TryGetConnection(null!, null!, null!, out _)); + } + } +}