public async Task HandleReference_ShouldCompleteTheIndexing() { // https://issues.hibernatingrhinos.com/issue/RavenDB-14506 const int batchSize = 128; using (var store = GetDocumentStore(new Options { ModifyDatabaseRecord = doc => { doc.Settings[RavenConfiguration.GetKey(x => x.Indexing.MapBatchSize)] = batchSize.ToString(); } })) { var index = new Companies_ByEmployeeLastName(); using (var session = store.OpenAsyncSession()) { var employees = Enumerable.Range(0, batchSize + 1) .Select(i => new Employee { Id = $"Employees/{i}" }) .ToArray(); var company = new Company { Name = "HR", EmployeesIds = employees.Select(e => e.Id).ToList() }; await session.StoreAsync(company); await session.SaveChangesAsync(); index.Execute(store); Indexes.WaitForIndexing(store); //Index disable store.Maintenance.Send(new DisableIndexOperation(index.IndexName)); foreach (var employee in employees) { employee.FirstName = "Changed"; await session.StoreAsync(employee); } await session.SaveChangesAsync(); //Index enable store.Maintenance.Send(new EnableIndexOperation(index.IndexName)); //Assert Indexes.WaitForIndexing(store, timeout: TimeSpan.FromSeconds(10)); } } }
public async Task HandleReferenceAndMapping_ShouldNotMissChangedReference() { // https://issues.hibernatingrhinos.com/issue/RavenDB-14506 const int batchSize = 128; using (var store = GetDocumentStore(new Options { ModifyDatabaseRecord = doc => { doc.Settings[RavenConfiguration.GetKey(x => x.Indexing.MapBatchSize)] = batchSize.ToString(); }, ModifyDocumentStore = localStore => { localStore.Conventions = new Raven.Client.Documents.Conventions.DocumentConventions { MaxNumberOfRequestsPerSession = int.MaxValue }; } })) { var index = new Companies_ByEmployeeLastName(); using (var session = store.OpenAsyncSession()) { var list = Enumerable.Range(0, batchSize + 1) .Select(i => { var employeeId = $"Employees/{i}"; return( new Company { Id = $"Companies/{i}", EmployeesIds = new List <string> { employeeId } }, new Employee { Id = employeeId } ); }) .ToArray(); var(firstCompany, _) = list[0]; foreach (var(company, _) in list) { await session.StoreAsync(company); } await session.SaveChangesAsync(); var newEmployee = new Employee { Id = $"Employees/{batchSize + 1}" }; firstCompany.EmployeesIds.Add(newEmployee.Id); await session.StoreAsync(firstCompany); await session.SaveChangesAsync(); index.Execute(store); Indexes.WaitForIndexing(store); //Index disable store.Maintenance.Send(new DisableIndexOperation(index.IndexName)); foreach (var(_, employee) in list) { await session.StoreAsync(employee); } await session.SaveChangesAsync(); await session.StoreAsync(newEmployee); await session.SaveChangesAsync(); await session.StoreAsync(newEmployee); await session.SaveChangesAsync(); await session.StoreAsync(new Company { EmployeesIds = new List <string> { newEmployee.Id } }); await session.SaveChangesAsync(); //Index enable store.Maintenance.Send(new EnableIndexOperation(index.IndexName)); Indexes.WaitForIndexing(store); //Assert var queryResult = await session .Query <Companies_ByEmployeeLastName.Result, Companies_ByEmployeeLastName>() .OfType <Company>() .ToArrayAsync(); Assert.Contains(queryResult, e => e.Id == $"Companies/{batchSize}"); } } }