示例#1
0
        public async Task BatchHandling()
        {
            var source    = new Source();
            var searchDoc = new SearchDocument();

            var indexer = new TestIndexer((s) => searchDoc, documentsPerIndexBatch: 2);

            //add doc to batch - too small to process
            await indexer.IndexAsync(source);

            Assert.Empty(indexer.IndexedDocuments);
            Assert.Equal(1, indexer.PendingDocumentCount);

            //add another doc - batch is big enough to trigger processing
            await indexer.IndexAsync(source);

            Assert.Equal(2, indexer.IndexedDocuments.Count);
            Assert.Equal(0, indexer.PendingDocumentCount);

            //add another doc - batch is too small for processing
            await indexer.IndexAsync(source);

            Assert.Equal(2, indexer.IndexedDocuments.Count);
            Assert.Equal(1, indexer.PendingDocumentCount);

            //force processing of pending docs
            await indexer.IndexPendingDocumentsAsync();

            Assert.Equal(3, indexer.IndexedDocuments.Count);
            Assert.Equal(0, indexer.PendingDocumentCount);
        }
示例#2
0
        public async Task InvokesMapper()
        {
            var source    = new Source();
            var searchDoc = new SearchDocument();

            var indexer = new TestIndexer((s) => searchDoc);

            await indexer.IndexAsync(source);

            Assert.Single(indexer.IndexedDocuments, searchDoc);
        }
示例#3
0
        public async Task WillNotSendANullSearchDocument()
        {
            var            source        = new Source();
            SearchDocument nullSearchDoc = null;

            // simulate the mapper returning a null
            var indexer = new TestIndexer((s) => nullSearchDoc);

            await indexer.IndexAsync(source);

            Assert.Empty(indexer.IndexedDocuments);
        }
示例#4
0
        public async Task IsThreadSafe()
        {
            const int DOCUMENTS_TO_INDEX = 100;

            var indexer = new TestIndexer((s) => new SearchDocument());

            foreach (var i in Enumerable.Range(0, DOCUMENTS_TO_INDEX).AsParallel())
            {
                await indexer.IndexAsync(new Source());
            }

            Assert.Equal(DOCUMENTS_TO_INDEX, indexer.IndexedDocuments.Count);
        }
示例#5
0
        public async Task SubmitsPendingDocumentsOnDispose()
        {
            var source    = new Source();
            var searchDoc = new SearchDocument();

            var indexer = new TestIndexer((s) => searchDoc, documentsPerIndexBatch: 2);

            //add doc to batch - too small to process
            await indexer.IndexAsync(source);

            Assert.Empty(indexer.IndexedDocuments);
            Assert.Equal(1, indexer.PendingDocumentCount);

            indexer.Dispose();
            Assert.Single(indexer.IndexedDocuments);
            Assert.Equal(0, indexer.PendingDocumentCount);
        }