Beispiel #1
0
        public async Task PurgeTombstonesFrom_should_work_properly()
        {
            using (var store = GetDocumentStore())
            {
                var userByAge             = new UserByAgeIndex();
                var userByName            = new UserByNameIndex();
                var userByNameAndBirthday = new UserByNameAndBirthday();
                userByName.Execute(store);
                userByAge.Execute(store);
                userByNameAndBirthday.Execute(store);

                store.DatabaseCommands.DeleteIndex(userByName.IndexName);
                store.DatabaseCommands.DeleteIndex(userByNameAndBirthday.IndexName);

                var databaseStore =
                    await Server.ServerStore.DatabasesLandlord.TryGetOrCreateResourceStore(store.DefaultDatabase);

                TransactionOperationContext context;
                using (databaseStore.ConfigurationStorage.ContextPool.AllocateOperationContext(out context))
                    using (var tx = context.OpenWriteTransaction())
                    {
                        databaseStore.IndexMetadataPersistence.PurgeTombstonesFrom(tx.InnerTransaction, context, 0, 1024);
                        tx.Commit();
                    }

                using (databaseStore.ConfigurationStorage.ContextPool.AllocateOperationContext(out context))
                    using (var tx = context.OpenReadTransaction())
                    {
                        var metadataCollection = databaseStore.IndexMetadataPersistence.GetAfter(tx.InnerTransaction, context, 0, 0, 1024);
                        Assert.Equal(1, metadataCollection.Count);
                        Assert.Equal(userByAge.IndexName.ToLower(), metadataCollection[0].Name);
                    }
            }
        }
Beispiel #2
0
        public async Task GetAfter_should_work_properly()
        {
            using (var store = GetDocumentStore())
            {
                var userByAge             = new UserByAgeIndex();
                var userByName            = new UserByNameIndex();
                var userByNameAndBirthday = new UserByNameAndBirthday();
                userByName.Execute(store);
                userByAge.Execute(store);
                userByNameAndBirthday.Execute(store);

                var databaseStore =
                    await Server.ServerStore.DatabasesLandlord.TryGetOrCreateResourceStore(store.DefaultDatabase);

                List <IndexesEtagsStorage.IndexEntryMetadata> metadataItems;
                TransactionOperationContext context;
                using (databaseStore.ConfigurationStorage.ContextPool.AllocateOperationContext(out context))
                    using (var tx = context.OpenReadTransaction())
                    {
                        metadataItems = databaseStore.IndexMetadataPersistence.GetAfter(tx.InnerTransaction, context, 0, 0, 1024);
                        Assert.Equal(3, metadataItems.Count);

                        metadataItems = databaseStore.IndexMetadataPersistence.GetAfter(tx.InnerTransaction, context, 3, 0, 1024);
                        Assert.Equal(1, metadataItems.Count);
                    }

                //this one was created last, so it has the largest etag
                Assert.Equal(userByNameAndBirthday.IndexName.ToLower(), metadataItems[0].Name);

                store.DatabaseCommands.DeleteIndex(userByName.IndexName);
                store.DatabaseCommands.DeleteIndex(userByNameAndBirthday.IndexName);


                using (databaseStore.ConfigurationStorage.ContextPool.AllocateOperationContext(out context))
                    using (var tx = context.OpenReadTransaction())
                    {
                        metadataItems = databaseStore.IndexMetadataPersistence.GetAfter(tx.InnerTransaction, context, 0, 0, 1024);
                        Assert.Equal(3, metadataItems.Count); //together with tombstones
                        Assert.Equal(2, metadataItems.Count(item => item.Id == -1));
                    }
            }
        }