-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support ability to resume export (#544)
- Loading branch information
Showing
16 changed files
with
387 additions
and
93 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
48 changes: 48 additions & 0 deletions
48
...icrosoft.Health.Fhir.Azure.UnitTests/ExportDestinationClient/OrderedSetOfBlockIdsTests.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,48 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using System.Collections.Generic; | ||
using Microsoft.Health.Fhir.Azure.ExportDestinationClient; | ||
using Xunit; | ||
|
||
namespace Microsoft.Health.Fhir.Azure.UnitTests.ExportDestinationClient | ||
{ | ||
public class OrderedSetOfBlockIdsTests | ||
{ | ||
[Fact] | ||
public void GivenOrderedSetOfBlockIds_WhenAddingExistingItem_ThenItemDoesNotGetAdded() | ||
{ | ||
string item1 = "item1"; | ||
string item2 = "item2"; | ||
|
||
var orderedSetOfBlockIds = new OrderedSetOfBlockIds(); | ||
orderedSetOfBlockIds.Add(item1); | ||
orderedSetOfBlockIds.Add(item1); | ||
orderedSetOfBlockIds.Add(item2); | ||
|
||
var result = orderedSetOfBlockIds.ToList(); | ||
|
||
Assert.Equal(2, result.Count); | ||
Assert.Contains(item1, result); | ||
Assert.Contains(item2, result); | ||
} | ||
|
||
[Fact] | ||
public void GivenListContainingDuplicateItems_WhenCreatingOrderedSetOfBlockIds_ThenOnlyDistinctItemsAreAdded() | ||
{ | ||
string item1 = "item1"; | ||
string item2 = "item2"; | ||
var input = new List<string>() { item1, item2, item2, item2, item1 }; | ||
|
||
var orderedSetOfBlockIds = new OrderedSetOfBlockIds(input); | ||
|
||
var result = orderedSetOfBlockIds.ToList(); | ||
|
||
Assert.Equal(2, result.Count); | ||
Assert.Contains(item1, result); | ||
Assert.Contains(item2, result); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/Microsoft.Health.Fhir.Azure.UnitTests/Microsoft.Health.Fhir.Azure.UnitTests.csproj
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,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.2</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" /> | ||
<PackageReference Include="NSubstitute" Version="4.0.0" /> | ||
<PackageReference Include="xunit" Version="2.4.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Microsoft.Health.Fhir.Azure\Microsoft.Health.Fhir.Azure.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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
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
62 changes: 62 additions & 0 deletions
62
src/Microsoft.Health.Fhir.Azure/ExportDestinationClient/OrderedSetOfBlockIds.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,62 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using System.Collections.Generic; | ||
using EnsureThat; | ||
|
||
namespace Microsoft.Health.Fhir.Azure.ExportDestinationClient | ||
{ | ||
/// <summary> | ||
/// A modified implementation of an ordered hash set using a list and hashset. This class is specifically used | ||
/// for maintaining the existing block ids that are part of a blob in <see cref="CloudBlockBlobWrapper"/>. We need to | ||
/// maintain ordering of the block ids but also make sure that we don't have multiple copies of a block id. Hence | ||
/// the need for an ordered hash set. | ||
/// </summary> | ||
internal class OrderedSetOfBlockIds | ||
{ | ||
private readonly List<string> _itemList; | ||
private readonly HashSet<string> _itemSet; | ||
|
||
public OrderedSetOfBlockIds() | ||
{ | ||
_itemList = new List<string>(); | ||
_itemSet = new HashSet<string>(); | ||
} | ||
|
||
public OrderedSetOfBlockIds(IEnumerable<string> existingItems) | ||
: this() | ||
{ | ||
EnsureArg.IsNotNull(existingItems, nameof(existingItems)); | ||
|
||
foreach (string item in existingItems) | ||
{ | ||
Add(item); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Will add the given <see cref="item"/> if it is not present already. | ||
/// </summary> | ||
/// <param name="item">Item to be added to the <see cref="OrderedSetOfBlockIds"/></param> | ||
public void Add(string item) | ||
{ | ||
EnsureArg.IsNotNullOrWhiteSpace(item, nameof(item)); | ||
|
||
// Add item to list if the hashset does not contain it. | ||
if (_itemSet.Add(item)) | ||
{ | ||
_itemList.Add(item); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Returns a list of all items that were added to the <see cref="OrderedSetOfBlockIds"/> | ||
/// </summary> | ||
public List<string> ToList() | ||
{ | ||
return new List<string>(_itemList); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.