Example #1
0
        public async Task DoNotRemoveExpirationFromNonVersionedDocuments()
        {
            // Arrange
            var configuration = new Configuration()
            {
                ExpirationEnabled = false
            };

            var utcNow             = DateTime.UtcNow;
            var expires            = new DateTime(utcNow.Year, utcNow.Month, utcNow.Day, utcNow.Hour, utcNow.Minute, utcNow.Second);
            var additionalMetadata = new Dictionary <string, object> {
                { Constants.Documents.Metadata.Expires, expires }
            };

            await PersistDocument("testdocument1", new { SomeProperty = "SomeValue" }, additionalMetadata);

            // Act
            var sut = new ExpirationManager(DocumentStoreProvider);
            await sut.ApplyExpirationPolicyAsync(configuration);

            WaitForIndexing(DocumentStore);

            // Assert
            await AssertMetadata("testdocument1", null, expires);
        }
Example #2
0
        public async Task RemoveExpirationWhenDisabled()
        {
            // Arrange
            var configuration = new Configuration()
            {
                ExpirationEnabled = false,
                ExpirationDays    = 1,
                ExpirationRegex   = @"\d"
            };

            var dbFeature = new DbFeature {
                Version = "1.0.0"
            };
            var additionalMetadata = new Dictionary <string, object> {
                { Constants.Documents.Metadata.Expires, DateTime.UtcNow }
            };
            var expectedUploadDate = await PersistDocument("testdocument1", dbFeature, additionalMetadata);

            // Act
            var sut = new ExpirationManager(DocumentStoreProvider);
            await sut.ApplyExpirationPolicyAsync(configuration);

            WaitForIndexing(DocumentStore);

            // Assert
            await AssertMetadata("testdocument1", expectedUploadDate, null);
        }
Example #3
0
 /// <summary>
 /// Libera a instancia.
 /// </summary>
 /// <param name="disposing"></param>
 private void Dispose(bool disposing)
 {
     lock (this)
     {
         if (this.SerializationContext != null)
         {
             CompactFormatterServices.UnregisterAllCustomCompactTypes(this.SerializationContext);
         }
         if (this.ExpiryMgr != null)
         {
             this.ExpiryMgr.Dispose();
             this.ExpiryMgr = null;
         }
         if (this.CacheImpl != null)
         {
             this.CacheImpl.Dispose();
             this.CacheImpl = null;
         }
         if (this.TimeSched != null)
         {
             this.TimeSched.Dispose();
             this.TimeSched = null;
         }
         if (this.AsyncProc != null)
         {
             this.AsyncProc.Stop();
             this.AsyncProc = null;
         }
         if (disposing)
         {
             GC.SuppressFinalize(this);
         }
     }
 }
        public void Ctor_CreatesInstance()
        {
            var storage = CreateStorageStub();

            var instance = new ExpirationManager(storage);

            Assert.Same(storage, Assert.IsType <EFCoreStorage>(instance.GetFieldValue("_storage")));
        }
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or
        /// resetting unmanaged resources.
        /// </summary>
        /// <param name="disposing"></param>
        private void Dispose(bool disposing)
        {
            lock (this)
            {
                if (SerializationContext != null)
                {
                    CompactFormatterServices.UnregisterAllCustomCompactTypes(SerializationContext);
                }


                if (PerfStatsColl != null)
                {
                    PerfStatsColl.Dispose();
                    PerfStatsColl = null;
                }

                if (ExpiryMgr != null)
                {
                    ExpiryMgr.Dispose();
                    ExpiryMgr = null;
                }
                if (MessageManager != null)
                {
                    MessageManager.StopMessageProcessing();
                    MessageManager = null;
                }
                if (CacheImpl != null)
                {
                    CacheImpl.Dispose();
                    CacheImpl = null;
                }
                if (TimeSched != null)
                {
                    TimeSched.Dispose();
                    TimeSched = null;
                }
                if (AsyncProc != null)
                {
                    AsyncProc.Stop();
                    AsyncProc = null;
                }

                if (HealthCollectorTimeSched != null)
                {
                    HealthCollectorTimeSched.Dispose();
                    HealthCollectorTimeSched = null;
                }

                if (disposing)
                {
                    GC.SuppressFinalize(this);
                }
            }
        }
        public void Execute_DoesNotRemoveEntries_WithFreshExpirationTime()
        {
            CreateExpirationEntries(DateTime.UtcNow.AddMonths(1));
            var instance = new ExpirationManager(Storage);
            var source   = new CancellationTokenSource(0);

            instance.Execute(source.Token);

            UseContext(context =>
            {
                Assert.Equal(1, context.Set <HangfireCounter>().Count());
                Assert.Equal(1, context.Set <HangfireJob>().Count());
                Assert.Equal(1, context.Set <HangfireList>().Count());
                Assert.Equal(1, context.Set <HangfireSet>().Count());
                Assert.Equal(1, context.Set <HangfireHash>().Count());
            });
        }
        public void Execute_RemovesOutdatedRecords()
        {
            CreateExpirationEntries(DateTime.UtcNow.AddMonths(-1));
            var instance = new ExpirationManager(Storage);
            var source   = new CancellationTokenSource(0);

            instance.Execute(source.Token);

            UseContext(context =>
            {
                Assert.False(context.Set <HangfireCounter>().Any());
                Assert.False(context.Set <HangfireJob>().Any());
                Assert.False(context.Set <HangfireList>().Any());
                Assert.False(context.Set <HangfireSet>().Any());
                Assert.False(context.Set <HangfireHash>().Any());
            });
        }
Example #8
0
        public async Task SetUploadDateOnNonMatchingVersion()
        {
            // Arrange
            var configuration = new Configuration()
            {
                ExpirationEnabled = true,
                ExpirationDays    = 1,
                ExpirationRegex   = @"Hello World"
            };

            var expectedUploadDate = await PersistDocument("testdocument1", new { Version = "1.0.0" });

            // Act
            var sut = new ExpirationManager(DocumentStoreProvider);
            await sut.ApplyExpirationPolicyAsync(configuration);

            WaitForIndexing(DocumentStore);

            // Assert
            await AssertMetadata("testdocument1", expectedUploadDate, null);
        }
Example #9
0
        public async Task DoNotSetExpirationOnNonVersionedDocuments()
        {
            // Arrange
            var configuration = new Configuration()
            {
                ExpirationEnabled = true,
                ExpirationDays    = 1,
                ExpirationRegex   = @"Hello World"
            };

            await PersistDocument("testdocument1", new { SomeProperty = "SomeValue" });

            // Act
            var sut = new ExpirationManager(DocumentStoreProvider);
            await sut.ApplyExpirationPolicyAsync(configuration);

            WaitForIndexing(DocumentStore);

            // Assert
            await AssertMetadata("testdocument1", null, null);
        }