Exemplo n.º 1
0
        public async Task CloudPageBlobMethodsOnBlockBlobAsync()
        {
            CloudBlobContainer container = GetRandomContainerReference();

            try
            {
                await container.CreateAsync();

                List <string> blobs = await CreateBlobsAsync(container, 1, BlobType.BlockBlob);

                CloudPageBlob blob = container.GetPageBlobReference(blobs.First());

                OperationContext operationContext = new OperationContext();
                using (MemoryStream stream = new MemoryStream())
                {
                    stream.SetLength(512);
                    await TestHelper.ExpectedExceptionAsync(
                        async() => await blob.WritePagesAsync(stream.AsInputStream(), 0, null, null, null, operationContext),
                        operationContext,
                        "Page operations should fail on block blobs",
                        HttpStatusCode.Conflict,
                        "InvalidBlobType");
                }

                await TestHelper.ExpectedExceptionAsync(
                    async() => await blob.ClearPagesAsync(0, 512, null, null, operationContext),
                    operationContext,
                    "Page operations should fail on block blobs",
                    HttpStatusCode.Conflict,
                    "InvalidBlobType");

                await TestHelper.ExpectedExceptionAsync(
                    async() => await blob.GetPageRangesAsync(null /* offset */, null /* length */, null, null, operationContext),
                    operationContext,
                    "Page operations should fail on block blobs",
                    HttpStatusCode.Conflict,
                    "InvalidBlobType");
            }
            finally
            {
                container.DeleteIfExistsAsync().AsTask().Wait();
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Test page blob reads, expecting success.
 /// </summary>
 /// <param name="testBlob">The page blob.</param>
 /// <param name="testAccessCondition">The access condition to use.</param>
 private async Task PageBlobReadExpectSuccessAsync(CloudPageBlob testBlob, AccessCondition testAccessCondition)
 {
     await testBlob.GetPageRangesAsync(null /* offset */, null /* length */, testAccessCondition, null /* options */, null);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Test page blob reads, expecting lease failure.
 /// </summary>
 /// <param name="testBlob">The page blob.</param>
 /// <param name="testAccessCondition">The failing access condition to use.</param>
 /// <param name="expectedErrorCode">The expected error code.</param>
 /// <param name="description">The reason why these calls should fail.</param>
 private async Task PageBlobReadExpectLeaseFailureAsync(CloudPageBlob testBlob, AccessCondition testAccessCondition, HttpStatusCode expectedStatusCode, string expectedErrorCode, string description)
 {
     OperationContext operationContext = new OperationContext();
     await TestHelper.ExpectedExceptionAsync(
         async () => await testBlob.GetPageRangesAsync(null /* offset */, null /* length */, testAccessCondition, null /* options */, operationContext),
         operationContext,
         description + "(Get Page Ranges)",
         expectedStatusCode,
         expectedErrorCode);
 }
Exemplo n.º 4
0
        public async Task CloudPageBlobGetPageRangesAsync()
        {
            byte[]             buffer    = GetRandomBuffer(1024);
            CloudBlobContainer container = GetRandomContainerReference();

            try
            {
                await container.CreateAsync();

                CloudPageBlob blob = container.GetPageBlobReference("blob1");
                await blob.CreateAsync(4 * 1024);

                using (MemoryStream memoryStream = new MemoryStream(buffer))
                {
                    await blob.WritePagesAsync(memoryStream.AsInputStream(), 512, null);
                }

                using (MemoryStream memoryStream = new MemoryStream(buffer))
                {
                    await blob.WritePagesAsync(memoryStream.AsInputStream(), 3 * 1024, null);
                }

                await blob.ClearPagesAsync(1024, 1024);

                await blob.ClearPagesAsync(0, 512);

                IEnumerable <PageRange> pageRanges = await blob.GetPageRangesAsync();

                List <string> expectedPageRanges = new List <string>()
                {
                    new PageRange(512, 1023).ToString(),
                    new PageRange(3 * 1024, 4 * 1024 - 1).ToString(),
                };
                foreach (PageRange pageRange in pageRanges)
                {
                    Assert.IsTrue(expectedPageRanges.Remove(pageRange.ToString()));
                }
                Assert.AreEqual(0, expectedPageRanges.Count);

                pageRanges = await blob.GetPageRangesAsync(1024, 1024, null, null, null);

                Assert.AreEqual(0, pageRanges.Count());

                pageRanges = await blob.GetPageRangesAsync(512, 3 * 1024, null, null, null);

                expectedPageRanges = new List <string>()
                {
                    new PageRange(512, 1023).ToString(),
                    new PageRange(3 * 1024, 7 * 512 - 1).ToString(),
                };
                foreach (PageRange pageRange in pageRanges)
                {
                    Assert.IsTrue(expectedPageRanges.Remove(pageRange.ToString()));
                }
                Assert.AreEqual(0, expectedPageRanges.Count);

                OperationContext opContext = new OperationContext();
                await TestHelper.ExpectedExceptionAsync(
                    async() => await blob.GetPageRangesAsync(1024, null, null, null, opContext),
                    opContext,
                    "Get Page Ranges with an offset but no count should fail",
                    HttpStatusCode.Unused);

                Assert.IsInstanceOfType(opContext.LastResult.Exception.InnerException, typeof(ArgumentNullException));
            }
            finally
            {
                container.DeleteIfExistsAsync().AsTask().Wait();
            }
        }