< Summary

Class:Azure.Storage.Blobs.ChangeFeed.Shard
Assembly:Azure.Storage.Blobs.ChangeFeed
File(s):C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs.ChangeFeed\src\Shard.cs
Covered lines:31
Uncovered lines:1
Coverable lines:32
Total lines:110
Line coverage:96.8% (31 of 32)
Covered branches:9
Total branches:12
Branch coverage:75% (9 of 12)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_ShardPath()-100%100%
GetCursor()-100%50%
HasNext()-100%75%
Next()-90.91%83.33%
.ctor(...)-100%100%
.ctor()-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs.ChangeFeed\src\Shard.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Collections.Generic;
 6using System.Threading.Tasks;
 7using System.Threading;
 8
 9namespace Azure.Storage.Blobs.ChangeFeed
 10{
 11    internal class Shard
 12    {
 13        /// <summary>
 14        /// Container Client for listing Chunks.
 15        /// </summary>
 16        private readonly BlobContainerClient _containerClient;
 17
 18        /// <summary>
 19        /// ChunkFactory.
 20        /// </summary>
 21        private readonly ChunkFactory _chunkFactory;
 22
 23        /// <summary>
 24        /// Queue of the paths to Chunks we haven't processed.
 25        /// </summary>
 26        private readonly Queue<string> _chunks;
 27
 28        /// <summary>
 29        /// The Chunk we are currently processing.
 30        /// </summary>
 31        private Chunk _currentChunk;
 32
 33        /// <summary>
 34        /// The index of the Chunk we are processing.
 35        /// </summary>
 36        private long _chunkIndex;
 37
 38        /// <summary>
 39        /// The index of the Chunk we are processing.
 40        /// </summary>
 16441        public virtual string ShardPath { get; }
 42
 43        /// <summary>
 44        /// Gets the <see cref="ShardCursor"/> for this Shard.
 45        /// </summary>
 46        public virtual ShardCursor GetCursor()
 40047            => _currentChunk == null ? null : new ShardCursor(
 40048                _currentChunk.ChunkPath,
 40049                _currentChunk.BlockOffset,
 40050                _currentChunk.EventIndex);
 51
 52        /// <summary>
 53        /// If this Shard has a next event.
 54        /// </summary>
 55        public virtual bool HasNext()
 5942056            => _chunks.Count > 0 || (_currentChunk != null && _currentChunk.HasNext());
 57
 58        /// <summary>
 59        /// Gets the next <see cref="BlobChangeFeedEvent"/>.
 60        /// </summary>
 61        public virtual async Task<BlobChangeFeedEvent> Next(
 62            bool async,
 63            CancellationToken cancellationToken = default)
 64        {
 2961265            if (!HasNext())
 66            {
 067                throw new InvalidOperationException("Shard doesn't have any more events");
 68            }
 69
 70            BlobChangeFeedEvent changeFeedEvent;
 71
 2961272            changeFeedEvent = await _currentChunk.Next(async, cancellationToken).ConfigureAwait(false);
 73
 74            // Remove currentChunk if it doesn't have another event.
 2961275            if (!_currentChunk.HasNext() && _chunks.Count > 0)
 76            {
 1277                _currentChunk = await _chunkFactory.BuildChunk(
 1278                    async,
 1279                    _chunks.Dequeue(),
 1280                    cancellationToken: cancellationToken).ConfigureAwait(false);
 1281                _chunkIndex++;
 82            }
 2961283            return changeFeedEvent;
 2961284        }
 85
 86        /// <summary>
 87        /// Constructor for use by <see cref="ShardFactory.BuildShard(bool, string, ShardCursor)"/>.
 88        /// </summary>
 23689        public Shard(
 23690            BlobContainerClient containerClient,
 23691            ChunkFactory chunkFactory,
 23692            Queue<string> chunks,
 23693            Chunk currentChunk,
 23694            long chunkIndex,
 23695            string shardPath)
 96        {
 23697            _containerClient = containerClient;
 23698            _chunkFactory = chunkFactory;
 23699            _chunks = chunks;
 236100            _currentChunk = currentChunk;
 236101            _chunkIndex = chunkIndex;
 236102            ShardPath = shardPath;
 236103        }
 104
 105        /// <summary>
 106        /// Constructor for mocking.
 107        /// </summary>
 48108        internal Shard() { }
 109    }
 110}