mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 09:59:48 -05:00
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
100 lines
4.0 KiB
C#
100 lines
4.0 KiB
C#
//
|
|
// Copyright (c) Microsoft. All rights reserved.
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
//
|
|
|
|
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;
|
|
|
|
namespace Microsoft.SqlTools.ServiceLayer.PerfTests
|
|
{
|
|
public class QueryExecutionTests
|
|
{
|
|
[Fact]
|
|
public async Task QueryResultSummaryOnPremTest()
|
|
{
|
|
TestServerType serverType = TestServerType.OnPrem;
|
|
|
|
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
|
using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
|
|
{
|
|
const string query = Scripts.MasterBasicQuery;
|
|
|
|
await testService.ConnectForQuery(serverType, query, queryTempFile.FilePath, SqlTestDb.MasterDatabaseName);
|
|
var queryResult = await testService.CalculateRunTime(() => testService.RunQueryAndWaitToComplete(queryTempFile.FilePath, query), true);
|
|
|
|
Assert.NotNull(queryResult);
|
|
Assert.True(queryResult.BatchSummaries.Any(x => x.ResultSetSummaries.Any(r => r.RowCount > 0)));
|
|
|
|
await testService.Disconnect(queryTempFile.FilePath);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public async Task QueryResultFirstOnPremTest()
|
|
{
|
|
TestServerType serverType = TestServerType.OnPrem;
|
|
|
|
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
|
using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
|
|
{
|
|
const string query = Scripts.MasterBasicQuery;
|
|
|
|
await testService.ConnectForQuery(serverType, query, queryTempFile.FilePath, SqlTestDb.MasterDatabaseName);
|
|
|
|
var queryResult = await testService.CalculateRunTime(async () =>
|
|
{
|
|
await testService.RunQueryAndWaitToComplete(queryTempFile.FilePath, query);
|
|
return await testService.ExecuteSubset(queryTempFile.FilePath, 0, 0, 0, 100);
|
|
}, true);
|
|
|
|
Assert.NotNull(queryResult);
|
|
Assert.NotNull(queryResult.ResultSubset);
|
|
Assert.True(queryResult.ResultSubset.Rows.Any());
|
|
|
|
await testService.Disconnect(queryTempFile.FilePath);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
[CreateTestDb(TestServerType.OnPrem)]
|
|
public async Task CancelQueryOnPremTest()
|
|
{
|
|
TestServerType serverType = TestServerType.OnPrem;
|
|
|
|
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
|
using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
|
|
{
|
|
await testService.ConnectForQuery(serverType, Scripts.DelayQuery, queryTempFile.FilePath, Common.PerfTestDatabaseName);
|
|
var queryParams = new ExecuteDocumentSelectionParams
|
|
{
|
|
OwnerUri = queryTempFile.FilePath,
|
|
QuerySelection = null
|
|
};
|
|
|
|
var result = await testService.Driver.SendRequest(ExecuteDocumentSelectionRequest.Type, queryParams);
|
|
if (result != null)
|
|
{
|
|
TestTimer timer = new TestTimer() { PrintResult = true };
|
|
await testService.ExecuteWithTimeout(timer, 100000, async () =>
|
|
{
|
|
var cancelQueryResult = await testService.CancelQuery(queryTempFile.FilePath);
|
|
return true;
|
|
}, TimeSpan.FromMilliseconds(10));
|
|
}
|
|
else
|
|
{
|
|
Assert.True(false, "Failed to run the query");
|
|
}
|
|
|
|
await testService.Disconnect(queryTempFile.FilePath);
|
|
}
|
|
}
|
|
}
|
|
}
|