示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        public void Batch_EmptyFails()
        {
            TestDiagnostics = false;

            using TestScenario scenario = Scenario();

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

            StringAssert.Contains("Cannot submit an empty batch", ex.Message);
        }
示例#5
0
        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);
        }
示例#6
0
        public async Task Delete_Basic_Convenience()
        {
            await using TestScenario scenario = Scenario();
            BlobClient[] blobs = await scenario.CreateBlobsAsync(3);

            Uri[] uris = blobs.Select(b => b.Uri).ToArray();

            BlobBatchClient client = scenario.GetBlobBatchClient();

            Response[] responses = await client.DeleteBlobsAsync(uris);

            scenario.AssertStatus(202, responses);
            await scenario.AssertDeleted(blobs);
        }
示例#7
0
        public async Task SetBlobAccessTier_Basic_Convenience()
        {
            await using TestScenario scenario = Scenario();
            BlobClient[] blobs = await scenario.CreateBlobsAsync(3);

            Uri[] uris = blobs.Select(b => b.Uri).ToArray();

            BlobBatchClient client = scenario.GetBlobBatchClient();

            Response[] responses = await client.SetBlobsAccessTierAsync(uris, AccessTier.Cool);

            scenario.AssertStatus(200, responses);
            await scenario.AssertTiers(AccessTier.Cool, blobs);
        }
示例#8
0
        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);
        }
示例#9
0
        public async Task Batch_SasUri_NotOwner()
        {
            // Create a container using SAS for Auth
            string containerName = GetNewContainerName();

            await using DisposingContainer test = await GetTestContainerAsync();

            await using TestScenario scenario = Scenario(GetServiceClient_BlobServiceSas_Container(containerName));
            Uri[] blobs = await scenario.CreateBlobUrisAsync(test.Container, 2);

            BlobBatchClient        client = scenario.GetBlobBatchClient();
            RequestFailedException ex     = Assert.ThrowsAsync <RequestFailedException>(
                async() => await client.DeleteBlobsAsync(blobs));

            Assert.AreEqual(403, ex.Status);
        }
示例#10
0
        public async Task SetBlobAccessTier_MultipleFail_Convenience()
        {
            await using TestScenario scenario = Scenario();
            BlobClient[] good = await scenario.CreateBlobsAsync(1);

            Uri[] bad  = scenario.GetInvalidBlobUris(2);
            Uri[] uris = good.Select(b => b.Uri).Concat(bad).ToArray();

            BlobBatchClient    client = scenario.GetBlobBatchClient();
            AggregateException exes   = Assert.ThrowsAsync <AggregateException>(
                async() => await client.SetBlobsAccessTierAsync(uris, AccessTier.Cool));

            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);
        }
示例#11
0
        public async Task Batch_Limit()
        {
            await using TestScenario scenario = Scenario();
            Uri[] blobs = await scenario.CreateBlobUrisAsync(257);

            BlobBatchClient client = scenario.GetBlobBatchClient();

            // One over the limit
            RequestFailedException ex = Assert.ThrowsAsync <RequestFailedException>(
                async() => await client.DeleteBlobsAsync(blobs));

            Assert.AreEqual(400, ex.Status);
            Assert.AreEqual("ExceedsMaxBatchRequestCount", ex.ErrorCode);

            // The exact limit
            await client.DeleteBlobsAsync(blobs.Take(256).ToArray());
        }
示例#12
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);
        }
示例#13
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);
        }
示例#14
0
        public async Task Batch_AzureSasCredential()
        {
            // Create a container using SAS for Auth
            await using DisposingContainer test = await GetTestContainerAsync();

            var serviceClient    = GetServiceClient_SharedKey();
            var sas              = GetAccountSasCredentials().SasToken;
            var sasServiceClient = InstrumentClient(new BlobServiceClient(serviceClient.Uri, new AzureSasCredential(sas), GetOptions()));

            await using TestScenario scenario = Scenario(sasServiceClient);
            Uri[] blobs = await scenario.CreateBlobUrisAsync(test.Container, 2);

            BlobBatchClient client = scenario.GetBlobBatchClient();

            Response[] responses = await client.DeleteBlobsAsync(blobs);

            scenario.AssertStatus(202, responses);
        }
示例#15
0
        public async Task Batch_AcrossContainers()
        {
            await using TestScenario scenario = Scenario();
            BlobContainerClient container1 = await scenario.CreateContainerAsync();

            Uri[] blobs1 = await scenario.CreateBlobUrisAsync(container1, 2);

            BlobContainerClient container2 = await scenario.CreateContainerAsync();

            Uri[] blobs2 = await scenario.CreateBlobUrisAsync(container2, 3);

            Uri[] blobs = blobs1.Concat(blobs2).ToArray();

            BlobBatchClient client = scenario.GetBlobBatchClient();

            Response[] responses = await client.DeleteBlobsAsync(blobs);

            scenario.AssertStatus(202, responses);
        }
示例#16
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);
        }
示例#17
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);
        }
示例#18
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);
        }
示例#19
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);
        }
示例#20
0
        public async Task SetBlobAccessTier_OneFails_Convenience()
        {
            await using TestScenario scenario = Scenario();
            BlobClient[] good = await scenario.CreateBlobsAsync(2);

            Uri[] bad  = scenario.GetInvalidBlobUris(1);
            Uri[] uris = good.Select(b => b.Uri).Concat(bad).ToArray();

            BlobBatchClient    client = scenario.GetBlobBatchClient();
            AggregateException exes   = Assert.ThrowsAsync <AggregateException>(
                async() => await client.SetBlobsAccessTierAsync(uris, AccessTier.Cool));

            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);
        }
示例#21
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);
        }
示例#22
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);
        }
示例#23
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);
        }
示例#24
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);
        }
示例#25
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);
        }
示例#26
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);
        }
示例#27
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);
        }