Skip to content

Commit

Permalink
Naming suggestions from review
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-mhofman committed Nov 8, 2023
1 parent cd5b568 commit 5f71f0e
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ public void TestConnectionPoolExpirationWorks()
// not just the connections created after the new setting,
// so expected result should be 0
Assert.AreEqual(0, SnowflakeDbConnectionPool.GetPool(ConnectionString).GetCurrentPoolSize());
SnowflakeDbConnectionPool.SetPooling(false);
}

[Test]
Expand Down
8 changes: 4 additions & 4 deletions Snowflake.Data.Tests/UnitTests/ConnectionPoolManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public void TestPoolManagerReturnsSessionPoolForGivenConnectionString()
var sessionPool = _connectionPoolManager.GetPool(ConnectionString1, _password);

// Assert
Assert.AreEqual(ConnectionString1, sessionPool._connectionString);
Assert.AreEqual(_password, sessionPool._password);
Assert.AreEqual(ConnectionString1, sessionPool.ConnectionString);
Assert.AreEqual(_password, sessionPool.Password);
}

[Test]
Expand Down Expand Up @@ -76,8 +76,8 @@ public void TestDifferentPoolsAreReturnedForDifferentConnectionStrings()

// Assert
Assert.AreNotSame(sessionPool1, sessionPool2);
Assert.AreEqual(ConnectionString1, sessionPool1._connectionString);
Assert.AreEqual(ConnectionString2, sessionPool2._connectionString);
Assert.AreEqual(ConnectionString1, sessionPool1.ConnectionString);
Assert.AreEqual(ConnectionString2, sessionPool2.ConnectionString);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Snowflake.Data.Tests.UnitTests
{
public class ConnectionPoolManagerSwitchTest
public class SnowflakeDbConnectionPoolTest
{
private readonly string _connectionString1 = "database=D1;warehouse=W1;account=A1;user=U1;password=P1;role=R1;";
private readonly string _connectionString2 = "database=D2;warehouse=W2;account=A2;user=U2;password=P2;role=R2;";
Expand All @@ -23,4 +23,3 @@ public void TestRevertPoolToPreviousVersion()
}
}
}

2 changes: 1 addition & 1 deletion Snowflake.Data/Core/Session/ConnectionCacheManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012-2021 Snowflake Computing Inc. All rights reserved.
* Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved.
*/

using System.Security;
Expand Down
10 changes: 3 additions & 7 deletions Snowflake.Data/Core/Session/ConnectionPoolManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,9 @@ public int GetCurrentPoolSize()
public bool SetPooling(bool poolingEnabled)
{
s_logger.Debug("ConnectionPoolManager::SetPooling for all pools");
bool switched = true;
foreach (var pool in _pools.Values)
{
if (!pool.SetPooling(poolingEnabled))
switched = false;
}
return switched;
return _pools.Values
.Select(pool => pool.SetPooling(poolingEnabled))
.All(setPoolingResult => setPoolingResult);
}

public bool GetPooling()
Expand Down
4 changes: 2 additions & 2 deletions Snowflake.Data/Core/Session/SFSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public class SFSession
private readonly EasyLoggingStarter _easyLoggingStarter = EasyLoggingStarter.Instance;

private long _startTime = 0;
internal readonly string ConnectionString;
internal readonly SecureString Password;
internal string ConnectionString { get; }
internal SecureString Password { get; }

private QueryContextCache _queryContextCache = new QueryContextCache(_defaultQueryContextCacheSize);

Expand Down
14 changes: 7 additions & 7 deletions Snowflake.Data/Core/Session/SessionPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ sealed class SessionPool : IDisposable
{
private static readonly SFLogger s_logger = SFLoggerFactory.GetLogger<SessionPool>();
private static readonly object s_sessionPoolLock = new object();
private static ISessionFactory s_sessionFactory = new SessionFactory();

private readonly List<SFSession> _idleSessions;
private int _maxPoolSize;
private long _timeout;
private const int MaxPoolSize = 10;
private const long Timeout = 3600;
internal string _connectionString;
internal SecureString _password;
internal string ConnectionString { get; }
internal SecureString Password { get; }
private bool _pooling = true;
private bool _allowExceedMaxPoolSize = true;

Check warning on line 30 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AWS)

The field 'SessionPool._allowExceedMaxPoolSize' is assigned but its value is never used

Check warning on line 30 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AZURE)

The field 'SessionPool._allowExceedMaxPoolSize' is assigned but its value is never used

Check warning on line 30 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, GCP)

The field 'SessionPool._allowExceedMaxPoolSize' is assigned but its value is never used

Check warning on line 30 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AZURE)

The field 'SessionPool._allowExceedMaxPoolSize' is assigned but its value is never used

Check warning on line 30 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AWS)

The field 'SessionPool._allowExceedMaxPoolSize' is assigned but its value is never used

Check warning on line 30 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, GCP)

The field 'SessionPool._allowExceedMaxPoolSize' is assigned but its value is never used
private static ISessionFactory s_sessionFactory = new SessionFactory();

private SessionPool()
{
Expand All @@ -41,8 +41,8 @@ private SessionPool()

private SessionPool(string connectionString, SecureString password) : this()
{
_connectionString = connectionString;
_password = password;
ConnectionString = connectionString;
Password = password;
_allowExceedMaxPoolSize = false; // TODO: SNOW-937190
}

Expand Down Expand Up @@ -104,10 +104,10 @@ internal Task<SFSession> GetSessionAsync(string connStr, SecureString password,
return session != null ? Task.FromResult(session) : NewSessionAsync(connStr, password, cancellationToken);
}

internal SFSession GetSession() => GetSession(_connectionString, _password);
internal SFSession GetSession() => GetSession(ConnectionString, Password);

internal Task<SFSession> GetSessionAsync(CancellationToken cancellationToken) =>
GetSessionAsync(_connectionString, _password, cancellationToken);
GetSessionAsync(ConnectionString, Password, cancellationToken);

private SFSession GetIdleSession(string connStr)
{
Expand Down

0 comments on commit 5f71f0e

Please sign in to comment.