Exemplo n.º 1
0
        public async Task Behavior_Retry(int status)
        {
            await using SearchResources resources = await SearchResources.CreateWithEmptyIndexAsync <SimpleDocument>(this);

            BatchingSearchClient client = GetBatchingSearchClient(resources);

            SimpleDocument[] data = SimpleDocument.GetDocuments(1);

            await using SearchIndexingBufferedSender <SimpleDocument> indexer =
                            client.CreateIndexingBufferedSender <SimpleDocument>();
            client.ResponseTransformer = (IndexingResult result) =>
            {
                client.ResponseTransformer = null;
                return(new IndexingResult(result.Key, false, status));
            };
            AssertNoFailures(indexer);
            int sent = 0;

            indexer.ActionSentAsync += (a, c) => { sent++; return(Task.CompletedTask); };
            await indexer.UploadDocumentsAsync(data);

            await indexer.FlushAsync();

            Assert.Less(1, sent);
        }
Exemplo n.º 2
0
        public async Task AutoFlushInterval_FullBatch()
        {
            await using SearchResources resources = await SearchResources.CreateWithEmptyIndexAsync <SimpleDocument>(this);

            BatchingSearchClient client = GetBatchingSearchClient(resources);

            SimpleDocument[] data = SimpleDocument.GetDocuments((int)(BatchSize * 1.5));

            await using SearchIndexingBufferedSender <SimpleDocument> indexer =
                            client.CreateIndexingBufferedSender(
                                new SearchIndexingBufferedSenderOptions <SimpleDocument>
            {
                AutoFlushInterval = TimeSpan.FromMilliseconds(500)
            });
            AssertNoFailures(indexer);
            ConcurrentDictionary <int, IndexDocumentsAction <SimpleDocument> > pending = TrackPending(indexer);

            Task <object> submitted = client.BatchSubmitted;
            await indexer.UploadDocumentsAsync(data);

            await submitted;

            await DelayAsync(EventDelay, EventDelay);

            Assert.AreEqual(data.Length - BatchSize, pending.Count);

            await DelayAsync(TimeSpan.FromSeconds(5), EventDelay);
            await WaitForDocumentCountAsync(resources.GetSearchClient(), data.Length);
        }
Exemplo n.º 3
0
        public async Task Behavior_Split()
        {
            await using SearchResources resources = await SearchResources.CreateWithEmptyIndexAsync <SimpleDocument>(this);

            BatchingSearchClient client = GetBatchingSearchClient(resources);

            SimpleDocument[] data = SimpleDocument.GetDocuments(BatchSize);

            await using SearchIndexingBufferedSender <SimpleDocument> indexer =
                            client.CreateIndexingBufferedSender <SimpleDocument>();
            AssertNoFailures(indexer);
            client.SplitNextBatch = true;
            await indexer.UploadDocumentsAsync(data);

            await indexer.FlushAsync();

            await WaitForDocumentCountAsync(resources.GetSearchClient(), data.Length);
        }
Exemplo n.º 4
0
        public async Task AutoFlushInterval_TinyInterval()
        {
            await using SearchResources resources = await SearchResources.CreateWithEmptyIndexAsync <SimpleDocument>(this);

            BatchingSearchClient client = GetBatchingSearchClient(resources);

            SimpleDocument[] data = SimpleDocument.GetDocuments((int)(BatchSize * 1.5));

            await using SearchIndexingBufferedSender <SimpleDocument> indexer =
                            client.CreateIndexingBufferedSender(
                                new SearchIndexingBufferedSenderOptions <SimpleDocument>
            {
                AutoFlushInterval = TimeSpan.FromMilliseconds(10)
            });
            AssertNoFailures(indexer);

            await indexer.UploadDocumentsAsync(data);

            await DelayAsync(TimeSpan.FromSeconds(5), EventDelay);
            await WaitForDocumentCountAsync(resources.GetSearchClient(), data.Length);
        }