mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 18:47:57 -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>
|
/// <summary>
|
||||||
/// filepath of scmp
|
/// filepath of scmp
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string filePath { get; set; }
|
public string FilePath { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -50,6 +50,11 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class SchemaCompareParams
|
public class SchemaCompareParams
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Operation id of the schema compare operation
|
||||||
|
/// </summary>
|
||||||
|
public string OperationId { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the source endpoint info
|
/// Gets or sets the source endpoint info
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -74,10 +74,10 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
|||||||
|
|
||||||
try
|
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
|
// 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()
|
this.Result = new SchemaCompareOpenScmpResult()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
|||||||
this.Parameters = parameters;
|
this.Parameters = parameters;
|
||||||
this.SourceConnectionString = SchemaCompareUtils.GetConnectionString(sourceConnInfo, parameters.SourceEndpointInfo.DatabaseName);
|
this.SourceConnectionString = SchemaCompareUtils.GetConnectionString(sourceConnInfo, parameters.SourceEndpointInfo.DatabaseName);
|
||||||
this.TargetConnectionString = SchemaCompareUtils.GetConnectionString(targetConnInfo, parameters.TargetEndpointInfo.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; } }
|
protected CancellationToken CancellationToken { get { return this.cancellation.Token; } }
|
||||||
|
|||||||
@@ -96,6 +96,10 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
|||||||
AreEqual = operation.ComparisonResult.IsEqual,
|
AreEqual = operation.ComparisonResult.IsEqual,
|
||||||
Differences = operation.Differences
|
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)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -126,7 +130,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
|||||||
Action cancelAction = null;
|
Action cancelAction = null;
|
||||||
if (currentComparisonCancellationAction.Value.TryRemove(parameters.OperationId, out cancelAction))
|
if (currentComparisonCancellationAction.Value.TryRemove(parameters.OperationId, out cancelAction))
|
||||||
{
|
{
|
||||||
if(cancelAction != null)
|
if (cancelAction != null)
|
||||||
{
|
{
|
||||||
cancelAction.Invoke();
|
cancelAction.Invoke();
|
||||||
await requestContext.SendResult(new ResultStatus()
|
await requestContext.SendResult(new ResultStatus()
|
||||||
@@ -136,11 +140,14 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
await requestContext.SendResult(new ResultStatus()
|
await requestContext.SendResult(new ResultStatus()
|
||||||
{
|
{
|
||||||
Success = false,
|
Success = false,
|
||||||
ErrorMessage = SR.SchemaCompareSessionNotFound
|
ErrorMessage = SR.SchemaCompareSessionNotFound
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|||||||
@@ -528,8 +528,9 @@ CREATE TABLE [dbo].[table3]
|
|||||||
[Fact]
|
[Fact]
|
||||||
public async Task VerifySchemaCompareServiceCalls()
|
public async Task VerifySchemaCompareServiceCalls()
|
||||||
{
|
{
|
||||||
string operationId = null;
|
string operationId = Guid.NewGuid().ToString();
|
||||||
DiffEntry diffEntry = null;
|
DiffEntry diffEntry = null;
|
||||||
|
bool cancelled = false;
|
||||||
var connectionObject = SchemaCompareTestUtils.GetLiveAutoCompleteTestObjects();
|
var connectionObject = SchemaCompareTestUtils.GetLiveAutoCompleteTestObjects();
|
||||||
|
|
||||||
SqlTestDb sourceDb = await SqlTestDb.CreateNewAsync(TestServerType.OnPrem, false, null, SourceScript, "SchemaCompareSource");
|
SqlTestDb sourceDb = await SqlTestDb.CreateNewAsync(TestServerType.OnPrem, false, null, SourceScript, "SchemaCompareSource");
|
||||||
@@ -550,15 +551,35 @@ CREATE TABLE [dbo].[table3]
|
|||||||
// Schema compare service call
|
// Schema compare service call
|
||||||
var schemaCompareRequestContext = new Mock<RequestContext<SchemaCompareResult>>();
|
var schemaCompareRequestContext = new Mock<RequestContext<SchemaCompareResult>>();
|
||||||
schemaCompareRequestContext.Setup((RequestContext<SchemaCompareResult> x) => x.SendResult(It.Is<SchemaCompareResult>((diffResult) =>
|
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
|
var schemaCompareParams = new SchemaCompareParams
|
||||||
{
|
{
|
||||||
|
OperationId = operationId,
|
||||||
SourceEndpointInfo = sourceInfo,
|
SourceEndpointInfo = sourceInfo,
|
||||||
TargetEndpointInfo = targetInfo,
|
TargetEndpointInfo = targetInfo,
|
||||||
DeploymentOptions = new DeploymentOptions()
|
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.HandleSchemaCompareRequest(schemaCompareParams, schemaCompareRequestContext.Object);
|
||||||
await SchemaCompareService.Instance.CurrentSchemaCompareTask;
|
await SchemaCompareService.Instance.CurrentSchemaCompareTask;
|
||||||
|
|
||||||
@@ -615,7 +636,19 @@ CREATE TABLE [dbo].[table3]
|
|||||||
ScmpFilePath = scmpFilePath
|
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;
|
await SchemaCompareService.Instance.CurrentSchemaCompareTask;
|
||||||
SchemaCompareTestUtils.VerifyAndCleanup(scmpFilePath);
|
SchemaCompareTestUtils.VerifyAndCleanup(scmpFilePath);
|
||||||
}
|
}
|
||||||
@@ -815,7 +848,7 @@ CREATE TABLE [dbo].[table3]
|
|||||||
|
|
||||||
var schemaCompareOpenScmpParams = new SchemaCompareOpenScmpParams
|
var schemaCompareOpenScmpParams = new SchemaCompareOpenScmpParams
|
||||||
{
|
{
|
||||||
filePath = filePath
|
FilePath = filePath
|
||||||
};
|
};
|
||||||
|
|
||||||
SchemaCompareOpenScmpOperation schemaCompareOpenScmpOperation = new SchemaCompareOpenScmpOperation(schemaCompareOpenScmpParams);
|
SchemaCompareOpenScmpOperation schemaCompareOpenScmpOperation = new SchemaCompareOpenScmpOperation(schemaCompareOpenScmpParams);
|
||||||
@@ -970,18 +1003,33 @@ CREATE TABLE [dbo].[table3]
|
|||||||
SchemaCompareTestUtils.VerifyAndCleanup(filePath);
|
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;
|
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);
|
diffEntry = diffResult.Differences.ElementAt(0);
|
||||||
return (diffResult.Success == true && diffResult.Differences != null && diffResult.Differences.Count > 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;
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
|
|
||||||
|
private bool ValidateScmpRoundtrip(SchemaCompareOpenScmpResult result, string sourceName, string targetName)
|
||||||
{
|
{
|
||||||
return false;
|
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