-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Server side changes for Schema migration (#19)
* Initial commit * Minor cleanup * Fixes background job * Adds TestFixture * Skips e2e test * Addresses feedback * Fixes status consistency * Addresses feedback. * Adds index on timeout * Turned on automatic updates * Minor refactoring * Minor code refactor * Addresses feedback * Updates test and adds 2.diff.sql * Fixes fixture configuration * Adds a validation * Adds enum for SchemaVersion status * Fixes build
- Loading branch information
Showing
45 changed files
with
1,949 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,8 +113,6 @@ ipch/ | |
*.vspx | ||
*.sap | ||
|
||
# Visual Studio Trace Files | ||
*.e2e | ||
|
||
# TFS 2012 Local Workspace | ||
$tf/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/Microsoft.Health.SqlServer.Api.UnitTests/Features/CompatibilityVersionHandlerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using MediatR; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.DependencyInjection.Extensions; | ||
using Microsoft.Health.Extensions.DependencyInjection; | ||
using Microsoft.Health.SqlServer.Api.Features; | ||
using Microsoft.Health.SqlServer.Features.Schema; | ||
using Microsoft.Health.SqlServer.Features.Schema.Extensions; | ||
using Microsoft.Health.SqlServer.Features.Schema.Messages.Get; | ||
using Microsoft.Health.SqlServer.Features.Schema.Model; | ||
using NSubstitute; | ||
using Xunit; | ||
|
||
namespace Microsoft.Health.SqlServer.Api.UnitTests.Features | ||
{ | ||
public class CompatibilityVersionHandlerTests | ||
{ | ||
private readonly ISchemaDataStore _schemaMigrationDataStore; | ||
private readonly IMediator _mediator; | ||
private readonly CancellationToken _cancellationToken; | ||
|
||
public CompatibilityVersionHandlerTests() | ||
{ | ||
_schemaMigrationDataStore = Substitute.For<ISchemaDataStore>(); | ||
var collection = new ServiceCollection(); | ||
collection.Add(sp => new CompatibilityVersionHandler(_schemaMigrationDataStore)).Singleton().AsSelf().AsImplementedInterfaces(); | ||
|
||
ServiceProvider provider = collection.BuildServiceProvider(); | ||
_mediator = new Mediator(type => provider.GetService(type)); | ||
_cancellationToken = new CancellationTokenSource().Token; | ||
} | ||
|
||
[Fact] | ||
public async Task GivenAMediator_WhenCompatibleRequest_ThenReturnsCompatibleVersions() | ||
{ | ||
_schemaMigrationDataStore.GetLatestCompatibleVersionsAsync(Arg.Any<CancellationToken>()) | ||
.Returns(new CompatibleVersions(1, 3)); | ||
GetCompatibilityVersionResponse response = await _mediator.GetCompatibleVersionAsync(_cancellationToken); | ||
|
||
Assert.Equal(1, response.CompatibleVersions.Min); | ||
Assert.Equal(3, response.CompatibleVersions.Max); | ||
} | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
src/Microsoft.Health.SqlServer.Api.UnitTests/Features/CurrentVersionHandlerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using MediatR; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.DependencyInjection.Extensions; | ||
using Microsoft.Health.Extensions.DependencyInjection; | ||
using Microsoft.Health.SqlServer.Api.Features; | ||
using Microsoft.Health.SqlServer.Features.Schema; | ||
using Microsoft.Health.SqlServer.Features.Schema.Extensions; | ||
using Microsoft.Health.SqlServer.Features.Schema.Messages.Get; | ||
using Microsoft.Health.SqlServer.Features.Schema.Model; | ||
using NSubstitute; | ||
using Xunit; | ||
|
||
namespace Microsoft.Health.SqlServer.Api.UnitTests.Features | ||
{ | ||
public class CurrentVersionHandlerTests | ||
{ | ||
private readonly ISchemaDataStore _schemaDataStore; | ||
private readonly IMediator _mediator; | ||
private readonly CancellationToken _cancellationToken; | ||
|
||
public CurrentVersionHandlerTests() | ||
{ | ||
_schemaDataStore = Substitute.For<ISchemaDataStore>(); | ||
var collection = new ServiceCollection(); | ||
collection.Add(sp => new CurrentVersionHandler(_schemaDataStore)).Singleton().AsSelf().AsImplementedInterfaces(); | ||
|
||
ServiceProvider provider = collection.BuildServiceProvider(); | ||
_mediator = new Mediator(type => provider.GetService(type)); | ||
_cancellationToken = new CancellationTokenSource().Token; | ||
} | ||
|
||
[Fact] | ||
public async Task GivenACurrentMediator_WhenCurrentRequest_ThenReturnsCurrentVersionInformation() | ||
{ | ||
string status = "completed"; | ||
|
||
var mockCurrentVersions = new List<CurrentVersionInformation>() | ||
{ | ||
new CurrentVersionInformation(1, (SchemaVersionStatus)Enum.Parse(typeof(SchemaVersionStatus), status, true), new List<string>() { "server1", "server2" }), | ||
new CurrentVersionInformation(2, (SchemaVersionStatus)Enum.Parse(typeof(SchemaVersionStatus), status, true), new List<string>()), | ||
}; | ||
|
||
_schemaDataStore.GetCurrentVersionAsync(Arg.Any<CancellationToken>()) | ||
.Returns(mockCurrentVersions); | ||
GetCurrentVersionResponse response = await _mediator.GetCurrentVersionAsync(_cancellationToken); | ||
var currentVersionsResponse = response.CurrentVersions; | ||
|
||
Assert.Equal(mockCurrentVersions.Count, currentVersionsResponse.Count); | ||
Assert.Equal(1, currentVersionsResponse[0].Id); | ||
Assert.Equal(SchemaVersionStatus.Completed, currentVersionsResponse[0].Status); | ||
Assert.Equal(2, currentVersionsResponse[0].Servers.Count); | ||
} | ||
|
||
[Fact] | ||
public async Task GivenACurrentMediator_WhenCurrentRequestAndEmptySchemaVersionTable_ThenReturnsEmptyArray() | ||
{ | ||
var mockCurrentVersions = new List<CurrentVersionInformation>(); | ||
|
||
_schemaDataStore.GetCurrentVersionAsync(Arg.Any<CancellationToken>()) | ||
.Returns(mockCurrentVersions); | ||
|
||
GetCurrentVersionResponse response = await _mediator.GetCurrentVersionAsync(_cancellationToken); | ||
|
||
Assert.Equal(0, response.CurrentVersions.Count); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/Microsoft.Health.SqlServer.Api/Features/CompatibilityVersionHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using EnsureThat; | ||
using MediatR; | ||
using Microsoft.Health.SqlServer.Features.Schema; | ||
using Microsoft.Health.SqlServer.Features.Schema.Messages.Get; | ||
using Microsoft.Health.SqlServer.Features.Schema.Model; | ||
|
||
namespace Microsoft.Health.SqlServer.Api.Features | ||
{ | ||
public class CompatibilityVersionHandler : IRequestHandler<GetCompatibilityVersionRequest, GetCompatibilityVersionResponse> | ||
{ | ||
private readonly ISchemaDataStore _schemaDataStore; | ||
|
||
public CompatibilityVersionHandler(ISchemaDataStore schemaDataStore) | ||
{ | ||
EnsureArg.IsNotNull(schemaDataStore, nameof(schemaDataStore)); | ||
_schemaDataStore = schemaDataStore; | ||
} | ||
|
||
public async Task<GetCompatibilityVersionResponse> Handle(GetCompatibilityVersionRequest request, CancellationToken cancellationToken) | ||
{ | ||
EnsureArg.IsNotNull(request, nameof(request)); | ||
|
||
CompatibleVersions compatibleVersions = await _schemaDataStore.GetLatestCompatibleVersionsAsync(cancellationToken); | ||
|
||
return new GetCompatibilityVersionResponse(compatibleVersions); | ||
} | ||
} | ||
} |
Oops, something went wrong.