public async Task Champion_BasicCheckpointing() { await using SearchResources resources = await SearchResources.CreateWithEmptyIndexAsync <SimpleDocument>(this); SearchClient client = resources.GetSearchClient(); SimpleDocument[] data = SimpleDocument.GetDocuments(1000); await using SearchIndexingBufferedSender <SimpleDocument> indexer = client.CreateIndexingBufferedSender( new SearchIndexingBufferedSenderOptions <SimpleDocument> { AutoFlush = true, AutoFlushInterval = null }); List <IndexDocumentsAction <SimpleDocument> > pending = new List <IndexDocumentsAction <SimpleDocument> >(); indexer.ActionAddedAsync += (IndexDocumentsAction <SimpleDocument> doc, CancellationToken cancellationToken) => { pending.Add(doc); return(Task.CompletedTask); }; indexer.ActionCompletedAsync += (IndexDocumentsAction <SimpleDocument> doc, IndexingResult result, CancellationToken cancellationToken) => { pending.Remove(doc); return(Task.CompletedTask); }; indexer.ActionFailedAsync += (IndexDocumentsAction <SimpleDocument> doc, IndexingResult result, Exception ex, CancellationToken cancellationToken) => { pending.Remove(doc); return(Task.CompletedTask); }; await indexer.UploadDocumentsAsync(data.Take(500)); await indexer.MergeDocumentsAsync(new[] { new SimpleDocument { Id = "Fake" } }); await indexer.UploadDocumentsAsync(data.Skip(500)); await DelayAsync(TimeSpan.FromSeconds(5), TimeSpan.FromMilliseconds(250)); Assert.AreEqual(1001 - BatchSize, pending.Count); await indexer.FlushAsync(); Assert.AreEqual(0, pending.Count); }
public async Task Convenience_Merge() { await using SearchResources resources = await SearchResources.CreateWithEmptyIndexAsync <SimpleDocument>(this); SearchClient client = resources.GetSearchClient(); SimpleDocument[] data = SimpleDocument.GetDocuments((int)(BatchSize * 1.5)); await using SearchIndexingBufferedSender <SimpleDocument> indexer = client.CreateIndexingBufferedSender( new SearchIndexingBufferedSenderOptions <SimpleDocument>()); ConcurrentQueue <IndexDocumentsAction <SimpleDocument> > failures = TrackFailures(indexer); await indexer.MergeDocumentsAsync(data); await indexer.FlushAsync(); Assert.AreEqual(data.Length, failures.Count); }
public async Task Champion_FineGrainedErrors() { await using SearchResources resources = await SearchResources.CreateWithEmptyIndexAsync <SimpleDocument>(this); SearchClient client = resources.GetSearchClient(); SimpleDocument[] data = SimpleDocument.GetDocuments(1000); // Don't touch the failures outside of the event handler until // we've finished flushing List <IndexingResult> failures = new List <IndexingResult>(); await using SearchIndexingBufferedSender <SimpleDocument> indexer = client.CreateIndexingBufferedSender <SimpleDocument>( new SearchIndexingBufferedSenderOptions <SimpleDocument> { AutoFlush = false }); indexer.ActionFailedAsync += (IndexDocumentsAction <SimpleDocument> doc, IndexingResult result, Exception ex, CancellationToken cancellationToken) => { failures.Add(result); return(Task.CompletedTask); }; await indexer.UploadDocumentsAsync(data.Take(500)); await indexer.MergeDocumentsAsync(new[] { new SimpleDocument { Id = "Fake" } }); await indexer.UploadDocumentsAsync(data.Skip(500)); await indexer.FlushAsync(); await WaitForDocumentCountAsync(resources.GetSearchClient(), 1000); Assert.AreEqual(1, failures.Count); Assert.AreEqual("Fake", failures[0].Key); Assert.AreEqual(404, failures[0].Status); }
public async Task Notifications_Failed() { await using SearchResources resources = await SearchResources.CreateWithEmptyIndexAsync <SimpleDocument>(this); SearchClient client = resources.GetSearchClient(); SimpleDocument[] data = SimpleDocument.GetDocuments((int)(BatchSize * 1.5)); await using SearchIndexingBufferedSender <SimpleDocument> indexer = client.CreateIndexingBufferedSender( new SearchIndexingBufferedSenderOptions <SimpleDocument>()); int failed = 0; indexer.ActionFailedAsync += (a, r, e, c) => { failed++; return(Task.CompletedTask); }; await indexer.MergeDocumentsAsync(data); await indexer.FlushAsync(); await DelayAsync(EventDelay, EventDelay); Assert.AreEqual(data.Length, failed); }