< Summary

Class:Azure.Storage.Blobs.ChangeFeed.SegmentFactory
Assembly:Azure.Storage.Blobs.ChangeFeed
File(s):C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs.ChangeFeed\src\SegmentFactory.cs
Covered lines:9
Uncovered lines:0
Coverable lines:9
Total lines:98
Line coverage:100% (9 of 9)
Covered branches:3
Total branches:4
Branch coverage:75% (3 of 4)

Metrics

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

File(s)

C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs.ChangeFeed\src\SegmentFactory.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.Text.Json;
 7using System.Threading.Tasks;
 8using Azure.Storage.Blobs.Models;
 9
 10namespace Azure.Storage.Blobs.ChangeFeed
 11{
 12    internal class SegmentFactory
 13    {
 14        private readonly BlobContainerClient _containerClient;
 15        private readonly ShardFactory _shardFactory;
 16
 17        /// <summary>
 18        ///  Constructor for mocking.
 19        /// </summary>
 4020        public SegmentFactory() { }
 21
 8422        public SegmentFactory(
 8423            BlobContainerClient containerClient,
 8424            ShardFactory shardFactory)
 25        {
 8426            _containerClient = containerClient;
 8427            _shardFactory = shardFactory;
 8428        }
 29
 30#pragma warning disable CA1822 // Does not acces instance data can be marked static.
 31        public virtual async Task<Segment> BuildSegment(
 32#pragma warning restore CA1822 // Can't mock static methods in MOQ.
 33            bool async,
 34            string manifestPath,
 35            SegmentCursor cursor = default)
 36        {
 37            // Models we need for later
 38            List<Shard> shards = new List<Shard>();
 39            DateTimeOffset dateTime = BlobChangeFeedExtensions.ToDateTimeOffset(manifestPath).Value;
 40
 41            // Download segment manifest
 42            BlobClient blobClient = _containerClient.GetBlobClient(manifestPath);
 43            BlobDownloadInfo blobDownloadInfo;
 44
 45            if (async)
 46            {
 47                blobDownloadInfo = await blobClient.DownloadAsync().ConfigureAwait(false);
 48            }
 49            else
 50            {
 51                blobDownloadInfo = blobClient.Download();
 52            }
 53
 54            // Parse segment manifest
 55            JsonDocument jsonManifest;
 56
 57            if (async)
 58            {
 59                jsonManifest = await JsonDocument.ParseAsync(blobDownloadInfo.Content).ConfigureAwait(false);
 60            }
 61            else
 62            {
 63                jsonManifest = JsonDocument.Parse(blobDownloadInfo.Content);
 64            }
 65
 66            foreach (JsonElement shardJsonElement in jsonManifest.RootElement.GetProperty("chunkFilePaths").EnumerateArr
 67            {
 68                string shardPath = shardJsonElement.ToString().Substring("$blobchangefeed/".Length);
 35269                var shardCursor = cursor?.ShardCursors?.Find(x => x.CurrentChunkPath.StartsWith(shardPath, StringCompari
 70                Shard shard = await _shardFactory.BuildShard(
 71                    async,
 72                    shardPath,
 73                    shardCursor)
 74                    .ConfigureAwait(false);
 75                if (shard.HasNext())
 76                {
 77                    shards.Add(shard);
 78                }
 79            }
 80
 81            int shardIndex = 0;
 82            string currentShardPath = cursor?.CurrentShardPath;
 83            if (!string.IsNullOrWhiteSpace(currentShardPath))
 84            {
 7285                shardIndex = shards.FindIndex(s => s.ShardPath == currentShardPath);
 86                if (shardIndex < 0)
 87                {
 88                    throw new ArgumentException($"Shard {currentShardPath} not found.");
 89                }
 90            }
 91            return new Segment(
 92                shards,
 93                shardIndex,
 94                dateTime,
 95                manifestPath);
 96        }
 97    }
 98}

Methods/Properties

.ctor()
.ctor(...)