public RegistrationComparerCollectorLogic(
     CommitCollectorUtility utility,
     HiveComparer comparer,
     IOptionsSnapshot <RegistrationComparerConfiguration> options,
     ILogger <RegistrationComparerCollectorLogic> logger)
 {
     _utility  = utility ?? throw new ArgumentNullException(nameof(utility));
     _comparer = comparer ?? throw new ArgumentNullException(nameof(comparer));
     _options  = options ?? throw new ArgumentNullException(nameof(options));
     _logger   = logger ?? throw new ArgumentNullException(nameof(logger));
 }
        public RegistrationCollectorLogic(
            CommitCollectorUtility utility,
            IRegistrationUpdater updater,
            IOptionsSnapshot <Catalog2RegistrationConfiguration> options,
            ILogger <RegistrationCollectorLogic> logger)
        {
            _utility = utility ?? throw new ArgumentNullException(nameof(utility));
            _updater = updater ?? throw new ArgumentNullException(nameof(updater));
            _options = options ?? throw new ArgumentNullException(nameof(options));
            _logger  = logger ?? throw new ArgumentNullException(nameof(logger));

            if (_options.Value.MaxConcurrentIds <= 0)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(options),
                          $"The {nameof(Catalog2RegistrationConfiguration.MaxConcurrentIds)} must be greater than zero.");
            }
        }
            public BaseFacts(ITestOutputHelper output)
            {
                _catalogClient             = new Mock <ICatalogClient>();
                _catalogIndexActionBuilder = new Mock <ICatalogIndexActionBuilder>();
                _batchPusher        = new Mock <IBatchPusher>();
                _fixUpEvaluator     = new Mock <IDocumentFixUpEvaluator>();
                _utilityOptions     = new Mock <IOptionsSnapshot <CommitCollectorConfiguration> >();
                _collectorOptions   = new Mock <IOptionsSnapshot <Catalog2AzureSearchConfiguration> >();
                _utilityConfig      = new CommitCollectorConfiguration();
                _collectorConfig    = new Catalog2AzureSearchConfiguration();
                _telemetryService   = new Mock <IAzureSearchTelemetryService>();
                _v3TelemetryService = new Mock <IV3TelemetryService>();
                _logger             = output.GetLogger <AzureSearchCollectorLogic>();
                _utilityLogger      = output.GetLogger <CommitCollectorUtility>();

                _batchPusher.SetReturnsDefault(Task.FromResult(new BatchPusherResult()));
                _utilityOptions.Setup(x => x.Value).Returns(() => _utilityConfig);
                _utilityConfig.MaxConcurrentCatalogLeafDownloads = 1;
                _collectorOptions.Setup(x => x.Value).Returns(() => _collectorConfig);
                _collectorConfig.MaxConcurrentBatches = 1;
                _fixUpEvaluator
                .Setup(x => x.TryFixUpAsync(
                           It.IsAny <IReadOnlyList <CatalogCommitItem> >(),
                           It.IsAny <ConcurrentBag <IdAndValue <IndexActions> > >(),
                           It.IsAny <InvalidOperationException>()))
                .ReturnsAsync(() => DocumentFixUp.IsNotApplicable());

                _utility = new CommitCollectorUtility(
                    _catalogClient.Object,
                    _v3TelemetryService.Object,
                    _utilityOptions.Object,
                    _utilityLogger);

                _target = new AzureSearchCollectorLogic(
                    _catalogIndexActionBuilder.Object,
                    () => _batchPusher.Object,
                    _fixUpEvaluator.Object,
                    _utility,
                    _collectorOptions.Object,
                    _telemetryService.Object,
                    _logger);
            }
Example #4
0
        public AzureSearchCollectorLogic(
            ICatalogIndexActionBuilder indexActionBuilder,
            Func <IBatchPusher> batchPusherFactory,
            IDocumentFixUpEvaluator fixUpEvaluator,
            CommitCollectorUtility utility,
            IOptionsSnapshot <Catalog2AzureSearchConfiguration> options,
            IAzureSearchTelemetryService telemetryService,
            ILogger <AzureSearchCollectorLogic> logger)
        {
            _indexActionBuilder = indexActionBuilder ?? throw new ArgumentNullException(nameof(indexActionBuilder));
            _batchPusherFactory = batchPusherFactory ?? throw new ArgumentNullException(nameof(batchPusherFactory));
            _fixUpEvaluator     = fixUpEvaluator ?? throw new ArgumentNullException(nameof(fixUpEvaluator));
            _utility            = utility ?? throw new ArgumentNullException(nameof(utility));
            _options            = options ?? throw new ArgumentNullException(nameof(options));
            _telemetryService   = telemetryService ?? throw new ArgumentNullException(nameof(telemetryService));
            _logger             = logger ?? throw new ArgumentNullException(nameof(logger));

            if (_options.Value.MaxConcurrentBatches <= 0)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(options),
                          $"The {nameof(AzureSearchJobConfiguration.MaxConcurrentBatches)} must be greater than zero.");
            }
        }
Example #5
0
        public AzureSearchCollectorLogicIntegrationTests(ITestOutputHelper output)
        {
            _utilityConfig = new CommitCollectorConfiguration
            {
                MaxConcurrentCatalogLeafDownloads = 1,
            };
            _utilityOptions = new Mock <IOptionsSnapshot <CommitCollectorConfiguration> >();
            _utilityOptions.Setup(x => x.Value).Returns(() => _utilityConfig);

            _config = new Catalog2AzureSearchConfiguration
            {
                MaxConcurrentBatches            = 1,
                MaxConcurrentVersionListWriters = 1,
                StorageContainer           = "integration-tests-container",
                StoragePath                = "integration-tests-path",
                RegistrationsBaseUrl       = "https://example/registrations/",
                GalleryBaseUrl             = Data.GalleryBaseUrl,
                FlatContainerBaseUrl       = Data.FlatContainerBaseUrl,
                FlatContainerContainerName = Data.FlatContainerContainerName,

                Scoring = new AzureSearchScoringConfiguration()
            };
            _options = new Mock <IOptionsSnapshot <Catalog2AzureSearchConfiguration> >();
            _options.Setup(x => x.Value).Returns(() => _config);

            _developmentConfig  = new AzureSearchJobDevelopmentConfiguration();
            _developmentOptions = new Mock <IOptionsSnapshot <AzureSearchJobDevelopmentConfiguration> >();
            _developmentOptions.Setup(x => x.Value).Returns(() => _developmentConfig);

            _telemetryClient    = new Mock <ITelemetryClient>();
            _telemetryService   = new AzureSearchTelemetryService(_telemetryClient.Object);
            _v3TelemetryService = new V3TelemetryService(_telemetryClient.Object);

            // Mock the database that is used for fetching owner information. The product code only reads
            // from the database so it is less important to have a realistic, stateful implementation.
            _entitiesContextFactory = new Mock <IEntitiesContextFactory>();
            _entitiesContext        = new Mock <IEntitiesContext>();
            _entitiesContextFactory.Setup(x => x.CreateAsync(It.IsAny <bool>())).ReturnsAsync(() => _entitiesContext.Object);
            _entitiesContext.Setup(x => x.PackageRegistrations).Returns(DbSetMockFactory.Create <PackageRegistration>());
            _ownerFetcher = new DatabaseAuxiliaryDataFetcher(
                new Mock <ISqlConnectionFactory <GalleryDbConfiguration> >().Object,
                _entitiesContextFactory.Object,
                _telemetryService,
                output.GetLogger <DatabaseAuxiliaryDataFetcher>());

            _cloudBlobClient       = new InMemoryCloudBlobClient();
            _versionListDataClient = new VersionListDataClient(
                _cloudBlobClient,
                _options.Object,
                output.GetLogger <VersionListDataClient>());
            _registrationClient = new InMemoryRegistrationClient();
            _catalogClient      = new InMemoryCatalogClient();
            _leafFetcher        = new CatalogLeafFetcher(
                _registrationClient,
                _catalogClient,
                _options.Object,
                _telemetryService,
                output.GetLogger <CatalogLeafFetcher>());
            _baseDocumentBuilder = new BaseDocumentBuilder(_options.Object);
            _search  = new SearchDocumentBuilder(_baseDocumentBuilder);
            _hijack  = new HijackDocumentBuilder(_baseDocumentBuilder);
            _builder = new CatalogIndexActionBuilder(
                _versionListDataClient,
                _leafFetcher,
                _ownerFetcher,
                _search,
                _hijack,
                output.GetLogger <CatalogIndexActionBuilder>());

            _searchIndex     = new Mock <ISearchIndexClientWrapper>();
            _searchDocuments = new InMemoryDocumentsOperations();
            _searchIndex.Setup(x => x.Documents).Returns(() => _searchDocuments);
            _hijackIndex     = new Mock <ISearchIndexClientWrapper>();
            _hijackDocuments = new InMemoryDocumentsOperations();
            _hijackIndex.Setup(x => x.Documents).Returns(() => _hijackDocuments);

            _fixUpEvaluator = new DocumentFixUpEvaluator(
                _versionListDataClient,
                _leafFetcher,
                output.GetLogger <DocumentFixUpEvaluator>());

            _commitCollectorUtility = new CommitCollectorUtility(
                _catalogClient,
                _v3TelemetryService,
                _utilityOptions.Object,
                output.GetLogger <CommitCollectorUtility>());

            _collector = new AzureSearchCollectorLogic(
                _builder,
                () => new BatchPusher(
                    _searchIndex.Object,
                    _hijackIndex.Object,
                    _versionListDataClient,
                    _options.Object,
                    _developmentOptions.Object,
                    _telemetryService,
                    output.GetLogger <BatchPusher>()),
                _fixUpEvaluator,
                _commitCollectorUtility,
                _options.Object,
                _telemetryService,
                output.GetLogger <AzureSearchCollectorLogic>());
        }