Пример #1
0
            public void RejectsEmptyEnqueue()
            {
                var emptyIndexActions = new IndexActions(
                    new List <IndexAction <KeyedDocument> >(),
                    new List <IndexAction <KeyedDocument> >(),
                    new ResultAndAccessCondition <VersionListData>(
                        new VersionListData(new Dictionary <string, VersionPropertiesData>()),
                        AccessConditionWrapper.GenerateEmptyCondition()));

                var ex = Assert.Throws <ArgumentException>(
                    () => _target.EnqueueIndexActions(IdA, emptyIndexActions));

                Assert.Contains("There must be at least one index action.", ex.Message);
                Assert.Empty(_target._searchActions);
                Assert.Empty(_target._hijackActions);
                Assert.Empty(_target._idReferenceCount);
                Assert.Empty(_target._versionListDataResults);
            }
Пример #2
0
        public void EnqueueIndexActions(string packageId, IndexActions indexActions)
        {
            if (_versionListDataResults.ContainsKey(packageId))
            {
                throw new ArgumentException("This package ID has already been enqueued.", nameof(packageId));
            }

            if (indexActions.IsEmpty)
            {
                throw new ArgumentException("There must be at least one index action.", nameof(indexActions));
            }

            foreach (var action in indexActions.Hijack)
            {
                EnqueueAndIncrement(_hijackActions, packageId, action);
            }

            foreach (var action in indexActions.Search)
            {
                EnqueueAndIncrement(_searchActions, packageId, action);
            }

            _versionListDataResults.Add(packageId, indexActions.VersionListDataResult);
        }
Пример #3
0
            public BaseFacts(ITestOutputHelper output)
            {
                _logger = output.GetLogger <BatchPusher>();
                _searchIndexClientWrapper = new Mock <ISearchIndexClientWrapper>();
                _searchDocumentsWrapper   = new Mock <IDocumentsOperationsWrapper>();
                _hijackIndexClientWrapper = new Mock <ISearchIndexClientWrapper>();
                _hijackDocumentsWrapper   = new Mock <IDocumentsOperationsWrapper>();
                _versionListDataClient    = new Mock <IVersionListDataClient>();
                _config             = new AzureSearchJobConfiguration();
                _developmentConfig  = new AzureSearchJobDevelopmentConfiguration();
                _options            = new Mock <IOptionsSnapshot <AzureSearchJobConfiguration> >();
                _developmentOptions = new Mock <IOptionsSnapshot <AzureSearchJobDevelopmentConfiguration> >();
                _telemetryService   = new Mock <IAzureSearchTelemetryService>();

                _searchIndexClientWrapper.Setup(x => x.IndexName).Returns("search");
                _searchIndexClientWrapper.Setup(x => x.Documents).Returns(() => _searchDocumentsWrapper.Object);
                _hijackIndexClientWrapper.Setup(x => x.IndexName).Returns("hijack");
                _hijackIndexClientWrapper.Setup(x => x.Documents).Returns(() => _hijackDocumentsWrapper.Object);
                _versionListDataClient
                .Setup(x => x.TryReplaceAsync(It.IsAny <string>(), It.IsAny <VersionListData>(), It.IsAny <IAccessCondition>()))
                .ReturnsAsync(true);
                _options.Setup(x => x.Value).Returns(() => _config);
                _developmentOptions.Setup(x => x.Value).Returns(() => _developmentConfig);

                _searchBatches = new List <IndexBatch <KeyedDocument> >();
                _hijackBatches = new List <IndexBatch <KeyedDocument> >();

                _searchDocumentsWrapper
                .Setup(x => x.IndexAsync(It.IsAny <IndexBatch <KeyedDocument> >()))
                .ReturnsAsync(() => new DocumentIndexResult(new List <IndexingResult>()))
                .Callback <IndexBatch <KeyedDocument> >(b => _searchBatches.Add(b));
                _hijackDocumentsWrapper
                .Setup(x => x.IndexAsync(It.IsAny <IndexBatch <KeyedDocument> >()))
                .ReturnsAsync(() => new DocumentIndexResult(new List <IndexingResult>()))
                .Callback <IndexBatch <KeyedDocument> >(b => _hijackBatches.Add(b));

                _config.AzureSearchBatchSize            = 2;
                _config.MaxConcurrentVersionListWriters = 1;

                _searchDocumentA = IndexAction.Upload(new KeyedDocument());
                _searchDocumentB = IndexAction.Upload(new KeyedDocument());
                _searchDocumentC = IndexAction.Upload(new KeyedDocument());
                _searchDocuments = new List <IndexAction <KeyedDocument> >
                {
                    _searchDocumentA,
                    _searchDocumentB,
                    _searchDocumentC,
                };

                _hijackDocumentA = IndexAction.Upload(new KeyedDocument());
                _hijackDocumentB = IndexAction.Upload(new KeyedDocument());
                _hijackDocumentC = IndexAction.Upload(new KeyedDocument());
                _hijackDocumentD = IndexAction.Upload(new KeyedDocument());
                _hijackDocumentE = IndexAction.Upload(new KeyedDocument());
                _hijackDocuments = new List <IndexAction <KeyedDocument> >
                {
                    _hijackDocumentA,
                    _hijackDocumentB,
                    _hijackDocumentC,
                    _hijackDocumentD,
                    _hijackDocumentE,
                };

                _indexActions = new IndexActions(
                    _searchDocuments,
                    _hijackDocuments,
                    new ResultAndAccessCondition <VersionListData>(
                        new VersionListData(new Dictionary <string, VersionPropertiesData>()),
                        AccessConditionWrapper.GenerateEmptyCondition()));

                _target = new BatchPusher(
                    _searchIndexClientWrapper.Object,
                    _hijackIndexClientWrapper.Object,
                    _versionListDataClient.Object,
                    _options.Object,
                    _developmentOptions.Object,
                    _telemetryService.Object,
                    _logger);
            }