public async Task GivenAStorageBlobNdjsonSource_WhenDownloadData_AllDataShouldbeReturned_Async() { if (string.IsNullOrEmpty(_testSettings.BlobUri)) { return; } var credential = Program.GetClientSecretCredential(_testSettings.TenantId, _testSettings.ClientId, _testSettings.Secret); string containerName = Guid.NewGuid().ToString("N"); string blobName = Guid.NewGuid().ToString("N"); Uri containerUri = new Uri(_testSettings.BlobUri + "/" + containerName); Uri docUri = new Uri(_testSettings.BlobUri + "/" + containerName + "/" + blobName); BlobContainerClient containerClient = new BlobContainerClient(containerUri, credential); var source = new StorageBlobNdjsonSource(docUri, credential); try { await source.OpenAsync(); await containerClient.CreateIfNotExistsAsync(); var blobClient = containerClient.GetBlobClient(blobName); List <string> expectedResult = GenerateTestBlobAsync(blobClient).Result; for (int i = 0; i < expectedResult.Count; ++i) { var content = await source.ReadAsync(); Assert.Equal(expectedResult[i], content); } } finally { await source.CloseAsync(); await containerClient.DeleteIfExistsAsync(); } return; }
public async Task GivenAStorageBlobNdjsonSource_WhenDownloadDataTimeout_OperationShouldBeRetried_Async() { if (string.IsNullOrEmpty(_testSettings.BlobUri)) { return; } var credential = Program.GetClientSecretCredential(_testSettings.TenantId, _testSettings.ClientId, _testSettings.Secret); string containerName = Guid.NewGuid().ToString("N"); string blobName = Guid.NewGuid().ToString("N"); Uri containerUri = new Uri(_testSettings.BlobUri + "/" + containerName); Uri docUri = new Uri(_testSettings.BlobUri + "/" + containerName + "/" + blobName); BlobContainerClient containerClient = new BlobContainerClient(containerUri, credential); var source = new StorageBlobNdjsonSource(docUri, credential); try { await containerClient.CreateIfNotExistsAsync(); var blobClient = containerClient.GetBlobClient(blobName); List <string> expectedResult = GenerateTestBlobAsync(blobClient).Result; Dictionary <long, int> enterRecord = new Dictionary <long, int>(); source.BlockDownloadTimeoutRetryCount = 1; source.BlockDownloadTimeoutInSeconds = 5; await source.OpenAsync(); source._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); return(downloadInfo.Value.Content); }; for (int i = 0; i < expectedResult.Count; ++i) { var content = await source.ReadAsync(); Assert.Equal(expectedResult[i], content); } foreach (int count in enterRecord.Values) { Assert.Equal(2, count); } } finally { await source.CloseAsync(); await containerClient.DeleteIfExistsAsync(); } return; }