public async Task CanIndexReferencedDocumentChangeWithQuery() { using (var cts = new CancellationTokenSource(TimeSpan.FromMinutes(5))) using (var store = GetDocumentStore(new Options { ModifyDatabaseRecord = x => x.Settings[RavenConfiguration.GetKey(x => x.Indexing.ManagedAllocationsBatchLimit)] = _managedAllocationsBatchLimit })) { var company = new Company { Name = _companyName1 }; using (var session = store.OpenAsyncSession()) { await session.StoreAsync(company); await session.SaveChangesAsync(cts.Token); using (var bulk = store.BulkInsert(token: cts.Token)) { for (var i = 0; i < _employeesCount; i++) { await bulk.StoreAsync(new Employee { CompanyId = company.Id }); } } } var index = new DocumentsIndex(); await index.ExecuteAsync(store, token : cts.Token); WaitForIndexing(store, timeout: TimeSpan.FromMinutes(3)); await AssertCount(store, _companyName1, _employeesCount, cts.Token); await AssertCount(store, _companyName2, 0, cts.Token); var batchCount = await AssertBatchCountProgress(store, index.IndexName, GetItemsCount, async token => { using (var session = store.OpenAsyncSession()) { company.Name = _companyName2; await session.StoreAsync(company, company.Id); await session.SaveChangesAsync(token); } }, cts.Token); await AssertCount(store, _companyName1, 0, cts.Token); await AssertCount(store, _companyName2, _employeesCount, cts.Token); Assert.True(batchCount > 1);
public async Task CanIndexReferencedDocumentChange() { using (var store = GetDocumentStore(new Options { ModifyDatabaseRecord = x => x.Settings[RavenConfiguration.GetKey(x => x.Indexing.ManagedAllocationsBatchLimit)] = _managedAllocationsBatchLimit })) { var company = new Company { Name = _companyName1 }; using (var session = store.OpenAsyncSession()) { await session.StoreAsync(company); await session.SaveChangesAsync(); using (var bulk = store.BulkInsert()) { for (var i = 0; i < _employeesCount; i++) { await bulk.StoreAsync(new Employee { CompanyId = company.Id }); } } } var index = new DocumentsIndex(); await new DocumentsIndex().ExecuteAsync(store); Indexes.WaitForIndexing(store, timeout: TimeSpan.FromMinutes(3)); await AssertCount(store, _companyName1, _employeesCount); var batchCount = 0; var tcs = new TaskCompletionSource <object>(TaskCreationOptions.RunContinuationsAsynchronously); store.Changes().ForIndex(index.IndexName).Subscribe(x => { if (x.Type == IndexChangeTypes.BatchCompleted) { if (Interlocked.Increment(ref batchCount) > 1) { tcs.TrySetResult(null); } } }); using (var session = store.OpenAsyncSession()) { company.Name = _companyName2; await session.StoreAsync(company, company.Id); await session.SaveChangesAsync(); } Indexes.WaitForIndexing(store, timeout: TimeSpan.FromMinutes(5)); await AssertCount(store, _companyName1, 0); await AssertCount(store, _companyName2, _employeesCount); Assert.True(await Task.WhenAny(tcs.Task, Task.Delay(10_000)) == tcs.Task); Assert.True(batchCount > 1); } }