Skip to content

Commit

Permalink
[Event Hubs Client] Move Blob Checkpoint Store to Shared (#18395)
Browse files Browse the repository at this point in the history
The focus of these changes is to complete migration of the Blobs Checkpoint
Store from the `Azure.Messaging.EventHubs.Processor` project to the
`Azure.Messaging.EventHubs.Shared` project.  To facilitate sharing the
checkpoint store between the processor and the Functions extensions, the
implementation for the store was moved into the shared project, though its
tests remained in the processor.  In order to follow the pattern of keeping
locality between shared code items and their tests, the checkpoint store
tests, both unit and live, have been migrated to the shared testing project.

In support of this, some of the live testing infrastructure specific to
managing storage resources has also been migrated into the shared project
as part of the `BlobTesting` category of shared items.

Some refactoring and reformatting of the storge tests has also been performed
to improve consistency with other Event Hubs code, trim dead areas, and
improve readability.
  • Loading branch information
jsquire authored Feb 3, 2021
1 parent 1b5c007 commit 9079bd2
Show file tree
Hide file tree
Showing 21 changed files with 1,850 additions and 458 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,11 @@ partial void OwnershipNotClaimable(string partitionId,
/// <param name="consumerGroup">The name of the consumer group the ownership is associated with.</param>
/// <param name="ownerIdentifier">The identifier of the processor that attempted to claim the ownership for.</param>
///
partial void OwnershipClaimed(string partitionId, string fullyQualifiedNamespace, string eventHubName, string consumerGroup, string ownerIdentifier) =>
partial void OwnershipClaimed(string partitionId,
string fullyQualifiedNamespace,
string eventHubName,
string consumerGroup,
string ownerIdentifier) =>
Logger.OwnershipClaimed(partitionId, fullyQualifiedNamespace, eventHubName, consumerGroup, ownerIdentifier);

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,18 @@
<PackageReference Include="NUnit" />
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="Polly" />
<PackageReference Include="System.Memory.Data" />
<PackageReference Include="System.Net.WebSockets.Client" />
<PackageReference Include="System.Threading.Tasks.Extensions" />
<PackageReference Include="System.ValueTuple" />

<!-- This package will be removed when v5.3.0 is released for GA as the dependency will be available from Core -->
<PackageReference Include="System.Memory.Data" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(AzureCoreTestFramework)" />
<ProjectReference Include="..\src\Azure.Messaging.EventHubs.Processor.csproj" />
</ItemGroup>

<!-- TEMP: Use a project reference to Data; remove when published"-->
<!-- END TEMP-->

<!-- Import Event Hubs shared source -->
<Import Project="$(MSBuildThisFileDirectory)..\..\Azure.Messaging.EventHubs.Shared\src\Azure.Messaging.EventHubs.Shared.Testing.projitems" Label="Testing" />

<Import Project="$(MSBuildThisFileDirectory)..\..\Azure.Messaging.EventHubs.Shared\src\Azure.Messaging.EventHubs.Shared.BlobStorageTesting.projitems" Label="BlobStorageTesting" />
</Project>

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<HasSharedItems>true</HasSharedItems>
<SharedGUID>b9a2bfb3-5636-45b8-9e94-f429ebf3fc1d</SharedGUID>
</PropertyGroup>

<PropertyGroup>
<Import_RootNamespace>Azure.Messaging.EventHubs.Tests</Import_RootNamespace>
</PropertyGroup>

<ItemGroup>
<Compile Include="$(MSBuildThisfileDirectory)BlobStorageTesting\*.cs" Link="SharedSource\Testing\%(Filename)%(Extension)" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />

<!-- Import shared source groups -->
<Import Project="Azure.Messaging.EventHubs.Shared.Authorization.projitems" Label="Authorization" />
<Import Project="Azure.Messaging.EventHubs.Shared.BlobCheckpointStore.projitems" Label="BlobCheckpointStore" />
<Import Project="Azure.Messaging.EventHubs.Shared.BlobStorageTesting.projitems" Label="BlobStorageTesting" />
<Import Project="Azure.Messaging.EventHubs.Shared.Core.projitems" Label="Core" />
<Import Project="Azure.Messaging.EventHubs.Shared.Diagnostics.projitems" Label="Diagnostics" />
<Import Project="Azure.Messaging.EventHubs.Shared.Authorization.projitems" Label="Authorization" />
<Import Project="Azure.Messaging.EventHubs.Shared.Processor.projitems" Label="Processor" />
<Import Project="Azure.Messaging.EventHubs.Shared.Testing.projitems" Label="Testing" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Azure.Messaging.EventHubs.Tests;
using Microsoft.Azure.Management.ResourceManager;
using Microsoft.Azure.Management.Storage;
using Microsoft.Azure.Management.Storage.Models;
using Microsoft.Rest;

namespace Azure.Messaging.EventHubs.Processor.Tests
namespace Azure.Messaging.EventHubs.Tests
{
/// <summary>
/// Provides a dynamically created Azure blob container instance which exists only in the context
Expand All @@ -32,7 +31,7 @@ public sealed class StorageScope : IAsyncDisposable
private static readonly Uri AzureResourceManagerUri = new Uri(EventHubsTestEnvironment.Instance.ResourceManagerUrl);

/// <summary>Serves as a sentinel flag to denote when the instance has been disposed.</summary>
private bool _disposed = false;
private volatile bool _disposed = false;

/// <summary>
/// The name of the blob storage container that was created.
Expand Down Expand Up @@ -64,7 +63,7 @@ public async ValueTask DisposeAsync()

var resourceGroup = EventHubsTestEnvironment.Instance.ResourceGroup;
var storageAccount = StorageTestEnvironment.Instance.StorageAccountName;
var token = await ResourceManager.AquireManagementTokenAsync().ConfigureAwait(false);
var token = await ResourceManager.AcquireManagementTokenAsync().ConfigureAwait(false);
var client = new StorageManagementClient(AzureResourceManagerUri, new TokenCredentials(token)) { SubscriptionId = EventHubsTestEnvironment.Instance.SubscriptionId };

try
Expand Down Expand Up @@ -103,7 +102,7 @@ public static async Task<StorageScope> CreateAsync([CallerMemberName] string cal

var resourceGroup = EventHubsTestEnvironment.Instance.ResourceGroup;
var storageAccount = StorageTestEnvironment.Instance.StorageAccountName;
var token = await ResourceManager.AquireManagementTokenAsync().ConfigureAwait(false);
var token = await ResourceManager.AcquireManagementTokenAsync().ConfigureAwait(false);

string CreateName() => $"{ Guid.NewGuid().ToString("D").Substring(0, 13) }-{ caller }";

Expand All @@ -125,7 +124,7 @@ public static async Task<StorageScope> CreateAsync([CallerMemberName] string cal
{
var subscription = EventHubsTestEnvironment.Instance.SubscriptionId;
var resourceGroup = EventHubsTestEnvironment.Instance.ResourceGroup;
var token = await ResourceManager.AquireManagementTokenAsync().ConfigureAwait(false);
var token = await ResourceManager.AcquireManagementTokenAsync().ConfigureAwait(false);

static string CreateName() => $"neteventhubs{ Guid.NewGuid().ToString("N").Substring(0, 12) }";

Expand All @@ -152,7 +151,7 @@ public static async Task DeleteStorageAccountAsync(string accountName)
{
var subscription = EventHubsTestEnvironment.Instance.SubscriptionId;
var resourceGroup = EventHubsTestEnvironment.Instance.ResourceGroup;
var token = await ResourceManager.AquireManagementTokenAsync().ConfigureAwait(false);
var token = await ResourceManager.AcquireManagementTokenAsync().ConfigureAwait(false);

using (var client = new StorageManagementClient(AzureResourceManagerUri, new TokenCredentials(token)) { SubscriptionId = subscription })
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Threading.Tasks;
using Azure.Core.TestFramework;

namespace Azure.Messaging.EventHubs.Processor.Tests
namespace Azure.Messaging.EventHubs.Tests
{
/// <summary>
/// Represents the ambient environment for Azure storage resource in which the test suite is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public sealed class EventHubScope : IAsyncDisposable
private static readonly Uri AzureResourceManagerUri = new Uri(EventHubsTestEnvironment.Instance.ResourceManagerUrl);

/// <summary>Serves as a sentinel flag to denote when the instance has been disposed.</summary>
private bool _disposed = false;
private volatile bool _disposed = false;

/// <summary>
/// The name of the Event Hub that was created.
Expand Down Expand Up @@ -88,7 +88,7 @@ public async ValueTask DisposeAsync()

var resourceGroup = EventHubsTestEnvironment.Instance.ResourceGroup;
var eventHubNamespace = EventHubsTestEnvironment.Instance.EventHubsNamespace;
var token = await ResourceManager.AquireManagementTokenAsync().ConfigureAwait(false);
var token = await ResourceManager.AcquireManagementTokenAsync().ConfigureAwait(false);
var client = new EventHubManagementClient(AzureResourceManagerUri, new TokenCredentials(token)) { SubscriptionId = EventHubsTestEnvironment.Instance.SubscriptionId };

try
Expand Down Expand Up @@ -147,7 +147,7 @@ public static Task<EventHubScope> CreateAsync(int partitionCount,
{
var subscription = EventHubsTestEnvironment.Instance.SubscriptionId;
var resourceGroup = EventHubsTestEnvironment.Instance.ResourceGroup;
var token = await ResourceManager.AquireManagementTokenAsync().ConfigureAwait(false);
var token = await ResourceManager.AcquireManagementTokenAsync().ConfigureAwait(false);

string CreateName() => $"net-eventhubs-{ Guid.NewGuid().ToString("D") }";

Expand All @@ -174,7 +174,7 @@ public static async Task DeleteNamespaceAsync(string namespaceName)
{
var subscription = EventHubsTestEnvironment.Instance.SubscriptionId;
var resourceGroup = EventHubsTestEnvironment.Instance.ResourceGroup;
var token = await ResourceManager.AquireManagementTokenAsync().ConfigureAwait(false);
var token = await ResourceManager.AcquireManagementTokenAsync().ConfigureAwait(false);

using (var client = new EventHubManagementClient(AzureResourceManagerUri, new TokenCredentials(token)) { SubscriptionId = subscription })
{
Expand Down Expand Up @@ -218,7 +218,7 @@ private static Task<EventHubScope> BuildScope(int partitionCount,
///
private static async Task<EventHubScope> BuildScopeFromExistingEventHub()
{
var token = await ResourceManager.AquireManagementTokenAsync().ConfigureAwait(false);
var token = await ResourceManager.AcquireManagementTokenAsync().ConfigureAwait(false);

using (var client = new EventHubManagementClient(AzureResourceManagerUri, new TokenCredentials(token)) { SubscriptionId = EventHubsTestEnvironment.Instance.SubscriptionId })
{
Expand Down Expand Up @@ -253,7 +253,7 @@ private static async Task<EventHubScope> BuildScopeWithNewEventHub(int partition
var groups = (consumerGroups ?? Enumerable.Empty<string>()).ToList();
var resourceGroup = EventHubsTestEnvironment.Instance.ResourceGroup;
var eventHubNamespace = EventHubsTestEnvironment.Instance.EventHubsNamespace;
var token = await ResourceManager.AquireManagementTokenAsync().ConfigureAwait(false);
var token = await ResourceManager.AcquireManagementTokenAsync().ConfigureAwait(false);

string CreateName() => $"{ Guid.NewGuid().ToString("D").Substring(0, 13) }-{ caller }";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public async Task<string> QueryResourceGroupLocationAsync(string accessToken,
///
/// <returns>The token to use for management operations against the Event Hubs Live test namespace.</returns>
///
public async Task<string> AquireManagementTokenAsync()
public async Task<string> AcquireManagementTokenAsync()
{
var token = s_managementToken;
var authority = new Uri(new Uri(EventHubsTestEnvironment.Instance.AuthorityHostUrl), EventHubsTestEnvironment.Instance.TenantId).ToString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Azure.Storage.Blobs" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Microsoft.Azure.Management.EventHub" />
<PackageReference Include="Microsoft.Azure.Management.Storage" />
<PackageReference Include="Microsoft.Azure.Management.ResourceManager" />
<PackageReference Include="Microsoft.Azure.Services.AppAuthentication" />
<PackageReference Include="Moq" />
<PackageReference Include="NUnit" />
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="Moq" />
<PackageReference Include="Polly" />
</ItemGroup>

<ItemGroup>
Expand All @@ -29,17 +35,13 @@
</ItemGroup>

<!-- Import Event Hubs shared source -->
<Import Project="..\src\Azure.Messaging.EventHubs.Shared.Authorization.projitems" Label="Authorization" />
<Import Project="..\src\Azure.Messaging.EventHubs.Shared.BlobCheckpointStore.projitems" Label="CheckpointStore" />
<Import Project="..\src\Azure.Messaging.EventHubs.Shared.Core.projitems" Label="Core" />
<Import Project="..\src\Azure.Messaging.EventHubs.Shared.Diagnostics.projitems" Label="Diagnostics" />
<Import Project="..\src\Azure.Messaging.EventHubs.Shared.Authorization.projitems" Label="Authorization" />
<Import Project="..\src\Azure.Messaging.EventHubs.Shared.Processor.projitems" Label="Processor" />

<ItemGroup>
<Compile Include="..\src\Testing\EventDataExtensions.cs" Link="SharedSource\Testing\EventDataExtensions.cs" />
<Compile Include="..\src\Testing\InMemoryStorageManager.cs" Link="SharedSource\Testing\InMemoryStorageManager.cs" />
<Compile Include="..\src\Testing\MockEventData.cs" Link="SharedSource\Testing\MockEventData.cs" />
<Compile Include="..\src\Testing\TaskExtensions.cs" Link="SharedSource\Testing\TaskExtensions.cs" />
</ItemGroup>
<Import Project="..\src\Azure.Messaging.EventHubs.Shared.Testing.projitems" Label="Testing" />
<Import Project="..\src\Azure.Messaging.EventHubs.Shared.BlobStorageTesting.projitems" Label="BlobStorageTesting" />

<!--Embed the shared resources -->
<ItemGroup>
Expand Down
Loading

0 comments on commit 9079bd2

Please sign in to comment.