mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-27 01:25:42 -05:00
Update connection logic to handle multiple connections per URI (#176)
* Add CancelTokenKey for uniquely identifying cancelations of Connections associated with an OwnerUri and ConnectionType string. * Update ConnectionInfo to use ConcurrentDictionary of DbConnection instances. Add wrapper functions for the ConcurrentDictionary. * Refactor Connect and Disconnect in ConnectionService. * Update ConnectionService: Handle multiple connections per ConnectionInfo. Handle cancelation tokens uniquely identified with CancelTokenKey. Add GetOrOpenConnection() for other services to request an existing or create a new DbConnection. * Add ConnectionType.cs for ConnectionType strings. * Add ConnectionType string to ConnectParams, ConnectionCompleteNotification, DisconnectParams. * Update Query ExecuteInternal to use the dedicated query connection and GetOrOpenConnection(). * Update test library to account for multiple connections in ConnectionInfo. * Write tests ensuring multiple connections don’t create redundant data. * Write tests ensuring database changes affect all connections of a given ConnectionInfo. * Write tests for TRANSACTION statements and temp tables.
This commit is contained in:
@@ -82,6 +82,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
||||
public static Query GetBasicExecutedQuery()
|
||||
{
|
||||
ConnectionInfo ci = CreateTestConnectionInfo(new[] {StandardTestData}, false);
|
||||
|
||||
// Query won't be able to request a new query DbConnection unless the ConnectionService has a
|
||||
// ConnectionInfo with the same URI as the query, so we will manually set it
|
||||
ConnectionService.Instance.OwnerToConnectionMap[ci.OwnerUri] = ci;
|
||||
|
||||
Query query = new Query(StandardQuery, ci, new QueryExecutionSettings(), GetFileStreamFactory(new Dictionary<string, byte[]>()));
|
||||
query.Execute();
|
||||
query.ExecutionTask.Wait();
|
||||
@@ -222,6 +227,23 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
||||
return new ConnectionInfo(CreateMockFactory(data, throwOnRead), OwnerUri, StandardConnectionDetails);
|
||||
}
|
||||
|
||||
public static ConnectionInfo CreateConnectedConnectionInfo(Dictionary<string, string>[][] data, bool throwOnRead, string type = ConnectionType.Default)
|
||||
{
|
||||
ConnectionService connectionService = ConnectionService.Instance;
|
||||
connectionService.OwnerToConnectionMap.Clear();
|
||||
connectionService.ConnectionFactory = CreateMockFactory(data, throwOnRead);
|
||||
|
||||
ConnectParams connectParams = new ConnectParams()
|
||||
{
|
||||
Connection = StandardConnectionDetails,
|
||||
OwnerUri = Common.OwnerUri,
|
||||
Type = type
|
||||
};
|
||||
|
||||
connectionService.Connect(connectParams).Wait();
|
||||
return connectionService.OwnerToConnectionMap[OwnerUri];
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Service Mocking
|
||||
@@ -233,12 +255,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
||||
// Create a place for the temp "files" to be written
|
||||
storage = new Dictionary<string, byte[]>();
|
||||
|
||||
// Create the connection factory with the dataset
|
||||
var factory = CreateTestConnectionInfo(data, throwOnRead).Factory;
|
||||
|
||||
// Mock the connection service
|
||||
var connectionService = new Mock<ConnectionService>();
|
||||
ConnectionInfo ci = new ConnectionInfo(factory, OwnerUri, StandardConnectionDetails);
|
||||
ConnectionInfo ci = CreateConnectedConnectionInfo(data, throwOnRead);
|
||||
ConnectionInfo outValMock;
|
||||
connectionService
|
||||
.Setup(service => service.TryFindConnection(It.IsAny<string>(), out outValMock))
|
||||
|
||||
Reference in New Issue
Block a user