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); }
static void Main(string[] args) { TestIndexer tx = new TestIndexer(); tx.TestIndexersInCollection(); TestConstructor tc = new TestConstructor(); tc.TestDiffConstructorParam(); }
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); }
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); }
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); }
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); }