public void MyTestInitialize() { if (TestBase.BlobBufferManager != null) { TestBase.BlobBufferManager.OutstandingBufferCount = 0; } this.container = GetRandomContainerReference(); this.container.CreateIfNotExists(); this.blob = this.container.GetBlockBlobReference(BlobTestBase.GetRandomContainerName()); this.blob.UploadText("test"); }
public async Task TestBlobAttributesEncryptionAsync() { CloudBlobContainer container = GetRandomContainerReference(); try { await container.CreateIfNotExistsAsync(); CloudBlockBlob blob = container.GetBlockBlobReference(BlobTestBase.GetRandomContainerName()); await blob.UploadTextAsync("test"); await blob.FetchAttributesAsync(); Assert.IsTrue(blob.Properties.IsServerEncrypted); CloudBlockBlob testBlob = container.GetBlockBlobReference(blob.Name); await testBlob.DownloadTextAsync(); Assert.IsTrue(testBlob.Properties.IsServerEncrypted); } finally { await container.DeleteAsync(); } }
public async Task CloudBlobClientMaximumExecutionTimeoutShouldNotBeHonoredForStreamsAsync() { CloudBlobClient blobClient = GenerateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference(Guid.NewGuid().ToString("N")); byte[] buffer = BlobTestBase.GetRandomBuffer(1024 * 1024); try { await container.CreateAsync(); blobClient.DefaultRequestOptions.MaximumExecutionTime = TimeSpan.FromSeconds(30); CloudBlockBlob blockBlob = container.GetBlockBlobReference("blob1"); CloudPageBlob pageBlob = container.GetPageBlobReference("blob2"); blockBlob.StreamWriteSizeInBytes = 1024 * 1024; blockBlob.StreamMinimumReadSizeInBytes = 1024 * 1024; pageBlob.StreamWriteSizeInBytes = 1024 * 1024; pageBlob.StreamMinimumReadSizeInBytes = 1024 * 1024; using (CloudBlobStream bos = await blockBlob.OpenWriteAsync()) { DateTime start = DateTime.Now; for (int i = 0; i < 7; i++) { await bos.WriteAsync(buffer, 0, buffer.Length); } // Sleep to ensure we are over the Max execution time when we do the last write int msRemaining = (int)(blobClient.DefaultRequestOptions.MaximumExecutionTime.Value - (DateTime.Now - start)).TotalMilliseconds; if (msRemaining > 0) { await Task.Delay(msRemaining); } await bos.WriteAsync(buffer, 0, buffer.Length); await bos.CommitAsync(); } using (Stream bis = (await blockBlob.OpenReadAsync())) { DateTime start = DateTime.Now; int total = 0; while (total < 7 * 1024 * 1024) { total += await bis.ReadAsync(buffer, 0, buffer.Length); } // Sleep to ensure we are over the Max execution time when we do the last read int msRemaining = (int)(blobClient.DefaultRequestOptions.MaximumExecutionTime.Value - (DateTime.Now - start)).TotalMilliseconds; if (msRemaining > 0) { await Task.Delay(msRemaining); } while (true) { int count = await bis.ReadAsync(buffer, 0, buffer.Length); total += count; if (count == 0) { break; } } } using (CloudBlobStream bos = await pageBlob.OpenWriteAsync(8 * 1024 * 1024)) { DateTime start = DateTime.Now; for (int i = 0; i < 7; i++) { await bos.WriteAsync(buffer, 0, buffer.Length); } // Sleep to ensure we are over the Max execution time when we do the last write int msRemaining = (int)(blobClient.DefaultRequestOptions.MaximumExecutionTime.Value - (DateTime.Now - start)).TotalMilliseconds; if (msRemaining > 0) { await Task.Delay(msRemaining); } await bos.WriteAsync(buffer, 0, buffer.Length); await bos.CommitAsync(); } using (Stream bis = (await pageBlob.OpenReadAsync())) { DateTime start = DateTime.Now; int total = 0; while (total < 7 * 1024 * 1024) { total += await bis.ReadAsync(buffer, 0, buffer.Length); } // Sleep to ensure we are over the Max execution time when we do the last read int msRemaining = (int)(blobClient.DefaultRequestOptions.MaximumExecutionTime.Value - (DateTime.Now - start)).TotalMilliseconds; if (msRemaining > 0) { await Task.Delay(msRemaining); } while (true) { int count = await bis.ReadAsync(buffer, 0, buffer.Length); total += count; if (count == 0) { break; } } } } finally { blobClient.DefaultRequestOptions.MaximumExecutionTime = null; container.DeleteIfExistsAsync().Wait(); } }
public async Task CloudBlobClientMaximumExecutionTimeoutAsync() { CloudBlobClient blobClient = GenerateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference(Guid.NewGuid().ToString("N")); byte[] buffer = BlobTestBase.GetRandomBuffer(80 * 1024 * 1024); try { await container.CreateAsync(); blobClient.DefaultRequestOptions.MaximumExecutionTime = TimeSpan.FromSeconds(5); blobClient.DefaultRequestOptions.SingleBlobUploadThresholdInBytes = 2 * 1024 * 1024; CloudBlockBlob blockBlob = container.GetBlockBlobReference("blob1"); blockBlob.StreamWriteSizeInBytes = 1 * 1024 * 1024; using (MemoryStream ms = new MemoryStream(buffer)) { try { await blockBlob.UploadFromStreamAsync(ms); Assert.Fail(); } catch (AggregateException ex) { #if !FACADE_NETCORE Assert.AreEqual("The client could not finish the operation within specified timeout.", RequestResult.TranslateFromExceptionMessage(ex.InnerException.Message).ExceptionInfo.Message); #else Assert.AreEqual("The client could not finish the operation within specified timeout.", RequestResult.TranslateFromExceptionMessage(ex.InnerException.Message).Exception.Message); #endif } catch (TaskCanceledException) { } } CloudPageBlob pageBlob = container.GetPageBlobReference("blob2"); pageBlob.StreamWriteSizeInBytes = 1 * 1024 * 1024; using (MemoryStream ms = new MemoryStream(buffer)) { try { await pageBlob.UploadFromStreamAsync(ms); Assert.Fail(); } catch (AggregateException ex) { #if !FACADE_NETCORE Assert.AreEqual("The client could not finish the operation within specified timeout.", RequestResult.TranslateFromExceptionMessage(ex.InnerException.Message).ExceptionInfo.Message); #else Assert.AreEqual("The client could not finish the operation within specified timeout.", RequestResult.TranslateFromExceptionMessage(ex.InnerException.Message).Exception.Message); #endif } catch (TaskCanceledException) { } } } finally { blobClient.DefaultRequestOptions.MaximumExecutionTime = null; container.DeleteIfExistsAsync().Wait(); } }
public void TestInitialize() { this.testContainer = BlobTestBase.GetRandomContainerReference(); this.testContainer.CreateIfNotExists(); }