-
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.
SNOW-937188 pool mode where a session gets destroyed on pooling when …
…some of its settings gets changed and no longer match the pool initial setup
- Loading branch information
1 parent
43d8fd4
commit e727d1a
Showing
9 changed files
with
619 additions
and
404 deletions.
There are no files selected for viewing
160 changes: 160 additions & 0 deletions
160
Snowflake.Data.Tests/IntegrationTests/ConnectionChangedSessionIT.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,160 @@ | ||
using NUnit.Framework; | ||
using Snowflake.Data.Client; | ||
using Snowflake.Data.Core; | ||
using Snowflake.Data.Core.Session; | ||
using Snowflake.Data.Tests.Util; | ||
|
||
namespace Snowflake.Data.Tests.IntegrationTests | ||
{ | ||
[TestFixture] | ||
[NonParallelizable] | ||
public class ConnectionChangedSessionIT : SFBaseTest | ||
{ | ||
private readonly QueryExecResponseData _queryExecResponseChangedRole = new() | ||
{ | ||
finalDatabaseName = TestEnvironment.TestConfig.database, | ||
finalSchemaName = TestEnvironment.TestConfig.schema, | ||
finalRoleName = "role change", | ||
finalWarehouseName = TestEnvironment.TestConfig.warehouse | ||
}; | ||
|
||
private readonly QueryExecResponseData _queryExecResponseChangedDatabase = new() | ||
{ | ||
finalDatabaseName = "database changed", | ||
finalSchemaName = TestEnvironment.TestConfig.schema, | ||
finalRoleName = TestEnvironment.TestConfig.role, | ||
finalWarehouseName = TestEnvironment.TestConfig.warehouse | ||
}; | ||
|
||
private readonly QueryExecResponseData _queryExecResponseChangedSchema = new() | ||
{ | ||
finalDatabaseName = TestEnvironment.TestConfig.database, | ||
finalSchemaName = "schema changed", | ||
finalRoleName = TestEnvironment.TestConfig.role, | ||
finalWarehouseName = TestEnvironment.TestConfig.warehouse | ||
}; | ||
|
||
private readonly QueryExecResponseData _queryExecResponseChangedWarehouse = new() | ||
{ | ||
finalDatabaseName = TestEnvironment.TestConfig.database, | ||
finalSchemaName = TestEnvironment.TestConfig.schema, | ||
finalRoleName = TestEnvironment.TestConfig.role, | ||
finalWarehouseName = "warehouse changed" | ||
}; | ||
|
||
private static PoolConfig s_previousPoolConfigRestorer; | ||
|
||
[OneTimeSetUp] | ||
public static void BeforeAllTests() | ||
{ | ||
s_previousPoolConfigRestorer = new PoolConfig(); | ||
SnowflakeDbConnectionPool.SetConnectionPoolVersion(ConnectionPoolType.MultipleConnectionPool); | ||
} | ||
|
||
[SetUp] | ||
public new void BeforeTest() | ||
{ | ||
SnowflakeDbConnectionPool.ClearAllPools(); | ||
} | ||
|
||
[TearDown] | ||
public new void AfterTest() | ||
{ | ||
SnowflakeDbConnectionPool.ClearAllPools(); | ||
} | ||
|
||
[OneTimeTearDown] | ||
public static void AfterAllTests() | ||
{ | ||
s_previousPoolConfigRestorer.Reset(); | ||
} | ||
|
||
[Test] | ||
public void TestPoolDestroysConnectionWhenChangedSessionProperties() | ||
{ | ||
var connectionString = ConnectionString + "application=Destroy;ChangedSession=Destroy;minPoolSize=0;maxPoolSize=3"; | ||
var pool = SnowflakeDbConnectionPool.GetPool(connectionString); | ||
|
||
var connection = new SnowflakeDbConnection(connectionString); | ||
connection.Open(); | ||
connection.SfSession.UpdateSessionProperties(_queryExecResponseChangedDatabase); | ||
connection.Close(); | ||
|
||
Assert.AreEqual(0, pool.GetCurrentPoolSize()); | ||
} | ||
|
||
[Test] | ||
public void TestPoolingWhenSessionPropertiesUnchanged() | ||
{ | ||
var connectionString = ConnectionString + "application=NoSessionChanges;ChangedSession=Destroy;minPoolSize=0;maxPoolSize=3"; | ||
var pool = SnowflakeDbConnectionPool.GetPool(connectionString); | ||
|
||
var connection = new SnowflakeDbConnection(connectionString); | ||
connection.Open(); | ||
connection.Close(); | ||
|
||
Assert.AreEqual(1, pool.GetCurrentPoolSize()); | ||
} | ||
|
||
[Test] | ||
public void TestPoolingWhenConnectionPropertiesChangedForOriginalPoolMode() | ||
{ | ||
var connectionString = ConnectionString + "application=OriginalPoolMode;ChangedSession=OriginalPool;minPoolSize=0;maxPoolSize=3"; | ||
var pool = SnowflakeDbConnectionPool.GetPool(connectionString); | ||
|
||
var connection = new SnowflakeDbConnection(connectionString); | ||
connection.Open(); | ||
connection.SfSession.UpdateSessionProperties(_queryExecResponseChangedWarehouse); | ||
var sessionId = connection.SfSession.sessionId; | ||
connection.Close(); | ||
|
||
Assert.AreEqual(1, pool.GetCurrentPoolSize()); | ||
connection.Close(); | ||
|
||
var connection2 = new SnowflakeDbConnection(connectionString); | ||
connection2.Open(); | ||
Assert.AreEqual(sessionId, connection2.SfSession.sessionId); | ||
connection2.Close(); | ||
} | ||
|
||
[Test] | ||
public void TestPoolingWhenConnectionPropertiesChangedForDefaultPoolMode() | ||
{ | ||
var connectionString = ConnectionString + "application=DefaultPoolMode;minPoolSize=0;maxPoolSize=3"; | ||
var pool = SnowflakeDbConnectionPool.GetPool(connectionString); | ||
|
||
var connection = new SnowflakeDbConnection(connectionString); | ||
connection.Open(); | ||
connection.SfSession.UpdateSessionProperties(_queryExecResponseChangedRole); | ||
var sessionId = connection.SfSession.sessionId; | ||
connection.Close(); | ||
|
||
Assert.AreEqual(1, pool.GetCurrentPoolSize()); | ||
|
||
var connection2 = new SnowflakeDbConnection(connectionString); | ||
connection2.Open(); | ||
Assert.AreEqual(sessionId, connection2.SfSession.sessionId); | ||
connection2.Close(); | ||
} | ||
|
||
[Test] | ||
public void TestPoolDestroysAndRecreatesConnection() | ||
{ | ||
var connectionString = ConnectionString + "application=DestroyRecreateSession;ChangedSession=Destroy;minPoolSize=1;maxPoolSize=3"; | ||
|
||
var connection = new SnowflakeDbConnection(connectionString); | ||
connection.Open(); | ||
var sessionId = connection.SfSession.sessionId; | ||
connection.SfSession.UpdateSessionProperties(_queryExecResponseChangedSchema); | ||
connection.Close(); | ||
|
||
var pool = SnowflakeDbConnectionPool.GetPool(connectionString); | ||
Assert.AreEqual(1, pool.GetCurrentPoolSize()); | ||
|
||
var connection2 = new SnowflakeDbConnection(connectionString); | ||
connection2.Open(); | ||
Assert.AreNotEqual(sessionId, connection2.SfSession.sessionId); | ||
connection2.Close(); | ||
} | ||
} | ||
} |
File renamed without changes.
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
Oops, something went wrong.