Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Event Hubs Client] Track Two: Fourth Preview (AMQP Receiver Scope) #7903

Merged
merged 1 commit into from
Oct 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ namespace Azure.Messaging.EventHubs.CheckpointStore.Blob.Tests.Infrastructure
public sealed class StorageScope : IAsyncDisposable
{
/// <summary>The set of characters considered invalid in a blob container name.</summary>
private static readonly Regex s_invalidContainerCharactersExpression = new Regex("[^a-z0-9]", RegexOptions.IgnoreCase | RegexOptions.Compiled);
private static readonly Regex InvalidContainerCharactersExpression = new Regex("[^a-z0-9]", RegexOptions.IgnoreCase | RegexOptions.Compiled);

/// <summary>The manager for common live test resource operations.</summary>
private static readonly LiveResourceManager s_resourceManager = new LiveResourceManager();
private static readonly LiveResourceManager ResourceManager = new LiveResourceManager();

/// <summary>Serves as a sentinel flag to denote when the instance has been disposed.</summary>
private bool _disposed = false;
Expand Down Expand Up @@ -62,12 +62,12 @@ public async ValueTask DisposeAsync()

var resourceGroup = TestEnvironment.EventHubsResourceGroup;
var storageAccount = StorageTestEnvironment.StorageAccountName;
var token = await s_resourceManager.AquireManagementTokenAsync();
var token = await ResourceManager.AquireManagementTokenAsync();
var client = new StorageManagementClient(new TokenCredentials(token)) { SubscriptionId = TestEnvironment.EventHubsSubscription };

try
{
await s_resourceManager.CreateRetryPolicy().ExecuteAsync(() => client.BlobContainers.DeleteAsync(resourceGroup, storageAccount, ContainerName));
await ResourceManager.CreateRetryPolicy().ExecuteAsync(() => client.BlobContainers.DeleteAsync(resourceGroup, storageAccount, ContainerName));
}
catch
{
Expand Down Expand Up @@ -96,18 +96,18 @@ public async ValueTask DisposeAsync()
///
public static async Task<StorageScope> CreateAsync([CallerMemberName] string caller = "")
{
caller = s_invalidContainerCharactersExpression.Replace(caller.ToLowerInvariant(), string.Empty);
caller = InvalidContainerCharactersExpression.Replace(caller.ToLowerInvariant(), string.Empty);
caller = (caller.Length < 16) ? caller : caller.Substring(0, 15);

var resourceGroup = TestEnvironment.EventHubsResourceGroup;
var storageAccount = StorageTestEnvironment.StorageAccountName;
var token = await s_resourceManager.AquireManagementTokenAsync();
var token = await ResourceManager.AquireManagementTokenAsync();

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

using (var client = new StorageManagementClient(new TokenCredentials(token)) { SubscriptionId = TestEnvironment.EventHubsSubscription })
{
BlobContainer container = await s_resourceManager.CreateRetryPolicy().ExecuteAsync(() => client.BlobContainers.CreateAsync(resourceGroup, storageAccount, CreateName(), PublicAccess.None));
BlobContainer container = await ResourceManager.CreateRetryPolicy().ExecuteAsync(() => client.BlobContainers.CreateAsync(resourceGroup, storageAccount, CreateName(), PublicAccess.None));
return new StorageScope(container.Name);
}
}
Expand All @@ -123,18 +123,18 @@ public static async Task<StorageProperties> CreateStorageAccountAsync()
{
var subscription = TestEnvironment.EventHubsSubscription;
var resourceGroup = TestEnvironment.EventHubsResourceGroup;
var token = await s_resourceManager.AquireManagementTokenAsync();
var token = await ResourceManager.AquireManagementTokenAsync();

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

using (var client = new StorageManagementClient(new TokenCredentials(token)) { SubscriptionId = subscription })
{
var location = await s_resourceManager.QueryResourceGroupLocationAsync(token, resourceGroup, subscription);
var location = await ResourceManager.QueryResourceGroupLocationAsync(token, resourceGroup, subscription);
var sku = new Sku(SkuName.StandardLRS, SkuTier.Standard);
var parameters = new StorageAccountCreateParameters(sku, Kind.BlobStorage, location: location, tags: s_resourceManager.GenerateTags(), accessTier: AccessTier.Hot);
StorageAccount storageAccount = await s_resourceManager.CreateRetryPolicy<StorageAccount>().ExecuteAsync(() => client.StorageAccounts.CreateAsync(resourceGroup, CreateName(), parameters));
var parameters = new StorageAccountCreateParameters(sku, Kind.BlobStorage, location: location, tags: ResourceManager.GenerateTags(), accessTier: AccessTier.Hot);
StorageAccount storageAccount = await ResourceManager.CreateRetryPolicy<StorageAccount>().ExecuteAsync(() => client.StorageAccounts.CreateAsync(resourceGroup, CreateName(), parameters));

StorageAccountListKeysResult storageKeys = await s_resourceManager.CreateRetryPolicy<StorageAccountListKeysResult>().ExecuteAsync(() => client.StorageAccounts.ListKeysAsync(resourceGroup, storageAccount.Name));
StorageAccountListKeysResult storageKeys = await ResourceManager.CreateRetryPolicy<StorageAccountListKeysResult>().ExecuteAsync(() => client.StorageAccounts.ListKeysAsync(resourceGroup, storageAccount.Name));
return new StorageProperties(storageAccount.Name, $"DefaultEndpointsProtocol=https;AccountName={ storageAccount.Name };AccountKey={ storageKeys.Keys[0].Value };EndpointSuffix=core.windows.net");
}
}
Expand All @@ -150,11 +150,11 @@ public static async Task DeleteStorageAccountAsync(string accountName)
{
var subscription = TestEnvironment.EventHubsSubscription;
var resourceGroup = TestEnvironment.EventHubsResourceGroup;
var token = await s_resourceManager.AquireManagementTokenAsync();
var token = await ResourceManager.AquireManagementTokenAsync();

using (var client = new StorageManagementClient(new TokenCredentials(token)) { SubscriptionId = subscription })
{
await s_resourceManager.CreateRetryPolicy().ExecuteAsync(() => client.StorageAccounts.DeleteAsync(resourceGroup, accountName));
await ResourceManager.CreateRetryPolicy().ExecuteAsync(() => client.StorageAccounts.DeleteAsync(resourceGroup, accountName));
}
}

Expand Down
Loading