mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 18:47:57 -05:00
query/executeString (#217)
This is a small API addition that allows us to execute queries directly as strings. This will make it easier to execute queries outside the confines of a workspace like VS Code.
* Refactor execution requests and events are now named less redundantly and moved into a separate namespace for organization. This is the bulk of the changes.
* QueryExecuteBatchNotification -> ExecuteRequests/BatchEvents
* QueryExecuteMessageNotification -> ExecuteRequests/MessageEvent
* QueryExecuteCompleteNotification -> ExecuteRequests/QueryCompleteEvent
* QueryExecuteResultSetCompleteNotification -> ExecuteRequests/ResultSetEvents
* QueryExecuteSubsetRequest -> SubsetRequest.cs
* Creating an inheritance pattern where
* `ExecuteRequestParamsBase` has execution options and ID for a query execute request
* `ExecuteDocumentSelectionParams` inherits from `ExecuteRequestParamsBase` and provides a document selection
* `ExecuteStringParams` inherits from `ExecuteRequestParamsBase` and provides the query text
* Adding a helper method to get SQL text based on request type
* Through the AWESOME POWER OF POLYMORPHISM, we are able to create a request for executing straight SQL basically for free.
* **Breaking change:** query/execute => query/executeDocumentSelection to make it more obvious what is expected.
* Adding unit tests for the code that gets SQL text
* Refactoring of execute contracts into their own namespace
* Refactoring application
* Adding new request for executing queries as strings
* Adding forgotten string request
* Changing the logic for checking the request param types
* Removing redundant declarations
This commit is contained in:
@@ -4,13 +4,13 @@
|
||||
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
|
||||
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests
|
||||
{
|
||||
/// <summary>
|
||||
/// Parameters to be sent back as part of a QueryExecuteBatchCompleteEvent to indicate that a
|
||||
/// batch of a query completed.
|
||||
/// Parameters to be sent back as part of a batch start or complete event to indicate that a
|
||||
/// batch of a query started or completed.
|
||||
/// </summary>
|
||||
public class QueryExecuteBatchNotificationParams
|
||||
public class BatchEventParams
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary of the batch that just completed
|
||||
@@ -23,17 +23,17 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
|
||||
public string OwnerUri { get; set; }
|
||||
}
|
||||
|
||||
public class QueryExecuteBatchCompleteEvent
|
||||
public class BatchCompleteEvent
|
||||
{
|
||||
public static readonly
|
||||
EventType<QueryExecuteBatchNotificationParams> Type =
|
||||
EventType<QueryExecuteBatchNotificationParams>.Create("query/batchComplete");
|
||||
EventType<BatchEventParams> Type =
|
||||
EventType<BatchEventParams>.Create("query/batchComplete");
|
||||
}
|
||||
|
||||
public class QueryExecuteBatchStartEvent
|
||||
public class BatchStartEvent
|
||||
{
|
||||
public static readonly
|
||||
EventType<QueryExecuteBatchNotificationParams> Type =
|
||||
EventType<QueryExecuteBatchNotificationParams>.Create("query/batchStart");
|
||||
EventType<BatchEventParams> Type =
|
||||
EventType<BatchEventParams>.Create("query/batchStart");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests
|
||||
{
|
||||
/// <summary>
|
||||
/// Parameters for executing a query from a document open in the workspace
|
||||
/// </summary>
|
||||
public class ExecuteDocumentSelectionParams : ExecuteRequestParamsBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The selection from the document
|
||||
/// </summary>
|
||||
public SelectionData QuerySelection { get; set; }
|
||||
}
|
||||
|
||||
public class ExecuteDocumentSelectionRequest
|
||||
{
|
||||
public static readonly
|
||||
RequestType<ExecuteDocumentSelectionParams, ExecuteRequestResult> Type =
|
||||
RequestType<ExecuteDocumentSelectionParams, ExecuteRequestResult>.Create("query/executeDocumentSelection");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests
|
||||
{
|
||||
/// <summary>
|
||||
/// Basic parameters that are required for executing a query
|
||||
/// </summary>
|
||||
public abstract class ExecuteRequestParamsBase
|
||||
{
|
||||
/// <summary>
|
||||
/// URI for the editor that is asking for the query execute
|
||||
/// </summary>
|
||||
public string OwnerUri { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Execution plan options
|
||||
/// </summary>
|
||||
public ExecutionPlanOptions ExecutionPlanOptions { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests
|
||||
{
|
||||
/// <summary>
|
||||
/// Parameters for the query execute result
|
||||
/// </summary>
|
||||
public class ExecuteRequestResult
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests
|
||||
{
|
||||
/// <summary>
|
||||
/// Parameters for executing a query directly
|
||||
/// </summary>
|
||||
public class ExecuteStringParams : ExecuteRequestParamsBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The query to execute
|
||||
/// </summary>
|
||||
public string Query { get; set; }
|
||||
}
|
||||
|
||||
public class ExecuteStringRequest
|
||||
{
|
||||
public static readonly
|
||||
RequestType<ExecuteStringParams, ExecuteRequestResult> Type =
|
||||
RequestType<ExecuteStringParams, ExecuteRequestResult>.Create("query/executeString");
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,12 @@
|
||||
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
|
||||
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests
|
||||
{
|
||||
/// <summary>
|
||||
/// Parameters to be sent back with a message notification
|
||||
/// </summary>
|
||||
public class QueryExecuteMessageParams
|
||||
public class MessageParams
|
||||
{
|
||||
/// <summary>
|
||||
/// URI for the editor that owns the query
|
||||
@@ -23,10 +23,10 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
|
||||
public ResultMessage Message { get; set; }
|
||||
}
|
||||
|
||||
public class QueryExecuteMessageEvent
|
||||
public class MessageEvent
|
||||
{
|
||||
public static readonly
|
||||
EventType<QueryExecuteMessageParams> Type =
|
||||
EventType<QueryExecuteMessageParams>.Create("query/message");
|
||||
EventType<MessageParams> Type =
|
||||
EventType<MessageParams>.Create("query/message");
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,12 @@
|
||||
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
|
||||
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests
|
||||
{
|
||||
/// <summary>
|
||||
/// Parameters to be sent back with a query execution complete event
|
||||
/// </summary>
|
||||
public class QueryExecuteCompleteParams
|
||||
public class QueryCompleteParams
|
||||
{
|
||||
/// <summary>
|
||||
/// URI for the editor that owns the query
|
||||
@@ -23,10 +23,10 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
|
||||
public BatchSummary[] BatchSummaries { get; set; }
|
||||
}
|
||||
|
||||
public class QueryExecuteCompleteEvent
|
||||
public class QueryCompleteEvent
|
||||
{
|
||||
public static readonly
|
||||
EventType<QueryExecuteCompleteParams> Type =
|
||||
EventType<QueryExecuteCompleteParams>.Create("query/complete");
|
||||
EventType<QueryCompleteParams> Type =
|
||||
EventType<QueryCompleteParams>.Create("query/complete");
|
||||
}
|
||||
}
|
||||
@@ -4,19 +4,22 @@
|
||||
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
|
||||
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests
|
||||
{
|
||||
public class QueryExecuteResultSetCompleteParams
|
||||
/// <summary>
|
||||
/// Parameters to return when a result set is started or completed
|
||||
/// </summary>
|
||||
public class ResultSetEventParams
|
||||
{
|
||||
public ResultSetSummary ResultSetSummary { get; set; }
|
||||
|
||||
public string OwnerUri { get; set; }
|
||||
}
|
||||
|
||||
public class QueryExecuteResultSetCompleteEvent
|
||||
public class ResultSetCompleteEvent
|
||||
{
|
||||
public static readonly
|
||||
EventType<QueryExecuteResultSetCompleteParams> Type =
|
||||
EventType<QueryExecuteResultSetCompleteParams>.Create("query/resultSetComplete");
|
||||
EventType<ResultSetEventParams> Type =
|
||||
EventType<ResultSetEventParams>.Create("query/resultSetComplete");
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Parameters for the query execute request
|
||||
/// </summary>
|
||||
public class QueryExecuteParams
|
||||
{
|
||||
/// <summary>
|
||||
/// The selection from the document
|
||||
/// </summary>
|
||||
public SelectionData QuerySelection { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// URI for the editor that is asking for the query execute
|
||||
/// </summary>
|
||||
public string OwnerUri { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Execution plan options
|
||||
/// </summary>
|
||||
public ExecutionPlanOptions ExecutionPlanOptions { get; set; }
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parameters for the query execute result
|
||||
/// </summary>
|
||||
public class QueryExecuteResult
|
||||
{
|
||||
}
|
||||
|
||||
public class QueryExecuteRequest
|
||||
{
|
||||
public static readonly
|
||||
RequestType<QueryExecuteParams, QueryExecuteResult> Type =
|
||||
RequestType<QueryExecuteParams, QueryExecuteResult>.Create("query/execute");
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
|
||||
/// <summary>
|
||||
/// Parameters for a query result subset retrieval request
|
||||
/// </summary>
|
||||
public class QueryExecuteSubsetParams
|
||||
public class SubsetParams
|
||||
{
|
||||
/// <summary>
|
||||
/// URI for the file that owns the query to look up the results for
|
||||
@@ -44,7 +44,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
|
||||
/// <summary>
|
||||
/// Parameters for the result of a subset retrieval request
|
||||
/// </summary>
|
||||
public class QueryExecuteSubsetResult
|
||||
public class SubsetResult
|
||||
{
|
||||
/// <summary>
|
||||
/// Subset request error messages. Optional, can be set to null to indicate no errors
|
||||
@@ -57,10 +57,10 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
|
||||
public ResultSetSubset ResultSubset { get; set; }
|
||||
}
|
||||
|
||||
public class QueryExecuteSubsetRequest
|
||||
public class SubsetRequest
|
||||
{
|
||||
public static readonly
|
||||
RequestType<QueryExecuteSubsetParams, QueryExecuteSubsetResult> Type =
|
||||
RequestType<QueryExecuteSubsetParams, QueryExecuteSubsetResult>.Create("query/subset");
|
||||
RequestType<SubsetParams, SubsetResult> Type =
|
||||
RequestType<SubsetParams, SubsetResult>.Create("query/subset");
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,12 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting;
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||
@@ -26,15 +26,12 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
{
|
||||
#region Singleton Instance Implementation
|
||||
|
||||
private static readonly Lazy<QueryExecutionService> instance = new Lazy<QueryExecutionService>(() => new QueryExecutionService());
|
||||
private static readonly Lazy<QueryExecutionService> LazyInstance = new Lazy<QueryExecutionService>(() => new QueryExecutionService());
|
||||
|
||||
/// <summary>
|
||||
/// Singleton instance of the query execution service
|
||||
/// </summary>
|
||||
public static QueryExecutionService Instance
|
||||
{
|
||||
get { return instance.Value; }
|
||||
}
|
||||
public static QueryExecutionService Instance => LazyInstance.Value;
|
||||
|
||||
private QueryExecutionService()
|
||||
{
|
||||
@@ -120,8 +117,9 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
public void InitializeService(ServiceHost serviceHost)
|
||||
{
|
||||
// Register handlers for requests
|
||||
serviceHost.SetRequestHandler(QueryExecuteRequest.Type, HandleExecuteRequest);
|
||||
serviceHost.SetRequestHandler(QueryExecuteSubsetRequest.Type, HandleResultSubsetRequest);
|
||||
serviceHost.SetRequestHandler(ExecuteDocumentSelectionRequest.Type, HandleExecuteRequest);
|
||||
serviceHost.SetRequestHandler(ExecuteStringRequest.Type, HandleExecuteRequest);
|
||||
serviceHost.SetRequestHandler(SubsetRequest.Type, HandleResultSubsetRequest);
|
||||
serviceHost.SetRequestHandler(QueryDisposeRequest.Type, HandleDisposeRequest);
|
||||
serviceHost.SetRequestHandler(QueryCancelRequest.Type, HandleCancelRequest);
|
||||
serviceHost.SetRequestHandler(SaveResultsAsCsvRequest.Type, HandleSaveResultsAsCsvRequest);
|
||||
@@ -146,23 +144,23 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
#region Request Handlers
|
||||
|
||||
/// <summary>
|
||||
/// Handles request to execute the query
|
||||
/// Handles request to execute a selection of a document in the workspace service
|
||||
/// </summary>
|
||||
public async Task HandleExecuteRequest(QueryExecuteParams executeParams,
|
||||
RequestContext<QueryExecuteResult> requestContext)
|
||||
public async Task HandleExecuteRequest(ExecuteRequestParamsBase executeDocumentSelectionParams,
|
||||
RequestContext<ExecuteRequestResult> requestContext)
|
||||
{
|
||||
// Get a query new active query
|
||||
Query newQuery = await CreateAndActivateNewQuery(executeParams, requestContext);
|
||||
Query newQuery = await CreateAndActivateNewQuery(executeDocumentSelectionParams, requestContext);
|
||||
|
||||
// Execute the query -- asynchronously
|
||||
ExecuteAndCompleteQuery(executeParams, requestContext, newQuery);
|
||||
ExecuteAndCompleteQuery(executeDocumentSelectionParams, requestContext, newQuery);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles a request to get a subset of the results of this query
|
||||
/// </summary>
|
||||
public async Task HandleResultSubsetRequest(QueryExecuteSubsetParams subsetParams,
|
||||
RequestContext<QueryExecuteSubsetResult> requestContext)
|
||||
public async Task HandleResultSubsetRequest(SubsetParams subsetParams,
|
||||
RequestContext<SubsetResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -170,7 +168,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
Query query;
|
||||
if (!ActiveQueries.TryGetValue(subsetParams.OwnerUri, out query))
|
||||
{
|
||||
await requestContext.SendResult(new QueryExecuteSubsetResult
|
||||
await requestContext.SendResult(new SubsetResult
|
||||
{
|
||||
Message = SR.QueryServiceRequestsNoQuery
|
||||
});
|
||||
@@ -178,7 +176,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
}
|
||||
|
||||
// Retrieve the requested subset and return it
|
||||
var result = new QueryExecuteSubsetResult
|
||||
var result = new SubsetResult
|
||||
{
|
||||
Message = null,
|
||||
ResultSubset = await query.GetSubset(subsetParams.BatchIndex,
|
||||
@@ -189,7 +187,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
catch (InvalidOperationException ioe)
|
||||
{
|
||||
// Return the error as a result
|
||||
await requestContext.SendResult(new QueryExecuteSubsetResult
|
||||
await requestContext.SendResult(new SubsetResult
|
||||
{
|
||||
Message = ioe.Message
|
||||
});
|
||||
@@ -197,7 +195,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
catch (ArgumentOutOfRangeException aoore)
|
||||
{
|
||||
// Return the error as a result
|
||||
await requestContext.SendResult(new QueryExecuteSubsetResult
|
||||
await requestContext.SendResult(new SubsetResult
|
||||
{
|
||||
Message = aoore.Message
|
||||
});
|
||||
@@ -342,7 +340,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
|
||||
#region Private Helpers
|
||||
|
||||
private async Task<Query> CreateAndActivateNewQuery(QueryExecuteParams executeParams, RequestContext<QueryExecuteResult> requestContext)
|
||||
private async Task<Query> CreateAndActivateNewQuery(ExecuteRequestParamsBase executeParams, RequestContext<ExecuteRequestResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -368,34 +366,8 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
// Apply execution parameter settings
|
||||
settings.ExecutionPlanOptions = executeParams.ExecutionPlanOptions;
|
||||
|
||||
// Get query text from the workspace.
|
||||
ScriptFile queryFile = WorkspaceService.Workspace.GetFile(executeParams.OwnerUri);
|
||||
|
||||
string queryText;
|
||||
|
||||
if (executeParams.QuerySelection != null)
|
||||
{
|
||||
string[] queryTextArray = queryFile.GetLinesInRange(
|
||||
new BufferRange(
|
||||
new BufferPosition(
|
||||
executeParams.QuerySelection.StartLine + 1,
|
||||
executeParams.QuerySelection.StartColumn + 1
|
||||
),
|
||||
new BufferPosition(
|
||||
executeParams.QuerySelection.EndLine + 1,
|
||||
executeParams.QuerySelection.EndColumn + 1
|
||||
)
|
||||
)
|
||||
);
|
||||
queryText = queryTextArray.Aggregate((a, b) => a + '\r' + '\n' + b);
|
||||
}
|
||||
else
|
||||
{
|
||||
queryText = queryFile.Contents;
|
||||
}
|
||||
|
||||
// If we can't add the query now, it's assumed the query is in progress
|
||||
Query newQuery = new Query(queryText, connectionInfo, settings, BufferFileFactory);
|
||||
Query newQuery = new Query(GetSqlText(executeParams), connectionInfo, settings, BufferFileFactory);
|
||||
if (!ActiveQueries.TryAdd(executeParams.OwnerUri, newQuery))
|
||||
{
|
||||
await requestContext.SendError(SR.QueryServiceQueryInProgress);
|
||||
@@ -404,7 +376,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
}
|
||||
|
||||
// Send the result stating that the query was successfully started
|
||||
await requestContext.SendResult(new QueryExecuteResult());
|
||||
await requestContext.SendResult(new ExecuteRequestResult());
|
||||
|
||||
return newQuery;
|
||||
}
|
||||
@@ -415,7 +387,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
}
|
||||
}
|
||||
|
||||
private static void ExecuteAndCompleteQuery(QueryExecuteParams executeParams, RequestContext<QueryExecuteResult> requestContext, Query query)
|
||||
private static void ExecuteAndCompleteQuery(ExecuteRequestParamsBase executeDocumentSelectionParams, RequestContext<ExecuteRequestResult> requestContext, Query query)
|
||||
{
|
||||
// Skip processing if the query is null
|
||||
if (query == null)
|
||||
@@ -427,24 +399,24 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
Query.QueryAsyncEventHandler callback = async q =>
|
||||
{
|
||||
// Send back the results
|
||||
QueryExecuteCompleteParams eventParams = new QueryExecuteCompleteParams
|
||||
QueryCompleteParams eventParams = new QueryCompleteParams
|
||||
{
|
||||
OwnerUri = executeParams.OwnerUri,
|
||||
OwnerUri = executeDocumentSelectionParams.OwnerUri,
|
||||
BatchSummaries = q.BatchSummaries
|
||||
};
|
||||
|
||||
await requestContext.SendEvent(QueryExecuteCompleteEvent.Type, eventParams);
|
||||
await requestContext.SendEvent(QueryCompleteEvent.Type, eventParams);
|
||||
};
|
||||
|
||||
Query.QueryAsyncErrorEventHandler errorCallback = async errorMessage =>
|
||||
{
|
||||
// Send back the error message
|
||||
QueryExecuteCompleteParams eventParams = new QueryExecuteCompleteParams
|
||||
QueryCompleteParams eventParams = new QueryCompleteParams
|
||||
{
|
||||
OwnerUri = executeParams.OwnerUri,
|
||||
OwnerUri = executeDocumentSelectionParams.OwnerUri,
|
||||
//Message = errorMessage
|
||||
};
|
||||
await requestContext.SendEvent(QueryExecuteCompleteEvent.Type, eventParams);
|
||||
await requestContext.SendEvent(QueryCompleteEvent.Type, eventParams);
|
||||
};
|
||||
|
||||
query.QueryCompleted += callback;
|
||||
@@ -454,48 +426,48 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
// Setup the batch callbacks
|
||||
Batch.BatchAsyncEventHandler batchStartCallback = async b =>
|
||||
{
|
||||
QueryExecuteBatchNotificationParams eventParams = new QueryExecuteBatchNotificationParams
|
||||
BatchEventParams eventParams = new BatchEventParams
|
||||
{
|
||||
BatchSummary = b.Summary,
|
||||
OwnerUri = executeParams.OwnerUri
|
||||
OwnerUri = executeDocumentSelectionParams.OwnerUri
|
||||
};
|
||||
|
||||
await requestContext.SendEvent(QueryExecuteBatchStartEvent.Type, eventParams);
|
||||
await requestContext.SendEvent(BatchStartEvent.Type, eventParams);
|
||||
};
|
||||
query.BatchStarted += batchStartCallback;
|
||||
|
||||
Batch.BatchAsyncEventHandler batchCompleteCallback = async b =>
|
||||
{
|
||||
QueryExecuteBatchNotificationParams eventParams = new QueryExecuteBatchNotificationParams
|
||||
BatchEventParams eventParams = new BatchEventParams
|
||||
{
|
||||
BatchSummary = b.Summary,
|
||||
OwnerUri = executeParams.OwnerUri
|
||||
OwnerUri = executeDocumentSelectionParams.OwnerUri
|
||||
};
|
||||
|
||||
await requestContext.SendEvent(QueryExecuteBatchCompleteEvent.Type, eventParams);
|
||||
await requestContext.SendEvent(BatchCompleteEvent.Type, eventParams);
|
||||
};
|
||||
query.BatchCompleted += batchCompleteCallback;
|
||||
|
||||
Batch.BatchAsyncMessageHandler batchMessageCallback = async m =>
|
||||
{
|
||||
QueryExecuteMessageParams eventParams = new QueryExecuteMessageParams
|
||||
MessageParams eventParams = new MessageParams
|
||||
{
|
||||
Message = m,
|
||||
OwnerUri = executeParams.OwnerUri
|
||||
OwnerUri = executeDocumentSelectionParams.OwnerUri
|
||||
};
|
||||
await requestContext.SendEvent(QueryExecuteMessageEvent.Type, eventParams);
|
||||
await requestContext.SendEvent(MessageEvent.Type, eventParams);
|
||||
};
|
||||
query.BatchMessageSent += batchMessageCallback;
|
||||
|
||||
// Setup the ResultSet completion callback
|
||||
ResultSet.ResultSetAsyncEventHandler resultCallback = async r =>
|
||||
{
|
||||
QueryExecuteResultSetCompleteParams eventParams = new QueryExecuteResultSetCompleteParams
|
||||
ResultSetEventParams eventParams = new ResultSetEventParams
|
||||
{
|
||||
ResultSetSummary = r.Summary,
|
||||
OwnerUri = executeParams.OwnerUri
|
||||
OwnerUri = executeDocumentSelectionParams.OwnerUri
|
||||
};
|
||||
await requestContext.SendEvent(QueryExecuteResultSetCompleteEvent.Type, eventParams);
|
||||
await requestContext.SendEvent(ResultSetCompleteEvent.Type, eventParams);
|
||||
};
|
||||
query.ResultSetCompleted += resultCallback;
|
||||
|
||||
@@ -539,6 +511,49 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
}
|
||||
}
|
||||
|
||||
// Internal for testing purposes
|
||||
internal string GetSqlText(ExecuteRequestParamsBase request)
|
||||
{
|
||||
// If it is a document selection, we'll retrieve the text from the document
|
||||
ExecuteDocumentSelectionParams docRequest = request as ExecuteDocumentSelectionParams;
|
||||
if (docRequest != null)
|
||||
{
|
||||
// Get the document from the parameters
|
||||
ScriptFile queryFile = WorkspaceService.Workspace.GetFile(docRequest.OwnerUri);
|
||||
|
||||
// If a selection was not provided, use the entire document
|
||||
if (docRequest.QuerySelection == null)
|
||||
{
|
||||
return queryFile.Contents;
|
||||
}
|
||||
|
||||
// A selection was provided, so get the lines in the selected range
|
||||
string[] queryTextArray = queryFile.GetLinesInRange(
|
||||
new BufferRange(
|
||||
new BufferPosition(
|
||||
docRequest.QuerySelection.StartLine + 1,
|
||||
docRequest.QuerySelection.StartColumn + 1
|
||||
),
|
||||
new BufferPosition(
|
||||
docRequest.QuerySelection.EndLine + 1,
|
||||
docRequest.QuerySelection.EndColumn + 1
|
||||
)
|
||||
)
|
||||
);
|
||||
return string.Join(Environment.NewLine, queryTextArray);
|
||||
}
|
||||
|
||||
// If it is an ExecuteStringParams, return the text as is
|
||||
ExecuteStringParams stringRequest = request as ExecuteStringParams;
|
||||
if (stringRequest != null)
|
||||
{
|
||||
return stringRequest.Query;
|
||||
}
|
||||
|
||||
// Note, this shouldn't be possible due to inheritance rules
|
||||
throw new InvalidCastException("Invalid request type");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDisposable Implementation
|
||||
|
||||
@@ -7,6 +7,7 @@ using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
using Xunit;
|
||||
|
||||
@@ -70,13 +71,13 @@ namespace Microsoft.SqlTools.ServiceLayer.PerfTests
|
||||
using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
|
||||
{
|
||||
await testService.ConnectForQuery(serverType, Scripts.DelayQuery, queryTempFile.FilePath, Common.PerfTestDatabaseName);
|
||||
var queryParams = new QueryExecuteParams
|
||||
var queryParams = new ExecuteDocumentSelectionParams
|
||||
{
|
||||
OwnerUri = queryTempFile.FilePath,
|
||||
QuerySelection = null
|
||||
};
|
||||
|
||||
var result = await testService.Driver.SendRequest(QueryExecuteRequest.Type, queryParams);
|
||||
var result = await testService.Driver.SendRequest(ExecuteDocumentSelectionRequest.Type, queryParams);
|
||||
if (result != null)
|
||||
{
|
||||
TestTimer timer = new TestTimer() { PrintResult = true };
|
||||
|
||||
@@ -9,6 +9,7 @@ using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests;
|
||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||
using Microsoft.SqlTools.ServiceLayer.TestDriver.Driver;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
@@ -157,9 +158,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Common
|
||||
/// <summary>
|
||||
/// Request the active SQL script is parsed for errors
|
||||
/// </summary>
|
||||
public async Task<QueryExecuteSubsetResult> RequestQueryExecuteSubset(QueryExecuteSubsetParams subsetParams)
|
||||
public async Task<SubsetResult> RequestQueryExecuteSubset(SubsetParams subsetParams)
|
||||
{
|
||||
return await Driver.SendRequest(QueryExecuteSubsetRequest.Type, subsetParams);
|
||||
return await Driver.SendRequest(SubsetRequest.Type, subsetParams);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -276,21 +277,21 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Common
|
||||
/// <summary>
|
||||
/// Run a query using a given connection bound to a URI
|
||||
/// </summary>
|
||||
public async Task<QueryExecuteCompleteParams> RunQueryAndWaitToComplete(string ownerUri, string query, int timeoutMilliseconds = 5000)
|
||||
public async Task<QueryCompleteParams> RunQueryAndWaitToComplete(string ownerUri, string query, int timeoutMilliseconds = 5000)
|
||||
{
|
||||
// Write the query text to a backing file
|
||||
WriteToFile(ownerUri, query);
|
||||
|
||||
var queryParams = new QueryExecuteParams
|
||||
var queryParams = new ExecuteDocumentSelectionParams
|
||||
{
|
||||
OwnerUri = ownerUri,
|
||||
QuerySelection = null
|
||||
};
|
||||
|
||||
var result = await Driver.SendRequest(QueryExecuteRequest.Type, queryParams);
|
||||
var result = await Driver.SendRequest(ExecuteDocumentSelectionRequest.Type, queryParams);
|
||||
if (result != null)
|
||||
{
|
||||
var eventResult = await Driver.WaitForEvent(QueryExecuteCompleteEvent.Type, timeoutMilliseconds);
|
||||
var eventResult = await Driver.WaitForEvent(QueryCompleteEvent.Type, timeoutMilliseconds);
|
||||
return eventResult;
|
||||
}
|
||||
else
|
||||
@@ -301,19 +302,19 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Common
|
||||
|
||||
/// <summary>
|
||||
/// Run a query using a given connection bound to a URI. This method only waits for the initial response from query
|
||||
/// execution (QueryExecuteResult). It is up to the caller to wait for the QueryExecuteCompleteEvent if they are interested.
|
||||
/// execution (QueryExecuteResult). It is up to the caller to wait for the QueryCompleteEvent if they are interested.
|
||||
/// </summary>
|
||||
public async Task<QueryExecuteResult> RunQueryAsync(string ownerUri, string query, int timeoutMilliseconds = 5000)
|
||||
public async Task<ExecuteRequestResult> RunQueryAsync(string ownerUri, string query, int timeoutMilliseconds = 5000)
|
||||
{
|
||||
WriteToFile(ownerUri, query);
|
||||
|
||||
var queryParams = new QueryExecuteParams
|
||||
var queryParams = new ExecuteDocumentSelectionParams
|
||||
{
|
||||
OwnerUri = ownerUri,
|
||||
QuerySelection = null
|
||||
};
|
||||
|
||||
return await Driver.SendRequest(QueryExecuteRequest.Type, queryParams);
|
||||
return await Driver.SendRequest(ExecuteDocumentSelectionRequest.Type, queryParams);
|
||||
}
|
||||
|
||||
public async Task RunQuery(TestServerType serverType, string databaseName, string query)
|
||||
@@ -408,16 +409,16 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Common
|
||||
/// <summary>
|
||||
/// Request a subset of results from a query
|
||||
/// </summary>
|
||||
public async Task<QueryExecuteSubsetResult> ExecuteSubset(string ownerUri, int batchIndex, int resultSetIndex, int rowStartIndex, int rowCount)
|
||||
public async Task<SubsetResult> ExecuteSubset(string ownerUri, int batchIndex, int resultSetIndex, int rowStartIndex, int rowCount)
|
||||
{
|
||||
var subsetParams = new QueryExecuteSubsetParams();
|
||||
var subsetParams = new SubsetParams();
|
||||
subsetParams.OwnerUri = ownerUri;
|
||||
subsetParams.BatchIndex = batchIndex;
|
||||
subsetParams.ResultSetIndex = resultSetIndex;
|
||||
subsetParams.RowsStartIndex = rowStartIndex;
|
||||
subsetParams.RowsCount = rowCount;
|
||||
|
||||
var result = await Driver.SendRequest(QueryExecuteSubsetRequest.Type, subsetParams);
|
||||
var result = await Driver.SendRequest(SubsetRequest.Type, subsetParams);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -425,9 +426,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Common
|
||||
/// Waits for a message to be returned by the service
|
||||
/// </summary>
|
||||
/// <returns>A message from the service layer</returns>
|
||||
public async Task<QueryExecuteMessageParams> WaitForMessage()
|
||||
public async Task<MessageParams> WaitForMessage()
|
||||
{
|
||||
return await Driver.WaitForEvent(QueryExecuteMessageEvent.Type);
|
||||
return await Driver.WaitForEvent(MessageEvent.Type);
|
||||
}
|
||||
|
||||
public void WriteToFile(string ownerUri, string query)
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests;
|
||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace;
|
||||
@@ -22,8 +23,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
||||
// ... I request a query (doesn't matter what kind) and execute it
|
||||
var workspaceService = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
||||
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
||||
var executeParams = new QueryExecuteParams { QuerySelection = Common.WholeDocument, OwnerUri = Common.OwnerUri };
|
||||
var executeRequest = RequestContextMocks.Create<QueryExecuteResult>(null);
|
||||
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = Common.WholeDocument, OwnerUri = Common.OwnerUri };
|
||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||
|
||||
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||
await queryService.ActiveQueries[Common.OwnerUri].ExecutionTask;
|
||||
@@ -51,8 +52,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
||||
// ... I request a query (doesn't matter what kind) and wait for execution
|
||||
var workspaceService = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
||||
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
||||
var executeParams = new QueryExecuteParams {QuerySelection = Common.WholeDocument, OwnerUri = Common.OwnerUri};
|
||||
var executeRequest = RequestContextMocks.Create<QueryExecuteResult>(null);
|
||||
var executeParams = new ExecuteDocumentSelectionParams {QuerySelection = Common.WholeDocument, OwnerUri = Common.OwnerUri};
|
||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||
|
||||
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||
await queryService.ActiveQueries[Common.OwnerUri].ExecutionTask;
|
||||
|
||||
@@ -14,6 +14,7 @@ using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
||||
@@ -96,6 +97,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
||||
public static Query GetBasicExecutedQuery(QueryExecutionSettings querySettings)
|
||||
{
|
||||
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;
|
||||
@@ -145,8 +147,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
||||
return output.ToArray();
|
||||
}
|
||||
|
||||
public static async Task AwaitExecution(QueryExecutionService service, QueryExecuteParams qeParams,
|
||||
RequestContext<QueryExecuteResult> requestContext)
|
||||
public static async Task AwaitExecution(QueryExecutionService service, ExecuteDocumentSelectionParams qeParams,
|
||||
RequestContext<ExecuteRequestResult> requestContext)
|
||||
{
|
||||
await service.HandleExecuteRequest(qeParams, requestContext);
|
||||
if (service.ActiveQueries.ContainsKey(qeParams.OwnerUri) && service.ActiveQueries[qeParams.OwnerUri].ExecutionTask != null)
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
||||
@@ -39,8 +40,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
||||
// ... I request a query (doesn't matter what kind)
|
||||
var workspaceService = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
||||
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
||||
var executeParams = new QueryExecuteParams {QuerySelection = null, OwnerUri = Common.OwnerUri};
|
||||
var executeRequest = RequestContextMocks.Create<QueryExecuteResult>(null);
|
||||
var executeParams = new ExecuteDocumentSelectionParams {QuerySelection = null, OwnerUri = Common.OwnerUri};
|
||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||
await queryService.ActiveQueries[Common.OwnerUri].ExecutionTask;
|
||||
|
||||
@@ -90,8 +91,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
||||
|
||||
// If:
|
||||
// ... I execute some bogus query
|
||||
var queryParams = new QueryExecuteParams { QuerySelection = Common.WholeDocument, OwnerUri = Common.OwnerUri };
|
||||
var requestContext = RequestContextMocks.Create<QueryExecuteResult>(null);
|
||||
var queryParams = new ExecuteDocumentSelectionParams { QuerySelection = Common.WholeDocument, OwnerUri = Common.OwnerUri };
|
||||
var requestContext = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||
await queryService.HandleExecuteRequest(queryParams, requestContext.Object);
|
||||
await queryService.ActiveQueries[Common.OwnerUri].ExecutionTask;
|
||||
|
||||
|
||||
@@ -3,30 +3,108 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests;
|
||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
||||
{
|
||||
public class ServiceIntegrationTests
|
||||
{
|
||||
#region Get SQL Tests
|
||||
|
||||
[Fact]
|
||||
public async Task QueryExecuteAllBatchesNoOp()
|
||||
public void GetSqlTextFromDocumentRequestFull()
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a workspace service with a multi-line constructed query
|
||||
// ... Create a query execution service without a connection service (we won't be
|
||||
// executing queries), and the previously created workspace service
|
||||
string query = string.Format("{0}{1}GO{1}{0}", Common.StandardQuery, Environment.NewLine);
|
||||
var workspaceService = GetDefaultWorkspaceService(query);
|
||||
var queryService = new QueryExecutionService(null, workspaceService);
|
||||
|
||||
// If: I attempt to get query text from execute document params (entire document)
|
||||
var queryParams = new ExecuteDocumentSelectionParams {OwnerUri = Common.OwnerUri, QuerySelection = Common.WholeDocument};
|
||||
var queryText = queryService.GetSqlText(queryParams);
|
||||
|
||||
// Then: The text should match the constructed query
|
||||
Assert.Equal(query, queryText);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetSqlTextFromDocumentRequestPartial()
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a workspace service with a multi-line constructed query
|
||||
string query = string.Format("{0}{1}GO{1}{0}", Common.StandardQuery, Environment.NewLine);
|
||||
var workspaceService = GetDefaultWorkspaceService(query);
|
||||
var queryService = new QueryExecutionService(null, workspaceService);
|
||||
|
||||
// If: I attempt to get query text from execute document params (partial document)
|
||||
var queryParams = new ExecuteDocumentSelectionParams {OwnerUri = Common.OwnerUri, QuerySelection = Common.SubsectionDocument};
|
||||
var queryText = queryService.GetSqlText(queryParams);
|
||||
|
||||
// Then: The text should be a subset of the constructed query
|
||||
Assert.Contains(queryText, query);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetSqlTextFromStringRequest()
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a query execution service without a connection service or workspace
|
||||
// service (we won't execute code that uses either
|
||||
var queryService = new QueryExecutionService(null, null);
|
||||
|
||||
// If: I attempt to get query text from execute string params
|
||||
var queryParams = new ExecuteStringParams {OwnerUri = Common.OwnerUri, Query = Common.StandardQuery};
|
||||
var queryText = queryService.GetSqlText(queryParams);
|
||||
|
||||
// Then: The text should match the standard query
|
||||
Assert.Equal(Common.StandardQuery, queryText);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetSqlTextFromInvalidType()
|
||||
{
|
||||
// Setup:
|
||||
// ... Mock up an implementation of ExecuteRequestParamsBase
|
||||
// ... Create a query execution service without a connection service or workspace
|
||||
// service (we won't execute code that uses either
|
||||
var mockParams = new Mock<ExecuteRequestParamsBase>().Object;
|
||||
var queryService = new QueryExecutionService(null, null);
|
||||
|
||||
// If: I attempt to get query text from the mock params
|
||||
// Then: It should throw an exception
|
||||
Assert.Throws<InvalidCastException>(() => queryService.GetSqlText(mockParams));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Execution Tests
|
||||
// NOTE: In order to limit test duplication, we're running the ExecuteDocumentSelection
|
||||
// version of execute query. The code paths are almost identical.
|
||||
|
||||
[Fact]
|
||||
private async Task QueryExecuteAllBatchesNoOp()
|
||||
{
|
||||
// If:
|
||||
// ... I request to execute a valid query with all batches as no op
|
||||
var workspaceService = GetDefaultWorkspaceService(string.Format("{0}\r\nGO\r\n{0}", Common.NoOpQuery));
|
||||
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
||||
var queryParams = new QueryExecuteParams {QuerySelection = Common.WholeDocument, OwnerUri = Common.OwnerUri};
|
||||
var queryParams = new ExecuteDocumentSelectionParams { QuerySelection = Common.WholeDocument, OwnerUri = Common.OwnerUri};
|
||||
|
||||
var efv = new EventFlowValidator<QueryExecuteResult>()
|
||||
var efv = new EventFlowValidator<ExecuteRequestResult>()
|
||||
.AddStandardQueryResultValidator()
|
||||
.AddStandardMessageValidator()
|
||||
.AddEventValidation(QueryExecuteCompleteEvent.Type, p =>
|
||||
.AddEventValidation(QueryCompleteEvent.Type, p =>
|
||||
{
|
||||
// Validate OwnerURI matches
|
||||
Assert.Equal(Common.OwnerUri, p.OwnerUri);
|
||||
@@ -50,9 +128,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
||||
// ... I request to execute a valid query with no results
|
||||
var workspaceService = GetDefaultWorkspaceService(Common.StandardQuery);
|
||||
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
||||
var queryParams = new QueryExecuteParams {QuerySelection = Common.WholeDocument, OwnerUri = Common.OwnerUri};
|
||||
var queryParams = new ExecuteDocumentSelectionParams { QuerySelection = Common.WholeDocument, OwnerUri = Common.OwnerUri};
|
||||
|
||||
var efv = new EventFlowValidator<QueryExecuteResult>()
|
||||
var efv = new EventFlowValidator<ExecuteRequestResult>()
|
||||
.AddStandardQueryResultValidator()
|
||||
.AddStandardBatchStartValidator()
|
||||
.AddStandardMessageValidator()
|
||||
@@ -78,9 +156,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
||||
var workspaceService = GetDefaultWorkspaceService(Common.StandardQuery);
|
||||
var queryService = Common.GetPrimedExecutionService(new[] {Common.StandardTestData}, true, false,
|
||||
workspaceService);
|
||||
var queryParams = new QueryExecuteParams {OwnerUri = Common.OwnerUri, QuerySelection = Common.WholeDocument};
|
||||
var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = Common.OwnerUri, QuerySelection = Common.WholeDocument};
|
||||
|
||||
var efv = new EventFlowValidator<QueryExecuteResult>()
|
||||
var efv = new EventFlowValidator<ExecuteRequestResult>()
|
||||
.AddStandardQueryResultValidator()
|
||||
.AddStandardBatchStartValidator()
|
||||
.AddStandardResultSetValidator()
|
||||
@@ -106,9 +184,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
||||
var workspaceService = GetDefaultWorkspaceService(Common.StandardQuery);
|
||||
var dataset = new[] {Common.StandardTestData, Common.StandardTestData};
|
||||
var queryService = Common.GetPrimedExecutionService(dataset, true, false, workspaceService);
|
||||
var queryParams = new QueryExecuteParams {OwnerUri = Common.OwnerUri, QuerySelection = Common.WholeDocument};
|
||||
var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = Common.OwnerUri, QuerySelection = Common.WholeDocument};
|
||||
|
||||
var efv = new EventFlowValidator<QueryExecuteResult>()
|
||||
var efv = new EventFlowValidator<ExecuteRequestResult>()
|
||||
.AddStandardQueryResultValidator()
|
||||
.AddStandardBatchStartValidator()
|
||||
.AddStandardResultSetValidator()
|
||||
@@ -134,9 +212,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
||||
var workspaceService = GetDefaultWorkspaceService(string.Format("{0}\r\nGO\r\n{0}", Common.StandardQuery));
|
||||
var dataSet = new[] {Common.StandardTestData};
|
||||
var queryService = Common.GetPrimedExecutionService(dataSet, true, false, workspaceService);
|
||||
var queryParams = new QueryExecuteParams {OwnerUri = Common.OwnerUri, QuerySelection = Common.WholeDocument};
|
||||
var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = Common.OwnerUri, QuerySelection = Common.WholeDocument};
|
||||
|
||||
var efv = new EventFlowValidator<QueryExecuteResult>()
|
||||
var efv = new EventFlowValidator<ExecuteRequestResult>()
|
||||
.AddStandardQueryResultValidator()
|
||||
.AddStandardBatchStartValidator()
|
||||
.AddStandardResultSetValidator()
|
||||
@@ -166,9 +244,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
||||
// ... I request to execute a query using a file URI that isn't connected
|
||||
var workspaceService = GetDefaultWorkspaceService(Common.StandardQuery);
|
||||
var queryService = Common.GetPrimedExecutionService(null, false, false, workspaceService);
|
||||
var queryParams = new QueryExecuteParams {OwnerUri = "notConnected", QuerySelection = Common.WholeDocument};
|
||||
var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = "notConnected", QuerySelection = Common.WholeDocument};
|
||||
|
||||
var efv = new EventFlowValidator<QueryExecuteResult>()
|
||||
var efv = new EventFlowValidator<ExecuteRequestResult>()
|
||||
.AddErrorValidation<string>(Assert.NotEmpty)
|
||||
.Complete();
|
||||
await Common.AwaitExecution(queryService, queryParams, efv.Object);
|
||||
@@ -188,15 +266,15 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
||||
// ... I request to execute a query
|
||||
var workspaceService = GetDefaultWorkspaceService(Common.StandardQuery);
|
||||
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
||||
var queryParams = new QueryExecuteParams {OwnerUri = Common.OwnerUri, QuerySelection = Common.WholeDocument};
|
||||
var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = Common.OwnerUri, QuerySelection = Common.WholeDocument};
|
||||
|
||||
// Note, we don't care about the results of the first request
|
||||
var firstRequestContext = RequestContextMocks.Create<QueryExecuteResult>(null);
|
||||
var firstRequestContext = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||
await Common.AwaitExecution(queryService, queryParams, firstRequestContext.Object);
|
||||
|
||||
// ... And then I request another query without waiting for the first to complete
|
||||
queryService.ActiveQueries[Common.OwnerUri].HasExecuted = false; // Simulate query hasn't finished
|
||||
var efv = new EventFlowValidator<QueryExecuteResult>()
|
||||
var efv = new EventFlowValidator<ExecuteRequestResult>()
|
||||
.AddErrorValidation<string>(Assert.NotEmpty)
|
||||
.Complete();
|
||||
await Common.AwaitExecution(queryService, queryParams, efv.Object);
|
||||
@@ -216,14 +294,14 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
||||
// ... I request to execute a query
|
||||
var workspaceService = GetDefaultWorkspaceService(Common.StandardQuery);
|
||||
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
||||
var queryParams = new QueryExecuteParams {OwnerUri = Common.OwnerUri, QuerySelection = Common.WholeDocument};
|
||||
var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = Common.OwnerUri, QuerySelection = Common.WholeDocument};
|
||||
|
||||
// Note, we don't care about the results of the first request
|
||||
var firstRequestContext = RequestContextMocks.Create<QueryExecuteResult>(null);
|
||||
var firstRequestContext = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||
await Common.AwaitExecution(queryService, queryParams, firstRequestContext.Object);
|
||||
|
||||
// ... And then I request another query after waiting for the first to complete
|
||||
var efv = new EventFlowValidator<QueryExecuteResult>()
|
||||
var efv = new EventFlowValidator<ExecuteRequestResult>()
|
||||
.AddStandardQueryResultValidator()
|
||||
.AddStandardBatchStartValidator()
|
||||
.AddStandardBatchCompleteValidator()
|
||||
@@ -250,9 +328,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
||||
// If:
|
||||
// ... I request to execute a query with a missing query string
|
||||
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
||||
var queryParams = new QueryExecuteParams {OwnerUri = Common.OwnerUri, QuerySelection = null};
|
||||
var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = Common.OwnerUri, QuerySelection = null};
|
||||
|
||||
var efv = new EventFlowValidator<QueryExecuteResult>()
|
||||
var efv = new EventFlowValidator<ExecuteRequestResult>()
|
||||
.AddErrorValidation<string>(Assert.NotEmpty)
|
||||
.Complete();
|
||||
await queryService.HandleExecuteRequest(queryParams, efv.Object);
|
||||
@@ -272,9 +350,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
||||
// ... I request to execute a query that is invalid
|
||||
var workspaceService = GetDefaultWorkspaceService(Common.StandardQuery);
|
||||
var queryService = Common.GetPrimedExecutionService(null, true, true, workspaceService);
|
||||
var queryParams = new QueryExecuteParams {OwnerUri = Common.OwnerUri, QuerySelection = Common.WholeDocument};
|
||||
var queryParams = new ExecuteDocumentSelectionParams {OwnerUri = Common.OwnerUri, QuerySelection = Common.WholeDocument};
|
||||
|
||||
var efv = new EventFlowValidator<QueryExecuteResult>()
|
||||
var efv = new EventFlowValidator<ExecuteRequestResult>()
|
||||
.AddStandardQueryResultValidator()
|
||||
.AddStandardBatchStartValidator()
|
||||
.AddStandardBatchCompleteValidator()
|
||||
@@ -290,6 +368,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
||||
Assert.Equal(1, queryService.ActiveQueries.Count);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private static WorkspaceService<SqlToolsSettings> GetDefaultWorkspaceService(string query)
|
||||
{
|
||||
WorkspaceService<SqlToolsSettings>.Instance.CurrentSettings = new SqlToolsSettings();
|
||||
@@ -300,8 +380,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
||||
|
||||
public static class EventFlowValidatorExtensions
|
||||
{
|
||||
public static EventFlowValidator<QueryExecuteResult> AddStandardQueryResultValidator(
|
||||
this EventFlowValidator<QueryExecuteResult> efv)
|
||||
public static EventFlowValidator<ExecuteRequestResult> AddStandardQueryResultValidator(
|
||||
this EventFlowValidator<ExecuteRequestResult> efv)
|
||||
{
|
||||
// We just need to makes sure we get a result back, there's no params to validate
|
||||
return efv.AddResultValidation(Assert.NotNull);
|
||||
@@ -310,7 +390,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
||||
public static EventFlowValidator<TRequestContext> AddStandardBatchStartValidator<TRequestContext>(
|
||||
this EventFlowValidator<TRequestContext> efv)
|
||||
{
|
||||
return efv.AddEventValidation(QueryExecuteBatchStartEvent.Type, p =>
|
||||
return efv.AddEventValidation(BatchStartEvent.Type, p =>
|
||||
{
|
||||
// Validate OwnerURI and batch summary is returned
|
||||
Assert.Equal(Common.OwnerUri, p.OwnerUri);
|
||||
@@ -321,7 +401,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
||||
public static EventFlowValidator<TRequestContext> AddStandardBatchCompleteValidator<TRequestContext>(
|
||||
this EventFlowValidator<TRequestContext> efv)
|
||||
{
|
||||
return efv.AddEventValidation(QueryExecuteBatchCompleteEvent.Type, p =>
|
||||
return efv.AddEventValidation(BatchCompleteEvent.Type, p =>
|
||||
{
|
||||
// Validate OwnerURI and result summary are returned
|
||||
Assert.Equal(Common.OwnerUri, p.OwnerUri);
|
||||
@@ -332,7 +412,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
||||
public static EventFlowValidator<TRequestContext> AddStandardMessageValidator<TRequestContext>(
|
||||
this EventFlowValidator<TRequestContext> efv)
|
||||
{
|
||||
return efv.AddEventValidation(QueryExecuteMessageEvent.Type, p =>
|
||||
return efv.AddEventValidation(MessageEvent.Type, p =>
|
||||
{
|
||||
// Validate OwnerURI and message are returned
|
||||
Assert.Equal(Common.OwnerUri, p.OwnerUri);
|
||||
@@ -343,7 +423,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
||||
public static EventFlowValidator<TRequestContext> AddStandardResultSetValidator<TRequestContext>(
|
||||
this EventFlowValidator<TRequestContext> efv)
|
||||
{
|
||||
return efv.AddEventValidation(QueryExecuteResultSetCompleteEvent.Type, p =>
|
||||
return efv.AddEventValidation(ResultSetCompleteEvent.Type, p =>
|
||||
{
|
||||
// Validate OwnerURI and summary are returned
|
||||
Assert.Equal(Common.OwnerUri, p.OwnerUri);
|
||||
@@ -354,7 +434,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
||||
public static EventFlowValidator<TRequestContext> AddStandardQueryCompleteValidator<TRequestContext>(
|
||||
this EventFlowValidator<TRequestContext> efv, int expectedBatches)
|
||||
{
|
||||
return efv.AddEventValidation(QueryExecuteCompleteEvent.Type, p =>
|
||||
return efv.AddEventValidation(QueryCompleteEvent.Type, p =>
|
||||
{
|
||||
Assert.Equal(Common.OwnerUri, p.OwnerUri);
|
||||
Assert.NotNull(p.BatchSummaries);
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||
using Xunit;
|
||||
@@ -38,7 +38,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExecutionPlanInvalid()
|
||||
public async Task ExecutionPlanInvalid()
|
||||
{
|
||||
// Setup:
|
||||
// ... I have a batch that has been executed
|
||||
@@ -50,7 +50,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
||||
|
||||
// Then:
|
||||
// ... It should throw an exception
|
||||
Assert.ThrowsAsync<Exception>(async () => await planResultSet.GetExecutionPlan());
|
||||
await Assert.ThrowsAsync<Exception>(() => planResultSet.GetExecutionPlan());
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -73,7 +73,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BatchExecutionPlanInvalidTest()
|
||||
public async Task BatchExecutionPlanInvalidTest()
|
||||
{
|
||||
// Setup:
|
||||
// ... I have a batch that has been executed without an execution plan
|
||||
@@ -81,13 +81,13 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
||||
|
||||
// If:
|
||||
// ... I ask for an invalid execution plan
|
||||
Assert.ThrowsAsync<Exception>(async () => await b.GetExecutionPlan(0));
|
||||
await Assert.ThrowsAsync<Exception>(() => b.GetExecutionPlan(0));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-1)] // Invalid result set, too low
|
||||
[InlineData(2)] // Invalid result set, too high
|
||||
public void BatchExecutionPlanInvalidParamsTest(int resultSetIndex)
|
||||
public async Task BatchExecutionPlanInvalidParamsTest(int resultSetIndex)
|
||||
{
|
||||
// If I have an executed batch which has an execution plan
|
||||
Batch b = Common.GetExecutedBatchWithExecutionPlan();
|
||||
@@ -95,7 +95,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
||||
// ... And I ask for an execution plan with an invalid result set index
|
||||
// Then:
|
||||
// ... It should throw an exception
|
||||
Assert.ThrowsAsync<ArgumentOutOfRangeException>(async () => await b.GetExecutionPlan(resultSetIndex));
|
||||
await Assert.ThrowsAsync<ArgumentOutOfRangeException>(() => b.GetExecutionPlan(resultSetIndex));
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -105,14 +105,16 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
||||
[Theory]
|
||||
[InlineData(-1)] // Invalid batch, too low
|
||||
[InlineData(2)] // Invalid batch, too high
|
||||
public void QueryExecutionPlanInvalidParamsTest(int batchIndex)
|
||||
public async Task QueryExecutionPlanInvalidParamsTest(int batchIndex)
|
||||
{
|
||||
// Setup query settings
|
||||
QueryExecutionSettings querySettings = new QueryExecutionSettings();
|
||||
querySettings.ExecutionPlanOptions = new ExecutionPlanOptions()
|
||||
{
|
||||
IncludeActualExecutionPlanXml = false,
|
||||
IncludeEstimatedExecutionPlanXml = true
|
||||
QueryExecutionSettings querySettings = new QueryExecutionSettings
|
||||
{
|
||||
ExecutionPlanOptions = new ExecutionPlanOptions
|
||||
{
|
||||
IncludeActualExecutionPlanXml = false,
|
||||
IncludeEstimatedExecutionPlanXml = true
|
||||
}
|
||||
};
|
||||
|
||||
// If I have an executed query
|
||||
@@ -121,7 +123,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
||||
// ... And I ask for a subset with an invalid result set index
|
||||
// Then:
|
||||
// ... It should throw an exception
|
||||
Assert.ThrowsAsync<ArgumentOutOfRangeException>(async () => await q.GetExecutionPlan(batchIndex, 0));
|
||||
await Assert.ThrowsAsync<ArgumentOutOfRangeException>(() => q.GetExecutionPlan(batchIndex, 0));
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -136,13 +138,17 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
||||
// ... I have a query that has results in the form of an execution plan
|
||||
var workspaceService = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
||||
var queryService = Common.GetPrimedExecutionService(new[] {Common.GetExecutionPlanTestData()}, true, false, workspaceService);
|
||||
var executeParams = new QueryExecuteParams {QuerySelection = null, OwnerUri = Common.OwnerUri};
|
||||
executeParams.ExecutionPlanOptions = new ExecutionPlanOptions()
|
||||
{
|
||||
IncludeActualExecutionPlanXml = false,
|
||||
IncludeEstimatedExecutionPlanXml = true
|
||||
var executeParams = new ExecuteDocumentSelectionParams
|
||||
{
|
||||
QuerySelection = null,
|
||||
OwnerUri = Common.OwnerUri,
|
||||
ExecutionPlanOptions = new ExecutionPlanOptions
|
||||
{
|
||||
IncludeActualExecutionPlanXml = false,
|
||||
IncludeEstimatedExecutionPlanXml = true
|
||||
}
|
||||
};
|
||||
var executeRequest = RequestContextMocks.Create<QueryExecuteResult>(null);
|
||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||
await queryService.ActiveQueries[Common.OwnerUri].ExecutionTask;
|
||||
|
||||
@@ -168,11 +174,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
||||
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
||||
var executionPlanParams = new QueryExecutionPlanParams { OwnerUri = Common.OwnerUri, ResultSetIndex = 0, BatchIndex = 0 };
|
||||
var executionPlanRequest = new EventFlowValidator<QueryExecutionPlanResult>()
|
||||
.AddErrorValidation<string>(r =>
|
||||
{
|
||||
// Then: It should return a populated error
|
||||
Assert.NotNull(r);
|
||||
}).Complete();
|
||||
.AddErrorValidation<string>(Assert.NotNull).Complete();
|
||||
await queryService.HandleExecutionPlanRequest(executionPlanParams, executionPlanRequest.Object);
|
||||
executionPlanRequest.Validate();
|
||||
}
|
||||
@@ -184,13 +186,17 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
||||
// ... I have a query that hasn't finished executing (doesn't matter what)
|
||||
var workspaceService = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
||||
var queryService = Common.GetPrimedExecutionService(new[] { Common.GetExecutionPlanTestData() }, true, false, workspaceService);
|
||||
var executeParams = new QueryExecuteParams { QuerySelection = null, OwnerUri = Common.OwnerUri };
|
||||
executeParams.ExecutionPlanOptions = new ExecutionPlanOptions()
|
||||
{
|
||||
IncludeActualExecutionPlanXml = false,
|
||||
IncludeEstimatedExecutionPlanXml = true
|
||||
var executeParams = new ExecuteDocumentSelectionParams
|
||||
{
|
||||
QuerySelection = null,
|
||||
OwnerUri = Common.OwnerUri,
|
||||
ExecutionPlanOptions = new ExecutionPlanOptions
|
||||
{
|
||||
IncludeActualExecutionPlanXml = false,
|
||||
IncludeEstimatedExecutionPlanXml = true
|
||||
}
|
||||
};
|
||||
var executeRequest = RequestContextMocks.Create<QueryExecuteResult>(null);
|
||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||
await queryService.ActiveQueries[Common.OwnerUri].ExecutionTask;
|
||||
queryService.ActiveQueries[Common.OwnerUri].Batches[0].ResultSets[0].hasBeenRead = false;
|
||||
@@ -198,11 +204,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
||||
// ... And I then ask for a valid execution plan from it
|
||||
var executionPlanParams = new QueryExecutionPlanParams { OwnerUri = Common.OwnerUri, ResultSetIndex = 0, BatchIndex = 0 };
|
||||
var executionPlanRequest = new EventFlowValidator<QueryExecutionPlanResult>()
|
||||
.AddErrorValidation<string>(r =>
|
||||
{
|
||||
// Then: It should return a populated error
|
||||
Assert.NotNull(r);
|
||||
}).Complete();
|
||||
.AddErrorValidation<string>(Assert.NotNull).Complete();
|
||||
await queryService.HandleExecutionPlanRequest(executionPlanParams, executionPlanRequest.Object);
|
||||
executionPlanRequest.Validate();
|
||||
}
|
||||
@@ -214,24 +216,24 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
||||
// ... I have a query that doesn't have any result sets
|
||||
var workspaceService = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
||||
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
||||
var executeParams = new QueryExecuteParams { QuerySelection = null, OwnerUri = Common.OwnerUri };
|
||||
executeParams.ExecutionPlanOptions = new ExecutionPlanOptions()
|
||||
{
|
||||
IncludeActualExecutionPlanXml = false,
|
||||
IncludeEstimatedExecutionPlanXml = true
|
||||
var executeParams = new ExecuteDocumentSelectionParams
|
||||
{
|
||||
QuerySelection = null,
|
||||
OwnerUri = Common.OwnerUri,
|
||||
ExecutionPlanOptions = new ExecutionPlanOptions
|
||||
{
|
||||
IncludeActualExecutionPlanXml = false,
|
||||
IncludeEstimatedExecutionPlanXml = true
|
||||
}
|
||||
};
|
||||
var executeRequest = RequestContextMocks.Create<QueryExecuteResult>(null);
|
||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||
await queryService.ActiveQueries[Common.OwnerUri].ExecutionTask;
|
||||
|
||||
// ... And I then ask for an execution plan from a result set
|
||||
var executionPlanParams = new QueryExecutionPlanParams { OwnerUri = Common.OwnerUri, ResultSetIndex = 0, BatchIndex = 0 };
|
||||
var executionPlanRequest = new EventFlowValidator<QueryExecutionPlanResult>()
|
||||
.AddErrorValidation<string>(r =>
|
||||
{
|
||||
// Then: It should return a populated error
|
||||
Assert.NotNull(r);
|
||||
}).Complete();
|
||||
.AddErrorValidation<string>(Assert.NotNull).Complete();
|
||||
await queryService.HandleExecutionPlanRequest(executionPlanParams, executionPlanRequest.Object);
|
||||
executionPlanRequest.Validate();
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
||||
@@ -59,8 +60,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
||||
QueryExecutionService qes = Common.GetPrimedExecutionService(new[] {Common.StandardTestData}, true, false, ws, out storage);
|
||||
|
||||
// ... The query execution service has executed a query with results
|
||||
var executeParams = new QueryExecuteParams { QuerySelection = null, OwnerUri = Common.OwnerUri };
|
||||
var executeRequest = RequestContextMocks.Create<QueryExecuteResult>(null);
|
||||
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Common.OwnerUri };
|
||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||
await qes.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||
await qes.ActiveQueries[Common.OwnerUri].ExecutionTask;
|
||||
|
||||
@@ -105,8 +106,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
||||
QueryExecutionService qes = Common.GetPrimedExecutionService(new[] {Common.StandardTestData}, true, false, ws, out storage);
|
||||
|
||||
// ... The query execution service has executed a query with results
|
||||
var executeParams = new QueryExecuteParams {QuerySelection = null, OwnerUri = Common.OwnerUri};
|
||||
var executeRequest = RequestContextMocks.Create<QueryExecuteResult>(null);
|
||||
var executeParams = new ExecuteDocumentSelectionParams {QuerySelection = null, OwnerUri = Common.OwnerUri};
|
||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||
await qes.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||
await qes.ActiveQueries[Common.OwnerUri].ExecutionTask;
|
||||
|
||||
@@ -176,8 +177,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
||||
QueryExecutionService qes = Common.GetPrimedExecutionService(new[] { Common.StandardTestData }, true, false, ws, out storage);
|
||||
|
||||
// ... The query execution service has executed a query with results
|
||||
var executeParams = new QueryExecuteParams { QuerySelection = null, OwnerUri = Common.OwnerUri };
|
||||
var executeRequest = RequestContextMocks.Create<QueryExecuteResult>(null);
|
||||
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Common.OwnerUri };
|
||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||
await qes.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||
await qes.ActiveQueries[Common.OwnerUri].ExecutionTask;
|
||||
|
||||
@@ -222,8 +223,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
||||
QueryExecutionService qes = Common.GetPrimedExecutionService(new[] { Common.StandardTestData }, true, false, ws, out storage);
|
||||
|
||||
// ... The query execution service has executed a query with results
|
||||
var executeParams = new QueryExecuteParams { QuerySelection = null, OwnerUri = Common.OwnerUri };
|
||||
var executeRequest = RequestContextMocks.Create<QueryExecuteResult>(null);
|
||||
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Common.OwnerUri };
|
||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||
await qes.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||
await qes.ActiveQueries[Common.OwnerUri].ExecutionTask;
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
||||
using Xunit;
|
||||
|
||||
@@ -131,14 +132,14 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
||||
// ... I have a query that has results (doesn't matter what)
|
||||
var workspaceService = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
||||
var queryService = Common.GetPrimedExecutionService(new[] {Common.StandardTestData}, true, false, workspaceService);
|
||||
var executeParams = new QueryExecuteParams {QuerySelection = null, OwnerUri = Common.OwnerUri};
|
||||
var executeRequest = RequestContextMocks.Create<QueryExecuteResult>(null);
|
||||
var executeParams = new ExecuteDocumentSelectionParams {QuerySelection = null, OwnerUri = Common.OwnerUri};
|
||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||
await queryService.ActiveQueries[Common.OwnerUri].ExecutionTask;
|
||||
|
||||
// ... And I then ask for a valid set of results from it
|
||||
var subsetParams = new QueryExecuteSubsetParams { OwnerUri = Common.OwnerUri, RowsCount = 1, ResultSetIndex = 0, RowsStartIndex = 0 };
|
||||
var subsetRequest = new EventFlowValidator<QueryExecuteSubsetResult>()
|
||||
var subsetParams = new SubsetParams { OwnerUri = Common.OwnerUri, RowsCount = 1, ResultSetIndex = 0, RowsStartIndex = 0 };
|
||||
var subsetRequest = new EventFlowValidator<SubsetResult>()
|
||||
.AddResultValidation(r =>
|
||||
{
|
||||
// Then: Messages should be null and subset should not be null
|
||||
@@ -156,8 +157,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
||||
// ... I ask for a set of results for a file that hasn't executed a query
|
||||
var workspaceService = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
||||
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
||||
var subsetParams = new QueryExecuteSubsetParams { OwnerUri = Common.OwnerUri, RowsCount = 1, ResultSetIndex = 0, RowsStartIndex = 0 };
|
||||
var subsetRequest = new EventFlowValidator<QueryExecuteSubsetResult>()
|
||||
var subsetParams = new SubsetParams { OwnerUri = Common.OwnerUri, RowsCount = 1, ResultSetIndex = 0, RowsStartIndex = 0 };
|
||||
var subsetRequest = new EventFlowValidator<SubsetResult>()
|
||||
.AddResultValidation(r =>
|
||||
{
|
||||
// Then: Messages should not be null and the subset should be null
|
||||
@@ -175,15 +176,15 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
||||
// ... I have a query that hasn't finished executing (doesn't matter what)
|
||||
var workspaceService = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
||||
var queryService = Common.GetPrimedExecutionService(new[] { Common.StandardTestData }, true, false, workspaceService);
|
||||
var executeParams = new QueryExecuteParams { QuerySelection = null, OwnerUri = Common.OwnerUri };
|
||||
var executeRequest = RequestContextMocks.Create<QueryExecuteResult>(null);
|
||||
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Common.OwnerUri };
|
||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||
await queryService.ActiveQueries[Common.OwnerUri].ExecutionTask;
|
||||
queryService.ActiveQueries[Common.OwnerUri].Batches[0].ResultSets[0].hasBeenRead = false;
|
||||
|
||||
// ... And I then ask for a valid set of results from it
|
||||
var subsetParams = new QueryExecuteSubsetParams { OwnerUri = Common.OwnerUri, RowsCount = 1, ResultSetIndex = 0, RowsStartIndex = 0 };
|
||||
var subsetRequest = new EventFlowValidator<QueryExecuteSubsetResult>()
|
||||
var subsetParams = new SubsetParams { OwnerUri = Common.OwnerUri, RowsCount = 1, ResultSetIndex = 0, RowsStartIndex = 0 };
|
||||
var subsetRequest = new EventFlowValidator<SubsetResult>()
|
||||
.AddResultValidation(r =>
|
||||
{
|
||||
// Then: There should not be a subset and message should not be null
|
||||
@@ -201,14 +202,14 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
||||
// ... I have a query that doesn't have any result sets
|
||||
var workspaceService = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
||||
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
||||
var executeParams = new QueryExecuteParams { QuerySelection = null, OwnerUri = Common.OwnerUri };
|
||||
var executeRequest = RequestContextMocks.Create<QueryExecuteResult>(null);
|
||||
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Common.OwnerUri };
|
||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||
await queryService.ActiveQueries[Common.OwnerUri].ExecutionTask;
|
||||
|
||||
// ... And I then ask for a set of results from it
|
||||
var subsetParams = new QueryExecuteSubsetParams { OwnerUri = Common.OwnerUri, RowsCount = 1, ResultSetIndex = 0, RowsStartIndex = 0 };
|
||||
var subsetRequest = new EventFlowValidator<QueryExecuteSubsetResult>()
|
||||
var subsetParams = new SubsetParams { OwnerUri = Common.OwnerUri, RowsCount = 1, ResultSetIndex = 0, RowsStartIndex = 0 };
|
||||
var subsetRequest = new EventFlowValidator<SubsetResult>()
|
||||
.AddResultValidation(r =>
|
||||
{
|
||||
// Then: There should be an error message and no subset
|
||||
|
||||
@@ -84,7 +84,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
}
|
||||
|
||||
// Run n queries at once
|
||||
var queryTasks = new Task<QueryExecuteCompleteParams>[queryCount];
|
||||
var queryTasks = new Task<QueryCompleteParams>[queryCount];
|
||||
for (int i = 0; i < queryCount; i++)
|
||||
{
|
||||
queryTasks[i] = TestService.RunQuery(ownerUris[i].FilePath, query);
|
||||
@@ -160,7 +160,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
await TestService.RunQuery(queryTempFile.FilePath, query);
|
||||
|
||||
// Spawn several tasks for subset requests
|
||||
var subsetTasks = new Task<QueryExecuteSubsetResult>[100];
|
||||
var subsetTasks = new Task<SubsetResult>[100];
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
subsetTasks[i] = TestService.ExecuteSubset(queryTempFile.FilePath, 0, 0, 0, 100);
|
||||
@@ -259,7 +259,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
}
|
||||
}
|
||||
|
||||
var subsetRequest = new QueryExecuteSubsetParams()
|
||||
var subsetRequest = new SubsetParams()
|
||||
{
|
||||
OwnerUri = queryTempFile.FilePath,
|
||||
BatchIndex = 0,
|
||||
|
||||
@@ -19,6 +19,7 @@ using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Channel;
|
||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Driver
|
||||
{
|
||||
@@ -121,7 +122,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Driver
|
||||
// Setup events to queue for testing
|
||||
this.QueueEventsForType(ConnectionCompleteNotification.Type);
|
||||
this.QueueEventsForType(IntelliSenseReadyNotification.Type);
|
||||
this.QueueEventsForType(QueryExecuteCompleteEvent.Type);
|
||||
this.QueueEventsForType(QueryCompleteEvent.Type);
|
||||
this.QueueEventsForType(PublishDiagnosticsNotification.Type);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user