Exemple #1
0
        public void MustNotShowThatIndexIsNonStale_BulkInsertCase()
        {
            using (var store = GetDocumentStore())
            {
                var companiesIndex         = new CompaniesIndex();
                var usersIndex             = new UsersIndex();
                var usersAndCompaniesIndex = new UsersAndCompaniesIndex();

                store.ExecuteIndex(companiesIndex);
                store.ExecuteIndex(usersIndex);
                store.ExecuteIndex(usersAndCompaniesIndex);

                using (var session = store.OpenSession())
                {
                    session.Store(new Company
                    {
                        Name = "A"
                    });

                    session.Store(new User
                    {
                        Name = "A"
                    });

                    session.SaveChanges();
                }

                using (var bulk = store.BulkInsert())
                {
                    for (int i = 0; i < 1000; i++)
                    {
                        bulk.Store(new Company
                        {
                            Name = "A"
                        });

                        bulk.Store(new User
                        {
                            Name = "A"
                        });
                    }
                }

                using (var session = store.OpenSession())
                {
                    Assert.Equal(2002, session.Query <Foo, UsersAndCompaniesIndex>().Customize(x => x.WaitForNonStaleResults()).Count());
                }
            }
        }
Exemple #2
0
        public void AddingUnrelevantDocumentForIndexShouldNotMarkItAsStale()
        {
            using (var store = GetDocumentStore())
            {
                var companiesIndex         = new CompaniesIndex();
                var usersIndex             = new UsersIndex();
                var usersAndCompaniesIndex = new UsersAndCompaniesIndex();

                store.ExecuteIndex(companiesIndex);
                store.ExecuteIndex(usersIndex);
                store.ExecuteIndex(usersAndCompaniesIndex);

                using (var session = store.OpenSession())
                {
                    session.Store(new Company
                    {
                        Name = "A"
                    });

                    session.Store(new User
                    {
                        Name = "A"
                    });

                    session.SaveChanges();
                }

                WaitForIndexing(store);

                store.Maintenance.Send(new StopIndexingOperation());

                using (var session = store.OpenSession())
                {
                    session.Store(new Company
                    {
                        Name = "B"
                    });

                    session.SaveChanges();
                }

                var databaseStatistics = store.Maintenance.Send(new GetStatisticsOperation());

                Assert.Equal(2, databaseStatistics.StaleIndexes.Length);
                Assert.Contains(companiesIndex.IndexName, databaseStatistics.StaleIndexes);
                Assert.Contains(usersAndCompaniesIndex.IndexName, databaseStatistics.StaleIndexes);

                using (var commands = store.Commands())
                {
                    var queryResult = commands.Query(new IndexQuery {
                        Query = $"FROM INDEX '{usersIndex.IndexName}'"
                    });

                    Assert.False(queryResult.IsStale);
                    Assert.True(queryResult.Results.Length > 0);

                    queryResult = commands.Query(new IndexQuery {
                        Query = $"FROM INDEX '{companiesIndex.IndexName}'"
                    });
                    Assert.True(queryResult.IsStale);

                    queryResult = commands.Query(new IndexQuery {
                        Query = $"FROM INDEX '{usersAndCompaniesIndex.IndexName}'"
                    });
                    Assert.True(queryResult.IsStale);
                }
            }
        }
Exemple #3
0
        public void AddingUnrelevantDocumentForIndexShouldNotMarkItAsStale()
        {
            using (var store = NewDocumentStore())
            {
                var companiesIndex         = new CompaniesIndex();
                var usersIndex             = new UsersIndex();
                var usersAndCompaniesIndex = new UsersAndCompaniesIndex();

                store.ExecuteIndex(companiesIndex);
                store.ExecuteIndex(usersIndex);
                store.ExecuteIndex(usersAndCompaniesIndex);

                using (var session = store.OpenSession())
                {
                    session.Store(new Company()
                    {
                        Name = "A"
                    });

                    session.Store(new User()
                    {
                        Name = "A"
                    });

                    session.SaveChanges();
                }

                WaitForIndexing(store);

                store.DatabaseCommands.Admin.StopIndexing();

                using (var session = store.OpenSession())
                {
                    session.Store(new Company()
                    {
                        Name = "B"
                    });

                    session.SaveChanges();
                }

                var databaseStatistics = store.DatabaseCommands.GetStatistics();

                Assert.Equal(3, databaseStatistics.StaleIndexes.Length);
                Assert.Contains(companiesIndex.IndexName, databaseStatistics.StaleIndexes);
                Assert.Contains(usersAndCompaniesIndex.IndexName, databaseStatistics.StaleIndexes);
                Assert.Contains(new RavenDocumentsByEntityName().IndexName, databaseStatistics.StaleIndexes);

                var queryResult = store.DatabaseCommands.Query(usersIndex.IndexName, new IndexQuery());

                Assert.False(queryResult.IsStale);
                Assert.True(queryResult.Results.Count > 0);


                queryResult = store.DatabaseCommands.Query(companiesIndex.IndexName, new IndexQuery());
                Assert.True(queryResult.IsStale);

                queryResult = store.DatabaseCommands.Query(usersAndCompaniesIndex.IndexName, new IndexQuery());
                Assert.True(queryResult.IsStale);

                queryResult = store.DatabaseCommands.Query(new RavenDocumentsByEntityName().IndexName, new IndexQuery());
                Assert.True(queryResult.IsStale);
            }
        }