public async Task Batch_CanUseResponseAfterException() { await using TestScenario scenario = Scenario(); Uri[] good = await scenario.CreateBlobUrisAsync(1); Uri[] bad = scenario.GetInvalidBlobUris(1); BlobBatchClient client = scenario.GetBlobBatchClient(); using BlobBatch batch = client.CreateBatch(); Response response1 = batch.DeleteBlob(good[0]); Response response2 = batch.DeleteBlob(bad[0]); try { await client.SubmitBatchAsync(batch); } catch (AggregateException) { // Swallow the exception } scenario.AssertStatus(202, response1); scenario.AssertStatus(404, response2); }
public async Task Delete_ContainerScoped_Basic_ContainerSas() { await using TestScenario scenario = Scenario(); BlobClient[] blobs = await scenario.CreateBlobsAsync(3); string containerName = scenario.Containers[0].Container.Name; BlobSasBuilder blobSasBuilder = new BlobSasBuilder(BlobContainerSasPermissions.All, Recording.Now.AddDays(1)) { BlobContainerName = containerName }; BlobSasQueryParameters sasQueryParameters = blobSasBuilder.ToSasQueryParameters(GetNewSharedKeyCredentials()); BlobUriBuilder blobUriBuilder = new BlobUriBuilder(scenario.Service.Uri) { BlobContainerName = containerName, Sas = sasQueryParameters }; BlobContainerClient sasContainerClient = InstrumentClient(new BlobContainerClient(blobUriBuilder.ToUri(), GetOptions())); BlobBatchClient blobBatchClient = sasContainerClient.GetBlobBatchClient(); using BlobBatch batch = blobBatchClient.CreateBatch(); Response[] responses = new Response[] { batch.DeleteBlob(new Uri($"{blobs[0].Uri}?{sasQueryParameters}")), batch.DeleteBlob(new Uri($"{blobs[1].Uri}?{sasQueryParameters}")), batch.DeleteBlob(new Uri($"{blobs[2].Uri}?{sasQueryParameters}")) }; Response response = await blobBatchClient.SubmitBatchAsync(batch); scenario.AssertStatus(202, response); scenario.AssertStatus(202, responses); await scenario.AssertDeleted(blobs); }
public async Task Delete_MultipleFail_NoThrow() { using TestScenario scenario = Scenario(); BlobClient[] good = await scenario.CreateBlobsAsync(1); Uri[] bad = scenario.GetInvalidBlobUris(2); BlobBatchClient client = scenario.GetBlobBatchClient(); BlobBatch batch = client.CreateBatch(); Response response1 = batch.DeleteBlob(good[0].Uri); Response response2 = batch.DeleteBlob(bad[0]); Response response3 = batch.DeleteBlob(bad[1]); Response response = await client.SubmitBatchAsync(batch, throwOnFailure : false); scenario.AssertStatus(202, response, response1); scenario.AssertStatus(404, response2, response3); await scenario.AssertDeleted(good); }
public async Task FineGrainedBatchingAsync() { // Get a connection string to our Azure Storage account. string connectionString = ConnectionString; // Get a reference to a container named "sample-container" and then create it BlobServiceClient service = new BlobServiceClient(connectionString); BlobContainerClient container = service.GetBlobContainerClient(Randomize("sample-container")); await container.CreateAsync(); try { // Create three blobs named "foo", "bar", and "baz" BlobClient foo = container.GetBlobClient("foo"); BlobClient bar = container.GetBlobClient("bar"); BlobClient baz = container.GetBlobClient("baz"); await foo.UploadAsync(BinaryData.FromString("Foo!")); await bar.UploadAsync(BinaryData.FromString("Bar!")); await baz.UploadAsync(BinaryData.FromString("Baz!")); // Create a batch with three deletes BlobBatchClient batchClient = service.GetBlobBatchClient(); BlobBatch batch = batchClient.CreateBatch(); Response fooResponse = batch.DeleteBlob(foo.Uri, DeleteSnapshotsOption.IncludeSnapshots); Response barResponse = batch.DeleteBlob(bar.Uri); Response bazResponse = batch.DeleteBlob(baz.Uri); // Submit the batch await batchClient.SubmitBatchAsync(batch); // Verify the results Assert.AreEqual(202, fooResponse.Status); Assert.AreEqual(202, barResponse.Status); Assert.AreEqual(202, bazResponse.Status); } finally { // Clean up after the test when we're finished await container.DeleteAsync(); } }
public void FineGrainedBatching() { string connectionString = ConnectionString; string containerName = Randomize("sample-container"); #region Snippet:SampleSnippetsBatch_FineGrainedBatching // Get a connection string to our Azure Storage account. //@@ string connectionString = "<connection_string>"; //@@ string containerName = "sample-container"; // Get a reference to a container named "sample-container" and then create it BlobServiceClient service = new BlobServiceClient(connectionString); BlobContainerClient container = service.GetBlobContainerClient(containerName); container.Create(); // Create three blobs named "foo", "bar", and "baz" BlobClient foo = container.GetBlobClient("foo"); BlobClient bar = container.GetBlobClient("bar"); BlobClient baz = container.GetBlobClient("baz"); foo.Upload(new MemoryStream(Encoding.UTF8.GetBytes("Foo!"))); foo.CreateSnapshot(); bar.Upload(new MemoryStream(Encoding.UTF8.GetBytes("Bar!"))); bar.CreateSnapshot(); baz.Upload(new MemoryStream(Encoding.UTF8.GetBytes("Baz!"))); // Create a batch with three deletes BlobBatchClient batchClient = service.GetBlobBatchClient(); BlobBatch batch = batchClient.CreateBatch(); batch.DeleteBlob(foo.Uri, DeleteSnapshotsOption.IncludeSnapshots); batch.DeleteBlob(bar.Uri, DeleteSnapshotsOption.OnlySnapshots); batch.DeleteBlob(baz.Uri); // Submit the batch batchClient.SubmitBatch(batch); #endregion Pageable <BlobItem> blobs = container.GetBlobs(states: BlobStates.Snapshots); Assert.AreEqual(1, blobs.Count()); Assert.AreEqual("bar", blobs.FirstOrDefault().Name); // Clean up after the test when we're finished container.Delete(); }
public async Task Delete_OneFails_NoThrow() { await using TestScenario scenario = Scenario(); BlobClient[] good = await scenario.CreateBlobsAsync(2); Uri[] bad = scenario.GetInvalidBlobUris(1); BlobBatchClient client = scenario.GetBlobBatchClient(); using BlobBatch batch = client.CreateBatch(); Response response1 = batch.DeleteBlob(good[0].Uri); Response response2 = batch.DeleteBlob(good[1].Uri); Response response3 = batch.DeleteBlob(bad[0]); Response response = await client.SubmitBatchAsync(batch, throwOnAnyFailure : false); Assert.AreEqual(3, batch.RequestCount); scenario.AssertStatus(202, response, response1, response2); scenario.AssertStatus(404, response3); await scenario.AssertDeleted(good); }
public async Task Delete_Basic() { await using TestScenario scenario = Scenario(); BlobClient[] blobs = await scenario.CreateBlobsAsync(3); BlobBatchClient client = scenario.GetBlobBatchClient(); using BlobBatch batch = client.CreateBatch(); Response[] responses = new Response[] { batch.DeleteBlob(blobs[0].Uri), batch.DeleteBlob(blobs[1].Uri), batch.DeleteBlob(blobs[2].Uri) }; Response response = await client.SubmitBatchAsync(batch); scenario.AssertStatus(202, response); scenario.AssertStatus(202, responses); await scenario.AssertDeleted(blobs); }
public async Task Delete_MultipleFail() { using TestScenario scenario = Scenario(); BlobClient[] good = await scenario.CreateBlobsAsync(1); Uri[] bad = scenario.GetInvalidBlobUris(2); BlobBatchClient client = scenario.GetBlobBatchClient(); BlobBatch batch = client.CreateBatch(); Response response1 = batch.DeleteBlob(good[0].Uri); Response response2 = batch.DeleteBlob(bad[0]); Response response3 = batch.DeleteBlob(bad[1]); AggregateException exes = Assert.ThrowsAsync <AggregateException>( async() => await client.SubmitBatchAsync(batch)); Assert.AreEqual(2, exes.InnerExceptions.Count); Assert.AreEqual(404, (exes.InnerExceptions[0] as RequestFailedException)?.Status); Assert.AreEqual(404, (exes.InnerExceptions[1] as RequestFailedException)?.Status); await scenario.AssertDeleted(good); }
public void Batch_StatusIndicatesCannotRead() { using TestScenario scenario = Scenario(); Uri uri = scenario.GetInvalidBlobUris(1)[0]; BlobBatchClient client = scenario.GetBlobBatchClient(); BlobBatch batch = client.CreateBatch(); Response response = batch.DeleteBlob(uri); Assert.AreEqual(0, response.Status); }
public async Task Batch_Dispose_Response_Still_Available() { await using TestScenario scenario = Scenario(); BlobClient[] blobs = await scenario.CreateBlobsAsync(3); BlobBatchClient client = scenario.GetBlobBatchClient(); Response[] responses = new Response[3]; Response response; using (BlobBatch batch = client.CreateBatch()) { responses[0] = batch.DeleteBlob(blobs[0].Uri); responses[1] = batch.DeleteBlob(blobs[1].Uri); responses[2] = batch.DeleteBlob(blobs[2].Uri); response = await client.SubmitBatchAsync(batch); } scenario.AssertStatus(202, response); scenario.AssertStatus(202, responses); await scenario.AssertDeleted(blobs); }
public void Batch_Homogenous_SetTier() { using TestScenario scenario = Scenario(); Uri[] uris = scenario.GetInvalidBlobUris(2); BlobBatchClient client = scenario.GetBlobBatchClient(); BlobBatch batch = client.CreateBatch(); batch.SetBlobAccessTier(uris[0], AccessTier.Cool); InvalidOperationException ex = Assert.Throws <InvalidOperationException>( () => batch.DeleteBlob(uris[1])); StringAssert.Contains("already being used for SetAccessTier operations", ex.Message); }
public async Task Delete_OneFails() { using TestScenario scenario = Scenario(); BlobClient[] good = await scenario.CreateBlobsAsync(2); Uri[] bad = scenario.GetInvalidBlobUris(1); BlobBatchClient client = scenario.GetBlobBatchClient(); BlobBatch batch = client.CreateBatch(); Response response1 = batch.DeleteBlob(good[0].Uri); Response response2 = batch.DeleteBlob(good[1].Uri); Response response3 = batch.DeleteBlob(bad[0]); AggregateException exes = Assert.ThrowsAsync <AggregateException>( async() => await client.SubmitBatchAsync(batch)); RequestFailedException ex = exes.InnerException as RequestFailedException; Assert.IsNotNull(ex); Assert.AreEqual(404, ex.Status); Assert.IsTrue(BlobErrorCode.ContainerNotFound == ex.ErrorCode); await scenario.AssertDeleted(good); }
public void Batch_CannotReadBeforeSubmit() { using TestScenario scenario = Scenario(); Uri uri = scenario.GetInvalidBlobUris(1)[0]; BlobBatchClient client = scenario.GetBlobBatchClient(); BlobBatch batch = client.CreateBatch(); Response response = batch.DeleteBlob(uri); InvalidOperationException ex = Assert.Throws <InvalidOperationException>( () => { var _ = response.ClientRequestId; }); StringAssert.Contains("Cannot use the Response before calling BlobBatchClient.SubmitBatch", ex.Message); }
public async Task Batch_Homogenous_Delete() { await using TestScenario scenario = Scenario(); Uri[] uris = scenario.GetInvalidBlobUris(2); BlobBatchClient client = scenario.GetBlobBatchClient(); using BlobBatch batch = client.CreateBatch(); batch.DeleteBlob(uris[0]); InvalidOperationException ex = Assert.Throws <InvalidOperationException>( () => batch.SetBlobAccessTier(uris[1], AccessTier.Cool)); batch.Dispose(); StringAssert.Contains("already being used for Delete operations", ex.Message); }
public async Task Delete_Error() { // Arrange BlobServiceClient service = GetServiceClient_SharedKey(); BlobServiceClient invalidServiceClient = InstrumentClient(new BlobServiceClient( GetServiceClient_SharedKey().Uri, GetOptions())); BlobBatchClient blobBatchClient = invalidServiceClient.GetBlobBatchClient(); using BlobBatch batch = blobBatchClient.CreateBatch(); batch.DeleteBlob(new Uri("https://account.blob.core.windows.net/container/blob")); // Act await TestHelper.AssertExpectedExceptionAsync <RequestFailedException>( blobBatchClient.SubmitBatchAsync(batch), e => Assert.AreEqual(BlobErrorCode.NoAuthenticationInformation.ToString(), e.ErrorCode)); }
public void Batch_CannotChangeClients() { TestDiagnostics = false; using TestScenario scenario1 = Scenario(); BlobBatchClient client1 = scenario1.GetBlobBatchClient(); Uri uri = scenario1.GetInvalidBlobUris(1)[0]; BlobBatch batch1 = client1.CreateBatch(); Response response = batch1.DeleteBlob(uri); using TestScenario scenario2 = Scenario(); BlobBatchClient client2 = scenario2.GetBlobBatchClient(); ArgumentException ex = Assert.ThrowsAsync <ArgumentException>( async() => await client2.SubmitBatchAsync(batch1)); StringAssert.Contains("BlobBatchClient used to create the BlobBatch must be used to submit it", ex.Message); }