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); CloudBlockBlob blockBlob = container.GetBlockBlobReference("blob1"); blockBlob.StreamWriteSizeInBytes = 1 * 1024 * 1024; using (MemoryStream ms = new MemoryStream(buffer)) { try { await blockBlob.UploadFromStreamAsync(ms); Assert.Fail(); } catch (TimeoutException ex) { Assert.IsInstanceOfType(ex, typeof(TimeoutException)); } catch (StorageException ex) { Assert.IsInstanceOfType(ex.InnerException, typeof(TimeoutException)); } } CloudPageBlob pageBlob = container.GetPageBlobReference("blob2"); pageBlob.StreamWriteSizeInBytes = 1 * 1024 * 1024; using (MemoryStream ms = new MemoryStream(buffer)) { try { await pageBlob.UploadFromStreamAsync(ms); Assert.Fail(); } catch (TimeoutException ex) { Assert.IsInstanceOfType(ex, typeof(TimeoutException)); } catch (StorageException ex) { Assert.IsInstanceOfType(ex.InnerException, typeof(TimeoutException)); } } } 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); CloudBlockBlob blockBlob = container.GetBlockBlobReference("blob1"); blockBlob.StreamWriteSizeInBytes = 1 * 1024 * 1024; using (MemoryStream ms = new MemoryStream(buffer)) { try { await blockBlob.UploadFromStreamAsync(ms.AsInputStream()); Assert.Fail(); } catch (AggregateException ex) { Assert.AreEqual("The client could not finish the operation within specified timeout.", RequestResult.TranslateFromExceptionMessage(ex.InnerException.InnerException.Message).ExceptionInfo.Message); } catch (TaskCanceledException) { } } CloudPageBlob pageBlob = container.GetPageBlobReference("blob2"); pageBlob.StreamWriteSizeInBytes = 1 * 1024 * 1024; using (MemoryStream ms = new MemoryStream(buffer)) { try { await pageBlob.UploadFromStreamAsync(ms.AsInputStream()); Assert.Fail(); } catch (AggregateException ex) { Assert.AreEqual("The client could not finish the operation within specified timeout.", RequestResult.TranslateFromExceptionMessage(ex.InnerException.InnerException.Message).ExceptionInfo.Message); } catch (TaskCanceledException) { } } } finally { blobClient.DefaultRequestOptions.MaximumExecutionTime = null; container.DeleteIfExistsAsync().AsTask().Wait(); } }
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 CloudBlobUploadCancellationAsync() { CloudBlobContainer container = DefaultBlobClient.GetContainerReference(Guid.NewGuid().ToString("N")); byte[] buffer = BlobTestBase.GetRandomBuffer(16 * 1024 * 1024); try { await container.CreateAsync(); CloudBlockBlob blob = container.GetBlockBlobReference("blob1"); BlobRequestOptions requestOptions = new BlobRequestOptions() { RetryPolicy = new NoRetry() }; CancellationTokenSource cts = new CancellationTokenSource(); CancellationToken token = cts.Token; new Task(() => { new System.Threading.ManualResetEvent(false).WaitOne(500); cts.Cancel(false); }).Start(); using (MemoryStream ms = new MemoryStream(buffer)) { #if ASPNET_K blob.UploadFromStreamAsync(ms, ms.Length, null, requestOptions, null, token).Wait(); #else blob.UploadFromStreamAsync(ms.AsInputStream(), null, requestOptions, null).AsTask(token).Wait(); #endif } Assert.Fail(); } catch (AggregateException e) { TaskCanceledException ex = new TaskCanceledException(); Assert.AreEqual(ex.HResult, e.InnerException.HResult); } finally { container.DeleteIfExistsAsync().AsTask().Wait(); } }
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 (var 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 (var 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 void TestInitialize() { this.testContainer = BlobTestBase.GetRandomContainerReference(); this.testContainer.CreateIfNotExists(); }