public async Task Batch_StatusIndicatesCannotRead()
        {
            await using TestScenario scenario = Scenario();
            Uri uri = scenario.GetInvalidBlobUris(1)[0];

            BlobBatchClient client = scenario.GetBlobBatchClient();

            using BlobBatch batch = client.CreateBatch();
            Response response = batch.DeleteBlob(uri);

            batch.Dispose();

            Assert.AreEqual(0, response.Status);
        }
        public async Task Batch_Homogenous_SetTier()
        {
            await using TestScenario scenario = Scenario();
            Uri[]           uris   = scenario.GetInvalidBlobUris(2);
            BlobBatchClient client = scenario.GetBlobBatchClient();

            using 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 Batch_EmptyFails()
        {
            TestDiagnostics = false;

            await using TestScenario scenario = Scenario();

            BlobBatchClient client = scenario.GetBlobBatchClient();

            using BlobBatch batch = client.CreateBatch();
            ArgumentException ex = Assert.ThrowsAsync <ArgumentException>(
                async() => await client.SubmitBatchAsync(batch));

            StringAssert.Contains("Cannot submit an empty batch", ex.Message);
        }
        public async Task Batch_CannotReadBeforeSubmit()
        {
            await using TestScenario scenario = Scenario();
            Uri uri = scenario.GetInvalidBlobUris(1)[0];

            BlobBatchClient client = scenario.GetBlobBatchClient();

            using 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);
        }
Exemple #5
0
        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));
        }
Exemple #6
0
        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);
        }
Exemple #7
0
        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);
        }
Exemple #8
0
        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();
            }
        }
Exemple #9
0
        public async Task SetBlobAccessTier_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.SetBlobAccessTier(good[0].Uri, AccessTier.Cool);
            Response        response2 = batch.SetBlobAccessTier(bad[0], AccessTier.Cool);
            Response        response3 = batch.SetBlobAccessTier(bad[1], AccessTier.Cool);
            Response        response  = await client.SubmitBatchAsync(batch, throwOnFailure : false);

            scenario.AssertStatus(202, response);
            scenario.AssertStatus(200, response1);
            scenario.AssertStatus(404, response2, response3);
            await scenario.AssertTiers(AccessTier.Cool, good);
        }
        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();
        }
Exemple #11
0
        public async Task SetBlobAccessTier_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.SetBlobAccessTier(blobs[0].Uri, AccessTier.Cool),
                batch.SetBlobAccessTier(blobs[1].Uri, AccessTier.Cool),
                batch.SetBlobAccessTier(blobs[2].Uri, AccessTier.Cool)
            };
            Response response = await client.SubmitBatchAsync(batch);

            scenario.AssertStatus(202, response);
            scenario.AssertStatus(200, responses);
            await scenario.AssertTiers(AccessTier.Cool, blobs);
        }
Exemple #12
0
        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);
        }
Exemple #13
0
        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);
        }
Exemple #14
0
        public async Task SetBlobAccessTier_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.SetBlobAccessTier(good[0].Uri, AccessTier.Cool);
            Response           response2 = batch.SetBlobAccessTier(bad[0], AccessTier.Cool);
            Response           response3 = batch.SetBlobAccessTier(bad[1], AccessTier.Cool);
            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.AssertTiers(AccessTier.Cool, good);
        }
Exemple #15
0
        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);
        }
Exemple #16
0
        public async Task Delete_MultipleFail()
        {
            await using TestScenario scenario = Scenario();
            BlobClient[] good = await scenario.CreateBlobsAsync(1);

            Uri[] bad = scenario.GetInvalidBlobUris(2);

            BlobBatchClient client = scenario.GetBlobBatchClient();

            using 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, throwOnAnyFailure: true));

            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);
        }
Exemple #17
0
        public async Task SetBlobAccessTier_Version()
        {
            await using TestScenario scenario = Scenario();
            BlockBlobClient[] blobs = await scenario.CreateBlockBlobsAsync(1);

            Response <BlobInfo> setMetadataResponse = await blobs[0].SetMetadataAsync(BuildMetadata());

            blobs[0] = blobs[0].WithVersion(setMetadataResponse.Value.VersionId);

            BlobBatchClient client = scenario.GetBlobBatchClient();

            using BlobBatch batch = client.CreateBatch();
            Response[] responses = new Response[]
            {
                batch.SetBlobAccessTier(blobs[0].Uri, AccessTier.Cool),
            };
            Response response = await client.SubmitBatchAsync(batch);

            scenario.AssertStatus(202, response);
            scenario.AssertStatus(200, responses);
            await scenario.AssertTiers(AccessTier.Cool, blobs);
        }
Exemple #18
0
        public async Task SetBlobAccessTier_Snapshot()
        {
            await using TestScenario scenario = Scenario();
            BlockBlobClient[] blobs = await scenario.CreateBlockBlobsAsync(1);

            Response <BlobSnapshotInfo> blobSnapshotResponse = await blobs[0].CreateSnapshotAsync();

            blobs[0] = blobs[0].WithSnapshot(blobSnapshotResponse.Value.Snapshot);

            BlobBatchClient client = scenario.GetBlobBatchClient();

            using BlobBatch batch = client.CreateBatch();
            Response[] responses = new Response[]
            {
                batch.SetBlobAccessTier(blobs[0].Uri, AccessTier.Cool),
            };
            Response response = await client.SubmitBatchAsync(batch);

            scenario.AssertStatus(202, response);
            scenario.AssertStatus(200, responses);
            await scenario.AssertTiers(AccessTier.Cool, blobs);
        }
Exemple #19
0
        public async Task SetBlobAccessTier_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.SetBlobAccessTier(good[0].Uri, AccessTier.Cool);
            Response           response2 = batch.SetBlobAccessTier(good[1].Uri, AccessTier.Cool);
            Response           response3 = batch.SetBlobAccessTier(bad[0], AccessTier.Cool);
            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.AssertTiers(AccessTier.Cool, good);
        }
Exemple #20
0
        public async Task Delete_OneFails()
        {
            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]);
            AggregateException exes      = Assert.ThrowsAsync <AggregateException>(
                async() => await client.SubmitBatchAsync(batch, throwOnAnyFailure: true));

            RequestFailedException ex = exes.InnerException as RequestFailedException;

            Assert.IsNotNull(ex);
            Assert.AreEqual(404, ex.Status);
            Assert.IsTrue(BlobErrorCode.ContainerNotFound == ex.ErrorCode);
            await scenario.AssertDeleted(good);
        }
Exemple #21
0
        public async Task Batch_CanUseResponseAfterException()
        {
            using TestScenario scenario = Scenario();
            Uri[] good = await scenario.CreateBlobUrisAsync(1);

            Uri[] bad = scenario.GetInvalidBlobUris(1);

            BlobBatchClient client    = scenario.GetBlobBatchClient();
            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);
        }