public async Task QueryAsync_Progress()
        {
            // Arrange
            await using DisposingContainer test = await GetTestContainerAsync();

            BlockBlobClient blockBlobClient = InstrumentClient(test.Container.GetBlockBlobClient(GetNewBlobName()));
            Stream          stream          = CreateDataStream(Constants.KB);
            await blockBlobClient.UploadAsync(stream);

            // Act
            string           query            = @"SELECT _2 from BlobStorage WHERE _1 > 250;";
            TestProgress     progressReporter = new TestProgress();
            BlobQueryOptions options          = new BlobQueryOptions
            {
                ProgressHandler = progressReporter
            };

            Response <BlobDownloadInfo> response = await blockBlobClient.QueryAsync(
                query,
                options);

            using StreamReader streamReader = new StreamReader(response.Value.Content);
            await streamReader.ReadToEndAsync();

            Assert.AreEqual(2, progressReporter.List.Count);
            Assert.AreEqual(Constants.KB, progressReporter.List[0]);
            Assert.AreEqual(Constants.KB, progressReporter.List[1]);
        }
        public async Task QueryAsync_Large()
        {
            // Arrange
            await using DisposingContainer test = await GetTestContainerAsync();

            BlockBlobClient blockBlobClient = InstrumentClient(test.Container.GetBlockBlobClient(GetNewBlobName()));
            Stream          stream          = CreateDataStream(250 * Constants.MB);
            await blockBlobClient.UploadAsync(stream);

            string query = @"SELECT * from BlobStorage";

            // Act
            TestProgress     progressReporter = new TestProgress();
            BlobQueryOptions options          = new BlobQueryOptions
            {
                ProgressHandler = progressReporter
            };
            Response <BlobDownloadInfo> response = await blockBlobClient.QueryAsync(
                query,
                options);

            stream.Seek(0, SeekOrigin.Begin);
            using StreamReader expectedStreamReader = new StreamReader(stream);
            string expected = await expectedStreamReader.ReadToEndAsync();

            using StreamReader actualStreamReader = new StreamReader(response.Value.Content);
            string actual = await actualStreamReader.ReadToEndAsync();

            // Assert
            // Check we got back the same content that we uploaded.
            Assert.AreEqual(expected, actual);
        }
        public async Task AppendBlockAsync_ProgressReporting()
        {
            await using DisposingContainer test = await GetTestContainerAsync();

            // Arrange
            var blobName          = GetNewBlobName();
            AppendBlobClient blob = InstrumentClient(test.Container.GetAppendBlobClient(blobName));
            await blob.CreateAsync();

            const int    blobSize = 4 * Constants.MB;
            var          data     = GetRandomBuffer(blobSize);
            TestProgress progress = new TestProgress();

            // Act
            using (var stream = new MemoryStream(data))
            {
                await blob.AppendBlockAsync(stream, progressHandler : progress);
            }

            // Assert
            Assert.IsFalse(progress.List.Count == 0);

            for (int i = 1; i < progress.List.Count; i++)
            {
                Assert.IsTrue(progress.List[i] >= progress.List[i - 1]);
            }

            Assert.AreEqual(blobSize, progress.List[progress.List.Count - 1]);
        }
Example #4
0
        public async Task UploadAsync_ProgressReporting()
        {
            // Arrange
            await using DisposingContainer test = await GetTestContainerAsync();

            BlobClient             blob     = InstrumentClient(test.Container.GetBlobClient(GetNewBlobName()));
            TestProgress           progress = new TestProgress();
            StorageTransferOptions options  = new StorageTransferOptions
            {
                MaximumTransferLength = Constants.MB,
                MaximumConcurrency    = 16
            };
            long size = new Specialized.BlockBlobClient(new Uri("")).BlockBlobMaxUploadBlobBytes + 1; // ensure that the Parallel upload code path is hit

            using var stream = new MemoryStream(GetRandomBuffer(size));

            // Act
            await blob.UploadAsync(content : stream, progressHandler : progress, transferOptions : options);

            // Assert
            Assert.IsFalse(progress.List.Count == 0);

            Assert.AreEqual(size, progress.List[progress.List.Count - 1]);
        }