示例#1
0
        private async Task ExecuteCatalog2DnxAsync(PerBatchContext context, IReadOnlyList <PerPackageContext> packageContexts, Uri catalogIndexUri)
        {
            var serviceProvider = GetServiceProvider(
                context,
                context.Global.FlatContainerContainerName,
                context.Process.FlatContainerStoragePath);

            var           storageFactory = serviceProvider.GetRequiredService <StorageFactory>();
            IAzureStorage preferredPackageSourceStorage = null;
            var           httpClientTimeout             = TimeSpan.FromMinutes(10);
            var           maxDegreeOfParallelism        = ServicePointManager.DefaultConnectionLimit;

            var collector = new DnxCatalogCollector(
                catalogIndexUri,
                storageFactory,
                preferredPackageSourceStorage,
                context.Global.ContentBaseAddress,
                serviceProvider.GetRequiredService <ITelemetryService>(),
                serviceProvider.GetRequiredService <ILogger>(),
                maxDegreeOfParallelism,
                () => serviceProvider.GetRequiredService <HttpMessageHandler>(),
                httpClientTimeout);

            var lowercasePackageIds = packageContexts.Select(x => x.PackageId.ToLowerInvariant());

            using (await _stringLocker.AcquireAsync(lowercasePackageIds, TimeSpan.FromMinutes(5)))
            {
                await collector.RunAsync(CancellationToken.None);
            }
        }
        public async Task RunAsync_WithFakeIAzureStorage_WhenPackageIsAlreadySynchronizedButDoesNotHaveRequiredProperties_ProcessesPackage()
        {
            _catalogToDnxStorage = new AzureSynchronizedMemoryStorageStub(new[]
            {
                new Uri("http://tempuri.org/packages/listedpackage.1.0.0.nupkg")
            }, areRequiredPropertiesPresentAsync: false);
            _catalogToDnxStorageFactory = new TestStorageFactory(name => _catalogToDnxStorage.WithName(name));

            var indexJsonUri  = _catalogToDnxStorage.ResolveUri("/listedpackage/index.json");
            var nupkgUri      = _catalogToDnxStorage.ResolveUri("/listedpackage/1.0.0/listedpackage.1.0.0.nupkg");
            var nuspecUri     = _catalogToDnxStorage.ResolveUri("/listedpackage/1.0.0/listedpackage.nuspec");
            var nupkgStream   = File.OpenRead("Packages\\ListedPackage.1.0.0.zip");
            var expectedNupkg = GetStreamBytes(nupkgStream);

            await _catalogToDnxStorage.SaveAsync(
                new Uri("http://tempuri.org/listedpackage/index.json"),
                new StringStorageContent(GetExpectedIndexJsonContent("1.0.0")),
                CancellationToken.None);

            _target = new DnxCatalogCollector(
                new Uri("http://tempuri.org/index.json"),
                _catalogToDnxStorageFactory,
                _nullPreferredPackageSourceStorage,
                _contentBaseAddress,
                Mock.Of <ITelemetryService>(),
                _logger,
                _maxDegreeOfParallelism,
                () => _mockServer);

            var catalogStorage = Catalogs.CreateTestCatalogWithOnePackage();
            await _mockServer.AddStorageAsync(catalogStorage);

            _mockServer.SetAction(
                "/packages/listedpackage.1.0.0.nupkg",
                request => Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StreamContent(nupkgStream)
            }));

            var        front = new DurableCursor(_cursorJsonUri, _catalogToDnxStorage, MemoryCursor.MinValue);
            ReadCursor back  = MemoryCursor.CreateMax();

            await _target.RunAsync(front, back, CancellationToken.None);

            Assert.Equal(4, _catalogToDnxStorage.Content.Count);
            Assert.True(_catalogToDnxStorage.Content.ContainsKey(_cursorJsonUri));
            Assert.True(_catalogToDnxStorage.Content.ContainsKey(indexJsonUri));
            Assert.True(_catalogToDnxStorage.Content.ContainsKey(nupkgUri));
            Assert.True(_catalogToDnxStorage.Content.ContainsKey(nuspecUri));
            Assert.True(_catalogToDnxStorage.ContentBytes.ContainsKey(_cursorJsonUri));
            Assert.True(_catalogToDnxStorage.ContentBytes.TryGetValue(indexJsonUri, out var indexJson));
            Assert.True(_catalogToDnxStorage.ContentBytes.ContainsKey(nupkgUri));
            Assert.True(_catalogToDnxStorage.ContentBytes.ContainsKey(nuspecUri));

            Assert.Equal(GetExpectedIndexJsonContent("1.0.0"), Encoding.UTF8.GetString(indexJson));
        }
        public async Task RunAsync_WhenPackageIsAlreadySynchronizedButNotInIndex_ProcessesPackage()
        {
            _catalogToDnxStorage = new SynchronizedMemoryStorage(new[]
            {
                new Uri("http://tempuri.org/packages/listedpackage.1.0.1.nupkg"),
            });
            _catalogToDnxStorageFactory = new TestStorageFactory(name => _catalogToDnxStorage.WithName(name));
            _mockServer = new MockServerHttpClientHandler();
            _mockServer.SetAction("/", request => Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)));

            var indexJsonUri = _catalogToDnxStorage.ResolveUri("/listedpackage/index.json");
            var nupkgUri     = _catalogToDnxStorage.ResolveUri("/listedpackage/1.0.1/listedpackage.1.0.1.nupkg");
            var nuspecUri    = _catalogToDnxStorage.ResolveUri("/listedpackage/1.0.1/listedpackage.nuspec");

            _target = new DnxCatalogCollector(
                new Uri("http://tempuri.org/index.json"),
                _catalogToDnxStorageFactory,
                _nullPreferredPackageSourceStorage,
                _contentBaseAddress,
                Mock.Of <ITelemetryService>(),
                new Mock <ILogger>().Object,
                _maxDegreeOfParallelism,
                () => _mockServer);

            var catalogStorage = Catalogs.CreateTestCatalogWithThreePackagesAndDelete();

            await _mockServer.AddStorageAsync(catalogStorage);

            _mockServer.SetAction(
                "/packages/listedpackage.1.0.1.nupkg",
                request => Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StreamContent(File.OpenRead("Packages\\ListedPackage.1.0.1.zip"))
            }));

            var        front = new DurableCursor(_cursorJsonUri, _catalogToDnxStorage, MemoryCursor.MinValue);
            ReadCursor back  = MemoryCursor.CreateMax();

            await _target.RunAsync(front, back, CancellationToken.None);

            Assert.Equal(2, _catalogToDnxStorage.Content.Count);
            Assert.True(_catalogToDnxStorage.Content.ContainsKey(_cursorJsonUri));
            Assert.True(_catalogToDnxStorage.Content.ContainsKey(indexJsonUri));
            Assert.False(_catalogToDnxStorage.Content.ContainsKey(nupkgUri));
            Assert.False(_catalogToDnxStorage.Content.ContainsKey(nuspecUri));
            Assert.True(_catalogToDnxStorage.ContentBytes.ContainsKey(_cursorJsonUri));
            Assert.True(_catalogToDnxStorage.ContentBytes.TryGetValue(indexJsonUri, out var indexJson));
            Assert.False(_catalogToDnxStorage.ContentBytes.ContainsKey(nupkgUri));
            Assert.False(_catalogToDnxStorage.ContentBytes.ContainsKey(nuspecUri));

            Assert.Equal(GetExpectedIndexJsonContent("1.0.1"), Encoding.UTF8.GetString(indexJson));
        }