-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
db8130a
commit 3ad6b97
Showing
8 changed files
with
232 additions
and
59 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
Snowflake.Data.Tests/IntegrationTests/ConnectionMultiplePoolsAsyncIT.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,48 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using NUnit.Framework; | ||
using Snowflake.Data.Client; | ||
using Snowflake.Data.Core.Session; | ||
using Snowflake.Data.Tests.Util; | ||
|
||
namespace Snowflake.Data.Tests.IntegrationTests | ||
{ | ||
[TestFixture] | ||
[NonParallelizable] | ||
public class ConnectionMultiplePoolsAsyncIT: SFBaseTestAsync | ||
{ | ||
private readonly PoolConfig _previousPoolConfig = new PoolConfig(); | ||
|
||
[SetUp] | ||
public new void BeforeTest() | ||
{ | ||
SnowflakeDbConnectionPool.SetConnectionPoolVersion(ConnectionPoolType.MultipleConnectionPool); | ||
SnowflakeDbConnectionPool.ClearAllPools(); | ||
} | ||
|
||
[TearDown] | ||
public new void AfterTest() | ||
{ | ||
_previousPoolConfig.Reset(); | ||
} | ||
|
||
[Test] | ||
public async Task TestMinPoolSizeAsync() | ||
{ | ||
// arrange | ||
var connection = new SnowflakeDbConnection(); | ||
connection.ConnectionString = ConnectionString + "application=TestMinPoolSizeAsync;minPoolSize=3"; | ||
|
||
// act | ||
await connection.OpenAsync().ConfigureAwait(false); | ||
Thread.Sleep(3000); | ||
|
||
// assert | ||
var pool = SnowflakeDbConnectionPool.GetPool(connection.ConnectionString); | ||
Assert.AreEqual(3, pool.GetCurrentPoolSize()); | ||
|
||
// cleanup | ||
await connection.CloseAsync(CancellationToken.None).ConfigureAwait(false); | ||
} | ||
} | ||
} |
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
62 changes: 62 additions & 0 deletions
62
Snowflake.Data.Tests/UnitTests/Session/SessionOrCreationTokensTest.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,62 @@ | ||
using System; | ||
using System.Linq; | ||
using NUnit.Framework; | ||
using Snowflake.Data.Core; | ||
using Snowflake.Data.Core.Session; | ||
|
||
namespace Snowflake.Data.Tests.UnitTests.Session | ||
{ | ||
[TestFixture] | ||
public class SessionOrCreationTokensTest | ||
{ | ||
private SFSession _session = new SFSession("account=test;user=test;password=test", null); | ||
|
||
[Test] | ||
public void TestNoBackgroundSessionsToCreateWhenInitialisedWithSession() | ||
{ | ||
// arrange | ||
var sessionOrTokens = new SessionOrCreationTokens(_session); | ||
|
||
// act | ||
var backgroundCreationTokens = sessionOrTokens.BackgroundSessionCreationTokens(); | ||
|
||
Assert.AreEqual(0, backgroundCreationTokens.Count); | ||
} | ||
|
||
[Test] | ||
public void TestReturnFirstCreationToken() | ||
{ | ||
// arrange | ||
var sessionCreationTokenCounter = new SessionCreationTokenCounter(TimeSpan.FromSeconds(10)); | ||
var tokens = Enumerable.Range(1, 3) | ||
.Select(_ => sessionCreationTokenCounter.NewToken()) | ||
.ToList(); | ||
var sessionOrTokens = new SessionOrCreationTokens(tokens); | ||
|
||
// act | ||
var token = sessionOrTokens.SessionCreationToken(); | ||
|
||
// assert | ||
Assert.AreSame(tokens[0], token); | ||
} | ||
|
||
[Test] | ||
public void TestReturnCreationTokensFromTheSecondOneForBackgroundExecution() | ||
{ | ||
// arrange | ||
var sessionCreationTokenCounter = new SessionCreationTokenCounter(TimeSpan.FromSeconds(10)); | ||
var tokens = Enumerable.Range(1, 3) | ||
.Select(_ => sessionCreationTokenCounter.NewToken()) | ||
.ToList(); | ||
var sessionOrTokens = new SessionOrCreationTokens(tokens); | ||
|
||
// act | ||
var backgroundTokens = sessionOrTokens.BackgroundSessionCreationTokens(); | ||
|
||
// assert | ||
Assert.AreEqual(2, backgroundTokens.Count); | ||
Assert.AreSame(tokens[1], backgroundTokens[0]); | ||
Assert.AreSame(tokens[2], backgroundTokens[1]); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Snowflake.Data.Core.Session | ||
{ | ||
internal class SessionOrCreationTokens | ||
{ | ||
private static readonly List<SessionCreationToken> s_emptySessionCreationTokenList = new List<SessionCreationToken>(); | ||
|
||
public SFSession Session { get; } | ||
public List<SessionCreationToken> SessionCreationTokens { get; } | ||
|
||
public SessionOrCreationTokens(SFSession session) | ||
{ | ||
Session = session ?? throw new Exception("Internal error: missing session"); | ||
SessionCreationTokens = s_emptySessionCreationTokenList; | ||
} | ||
|
||
public SessionOrCreationTokens(List<SessionCreationToken> sessionCreationTokens) | ||
{ | ||
Session = null; | ||
if (sessionCreationTokens == null || sessionCreationTokens.Count == 0) | ||
{ | ||
throw new Exception("Internal error: missing session creation token"); | ||
} | ||
SessionCreationTokens = sessionCreationTokens; | ||
} | ||
|
||
public List<SessionCreationToken> BackgroundSessionCreationTokens() | ||
{ | ||
if (Session == null) | ||
{ | ||
return SessionCreationTokens.Skip(1).ToList(); | ||
} | ||
return SessionCreationTokens; | ||
} | ||
|
||
public SessionCreationToken SessionCreationToken() => SessionCreationTokens.First(); | ||
} | ||
} |
Oops, something went wrong.