public async Task BlobContentHash() { string data = "hello world"; using Stream contentStream = new MemoryStream(Encoding.UTF8.GetBytes(data)); // precalculate hash for sample byte[] precalculatedContentHash; using (var md5 = MD5.Create()) { precalculatedContentHash = md5.ComputeHash(contentStream); } contentStream.Position = 0; // setup blob string containerName = Randomize("sample-container"); string blobName = Randomize("sample-file"); var containerClient = new BlobContainerClient(ConnectionString, containerName); try { containerClient.Create(); var blobClient = containerClient.GetBlobClient(blobName); #region Snippet:SampleSnippetsBlobMigration_BlobContentMD5 // upload with blob content hash await blobClient.UploadAsync( contentStream, new BlobUploadOptions() { HttpHeaders = new BlobHttpHeaders() { ContentHash = precalculatedContentHash } }); // download whole blob and validate against stored blob content hash Response <BlobDownloadInfo> response = await blobClient.DownloadAsync(); Stream downloadStream = response.Value.Content; byte[] blobContentMD5 = response.Value.Details.BlobContentHash ?? response.Value.ContentHash; // validate stream against hash in your workflow #endregion byte[] downloadedBytes; using (var memStream = new MemoryStream()) { await downloadStream.CopyToAsync(memStream); downloadedBytes = memStream.ToArray(); } Assert.AreEqual(data, Encoding.UTF8.GetString(downloadedBytes)); Assert.IsTrue(Enumerable.SequenceEqual(precalculatedContentHash, blobContentMD5)); } finally { await containerClient.DeleteIfExistsAsync(); } }
public async Task DownloadBlob() { string data = "hello world"; //setup blob string containerName = Randomize("sample-container"); string blobName = Randomize("sample-file"); var containerClient = new BlobContainerClient(ConnectionString, containerName); string downloadFilePath = this.CreateTempPath(); try { containerClient.Create(); containerClient.GetBlobClient(blobName).Upload(new MemoryStream(Encoding.UTF8.GetBytes(data))); #region Snippet:SampleSnippetsBlobMigration_DownloadBlob BlobClient blobClient = containerClient.GetBlobClient(blobName); await blobClient.DownloadToAsync(downloadFilePath); #endregion FileStream fs = File.OpenRead(downloadFilePath); string downloadedData = await new StreamReader(fs).ReadToEndAsync(); fs.Close(); Assert.AreEqual(data, downloadedData); } finally { await containerClient.DeleteIfExistsAsync(); } }
public async Task DownloadBlobText() { string data = "hello world"; //setup blob string containerName = Randomize("sample-container"); string blobName = Randomize("sample-file"); var containerClient = new BlobContainerClient(ConnectionString, containerName); try { containerClient.Create(); containerClient.GetBlobClient(blobName).Upload(BinaryData.FromString(data)); #region Snippet:SampleSnippetsBlobMigration_DownloadBlobText BlobClient blobClient = containerClient.GetBlobClient(blobName); BlobDownloadResult downloadResult = await blobClient.DownloadContentAsync(); string downloadedData = downloadResult.Content.ToString(); #endregion Assert.AreEqual(data, downloadedData); } finally { await containerClient.DeleteIfExistsAsync(); } }
public async Task MaximumExecutionTime() { string connectionString = this.ConnectionString; string data = "hello world"; //setup blob string containerName = Randomize("sample-container"); string blobName = Randomize("sample-file"); var containerClient = new BlobContainerClient(ConnectionString, containerName); try { await containerClient.CreateIfNotExistsAsync(); await containerClient.GetBlobClient(blobName).UploadAsync(BinaryData.FromString(data)); #region Snippet:SampleSnippetsBlobMigration_MaximumExecutionTime BlobClient blobClient = containerClient.GetBlobClient(blobName); CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); cancellationTokenSource.CancelAfter(TimeSpan.FromSeconds(30)); Stream targetStream = new MemoryStream(); await blobClient.DownloadToAsync(targetStream, cancellationTokenSource.Token); #endregion } finally { await containerClient.DeleteIfExistsAsync(); } Assert.Pass(); }
/// <summary> /// Performs the tasks needed to remove the dynamically created blob container. /// </summary> /// public async ValueTask DisposeAsync() { if (_disposed) { return; } try { var options = new BlobClientOptions(); options.Retry.MaxRetries = LiveResourceManager.RetryMaximumAttempts; var containerClient = new BlobContainerClient(StorageTestEnvironment.Instance.StorageConnectionString, ContainerName, options); await containerClient.DeleteIfExistsAsync().ConfigureAwait(false); } catch { // This should not be considered a critical failure that results in a test failure. Due // to ARM being temperamental, some management operations may be rejected. Throwing here // does not help to ensure resource cleanup only flags the test itself as a failure. // // If a blob container fails to be deleted, removing of the associated storage account at the end // of the test run will also remove the orphan. } _disposed = true; }
public async Task GivenABlobFile_WhenExecutorWithoutAnonymize_DataShouldBeSame(string connectionString, string containerName, string blobName) { string targetContainerName = Guid.NewGuid().ToString("N"); string targetBlobName = Guid.NewGuid().ToString("N"); BlobContainerClient containerClient = new BlobContainerClient(connectionString, targetContainerName); await containerClient.CreateIfNotExistsAsync(); try { BlobClient sourceBlobClient = new BlobClient(connectionString, containerName, blobName, DataFactoryCustomActivity.BlobClientOptions.Value); BlockBlobClient targetBlobClient = new BlockBlobClient(connectionString, targetContainerName, targetBlobName, DataFactoryCustomActivity.BlobClientOptions.Value); using FhirBlobDataStream stream = new FhirBlobDataStream(sourceBlobClient); using FhirStreamReader reader = new FhirStreamReader(stream); FhirBlobConsumer consumer = new FhirBlobConsumer(targetBlobClient); var executor = new FhirPartitionedExecutor <string, string>(reader, consumer, content => content); await executor.ExecuteAsync(CancellationToken.None).ConfigureAwait(false); Assert.Equal(sourceBlobClient.GetProperties().Value.ContentLength, targetBlobClient.GetProperties().Value.ContentLength); } finally { await containerClient.DeleteIfExistsAsync().ConfigureAwait(false); } }
public async Task GivenAFhirBlobStream_WhenDownloadData_AllDataShouldbeReturned() { string containerName = Guid.NewGuid().ToString("N"); string blobName = Guid.NewGuid().ToString("N"); BlobContainerClient containerClient = new BlobContainerClient("UseDevelopmentStorage=true", containerName); try { await containerClient.CreateIfNotExistsAsync(); var blobClient = containerClient.GetBlobClient(blobName); List <string> expectedResult = await GenerateTestBlob(blobClient); FhirBlobDataStream stream = new FhirBlobDataStream(blobClient); StreamReader reader = new StreamReader(stream); for (int i = 0; i < expectedResult.Count; ++i) { var content = await reader.ReadLineAsync(); Assert.Equal(expectedResult[i], content); } } finally { await containerClient.DeleteIfExistsAsync(); } }
public async Task <bool> DeleteContainerIfExistsAsync(string containerName) { var blobContainerClient = new BlobContainerClient(this.ConnectionString, containerName); var deleteInfo = await blobContainerClient.DeleteIfExistsAsync(); return(deleteInfo.Value); }
public async Task GivenValidDataClient_WhenExecuteTask_DataShouldBeSavedToBlob() { var containerName = Guid.NewGuid().ToString("N"); var taskExecutor = GetTaskExecutor(TestDataProvider.GetBundleFromFile(TestDataConstants.PatientBundleFile1), containerName); var typeFilters = new List <TypeFilter> { new ("Patient", null) }; var filterInfo = new FilterInfo(FilterScope.System, null, DateTimeOffset.MinValue, typeFilters, null); // Create an active job. var activeJob = Job.Create( containerName, JobStatus.Running, new DataPeriod(DateTimeOffset.MinValue, DateTimeOffset.MaxValue), filterInfo); var taskContext = TaskContext.CreateFromJob(activeJob, typeFilters); activeJob.RunningTasks[taskContext.Id] = taskContext; var jobUpdater = GetJobUpdater(activeJob); var taskResult = await taskExecutor.ExecuteAsync(taskContext, jobUpdater); // verify task result; Assert.True(taskResult.IsCompleted); Assert.Equal(3, taskResult.SearchCount["Patient"]); Assert.Equal(3, taskResult.ProcessedCount["Patient"]); Assert.Equal(0, taskResult.SkippedCount["Patient"]); jobUpdater.Complete(); await jobUpdater.Consume(); // verify blob data; var blobClient = new BlobContainerClient(TestBlobEndpoint, containerName); var blobPages = blobClient.GetBlobs(prefix: "staging").AsPages(); Assert.Single(blobPages.First().Values); // verify job data var jobBlob = blobClient.GetBlobClient($"{AzureBlobJobConstants.ActiveJobFolder}/{activeJob.Id}.json"); using var stream = new MemoryStream(); jobBlob.DownloadTo(stream); stream.Position = 0; using var streamReader = new StreamReader(stream); var jobContent = streamReader.ReadToEnd(); var job = JsonConvert.DeserializeObject <Job>(jobContent); Assert.Equal(activeJob.Id, job.Id); Assert.Empty(job.RunningTasks); Assert.Equal(3, job.ProcessedResourceCounts["Patient"]); Assert.Equal(3, job.TotalResourceCounts["Patient"]); Assert.Equal(0, job.SkippedResourceCounts["Patient"]); await blobClient.DeleteIfExistsAsync(); }
public async Task SasBuilderIdentifier() { string accountName = StorageAccountName; string accountKey = StorageAccountKey; string containerName = Randomize("sample-container"); string blobName = Randomize("sample-blob"); StorageSharedKeyCredential sharedKeyCredential = new StorageSharedKeyCredential(StorageAccountName, StorageAccountKey); // setup blob var container = new BlobContainerClient(ConnectionString, containerName); try { await container.CreateAsync(); await container.GetBlobClient(blobName).UploadAsync(new MemoryStream(Encoding.UTF8.GetBytes("hello world"))); // Create one or more stored access policies. List <BlobSignedIdentifier> signedIdentifiers = new List <BlobSignedIdentifier> { new BlobSignedIdentifier { Id = "mysignedidentifier", AccessPolicy = new BlobAccessPolicy { StartsOn = DateTimeOffset.UtcNow.AddHours(-1), ExpiresOn = DateTimeOffset.UtcNow.AddDays(1), Permissions = "rw" } } }; // Set the container's access policy. await container.SetAccessPolicyAsync(permissions : signedIdentifiers); #region Snippet:SampleSnippetsBlobMigration_SasBuilderIdentifier // Create BlobSasBuilder and specify parameters BlobSasBuilder sasBuilder = new BlobSasBuilder() { Identifier = "mysignedidentifier" }; #endregion // Create full, self-authenticating URI to the resource BlobUriBuilder uriBuilder = new BlobUriBuilder(StorageAccountBlobUri) { BlobContainerName = containerName, BlobName = blobName, Sas = sasBuilder.ToSasQueryParameters(sharedKeyCredential) }; Uri sasUri = uriBuilder.ToUri(); // successful download indicates pass await new BlobClient(sasUri).DownloadToAsync(new MemoryStream()); } finally { await container.DeleteIfExistsAsync(); } }
public async Task DeleteIfExistsAsync() { await Task.WhenAll( _container.DeleteIfExistsAsync(), _queue.DeleteIfExistsAsync(), _dlQueue.DeleteIfExistsAsync() ).ConfigureAwait(false); }
private static async Task DeleteContainerAsync() { Console.WriteLine($"5. Deleting blob container '{_blobContainerName}'"); var blobContainerClient = new BlobContainerClient(_connectionString, _blobContainerName); await blobContainerClient.DeleteIfExistsAsync(); }
public async Task ListBlobsHierarchy() { string data = "hello world"; string virtualDirName = Randomize("sample-virtual-dir"); string containerName = Randomize("sample-container"); var containerClient = new BlobContainerClient(ConnectionString, containerName); try { containerClient.Create(); foreach (var blobName in new List <string> { "foo.txt", "bar.txt", virtualDirName + "/fizz.txt", virtualDirName + "/buzz.txt" }) { containerClient.GetBlobClient(blobName).Upload(BinaryData.FromString(data)); } var expectedBlobNamesResult = new HashSet <string> { "foo.txt", "bar.txt" }; // tools to consume blob listing while looking good in the sample snippet HashSet <string> downloadedBlobNames = new HashSet <string>(); HashSet <string> downloadedPrefixNames = new HashSet <string>(); void MyConsumeBlobItemFunc(BlobHierarchyItem item) { if (item.IsPrefix) { downloadedPrefixNames.Add(item.Prefix); } else { downloadedBlobNames.Add(item.Blob.Name); } } // show in snippet where the prefix goes, but our test doesn't want a prefix for its data set string blobPrefix = null; string delimiter = "/"; #region Snippet:SampleSnippetsBlobMigration_ListHierarchy IAsyncEnumerable <BlobHierarchyItem> results = containerClient.GetBlobsByHierarchyAsync(prefix: blobPrefix, delimiter: delimiter); await foreach (BlobHierarchyItem item in results) { MyConsumeBlobItemFunc(item); } #endregion Assert.IsTrue(expectedBlobNamesResult.SetEquals(downloadedBlobNames)); Assert.IsTrue(new HashSet <string> { virtualDirName + '/' }.SetEquals(downloadedPrefixNames)); } finally { await containerClient.DeleteIfExistsAsync(); } }
public async Task ComputeNodeUploadLogs() { Func <Task> test = async() => { using (BatchClient batchCli = TestUtilities.OpenBatchClientFromEnvironmentAsync().Result) { const string containerName = "computenodelogscontainer"; // Generate a storage container URL StagingStorageAccount storageAccount = TestUtilities.GetStorageCredentialsFromEnvironment(); BlobServiceClient blobClient = BlobUtilities.GetBlobServiceClient(storageAccount); BlobContainerClient containerClient = BlobUtilities.GetBlobContainerClient(containerName, blobClient, storageAccount); try { containerClient.CreateIfNotExists(); string sasUri = BlobUtilities.GetWriteableSasUri(containerClient, storageAccount); var blobs = containerClient.GetAllBlobs(); // Ensure that there are no items in the container to begin with Assert.Empty(blobs); var startTime = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(5)); var node = batchCli.PoolOperations.ListComputeNodes(this.poolFixture.PoolId).First(); var result = batchCli.PoolOperations.UploadComputeNodeBatchServiceLogs( this.poolFixture.PoolId, node.Id, sasUri, startTime); Assert.NotEqual(0, result.NumberOfFilesUploaded); Assert.NotEmpty(result.VirtualDirectoryName); // Allow up to 2m for files to get uploaded DateTime timeoutAt = DateTime.UtcNow.AddMinutes(2); while (DateTime.UtcNow < timeoutAt) { blobs = containerClient.GetAllBlobs(); if (blobs.Any()) { break; } } Assert.NotEmpty(blobs); } finally { await containerClient.DeleteIfExistsAsync(); } } }; await SynchronizationContextHelper.RunTestAsync(test, TestTimeout); }
private static async Task DeleteContainer(BlobContainerClient container) { await container.DeleteIfExistsAsync(); do { await Task.Delay(1000); } while (await container.ExistsAsync()); }
public async Task UploadRangeFromUriAsync_SourceBearerToken() { // Arrange BlobServiceClient blobServiceClient = InstrumentClient(new BlobServiceClient( new Uri(TestConfigOAuth.BlobServiceEndpoint), GetOAuthCredential(TestConfigOAuth), GetBlobOptions())); BlobContainerClient containerClient = InstrumentClient(blobServiceClient.GetBlobContainerClient(GetNewShareName())); try { await containerClient.CreateIfNotExistsAsync(); AppendBlobClient appendBlobClient = InstrumentClient(containerClient.GetAppendBlobClient(GetNewFileName())); await appendBlobClient.CreateAsync(); byte[] data = GetRandomBuffer(Constants.KB); using Stream stream = new MemoryStream(data); await appendBlobClient.AppendBlockAsync(stream); ShareServiceClient serviceClient = GetServiceClient_OAuth_SharedKey(); await using DisposingShare test = await GetTestShareAsync( service : serviceClient, shareName : GetNewShareName()); ShareDirectoryClient directoryClient = InstrumentClient(test.Share.GetDirectoryClient(GetNewDirectoryName())); await directoryClient.CreateAsync(); ShareFileClient fileClient = InstrumentClient(directoryClient.GetFileClient(GetNewFileName())); await fileClient.CreateAsync(Constants.KB); string sourceBearerToken = await GetAuthToken(); HttpAuthorization sourceAuthHeader = new HttpAuthorization( "Bearer", sourceBearerToken); ShareFileUploadRangeFromUriOptions options = new ShareFileUploadRangeFromUriOptions { SourceAuthentication = sourceAuthHeader }; HttpRange range = new HttpRange(0, Constants.KB); // Act await fileClient.UploadRangeFromUriAsync( sourceUri : appendBlobClient.Uri, range : range, sourceRange : range, options : options); } finally { await containerClient.DeleteIfExistsAsync(); } }
public async Task UploadRangeFromUriAsync_SourceBearerTokenFail() { // Arrange BlobServiceClient blobServiceClient = InstrumentClient(new BlobServiceClient( new Uri(Tenants.TestConfigOAuth.BlobServiceEndpoint), Tenants.GetOAuthCredential(Tenants.TestConfigOAuth), GetBlobOptions())); BlobContainerClient containerClient = InstrumentClient(blobServiceClient.GetBlobContainerClient(GetNewShareName())); try { await containerClient.CreateIfNotExistsAsync(); AppendBlobClient appendBlobClient = InstrumentClient(containerClient.GetAppendBlobClient(GetNewFileName())); await appendBlobClient.CreateAsync(); byte[] data = GetRandomBuffer(Constants.KB); using Stream stream = new MemoryStream(data); await appendBlobClient.AppendBlockAsync(stream); ShareServiceClient serviceClient = SharesClientBuilder.GetServiceClient_OAuthAccount_SharedKey(); await using DisposingShare test = await GetTestShareAsync( service : serviceClient, shareName : GetNewShareName()); ShareDirectoryClient directoryClient = InstrumentClient(test.Share.GetDirectoryClient(GetNewDirectoryName())); await directoryClient.CreateAsync(); ShareFileClient fileClient = InstrumentClient(directoryClient.GetFileClient(GetNewFileName())); await fileClient.CreateAsync(Constants.KB); HttpAuthorization sourceAuthHeader = new HttpAuthorization( "Bearer", "auth token"); ShareFileUploadRangeFromUriOptions options = new ShareFileUploadRangeFromUriOptions { SourceAuthentication = sourceAuthHeader }; HttpRange range = new HttpRange(0, Constants.KB); // Act await TestHelper.AssertExpectedExceptionAsync <RequestFailedException>( fileClient.UploadRangeFromUriAsync( sourceUri: appendBlobClient.Uri, range: range, sourceRange: range, options: options), e => Assert.AreEqual("CannotVerifyCopySource", e.ErrorCode)); } finally { await containerClient.DeleteIfExistsAsync(); } }
public async Task ListBlobsManual() { string data = "hello world"; string containerName = Randomize("sample-container"); var containerClient = new BlobContainerClient(ConnectionString, containerName); try { containerClient.Create(); HashSet <string> blobNames = new HashSet <string>(); foreach (var _ in Enumerable.Range(0, 10)) { string blobName = Randomize("sample-blob"); containerClient.GetBlobClient(blobName).Upload(new MemoryStream(Encoding.UTF8.GetBytes(data))); blobNames.Add(blobName); } // tools to consume blob listing while looking good in the sample snippet HashSet <string> downloadedBlobNames = new HashSet <string>(); void MyConsumeBlobItemFunc(BlobItem item) { downloadedBlobNames.Add(item.Name); } #region Snippet:SampleSnippetsBlobMigration_ListBlobsManual // set this to already existing continuation token to pick up where you previously left off string initialContinuationToken = null; AsyncPageable <BlobItem> results = containerClient.GetBlobsAsync(); IAsyncEnumerable <Page <BlobItem> > pages = results.AsPages(initialContinuationToken); // the foreach loop requests the next page of results every loop // you do not need to explicitly access the continuation token just to get the next page // to stop requesting new pages, break from the loop // you also have access to the contination token returned with each page if needed await foreach (Page <BlobItem> page in pages) { // process page foreach (BlobItem item in page.Values) { MyConsumeBlobItemFunc(item); } // access continuation token if desired string continuationToken = page.ContinuationToken; } #endregion Assert.IsTrue(blobNames.SetEquals(downloadedBlobNames)); } finally { await containerClient.DeleteIfExistsAsync(); } }
public async Task DisposeAsync() { using (_blobClient as IDisposable) { BlobContainerClient blobContainer = _blobClient.GetBlobContainerClient(_blobContainerConfiguration.ContainerName); await blobContainer.DeleteIfExistsAsync(); BlobContainerClient metadataContainer = _blobClient.GetBlobContainerClient(_metadataContainerConfiguration.ContainerName); await metadataContainer.DeleteIfExistsAsync(); } }
private static async Task DeleteContainer(string connString) { try { BlobContainerClient containerClient = new BlobContainerClient(connString, "my-container"); await containerClient.DeleteIfExistsAsync(); } catch (Exception e) { Console.WriteLine("OH SNAP!: " + e.Message); } }
public async void RenewLease_WhenBlobNotExists_NoLeaseShouldReturn() { var uniqueContainerName = Guid.NewGuid().ToString("N"); AzureBlobContainerClient blobProvider = GetTestBlobProvider(ConnectionString, uniqueContainerName); string blobName = Guid.NewGuid().ToString("N"); await Assert.ThrowsAsync <AzureBlobOperationFailedException>(() => blobProvider.RenewLeaseAsync(blobName, null, default)); var blobContainerClient = new BlobContainerClient(ConnectionString, uniqueContainerName); await blobContainerClient.DeleteIfExistsAsync(); }
/// <summary> /// Basic operations to work with page blobs /// </summary> /// <returns>A Task object.</returns> private static async Task BasicStoragePageBlobOperationsAsync() { const string PageBlobName = "samplepageblob"; string containerName = ContainerPrefix + Guid.NewGuid(); // Retrieve storage account information from connection string BlobServiceClient blobServiceClient = Common.CreateblobServiceClientFromConnectionString(); // Create a container for organizing blobs within the storage account. Console.WriteLine("1. Creating Container"); BlobContainerClient container = blobServiceClient.GetBlobContainerClient(containerName); await container.CreateIfNotExistsAsync(); // Create a page blob in the newly created container. Console.WriteLine("2. Creating Page Blob"); PageBlobClient pageBlob = container.GetPageBlobClient(PageBlobName); await pageBlob.CreateAsync(512 * 2 /*size*/); // size needs to be multiple of 512 bytes // Write to a page blob Console.WriteLine("3. Write to a Page Blob"); byte[] samplePagedata = new byte[512]; Random random = new Random(); random.NextBytes(samplePagedata); using (var stream = new MemoryStream(samplePagedata)) { await pageBlob.UploadPagesAsync(stream, 0); } // List all blobs in this container. Because a container can contain a large number of blobs the results // are returned in segments with a maximum of 5000 blobs per segment. You can define a smaller maximum segment size // using the maxResults parameter on ListBlobsSegmentedAsync. Console.WriteLine("4. List Blobs in Container"); var resultSegment = container.GetBlobsAsync(); await foreach (var blob in resultSegment) { // Blob type will be BlobClient, CloudPageBlob or BlobClientDirectory Console.WriteLine("{0} (type: {1}", blob.Name, blob.GetType()); } // Read from a page blob Console.WriteLine("5. Read from a Page Blob"); var httpRange = new HttpRange(0, samplePagedata.Count()); var downloadInfo = await pageBlob.DownloadAsync(httpRange); // Clean up after the demo Console.WriteLine("6. Delete page Blob"); await pageBlob.DeleteIfExistsAsync(); Console.WriteLine("7. Delete Container"); await container.DeleteIfExistsAsync(); }
public async Task GivenAFhirBlobStream_WhenDownloadDataTimeout_OperationShouldBeRetried() { string containerName = Guid.NewGuid().ToString("N"); string blobName = Guid.NewGuid().ToString("N"); BlobContainerClient containerClient = new BlobContainerClient("UseDevelopmentStorage=true", containerName); try { await containerClient.CreateIfNotExistsAsync(); var blobClient = containerClient.GetBlobClient(blobName); List <string> expectedResult = await GenerateTestBlob(blobClient); FhirBlobDataStream stream = new FhirBlobDataStream(blobClient); Dictionary <long, int> enterRecord = new Dictionary <long, int>(); stream.BlockDownloadTimeoutRetryCount = 1; stream.BlockDownloadTimeoutInSeconds = 5; stream.DownloadDataFunc = async(client, range) => { if (!enterRecord.ContainsKey(range.Offset)) { enterRecord[range.Offset] = 0; } if (enterRecord[range.Offset]++ < 1) { Thread.Sleep(TimeSpan.FromSeconds(10)); } var downloadInfo = await client.DownloadAsync(range).ConfigureAwait(false); return(downloadInfo.Value.Content); }; StreamReader reader = new StreamReader(stream); for (int i = 0; i < expectedResult.Count; ++i) { var content = await reader.ReadLineAsync(); Assert.Equal(expectedResult[i], content); } foreach (int count in enterRecord.Values) { Assert.Equal(2, count); } } finally { await containerClient.DeleteIfExistsAsync(); } }
public async void AcquireLease_WhenBlobNotExists_NoLeaseShouldReturn() { var uniqueContainerName = Guid.NewGuid().ToString("N"); AzureBlobContainerClient blobProvider = GetTestBlobProvider(ConnectionString, uniqueContainerName); string blobName = Guid.NewGuid().ToString("N"); var lease = await blobProvider.AcquireLeaseAsync(blobName, null, TimeSpan.FromSeconds(30), default); Assert.Null(lease); var blobContainerClient = new BlobContainerClient(ConnectionString, uniqueContainerName); await blobContainerClient.DeleteIfExistsAsync(); }
public async void ReleaseLease_WhenBlobNotExists_NoLeaseShouldReturn() { var uniqueContainerName = Guid.NewGuid().ToString("N"); AzureBlobContainerClient blobProvider = GetTestBlobProvider(ConnectionString, uniqueContainerName); string blobName = Guid.NewGuid().ToString("N"); var result = await blobProvider.ReleaseLeaseAsync(blobName, null, default); Assert.False(result); var blobContainerClient = new BlobContainerClient(ConnectionString, uniqueContainerName); await blobContainerClient.DeleteIfExistsAsync(); }
/// <summary> /// Performs the tasks needed to initialize and set up the environment for the test scenario. /// This setup will take place once for each instance, running before the global cleanup is /// run. /// </summary> /// public override async Task CleanupAsync() { try { await _checkpointStore.DeleteIfExistsAsync().ConfigureAwait(false); } finally { await Scope.DisposeAsync().ConfigureAwait(false); } await base.CleanupAsync().ConfigureAwait(false); }
public async Task GivenAllPatientGroupWithFilters_WhenProcessGroupScope_CorrectResultShouldBeReturnedAsync() { Skip.If(_blobServiceClient == null); var uniqueContainerName = Guid.NewGuid().ToString("N"); BlobContainerClient blobContainerClient = _blobServiceClient.GetBlobContainerClient(uniqueContainerName); // Make sure the container is deleted before running the tests Assert.False(await blobContainerClient.ExistsAsync()); // Load configuration Environment.SetEnvironmentVariable("job:containerName", uniqueContainerName); Environment.SetEnvironmentVariable("filter:filterScope", "Group"); Environment.SetEnvironmentVariable("filter:requiredTypes", "Condition,MedicationRequest,Patient"); Environment.SetEnvironmentVariable("filter:typeFilters", "MedicationRequest?status=active,MedicationRequest?status=completed&date=gt2018-07-01T00:00:00Z"); // this group includes all the 80 patients Environment.SetEnvironmentVariable("filter:groupId", "72d653ce-2dbb-4432-bfa0-9ac47d0e0a2c"); var configuration = new ConfigurationBuilder() .AddJsonFile(TestConfigurationPath) .AddEnvironmentVariables() .Build(); try { // Run e2e var host = CreateHostBuilder(configuration).Build(); await host.RunAsync(); // Check job status var fileName = Path.Combine(_expectedDataFolder, "GroupScope_AllPatient_Filters.json"); var expectedJob = JsonConvert.DeserializeObject <Job>(File.ReadAllText(fileName)); await CheckJobStatus(blobContainerClient, expectedJob); // Check result files Assert.Equal(1, await GetResultFileCount(blobContainerClient, "result/Patient/2022/07/01")); Assert.Equal(1, await GetResultFileCount(blobContainerClient, "result/Condition/2022/07/01")); Assert.Equal(1, await GetResultFileCount(blobContainerClient, "result/MedicationRequest/2022/07/01")); var schedulerMetadata = await GetSchedulerMetadata(blobContainerClient); Assert.Empty(schedulerMetadata.FailedJobs); Assert.Equal(80, schedulerMetadata.ProcessedPatients.Count()); } finally { await blobContainerClient.DeleteIfExistsAsync(); } }
public async Task GivenOnePatientGroup_WhenProcessGroupScope_CorrectResultShouldBeReturnedAsync() { Skip.If(_blobServiceClient == null); var uniqueContainerName = Guid.NewGuid().ToString("N"); BlobContainerClient blobContainerClient = _blobServiceClient.GetBlobContainerClient(uniqueContainerName); // Make sure the container is deleted before running the tests Assert.False(await blobContainerClient.ExistsAsync()); // Load configuration Environment.SetEnvironmentVariable("job:containerName", uniqueContainerName); Environment.SetEnvironmentVariable("filter:filterScope", "Group"); // only patient cbe1a164-c5c8-65b4-747a-829a6bd4e85f is included in this group Environment.SetEnvironmentVariable("filter:groupId", "af3aba4f-7bb6-41e3-85e4-d931d7653ede"); Environment.SetEnvironmentVariable("filter:requiredTypes", string.Empty); Environment.SetEnvironmentVariable("filter:typeFilters", string.Empty); var configuration = new ConfigurationBuilder() .AddJsonFile(TestConfigurationPath) .AddEnvironmentVariables() .Build(); try { // Run e2e var host = CreateHostBuilder(configuration).Build(); await host.RunAsync(); // Check job status var fileName = Path.Combine(_expectedDataFolder, "GroupScope_OnePatient_All.json"); var expectedJob = JsonConvert.DeserializeObject <Job>(File.ReadAllText(fileName)); await CheckJobStatus(blobContainerClient, expectedJob); // Check result files Assert.Equal(20, await GetResultFileCount(blobContainerClient, "result")); var schedulerMetadata = await GetSchedulerMetadata(blobContainerClient); Assert.Empty(schedulerMetadata.FailedJobs); Assert.Single(schedulerMetadata.ProcessedPatients); } finally { await blobContainerClient.DeleteIfExistsAsync(); } }
public static async Task TearDownTenants(FeatureContext featureContext) { var tenantManager = TransientTenantManager.GetInstance(featureContext); await featureContext.RunAndStoreExceptionsAsync(async() => { IBlobContainerSourceWithTenantLegacyTransition cloudBlobContainerFactory = ContainerBindings.GetServiceProvider(featureContext).GetRequiredService <IBlobContainerSourceWithTenantLegacyTransition>(); BlobContainerClient testContainer = await cloudBlobContainerFactory.GetBlobContainerClientFromTenantAsync( tenantManager.PrimaryTransientClient, OperationsRepository.OperationsV2ConfigKey, OperationsRepository.OperationsV3ConfigKey).ConfigureAwait(false); await testContainer.DeleteIfExistsAsync().ConfigureAwait(false); }).ConfigureAwait(false); await featureContext.RunAndStoreExceptionsAsync(() => tenantManager.CleanupAsync()).ConfigureAwait(false); }
public async ValueTask DisposeAsync() { if (Container != null) { try { await Container.DeleteIfExistsAsync(); Container = null; } catch { // swallow the exception to avoid hiding another test failure } } }