< Summary

Class:Azure.Storage.Blobs.ChangeFeed.ShardFactory
Assembly:Azure.Storage.Blobs.ChangeFeed
File(s):C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs.ChangeFeed\src\ShardFactory.cs
Covered lines:42
Uncovered lines:1
Coverable lines:43
Total lines:111
Line coverage:97.6% (42 of 43)
Covered branches:26
Total branches:30
Branch coverage:86.6% (26 of 30)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-100%100%
.ctor()-100%100%
BuildShard()-97.22%86.67%

File(s)

C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs.ChangeFeed\src\ShardFactory.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 Azure.Storage.Blobs.Models;
 8
 9namespace Azure.Storage.Blobs.ChangeFeed
 10{
 11    /// <summary>
 12    /// Builds a Shard.
 13    /// </summary>
 14    internal class ShardFactory
 15    {
 16        private readonly ChunkFactory _chunkFactory;
 17        private readonly BlobContainerClient _containerClient;
 18
 9619        public ShardFactory(
 9620            BlobContainerClient containerClient,
 9621            ChunkFactory chunkFactory)
 22        {
 9623            _containerClient = containerClient;
 9624            _chunkFactory = chunkFactory;
 9625        }
 26
 27        /// <summary>
 28        /// Constructor for mocking.
 29        /// </summary>
 1630        public ShardFactory() { }
 31
 32#pragma warning disable CA1822 // Does not acces instance data can be marked static.
 33        public virtual async Task<Shard> BuildShard(
 34#pragma warning restore CA1822 // Can't mock static methods in MOQ.
 35            bool async,
 36            string shardPath,
 37            ShardCursor shardCursor = default)
 38        {
 39            // Models we'll need later
 23640            Queue<string> chunks = new Queue<string>();
 23641            long blockOffset = shardCursor?.BlockOffset ?? 0;
 23642            long eventIndex = shardCursor?.EventIndex ?? 0;
 43
 44            // Get Chunks
 23645            if (async)
 46            {
 100447                await foreach (BlobHierarchyItem blobHierarchyItem in _containerClient.GetBlobsByHierarchyAsync(
 22648                    prefix: shardPath).ConfigureAwait(false))
 49                {
 27650                    if (blobHierarchyItem.IsPrefix)
 51                        continue;
 52
 53                    //Chunk chunk = new Chunk(_containerClient, blobHierarchyItem.Blob.Name);
 27654                    chunks.Enqueue(blobHierarchyItem.Blob.Name);
 55                }
 56            }
 57            else
 58            {
 14059                foreach (BlobHierarchyItem blobHierarchyItem in _containerClient.GetBlobsByHierarchy(
 1060                    prefix: shardPath))
 61                {
 6062                    if (blobHierarchyItem.IsPrefix)
 63                        continue;
 64
 6065                    chunks.Enqueue(blobHierarchyItem.Blob.Name);
 66                }
 67            }
 68
 23669            long chunkIndex = 0;
 23670            string currentChunkPath = shardCursor?.CurrentChunkPath;
 23671            Chunk currentChunk = null;
 23672            if (chunks.Count > 0) // Chunks can be empty right after hour flips.
 73            {
 74                // Fast forward to current Chunk
 23675                if (!string.IsNullOrWhiteSpace(currentChunkPath))
 76                {
 13277                    while (chunks.Count > 0)
 78                    {
 13279                        if (chunks.Peek() == currentChunkPath)
 80                        {
 81                            break;
 82                        }
 83                        else
 84                        {
 6485                            chunks.Dequeue();
 6486                            chunkIndex++;
 87                        }
 88                    }
 6889                    if (chunks.Count == 0)
 90                    {
 091                        throw new ArgumentException($"Chunk {currentChunkPath} not found.");
 92                    }
 93                }
 94
 23695                currentChunk = await _chunkFactory.BuildChunk(
 23696                    async,
 23697                    chunks.Dequeue(),
 23698                    blockOffset,
 23699                    eventIndex).ConfigureAwait(false);
 100            }
 101
 236102            return new Shard(
 236103                _containerClient,
 236104                _chunkFactory,
 236105                chunks,
 236106                currentChunk,
 236107                chunkIndex,
 236108                shardPath);
 236109        }
 110    }
 111}

Methods/Properties

.ctor(...)
.ctor()
BuildShard()