public void Old_documents_are_being_expired()
        {
            using (var documentStore = InMemoryStoreBuilder.GetInMemoryStore())
            {
                var expiredDate   = DateTime.UtcNow.AddDays(-3);
                var thresholdDate = DateTime.UtcNow.AddDays(-2);

                var sagaHistoryId = Guid.NewGuid();
                var sagaHistory   = new SagaSnapshot
                {
                    Id = sagaHistoryId,
                };

                using (new RavenLastModifiedScope(expiredDate))
                    using (var session = documentStore.OpenSession())
                    {
                        session.Store(sagaHistory);
                        session.SaveChanges();
                    }
                RunExpiry(documentStore, thresholdDate);

                using (var session = documentStore.OpenSession())
                {
                    Assert.IsEmpty(session.Query <SagaSnapshot>());
                }
            }
        }
示例#2
0
        public void Recent_processed_messages_are_not_being_expired()
        {
            using (var documentStore = InMemoryStoreBuilder.GetInMemoryStore())
            {
                var thresholdDate = DateTime.UtcNow.AddDays(-2);
                var recentDate    = DateTime.UtcNow.AddDays(-1);
                var sagaHistory   = new SagaSnapshot
                {
                    Id = Guid.NewGuid()
                };

                using (new RavenLastModifiedScope(recentDate))
                    using (var session = documentStore.OpenSession())
                    {
                        session.Store(sagaHistory);
                        session.SaveChanges();
                    }

                RunExpiry(documentStore, thresholdDate);
                using (var session = documentStore.OpenSession())
                {
                    Assert.AreEqual(1, session.Query <SagaSnapshot>().Count());
                }
            }
        }
示例#3
0
        public void Many_documents_are_being_expired()
        {
            using (var documentStore = InMemoryStoreBuilder.GetInMemoryStore())
            {
                var expiredDate     = DateTime.UtcNow.AddDays(-3);
                var thresholdDate   = DateTime.UtcNow.AddDays(-2);
                var recentDate      = DateTime.UtcNow.AddDays(-1);
                var expiredMessages = BuilExpiredMessaged().ToList();
                using (new RavenLastModifiedScope(expiredDate))
                {
                    using (var session = documentStore.OpenSession())
                    {
                        foreach (var message in expiredMessages)
                        {
                            session.Store(message);
                        }

                        session.SaveChanges();
                    }
                }

                using (new RavenLastModifiedScope(recentDate))
                    using (var session = documentStore.OpenSession())
                    {
                        var recentSagaHistory = new SagaSnapshot
                        {
                            Id = Guid.NewGuid()
                        };
                        session.Store(recentSagaHistory);
                        session.SaveChanges();
                    }

                RunExpiry(documentStore, thresholdDate);

                using (var session = documentStore.OpenSession())
                {
                    Assert.AreEqual(1, session.Query <SagaSnapshot>().Count());
                }
            }
        }
示例#4
0
        public void Only_expired_being_deleted()
        {
            using (var documentStore = InMemoryStoreBuilder.GetInMemoryStore())
            {
                var expiredDate   = DateTime.UtcNow.AddDays(-3);
                var thresholdDate = DateTime.UtcNow.AddDays(-2);
                var recentDate    = DateTime.UtcNow.AddDays(-1);

                var expiredSagaHistory = new SagaSnapshot
                {
                    Id = Guid.NewGuid()
                };

                using (new RavenLastModifiedScope(expiredDate))
                    using (var session = documentStore.OpenSession())
                    {
                        session.Store(expiredSagaHistory);
                        session.SaveChanges();
                    }

                var recentSagaHistory = new SagaSnapshot
                {
                    Id = Guid.NewGuid()
                };
                using (new RavenLastModifiedScope(recentDate))
                    using (var session = documentStore.OpenSession())
                    {
                        session.Store(recentSagaHistory);
                        session.SaveChanges();
                    }

                RunExpiry(documentStore, thresholdDate);

                using (var session = documentStore.OpenSession())
                {
                    Assert.Null(session.Load <SagaSnapshot>(expiredSagaHistory.Id));
                    Assert.NotNull(session.Load <SagaSnapshot>(recentSagaHistory.Id));
                }
            }
        }