Separating Migration into its own project (#1828)

* Moving Migration service to its own project

* Adding loc files to the project

* Adding Migration to build

* Adding Migration Integration Tests

* Trying loops

* Fixing params

* Fixing indent

* Cleaning up yaml

* Getting command line arg for auto flush log

* Adding tde service
This commit is contained in:
Aasim Khan
2023-01-30 10:30:28 -08:00
committed by GitHub
parent 82171740bc
commit ab5a1e6c85
38 changed files with 6163 additions and 64 deletions

View File

@@ -0,0 +1,5 @@
ServerName,DatabaseName,LogicalName,PhysicalFullName,FileType,SizeMB,IsMemoryOptimizedDataOptionEnabled,TimeDataCollected
TEST,test,test,C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\test.mdf,Rows,3,False,2021-10-28 19:08:03
TEST,test,test_log,C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\test_log.ldf,Log,1,False,2021-10-28 19:08:03
TEST,test1,AdventureWorks2008R2_Data,C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\test1.mdf,Rows,195.9375,False,2021-10-28 19:08:03
TEST,test1,AdventureWorks2008R2_Log,C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\test1_1.LDF,Log,3.75,False,2021-10-28 19:08:03
1 ServerName DatabaseName LogicalName PhysicalFullName FileType SizeMB IsMemoryOptimizedDataOptionEnabled TimeDataCollected
2 TEST test test C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\test.mdf Rows 3 False 2021-10-28 19:08:03
3 TEST test test_log C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\test_log.ldf Log 1 False 2021-10-28 19:08:03
4 TEST test1 AdventureWorks2008R2_Data C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\test1.mdf Rows 195.9375 False 2021-10-28 19:08:03
5 TEST test1 AdventureWorks2008R2_Log C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\test1_1.LDF Log 3.75 False 2021-10-28 19:08:03

View File

@@ -0,0 +1,2 @@
ServerName,Edition,HyperthreadRatio,IsClustered,IsHadrEnabled,LogicalCpuCount,MaxServerMemoryInUse,NumberCoresUsed,NumberOfUserDatabases,PhysicalCpuCount,ProductVersion,SqlStartTime,SumOfUserDatabasesSize,TempDbSize,NumOfLogins,TimeDataCollected
TEST,Enterprise Edition (64-bit),2,False,False,2,2147483647,2,2,1,10.50.6592.0,2021-10-26 19:26:06,203,8,13,2021-10-28 19:08:03
1 ServerName Edition HyperthreadRatio IsClustered IsHadrEnabled LogicalCpuCount MaxServerMemoryInUse NumberCoresUsed NumberOfUserDatabases PhysicalCpuCount ProductVersion SqlStartTime SumOfUserDatabasesSize TempDbSize NumOfLogins TimeDataCollected
2 TEST Enterprise Edition (64-bit) 2 False False 2 2147483647 2 2 1 10.50.6592.0 2021-10-26 19:26:06 203 8 13 2021-10-28 19:08:03

View File

@@ -0,0 +1,121 @@
//
// 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.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.SqlTools.Hosting.Protocol;
using Microsoft.SqlTools.Migration.IntegrationTests.Utility;
using Microsoft.SqlTools.Migration.Contracts;
using Microsoft.SqlTools.ServiceLayer.Test.Common;
using Microsoft.SqlTools.ServiceLayer.Test.Common.RequestContextMocking;
using Moq;
using NUnit.Framework;
namespace Microsoft.SqlTools.Migration.IntegrationTests.Migration
{
public class MigrationServiceTests
{
[Test]
public async Task TestHandleMigrationAssessmentRequest()
{
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
{
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);
var requestParams = new MigrationAssessmentsParams()
{
ConnectionString = connectionResult.ConnectionInfo.ConnectionDetails.ConnectionString
};
var requestContext = new Mock<RequestContext<MigrationAssessmentResult>>();
MigrationService service = new MigrationService();
await service.HandleMigrationAssessmentsRequest(requestParams, requestContext.Object);
requestContext.VerifyAll();
}
}
[Test]
[Ignore("Disable failing test")]
public async Task TestHandleMigrationGetSkuRecommendationsRequest()
{
GetSkuRecommendationsResult result = null;
var requestParams = new GetSkuRecommendationsParams()
{
DataFolder = Path.Combine("..", "..", "..", "Migration", "Data"),
TargetPlatforms = new List<string> { "AzureSqlManagedInstance" },
TargetSqlInstance = "Test",
TargetPercentile = 95,
StartTime = new DateTime(2020, 01, 01).ToString("yyyy-MM-dd HH:mm:ss"),
EndTime = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"),
PerfQueryIntervalInSec = 30,
ScalingFactor = 1,
DatabaseAllowList = new List<string> { "test", "test1" }
};
var requestContext = RequestContextMocks.Create<GetSkuRecommendationsResult>(r => result = r).AddErrorHandling(null);
MigrationService service = new MigrationService();
await service.HandleGetSkuRecommendationsRequest(requestParams, requestContext.Object);
Assert.IsNotNull(result, "Get SKU Recommendation result is null");
Assert.IsNotNull(result.SqlMiRecommendationResults, "Get MI SKU Recommendation baseline result is null");
Assert.IsNotNull(result.ElasticSqlMiRecommendationResults, "Get MI SKU Recommendation elastic result is null");
// TODO: Include Negative Justification in future when we start recommending more than one SKU.
Assert.Greater(result.SqlMiRecommendationResults.First().PositiveJustifications.Count, 0, "No positive justification for MI SKU Recommendation result");
Assert.Greater(result.ElasticSqlMiRecommendationResults.First().PositiveJustifications.Count, 0, "No positive justification for MI SKU elastic Recommendation result");
Assert.IsNotNull(result.InstanceRequirements);
Assert.AreEqual(result.InstanceRequirements.InstanceId, "TEST");
Assert.AreEqual(result.InstanceRequirements.DatabaseLevelRequirements.Count, 2);
Assert.AreEqual(result.InstanceRequirements.DatabaseLevelRequirements.Sum(db => db.FileLevelRequirements.Count), 4);
}
[Test]
public async Task TestHandleStartStopPerfDataCollectionRequest()
{
StartPerfDataCollectionResult result = null;
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
{
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);
string folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "SkuRecommendationTest");
Directory.CreateDirectory(folderPath);
var requestParams = new StartPerfDataCollectionParams()
{
ConnectionString = connectionResult.ConnectionInfo.ConnectionDetails.ConnectionString,
DataFolder = folderPath,
PerfQueryIntervalInSec = 30,
NumberOfIterations = 20,
StaticQueryIntervalInSec = 3600,
};
var requestContext = RequestContextMocks.Create<StartPerfDataCollectionResult>(r => result = r).AddErrorHandling(null);
MigrationService service = new MigrationService();
await service.HandleStartPerfDataCollectionRequest(requestParams, requestContext.Object);
Assert.IsNotNull(result, "Start Perf Data Collection result is null");
Assert.IsNotNull(result.DateTimeStarted, "Time perf data collection started is null");
// Stop data collection
StopPerfDataCollectionResult stopResult = null;
var stopRequestParams = new StopPerfDataCollectionParams()
{
};
var stopRequestContext = RequestContextMocks.Create<StopPerfDataCollectionResult>(r => stopResult = r).AddErrorHandling(null);
await service.HandleStopPerfDataCollectionRequest(stopRequestParams, stopRequestContext.Object);
Assert.IsNotNull(stopResult, "Stop Perf Data Collection result is null");
Assert.IsNotNull(stopResult.DateTimeStopped, "Time perf data collection stoped is null");
}
}
}
}