Exemplo n.º 1
0
            public async Task UsesProperReplicaHives()
            {
                await Target.UpdateAsync(Id, Entries, EntryToLeaf);

                HiveUpdater.Verify(
                    x => x.UpdateAsync(
                        It.IsAny <HiveType>(),
                        It.IsAny <IReadOnlyList <HiveType> >(),
                        It.IsAny <string>(),
                        It.IsAny <IReadOnlyList <CatalogCommitItem> >(),
                        It.IsAny <IReadOnlyDictionary <CatalogCommitItem, PackageDetailsCatalogLeaf> >(),
                        It.IsAny <CatalogCommit>()),
                    Times.Exactly(2));
                HiveUpdater.Verify(
                    x => x.UpdateAsync(
                        HiveType.Legacy,
                        It.Is <IReadOnlyList <HiveType> >(r => r.Count == 1 && r[0] == HiveType.Gzipped),
                        Id,
                        Entries,
                        EntryToLeaf,
                        It.IsAny <CatalogCommit>()),
                    Times.Once);
                HiveUpdater.Verify(
                    x => x.UpdateAsync(
                        HiveType.SemVer2,
                        It.Is <IReadOnlyList <HiveType> >(r => r.Count == 0),
                        Id,
                        Entries,
                        EntryToLeaf,
                        It.IsAny <CatalogCommit>()),
                    Times.Once);
            }
Exemplo n.º 2
0
        public IntegrationTests(ITestOutputHelper output)
        {
            Options = new Mock <IOptionsSnapshot <Catalog2RegistrationConfiguration> >();
            Config  = new Catalog2RegistrationConfiguration
            {
                LegacyBaseUrl                  = "https://example/v3/reg",
                LegacyStorageContainer         = "v3-reg",
                GzippedBaseUrl                 = "https://example/v3/reg-gz",
                GzippedStorageContainer        = "v3-reg-gz",
                SemVer2BaseUrl                 = "https://example/v3/reg-gz-semver2",
                SemVer2StorageContainer        = "v3-reg-gz-semver2",
                FlatContainerBaseUrl           = "https://example/v3/flatcontainer",
                GalleryBaseUrl                 = "https://example-gallery",
                MaxConcurrentHivesPerId        = 1,
                MaxConcurrentIds               = 1,
                MaxConcurrentOperationsPerHive = 1,
                MaxConcurrentStorageOperations = 1,
                EnsureSingleSnapshot           = false,
            };
            Options.Setup(x => x.Value).Returns(() => Config);

            CloudBlobClient        = new InMemoryCloudBlobClient();
            RegistrationUrlBuilder = new RegistrationUrlBuilder(Options.Object);
            EntityBuilder          = new EntityBuilder(RegistrationUrlBuilder, Options.Object);
            Throttle    = NullThrottle.Instance;
            HiveStorage = new HiveStorage(
                CloudBlobClient,
                RegistrationUrlBuilder,
                EntityBuilder,
                Throttle,
                Options.Object,
                output.GetLogger <HiveStorage>());
            HiveMerger  = new HiveMerger(Options.Object, output.GetLogger <HiveMerger>());
            HiveUpdater = new HiveUpdater(
                HiveStorage,
                HiveMerger,
                EntityBuilder,
                Options.Object,
                output.GetLogger <HiveUpdater>());
            RegistrationUpdater = new RegistrationUpdater(
                HiveUpdater,
                Options.Object,
                output.GetLogger <RegistrationUpdater>());
        }
Exemplo n.º 3
0
            public async Task UsesDifferentCommitIdButSameCommitTimestamp()
            {
                var commits = new ConcurrentBag <CatalogCommit>();

                HiveUpdater
                .Setup(x => x.UpdateAsync(
                           It.IsAny <HiveType>(),
                           It.IsAny <IReadOnlyList <HiveType> >(),
                           It.IsAny <string>(),
                           It.IsAny <IReadOnlyList <CatalogCommitItem> >(),
                           It.IsAny <IReadOnlyDictionary <CatalogCommitItem, PackageDetailsCatalogLeaf> >(),
                           It.IsAny <CatalogCommit>()))
                .Returns(Task.CompletedTask)
                .Callback <HiveType, IReadOnlyList <HiveType>, string, IReadOnlyList <CatalogCommitItem>, IReadOnlyDictionary <CatalogCommitItem, PackageDetailsCatalogLeaf>, CatalogCommit>(
                    (h, r, i, e, l, c) => commits.Add(c));

                await Target.UpdateAsync(Id, Entries, EntryToLeaf);

                Assert.Equal(2, commits.Count);
                Assert.Single(commits.Select(x => x.Timestamp).Distinct());
                Assert.Equal(2, commits.Select(x => x.Id).Distinct().Count());
            }
Exemplo n.º 4
0
            public Facts(ITestOutputHelper output)
            {
                Storage       = new Mock <IHiveStorage>();
                Merger        = new Mock <IHiveMerger>();
                EntityBuilder = new Mock <IEntityBuilder>();
                Options       = new Mock <IOptionsSnapshot <Catalog2RegistrationConfiguration> >();
                Logger        = output.GetLogger <HiveUpdater>();

                Config             = new Catalog2RegistrationConfiguration();
                Hive               = HiveType.SemVer2;
                ReplicaHives       = new List <HiveType>();
                Id                 = "NuGet.Versioning";
                Entries            = new List <CatalogCommitItem>();
                EntryToCatalogLeaf = new Dictionary <CatalogCommitItem, PackageDetailsCatalogLeaf>(
                    ReferenceEqualityComparer <CatalogCommitItem> .Default);
                RegistrationIndex = new RegistrationIndex
                {
                    Items = new List <RegistrationPage>
                    {
                        new RegistrationPage
                        {
                            Lower = "1.0.0",
                            Upper = "3.0.0",
                            Count = 2,
                            Items = new List <RegistrationLeafItem>
                            {
                                new RegistrationLeafItem
                                {
                                    Url          = $"https://example/reg/{Id.ToLowerInvariant()}/1.0.0.json",
                                    CatalogEntry = new RegistrationCatalogEntry
                                    {
                                        Version = "1.0.0",
                                    }
                                },
                                new RegistrationLeafItem
                                {
                                    Url          = $"https://example/reg/{Id.ToLowerInvariant()}/3.0.0.json",
                                    CatalogEntry = new RegistrationCatalogEntry
                                    {
                                        Version = "3.0.0",
                                    }
                                },
                            }
                        }
                    }
                };
                MergeResult = new HiveMergeResult(
                    new HashSet <PageInfo>(),
                    new HashSet <LeafInfo>(),
                    new HashSet <LeafInfo>());
                RegistrationLeaf   = new RegistrationLeaf();
                RegistrationCommit = new CatalogCommit(
                    "b580f835-f041-4361-aa46-57e5dc338a63",
                    new DateTimeOffset(2019, 10, 25, 0, 0, 0, TimeSpan.Zero));

                Options.Setup(x => x.Value).Returns(() => Config);
                Storage
                .Setup(x => x.ReadIndexOrNullAsync(It.IsAny <HiveType>(), It.IsAny <string>()))
                .ReturnsAsync(() => RegistrationIndex);
                var concreteHiveMerger = new HiveMerger(Options.Object, output.GetLogger <HiveMerger>());

                Merger
                .Setup(x => x.MergeAsync(It.IsAny <IndexInfo>(), It.IsAny <IReadOnlyList <CatalogCommitItem> >()))
                .Returns <IndexInfo, IReadOnlyList <CatalogCommitItem> >((i, e) => concreteHiveMerger.MergeAsync(i, e));
                EntityBuilder
                .Setup(x => x.NewLeaf(It.IsAny <RegistrationLeafItem>()))
                .Returns(() => RegistrationLeaf);
                EntityBuilder
                .Setup(x => x.UpdateNonInlinedPageItem(
                           It.IsAny <RegistrationPage>(),
                           It.IsAny <HiveType>(),
                           It.IsAny <string>(),
                           It.IsAny <int>(),
                           It.IsAny <NuGetVersion>(),
                           It.IsAny <NuGetVersion>()))
                .Callback <RegistrationPage, HiveType, string, int, NuGetVersion, NuGetVersion>((p, h, id, c, l, u) =>
                {
                    p.Url = $"https://example/reg/" +
                            $"{id.ToLowerInvariant()}/" +
                            $"{l.ToNormalizedString().ToLowerInvariant()}/" +
                            $"{u.ToNormalizedString().ToLowerInvariant()}.json";
                });

                Target = new HiveUpdater(
                    Storage.Object,
                    Merger.Object,
                    EntityBuilder.Object,
                    Options.Object,
                    Logger);
            }