Skip to content

Commit 0444198

Browse files
authored
Add ChannelDbConnectionPool and unit tests. (#3396)
1 parent 194fada commit 0444198

File tree

5 files changed

+282
-0
lines changed

5 files changed

+282
-0
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@
102102
<Compile Include="$(CommonSourceRoot)\Microsoft\Data\ProviderBase\DbConnectionFactory.cs">
103103
<Link>Microsoft\Data\ProviderBase\DbConnectionFactory.cs</Link>
104104
</Compile>
105+
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\ConnectionPool\ChannelDbConnectionPool.cs">
106+
<Link>Microsoft\Data\SqlClient\ConnectionPool\ChannelDbConnectionPool.cs</Link>
107+
</Compile>
105108
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\ConnectionPool\DbConnectionPoolAuthenticationContext.cs">
106109
<Link>Microsoft\Data\SqlClient\ConnectionPool\DbConnectionPoolAuthenticationContext.cs</Link>
107110
</Compile>

src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,9 @@
288288
<Compile Include="$(CommonSourceRoot)Microsoft\Data\ProviderBase\DbConnectionInternal.cs">
289289
<Link>Microsoft\Data\ProviderBase\DbConnectionInternal.cs</Link>
290290
</Compile>
291+
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\ConnectionPool\ChannelDbConnectionPool.cs">
292+
<Link>Microsoft\Data\SqlClient\ConnectionPool\ChannelDbConnectionPool.cs</Link>
293+
</Compile>
291294
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\ConnectionPool\DbConnectionPoolAuthenticationContext.cs">
292295
<Link>Microsoft\Data\SqlClient\ConnectionPool\DbConnectionPoolAuthenticationContext.cs</Link>
293296
</Compile>
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
using System;
5+
using System.Collections.Concurrent;
6+
using System.Data.Common;
7+
using System.Threading.Tasks;
8+
using System.Transactions;
9+
using Microsoft.Data.Common;
10+
using Microsoft.Data.Common.ConnectionString;
11+
using Microsoft.Data.ProviderBase;
12+
13+
#nullable enable
14+
15+
namespace Microsoft.Data.SqlClient.ConnectionPool
16+
{
17+
/// <summary>
18+
/// A connection pool implementation based on the channel data structure.
19+
/// Provides methods to manage the pool of connections, including acquiring and releasing connections.
20+
/// </summary>
21+
internal sealed class ChannelDbConnectionPool : IDbConnectionPool
22+
{
23+
#region Properties
24+
/// <inheritdoc />
25+
public ConcurrentDictionary<DbConnectionPoolAuthenticationContextKey, DbConnectionPoolAuthenticationContext> AuthenticationContexts => throw new NotImplementedException();
26+
27+
/// <inheritdoc />
28+
public DbConnectionFactory ConnectionFactory => throw new NotImplementedException();
29+
30+
/// <inheritdoc />
31+
public int Count => throw new NotImplementedException();
32+
33+
/// <inheritdoc />
34+
public bool ErrorOccurred => throw new NotImplementedException();
35+
36+
/// <inheritdoc />
37+
public int Id => throw new NotImplementedException();
38+
39+
/// <inheritdoc />
40+
public DbConnectionPoolIdentity Identity => throw new NotImplementedException();
41+
42+
/// <inheritdoc />
43+
public bool IsRunning => throw new NotImplementedException();
44+
45+
/// <inheritdoc />
46+
public TimeSpan LoadBalanceTimeout => throw new NotImplementedException();
47+
48+
/// <inheritdoc />
49+
public DbConnectionPoolGroup PoolGroup => throw new NotImplementedException();
50+
51+
/// <inheritdoc />
52+
public DbConnectionPoolGroupOptions PoolGroupOptions => throw new NotImplementedException();
53+
54+
/// <inheritdoc />
55+
public DbConnectionPoolProviderInfo ProviderInfo => throw new NotImplementedException();
56+
57+
/// <inheritdoc />
58+
public DbConnectionPoolState State
59+
{
60+
get => throw new NotImplementedException();
61+
set => throw new NotImplementedException();
62+
}
63+
64+
/// <inheritdoc />
65+
public bool UseLoadBalancing => throw new NotImplementedException();
66+
#endregion
67+
68+
69+
70+
#region Methods
71+
/// <inheritdoc />
72+
public void Clear()
73+
{
74+
throw new NotImplementedException();
75+
}
76+
77+
/// <inheritdoc />
78+
public void PutObjectFromTransactedPool(DbConnectionInternal obj)
79+
{
80+
throw new NotImplementedException();
81+
}
82+
83+
/// <inheritdoc />
84+
public DbConnectionInternal ReplaceConnection(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
85+
{
86+
throw new NotImplementedException();
87+
}
88+
89+
/// <inheritdoc />
90+
public void ReturnInternalConnection(DbConnectionInternal obj, object owningObject)
91+
{
92+
throw new NotImplementedException();
93+
}
94+
95+
/// <inheritdoc />
96+
public void Shutdown()
97+
{
98+
throw new NotImplementedException();
99+
}
100+
101+
/// <inheritdoc />
102+
public void Startup()
103+
{
104+
throw new NotImplementedException();
105+
}
106+
107+
/// <inheritdoc />
108+
public void TransactionEnded(Transaction transaction, DbConnectionInternal transactedObject)
109+
{
110+
throw new NotImplementedException();
111+
}
112+
113+
/// <inheritdoc />
114+
public bool TryGetConnection(DbConnection owningObject, TaskCompletionSource<DbConnectionInternal> taskCompletionSource, DbConnectionOptions userOptions, out DbConnectionInternal connection)
115+
{
116+
throw new NotImplementedException();
117+
}
118+
#endregion
119+
}
120+
}

src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft.Data.SqlClient.UnitTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<ItemGroup Condition="$(TargetGroup) == 'netfx'">
3131
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="$(SystemRuntimeInteropServicesRuntimeInformationVersion)" />
3232
<ProjectReference Include="$(NetFxSource)src\Microsoft.Data.SqlClient.csproj" />
33+
<Reference Include="System.Transactions" />
3334
</ItemGroup>
3435
<!-- .NET references -->
3536
<ItemGroup Condition="'$(TargetGroup)'=='netcoreapp'">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Data.Common;
7+
using System.Threading.Tasks;
8+
using System.Transactions;
9+
using Microsoft.Data.SqlClient.ConnectionPool;
10+
using Xunit;
11+
12+
namespace Microsoft.Data.SqlClient.UnitTests
13+
{
14+
public class ChannelDbConnectionPoolTest
15+
{
16+
private readonly ChannelDbConnectionPool _pool;
17+
18+
public ChannelDbConnectionPoolTest()
19+
{
20+
_pool = new ChannelDbConnectionPool();
21+
}
22+
23+
[Fact]
24+
public void TestAuthenticationContexts()
25+
{
26+
Assert.Throws<NotImplementedException>(() => _ = _pool.AuthenticationContexts);
27+
}
28+
29+
[Fact]
30+
public void TestConnectionFactory()
31+
{
32+
Assert.Throws<NotImplementedException>(() => _ = _pool.ConnectionFactory);
33+
}
34+
35+
[Fact]
36+
public void TestCount()
37+
{
38+
Assert.Throws<NotImplementedException>(() => _ = _pool.Count);
39+
}
40+
41+
[Fact]
42+
public void TestErrorOccurred()
43+
{
44+
Assert.Throws<NotImplementedException>(() => _ = _pool.ErrorOccurred);
45+
}
46+
47+
[Fact]
48+
public void TestId()
49+
{
50+
Assert.Throws<NotImplementedException>(() => _ = _pool.Id);
51+
}
52+
53+
[Fact]
54+
public void TestIdentity()
55+
{
56+
Assert.Throws<NotImplementedException>(() => _ = _pool.Identity);
57+
}
58+
59+
[Fact]
60+
public void TestIsRunning()
61+
{
62+
Assert.Throws<NotImplementedException>(() => _ = _pool.IsRunning);
63+
}
64+
65+
[Fact]
66+
public void TestLoadBalanceTimeout()
67+
{
68+
Assert.Throws<NotImplementedException>(() => _ = _pool.LoadBalanceTimeout);
69+
}
70+
71+
[Fact]
72+
public void TestPoolGroup()
73+
{
74+
Assert.Throws<NotImplementedException>(() => _ = _pool.PoolGroup);
75+
}
76+
77+
[Fact]
78+
public void TestPoolGroupOptions()
79+
{
80+
Assert.Throws<NotImplementedException>(() => _ = _pool.PoolGroupOptions);
81+
}
82+
83+
[Fact]
84+
public void TestProviderInfo()
85+
{
86+
Assert.Throws<NotImplementedException>(() => _ = _pool.ProviderInfo);
87+
}
88+
89+
[Fact]
90+
public void TestStateGetter()
91+
{
92+
Assert.Throws<NotImplementedException>(() => _ = _pool.State);
93+
}
94+
95+
[Fact]
96+
public void TestStateSetter()
97+
{
98+
Assert.Throws<NotImplementedException>(() => _pool.State = DbConnectionPoolState.Running);
99+
}
100+
101+
[Fact]
102+
public void TestUseLoadBalancing()
103+
{
104+
Assert.Throws<NotImplementedException>(() => _ = _pool.UseLoadBalancing);
105+
}
106+
107+
[Fact]
108+
public void TestClear()
109+
{
110+
Assert.Throws<NotImplementedException>(() => _pool.Clear());
111+
}
112+
113+
[Fact]
114+
public void TestPutObjectFromTransactedPool()
115+
{
116+
Assert.Throws<NotImplementedException>(() => _pool.PutObjectFromTransactedPool(null!));
117+
}
118+
119+
[Fact]
120+
public void TestReplaceConnection()
121+
{
122+
Assert.Throws<NotImplementedException>(() => _pool.ReplaceConnection(null!, null!, null!));
123+
}
124+
125+
[Fact]
126+
public void TestReturnInternalConnection()
127+
{
128+
Assert.Throws<NotImplementedException>(() => _pool.ReturnInternalConnection(null!, null!));
129+
}
130+
131+
[Fact]
132+
public void TestShutdown()
133+
{
134+
Assert.Throws<NotImplementedException>(() => _pool.Shutdown());
135+
}
136+
137+
[Fact]
138+
public void TestStartup()
139+
{
140+
Assert.Throws<NotImplementedException>(() => _pool.Startup());
141+
}
142+
143+
[Fact]
144+
public void TestTransactionEnded()
145+
{
146+
Assert.Throws<NotImplementedException>(() => _pool.TransactionEnded(null!, null!));
147+
}
148+
149+
[Fact]
150+
public void TestTryGetConnection()
151+
{
152+
Assert.Throws<NotImplementedException>(() => _pool.TryGetConnection(null!, null!, null!, out _));
153+
}
154+
}
155+
}

0 commit comments

Comments
 (0)