mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-19 09:35:36 -05:00
Change to pass Schema compare Operation id from ADS (#828)
* Changing that SC Operation id be passed from ADS and some test addition * Fixing typos
This commit is contained in:
@@ -30,7 +30,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts
|
||||
/// <summary>
|
||||
/// filepath of scmp
|
||||
/// </summary>
|
||||
public string filePath { get; set; }
|
||||
public string FilePath { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -50,6 +50,11 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts
|
||||
/// </summary>
|
||||
public class SchemaCompareParams
|
||||
{
|
||||
/// <summary>
|
||||
/// Operation id of the schema compare operation
|
||||
/// </summary>
|
||||
public string OperationId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the source endpoint info
|
||||
/// </summary>
|
||||
|
||||
@@ -74,10 +74,10 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
|
||||
try
|
||||
{
|
||||
SchemaComparison compare = new SchemaComparison(this.Parameters.filePath);
|
||||
SchemaComparison compare = new SchemaComparison(this.Parameters.FilePath);
|
||||
|
||||
// load xml file because some parsing still needs to be done
|
||||
this.scmpInfo = XDocument.Load(this.Parameters.filePath);
|
||||
this.scmpInfo = XDocument.Load(this.Parameters.FilePath);
|
||||
|
||||
this.Result = new SchemaCompareOpenScmpResult()
|
||||
{
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
this.Parameters = parameters;
|
||||
this.SourceConnectionString = SchemaCompareUtils.GetConnectionString(sourceConnInfo, parameters.SourceEndpointInfo.DatabaseName);
|
||||
this.TargetConnectionString = SchemaCompareUtils.GetConnectionString(targetConnInfo, parameters.TargetEndpointInfo.DatabaseName);
|
||||
this.OperationId = Guid.NewGuid().ToString();
|
||||
this.OperationId = !string.IsNullOrEmpty(parameters.OperationId) ? parameters.OperationId : Guid.NewGuid().ToString();
|
||||
}
|
||||
|
||||
protected CancellationToken CancellationToken { get { return this.cancellation.Token; } }
|
||||
|
||||
@@ -96,6 +96,10 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
AreEqual = operation.ComparisonResult.IsEqual,
|
||||
Differences = operation.Differences
|
||||
});
|
||||
|
||||
// clean up cancellation action now that the operation is complete (using try remove to avoid exception)
|
||||
Action cancelAction = null;
|
||||
currentComparisonCancellationAction.Value.TryRemove(operation.OperationId, out cancelAction);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -126,7 +130,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
Action cancelAction = null;
|
||||
if (currentComparisonCancellationAction.Value.TryRemove(parameters.OperationId, out cancelAction))
|
||||
{
|
||||
if(cancelAction != null)
|
||||
if (cancelAction != null)
|
||||
{
|
||||
cancelAction.Invoke();
|
||||
await requestContext.SendResult(new ResultStatus()
|
||||
@@ -136,11 +140,14 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
});
|
||||
}
|
||||
}
|
||||
await requestContext.SendResult(new ResultStatus()
|
||||
else
|
||||
{
|
||||
Success = false,
|
||||
ErrorMessage = SR.SchemaCompareSessionNotFound
|
||||
});
|
||||
await requestContext.SendResult(new ResultStatus()
|
||||
{
|
||||
Success = false,
|
||||
ErrorMessage = SR.SchemaCompareSessionNotFound
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -183,7 +190,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
{
|
||||
Success = false,
|
||||
ErrorMessage = operation == null ? e.Message : operation.ErrorMessage,
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -340,7 +347,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
{
|
||||
operation = new SchemaCompareSaveScmpOperation(parameters, sourceConnInfo, targetConnInfo);
|
||||
operation.Execute(parameters.TaskExecutionMode);
|
||||
|
||||
|
||||
await requestContext.SendResult(new ResultStatus()
|
||||
{
|
||||
Success = true,
|
||||
@@ -357,7 +364,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
ErrorMessage = operation == null ? e.Message : operation.ErrorMessage,
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
@@ -528,8 +528,9 @@ CREATE TABLE [dbo].[table3]
|
||||
[Fact]
|
||||
public async Task VerifySchemaCompareServiceCalls()
|
||||
{
|
||||
string operationId = null;
|
||||
string operationId = Guid.NewGuid().ToString();
|
||||
DiffEntry diffEntry = null;
|
||||
bool cancelled = false;
|
||||
var connectionObject = SchemaCompareTestUtils.GetLiveAutoCompleteTestObjects();
|
||||
|
||||
SqlTestDb sourceDb = await SqlTestDb.CreateNewAsync(TestServerType.OnPrem, false, null, SourceScript, "SchemaCompareSource");
|
||||
@@ -550,15 +551,35 @@ CREATE TABLE [dbo].[table3]
|
||||
// Schema compare service call
|
||||
var schemaCompareRequestContext = new Mock<RequestContext<SchemaCompareResult>>();
|
||||
schemaCompareRequestContext.Setup((RequestContext<SchemaCompareResult> x) => x.SendResult(It.Is<SchemaCompareResult>((diffResult) =>
|
||||
ValidateScResult(diffResult, ref diffEntry, ref operationId)))).Returns(Task.FromResult(new object()));
|
||||
ValidateScResult(diffResult, out diffEntry, operationId, ref cancelled)))).Returns(Task.FromResult(new object()));
|
||||
|
||||
var schemaCompareParams = new SchemaCompareParams
|
||||
{
|
||||
OperationId = operationId,
|
||||
SourceEndpointInfo = sourceInfo,
|
||||
TargetEndpointInfo = targetInfo,
|
||||
DeploymentOptions = new DeploymentOptions()
|
||||
};
|
||||
|
||||
await SchemaCompareService.Instance.HandleSchemaCompareRequest(schemaCompareParams, schemaCompareRequestContext.Object);
|
||||
|
||||
// Schema compare Cancel call
|
||||
var schemaCompareCancelRequestContext = new Mock<RequestContext<ResultStatus>>();
|
||||
schemaCompareCancelRequestContext.Setup((RequestContext<ResultStatus> x) => x.SendResult(It.Is<ResultStatus>((result) =>
|
||||
result.Success == true))).Returns(Task.FromResult(new object()));
|
||||
|
||||
var schemaCompareCancelParams = new SchemaCompareCancelParams
|
||||
{
|
||||
OperationId = operationId
|
||||
};
|
||||
|
||||
cancelled = true;
|
||||
await SchemaCompareService.Instance.HandleSchemaCompareCancelRequest(schemaCompareCancelParams, schemaCompareCancelRequestContext.Object);
|
||||
await SchemaCompareService.Instance.CurrentSchemaCompareTask;
|
||||
|
||||
|
||||
// complete schema compare call for further testing
|
||||
cancelled = false;
|
||||
await SchemaCompareService.Instance.HandleSchemaCompareRequest(schemaCompareParams, schemaCompareRequestContext.Object);
|
||||
await SchemaCompareService.Instance.CurrentSchemaCompareTask;
|
||||
|
||||
@@ -615,7 +636,19 @@ CREATE TABLE [dbo].[table3]
|
||||
ScmpFilePath = scmpFilePath
|
||||
};
|
||||
|
||||
await SchemaCompareService.Instance.HandleSchemaCompareSaveScmpRequest(saveScmpParams, publishRequestContext.Object);
|
||||
await SchemaCompareService.Instance.HandleSchemaCompareSaveScmpRequest(saveScmpParams, saveScmpRequestContext.Object);
|
||||
await SchemaCompareService.Instance.CurrentSchemaCompareTask;
|
||||
|
||||
// Open Scmp service call
|
||||
var openScmpRequestContext = new Mock<RequestContext<SchemaCompareOpenScmpResult>>();
|
||||
openScmpRequestContext.Setup((RequestContext<SchemaCompareOpenScmpResult> x) => x.SendResult(It.Is<SchemaCompareOpenScmpResult>((result) => ValidateScmpRoundtrip(result, sourceDb.DatabaseName, targetDb.DatabaseName)))).Returns(Task.FromResult(new object()));
|
||||
|
||||
var openScmpParams = new SchemaCompareOpenScmpParams
|
||||
{
|
||||
FilePath = scmpFilePath
|
||||
};
|
||||
|
||||
await SchemaCompareService.Instance.HandleSchemaCompareOpenScmpRequest(openScmpParams, openScmpRequestContext.Object);
|
||||
await SchemaCompareService.Instance.CurrentSchemaCompareTask;
|
||||
SchemaCompareTestUtils.VerifyAndCleanup(scmpFilePath);
|
||||
}
|
||||
@@ -815,7 +848,7 @@ CREATE TABLE [dbo].[table3]
|
||||
|
||||
var schemaCompareOpenScmpParams = new SchemaCompareOpenScmpParams
|
||||
{
|
||||
filePath = filePath
|
||||
FilePath = filePath
|
||||
};
|
||||
|
||||
SchemaCompareOpenScmpOperation schemaCompareOpenScmpOperation = new SchemaCompareOpenScmpOperation(schemaCompareOpenScmpParams);
|
||||
@@ -970,18 +1003,33 @@ CREATE TABLE [dbo].[table3]
|
||||
SchemaCompareTestUtils.VerifyAndCleanup(filePath);
|
||||
}
|
||||
|
||||
private bool ValidateScResult(SchemaCompareResult diffResult, ref DiffEntry diffEntry, ref string operationId)
|
||||
private bool ValidateScResult(SchemaCompareResult diffResult, out DiffEntry diffEntry, string operationId, ref bool cancelled)
|
||||
{
|
||||
try
|
||||
if (cancelled)
|
||||
{
|
||||
operationId = diffResult.OperationId;
|
||||
diffEntry = diffResult.Differences.ElementAt(0);
|
||||
return (diffResult.Success == true && diffResult.Differences != null && diffResult.Differences.Count > 0);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
Assert.True(diffResult.Differences == null, "Differences should be null after cancel");
|
||||
Assert.True(diffResult.Success == false, "Result success for schema compare should be false after cancel");
|
||||
diffEntry = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
diffEntry = diffResult.Differences.ElementAt(0);
|
||||
Assert.True(diffResult.Success == true, "Result success is false for schema compare");
|
||||
Assert.True(diffResult.Differences != null, "Schema compare Differences should not be null");
|
||||
Assert.True(diffResult.Differences.Count > 0, "Schema compare difference count should be greater than 0");
|
||||
Assert.True(diffResult.OperationId == operationId, $"Expected Operation id {operationId}. Actual {diffResult.OperationId}");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private bool ValidateScmpRoundtrip(SchemaCompareOpenScmpResult result, string sourceName, string targetName)
|
||||
{
|
||||
Assert.True(true == result.Success, "Result Success is false");
|
||||
Assert.True(SchemaCompareEndpointType.Database == result.SourceEndpointInfo.EndpointType, $"Source Endpoint type does not match. Expected {SchemaCompareEndpointType.Database}. Actual {result.SourceEndpointInfo.EndpointType}");
|
||||
Assert.True(SchemaCompareEndpointType.Database == result.TargetEndpointInfo.EndpointType, $"Target Endpoint type does not match. Expected {SchemaCompareEndpointType.Database}. Actual {result.TargetEndpointInfo.EndpointType}");
|
||||
Assert.True(sourceName == result.SourceEndpointInfo.DatabaseName, $"Source Endpoint name does not match. Expected {sourceName}, Actual {result.SourceEndpointInfo.DatabaseName}");
|
||||
Assert.True(targetName == result.TargetEndpointInfo.DatabaseName, $"Source Endpoint name does not match. Expected {targetName}, Actual {result.TargetEndpointInfo.DatabaseName}");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user