Beispiel #1
0
        public async Task DownloadsInBlocksWhenOverTheLimit()
        {
            MemoryStream          stream      = new MemoryStream();
            MockDataSource        dataSource  = new MockDataSource(100);
            Mock <BlobBaseClient> blockClient = new Mock <BlobBaseClient>(MockBehavior.Strict, new Uri("http://mock"), new BlobClientOptions());

            blockClient.SetupGet(c => c.ClientDiagnostics).CallBase();
            BlobProperties smallLengthProperties = new BlobProperties()
            {
                ContentLength = 100
            };

            SetupDownload(blockClient, dataSource);

            PartitionedDownloader downloader = new PartitionedDownloader(
                blockClient.Object,
                new StorageTransferOptions()
            {
                MaximumTransferLength = 10,
                InitialTransferLength = 20
            });

            Response result = await InvokeDownloadToAsync(downloader, stream);

            Assert.AreEqual(dataSource.Requests.Count, 9);
            AssertContent(100, stream);
            Assert.NotNull(result);
        }
Beispiel #2
0
        public void SurfacesDownloadExceptions()
        {
            Exception e = new Exception();

            MemoryStream          stream      = new MemoryStream();
            Mock <BlobBaseClient> blockClient = new Mock <BlobBaseClient>(MockBehavior.Strict, new Uri("http://mock"), new BlobClientOptions());

            blockClient.SetupGet(c => c.ClientDiagnostics).CallBase();
            BlobProperties smallLengthProperties = new BlobProperties()
            {
                ContentLength = 100
            };

            if (_async)
            {
                blockClient.Setup(c => c.DownloadAsync(It.IsAny <HttpRange>(), It.IsAny <BlobRequestConditions>(), false, s_cancellationToken))
                .ThrowsAsync(e);
            }
            else
            {
                blockClient.Setup(c => c.Download(It.IsAny <HttpRange>(), It.IsAny <BlobRequestConditions>(), false, s_cancellationToken))
                .Throws(e);
            }

            PartitionedDownloader downloader = new PartitionedDownloader(blockClient.Object, new StorageTransferOptions()
            {
                MaximumTransferLength = 10
            });

            Exception thrown = Assert.ThrowsAsync <Exception>(async() => await InvokeDownloadToAsync(downloader, stream));

            Assert.AreSame(e, thrown);
        }
Beispiel #3
0
        public void SurfacesDownloadExceptions()
        {
            Exception e = new Exception();

            MemoryStream          stream      = new MemoryStream();
            Mock <BlobBaseClient> blockClient = new Mock <BlobBaseClient>(MockBehavior.Strict, new Uri("http://mock"), new BlobClientOptions());

            blockClient.SetupGet(c => c.ClientConfiguration).CallBase();

            blockClient.SetupGet(c => c.UsingClientSideEncryption).Returns(false);
            blockClient.Setup(c => c.DownloadStreamingInternal(
                                  It.IsAny <HttpRange>(),
                                  It.IsAny <BlobRequestConditions>(),
                                  false,
                                  It.IsAny <IProgress <long> >(),
                                  $"{nameof(BlobBaseClient)}.{nameof(BlobBaseClient.DownloadStreaming)}",
                                  _async,
                                  s_cancellationToken)).ThrowsAsync(e);

            PartitionedDownloader downloader = new PartitionedDownloader(blockClient.Object, new StorageTransferOptions()
            {
                MaximumTransferLength = 10
            });

            Exception thrown = Assert.ThrowsAsync <Exception>(async() => await InvokeDownloadToAsync(downloader, stream));

            Assert.AreSame(e, thrown);
        }
Beispiel #4
0
 private async Task <Response> InvokeDownloadToAsync(PartitionedDownloader downloader, Stream stream)
 {
     if (_async)
     {
         return(await downloader.DownloadToAsync(stream, s_conditions, s_cancellationToken));
     }
     else
     {
         return(downloader.DownloadTo(stream, s_conditions, s_cancellationToken));
     }
 }
Beispiel #5
0
        public async Task IncludesEtagInConditions()
        {
            MemoryStream          stream      = new MemoryStream();
            MockDataSource        dataSource  = new MockDataSource(100);
            Mock <BlobBaseClient> blockClient = new Mock <BlobBaseClient>(MockBehavior.Strict, new Uri("http://mock"), new BlobClientOptions());

            blockClient.SetupGet(c => c.ClientDiagnostics).CallBase();
            BlobProperties properties = new BlobProperties()
            {
                ContentLength = 100,
                ETag          = s_etag
            };

            SetupDownload(blockClient, dataSource);

            PartitionedDownloader downloader = new PartitionedDownloader(
                blockClient.Object,
                new StorageTransferOptions()
            {
                MaximumTransferLength = 10,
                InitialTransferLength = 10
            });

            Response result = await InvokeDownloadToAsync(downloader, stream);

            Assert.AreEqual(dataSource.Requests.Count, 10);
            AssertContent(100, stream);
            Assert.NotNull(result);

            bool first = true;

            foreach ((HttpRange Range, BlobRequestConditions Conditions)request in dataSource.Requests)
            {
                Assert.AreEqual(s_conditions.LeaseId, request.Conditions.LeaseId);
                Assert.AreEqual(s_conditions.IfModifiedSince, request.Conditions.IfModifiedSince);
                Assert.AreEqual(s_conditions.IfUnmodifiedSince, request.Conditions.IfUnmodifiedSince);
                Assert.AreEqual(s_conditions.IfNoneMatch, request.Conditions.IfNoneMatch);
                if (first)
                {
                    first = false;
                }
                else
                {
                    Assert.AreEqual(s_etag, request.Conditions.IfMatch);
                }
            }
        }
Beispiel #6
0
        public async Task DownloadsInOneBlockIfUnderLimit()
        {
            MemoryStream          stream      = new MemoryStream();
            MockDataSource        dataSource  = new MockDataSource(10);
            Mock <BlobBaseClient> blockClient = new Mock <BlobBaseClient>(MockBehavior.Strict, new Uri("http://mock"), new BlobClientOptions());

            blockClient.SetupGet(c => c.ClientDiagnostics).CallBase();

            SetupDownload(blockClient, dataSource);

            PartitionedDownloader downloader = new PartitionedDownloader(blockClient.Object);

            Response result = await InvokeDownloadToAsync(downloader, stream);

            AssertContent(10, stream);
            Assert.NotNull(result);
        }
Beispiel #7
0
        public async Task ReturnsPropertiesForZeroLength()
        {
            MemoryStream          stream      = new MemoryStream();
            MockDataSource        dataSource  = new MockDataSource(0);
            Mock <BlobBaseClient> blockClient = new Mock <BlobBaseClient>(MockBehavior.Strict, new Uri("http://mock"), new BlobClientOptions());

            blockClient.SetupGet(c => c.ClientDiagnostics).CallBase();

            SetupDownload(blockClient, dataSource);

            PartitionedDownloader downloader = new PartitionedDownloader(blockClient.Object);

            Response result = await InvokeDownloadToAsync(downloader, stream);

            Assert.AreEqual(0, stream.Length);
            Assert.NotNull(result);
        }
Beispiel #8
0
        public async Task RespectsInitialTransferSizeBeforeDownloadingInBlocks()
        {
            MemoryStream          stream      = new MemoryStream();
            MockDataSource        dataSource  = new MockDataSource(100);
            Mock <BlobBaseClient> blockClient = new Mock <BlobBaseClient>(MockBehavior.Strict, new Uri("http://mock"), new BlobClientOptions());

            blockClient.SetupGet(c => c.ClientConfiguration).CallBase();

            SetupDownload(blockClient, dataSource);

            PartitionedDownloader downloader = new PartitionedDownloader(
                blockClient.Object,
                new StorageTransferOptions()
            {
                MaximumTransferLength = 40,
                InitialTransferLength = 10
            });

            Response result = await InvokeDownloadToAsync(downloader, stream);

            Assert.AreEqual(dataSource.Requests.Count, 4);
            AssertContent(100, stream);
            Assert.NotNull(result);
        }