Пример #1
0
        public void CanProperlyComputeTotalsWithoutAbandonedOrDisabled()
        {
            using (var store = NewDocumentStore())
            {
                var companiesIndex         = new RavenDB_2607.CompaniesIndex();
                var usersIndex             = new RavenDB_2607.UsersIndex();
                var usersAndCompaniesIndex = new RavenDB_2607.UsersAndCompaniesIndex();

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

                store.DatabaseCommands.SetIndexPriority(usersAndCompaniesIndex.IndexName, IndexingPriority.Abandoned);

                WaitForIndexing(store);

                store.DatabaseCommands.Admin.StopIndexing();

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

                    session.SaveChanges();
                }

                var databaseStatistics = store.DatabaseCommands.GetStatistics();
                Assert.Equal(4, databaseStatistics.StaleIndexes.Length);
                Assert.Equal(4, databaseStatistics.Indexes.Length);
                Assert.Equal(3, databaseStatistics.CountOfStaleIndexesExcludingDisabledAndAbandoned);
                Assert.Equal(3, databaseStatistics.CountOfIndexesExcludingDisabledAndAbandoned);
            }
        }
Пример #2
0
        public void ShouldRecoverLastCollectionEtags()
        {
            var dataDir       = NewDataPath();
            var ravenDbServer = GetNewServer(runInMemory: false, dataDirectory: dataDir);

            var companiesIndex = new RavenDB_2607.CompaniesIndex();
            var usersIndex     = new RavenDB_2607.UsersIndex();

            using (var store = ravenDbServer.DocumentStore)
            {
                store.ExecuteIndex(companiesIndex);
                store.ExecuteIndex(usersIndex);

                using (var session = store.OpenSession())
                {
                    session.Store(new Company {
                        Id = "companies/1", Name = "test"
                    });
                    session.Store(new User {
                        Id = "users/1", Name = "test"
                    });
                    session.SaveChanges();
                }

                WaitForIndexing(store);
            }

            // restart server
            ravenDbServer.Dispose();
            ravenDbServer = GetNewServer(runInMemory: false, dataDirectory: dataDir);

            var companiesCollectioEtag = ravenDbServer.SystemDatabase.LastCollectionEtags.GetLastEtagForCollection("Companies");
            var usersCollectionEtag    = ravenDbServer.SystemDatabase.LastCollectionEtags.GetLastEtagForCollection("Users");

            Assert.NotNull(companiesCollectioEtag);
            Assert.NotNull(usersCollectionEtag);

            using (var store = ravenDbServer.DocumentStore)
            {
                store.DatabaseCommands.Admin.StopIndexing();

                using (var session = store.OpenSession())
                {
                    session.Store(new Company
                    {
                        Id = "companies/2", Name = "test"
                    });

                    session.SaveChanges();
                }

                var staleIndexes = store.DatabaseCommands.GetStatistics().StaleIndexes;

                Assert.DoesNotContain(usersIndex.IndexName, staleIndexes);
            }
        }