public async Task ShouldNotThrottleBetweenBatchesWhereThereAreStillDocumentsToProcess() { using (var store = GetDocumentStore()) { var now = DateTime.Now; using (var session = store.OpenSession()) { for (int i = 0; i < 512; i++) { session.Store(new Order { OrderedAt = now.AddDays(i % 20), ShippedAt = null }); } session.SaveChanges(); } var index = new Orders_ByOrderedAtAndShippedAt { Configuration = { [RavenConfiguration.GetKey(x => x.Indexing.ThrottlingTimeInterval)] = TimeSpan.FromHours(1).TotalMilliseconds.ToString(), [RavenConfiguration.GetKey(x => x.Indexing.MapBatchSize)] = "128", // make sure we'll need multiple batches to index all docs } }; await index.ExecuteAsync(store); // should index all documents regardless throttling set to 1 hour Indexes.WaitForIndexing(store, timeout: TimeSpan.FromSeconds(30)); } }
public async Task IndexMustBeStaleDuringThrottlingTime() { using (var store = GetDocumentStore()) { var now = DateTime.Now; var index = new Orders_ByOrderedAtAndShippedAt { Configuration = { [RavenConfiguration.GetKey(x => x.Indexing.ThrottlingTimeInterval)] = TimeSpan.FromHours(1).TotalMilliseconds.ToString(), } }; await index.ExecuteAsync(store); using (var session = store.OpenSession()) { session.Store(new Order { OrderedAt = now, ShippedAt = null }); session.SaveChanges(); } var stats = store.Maintenance.Send(new GetIndexStatisticsOperation(index.IndexName)); Assert.True(stats.IsStale); } }
public async Task ShouldIndexAllDocumentsWithThrottlingSet() { using (var store = GetDocumentStore()) { var now = DateTime.Now; var index = new Orders_ByOrderedAtAndShippedAt { Configuration = { [RavenConfiguration.GetKey(x => x.Indexing.ThrottlingTimeInterval)] = TimeSpan.FromSeconds(5).TotalMilliseconds.ToString(), } }; await index.ExecuteAsync(store); using (var session = store.OpenSession()) { for (int i = 0; i < 10; i++) { session.Store(new Order { OrderedAt = now.AddDays(i % 20), ShippedAt = null }); } session.SaveChanges(); } var indexingDuration = Stopwatch.StartNew(); Indexes.WaitForIndexing(store); indexingDuration.Stop(); Assert.True(indexingDuration.Elapsed >= TimeSpan.FromSeconds(4), $"{indexingDuration.Elapsed} >= {TimeSpan.FromSeconds(4)}"); using (var session = store.OpenSession()) { for (int i = 0; i < 10; i++) { session.Store(new Order { OrderedAt = now.AddDays(i % 20), ShippedAt = null }); } session.SaveChanges(); } indexingDuration.Restart(); Indexes.WaitForIndexing(store); indexingDuration.Stop(); Assert.True(indexingDuration.Elapsed >= TimeSpan.FromSeconds(4)); } }
public async Task ChangingThrottlingConfigurationDoesNotRequireIndexReset() { using (var store = GetDocumentStore()) { var indexDef = new Orders_ByOrderedAtAndShippedAt(); await indexDef.ExecuteAsync(store); var database = await GetDatabase(store.Database); var indexDefWithThrottling = new Orders_ByOrderedAtAndShippedAt { Configuration = { [RavenConfiguration.GetKey(x => x.Indexing.ThrottlingTimeInterval)] = "1000" } }; var index = database.IndexStore.GetIndex(indexDef.IndexName); var options = database.IndexStore.GetIndexCreationOptions(indexDefWithThrottling.CreateIndexDefinition(), index, out var _); Assert.Equal(IndexCreationOptions.UpdateWithoutUpdatingCompiledIndex, options); } }
public async Task CanGetThrottlingValueFromIndexDefinition() { using (var store = GetDocumentStore()) { var now = DateTime.Now; var index = new Orders_ByOrderedAtAndShippedAt { Configuration = { [RavenConfiguration.GetKey(x => x.Indexing.ThrottlingTimeInterval)] = TimeSpan.FromSeconds(5).TotalMilliseconds.ToString(), } }; await index.ExecuteAsync(store); var def = store.Maintenance.Send(new GetIndexOperation(index.IndexName)); Assert.Equal("5000", def.Configuration[RavenConfiguration.GetKey(x => x.Indexing.ThrottlingTimeInterval)]); } }
public async Task MustNotDisableThrottlingTimerOnUpdatingIndexDefinitionOfThrottledIndex() { using (var store = GetDocumentStore()) { var indexDef = new Orders_ByOrderedAtAndShippedAt(storeFields: false) { Configuration = { [RavenConfiguration.GetKey(x => x.Indexing.ThrottlingTimeInterval)] = "1000" } }; await indexDef.ExecuteAsync(store); Indexes.WaitForIndexing(store); var database = await GetDatabase(store.Database); var index = database.IndexStore.GetIndex(indexDef.IndexName); using (var session = store.OpenSession()) { session.Store(new Order { ShippedAt = DateTime.Now, OrderedAt = DateTime.Now }); session.SaveChanges(); } Indexes.WaitForIndexing(store); Assert.Equal(TimeSpan.FromSeconds(1), index._mre.ThrottlingInterval); Assert.NotNull(index._mre._timerTask); Assert.False(index._mre.Wait(100, CancellationToken.None)); // update index def store.Maintenance.Send(new StopIndexingOperation()); var updatedIndexDef = new Orders_ByOrderedAtAndShippedAt(storeFields: true) { Configuration = { [RavenConfiguration.GetKey(x => x.Indexing.ThrottlingTimeInterval)] = "1000" } }; await updatedIndexDef.ExecuteAsync(store); var replacementIndex = database.IndexStore.GetIndex(Constants.Documents.Indexing.SideBySideIndexNamePrefix + updatedIndexDef.IndexName); using (index.ForTestingPurposesOnly().CallDuringFinallyOfExecuteIndexing(() => { // stop the current index for a moment to ensure that a new thread will start - the one after renaming the replacement index Thread.Sleep(2000); })) { store.Maintenance.Send(new StartIndexingOperation()); Indexes.WaitForIndexing(store); } Assert.NotNull(replacementIndex._mre._timerTask); Assert.False(replacementIndex._mre.Wait(100, CancellationToken.None)); using (var session = store.OpenSession()) { session.Store(new Order { ShippedAt = DateTime.Now, OrderedAt = DateTime.Now }); session.SaveChanges(); } Indexes.WaitForIndexing(store); } }