Esempio n. 1
0
        public void Dispose_ReallyDisposesTransaction()
        {
            var expiration = new ConsoleExpirationTransaction(_transaction.Object);

            expiration.Dispose();

            _transaction.Verify(x => x.Dispose());
        }
Esempio n. 2
0
        public void Persist_PersistsSetAndHash()
        {
            var expiration = new ConsoleExpirationTransaction(_transaction.Object);

            expiration.Persist(_consoleId);

            _transaction.Verify(x => x.PersistSet(_consoleId.GetSetKey()));
            _transaction.Verify(x => x.PersistHash(_consoleId.GetHashKey()));

            // backward compatibility:
            _transaction.Verify(x => x.PersistSet(_consoleId.GetOldConsoleKey()));
            _transaction.Verify(x => x.PersistHash(_consoleId.GetOldConsoleKey()));
        }
Esempio n. 3
0
        public void Expire_ExpiresSetAndHash()
        {
            var expiration = new ConsoleExpirationTransaction(_transaction.Object);

            expiration.Expire(_consoleId, TimeSpan.FromHours(1));

            _transaction.Verify(x => x.ExpireSet(_consoleId.GetSetKey(), It.IsAny <TimeSpan>()));
            _transaction.Verify(x => x.ExpireHash(_consoleId.GetHashKey(), It.IsAny <TimeSpan>()));

            // backward compatibility:
            _transaction.Verify(x => x.ExpireSet(_consoleId.GetOldConsoleKey(), It.IsAny <TimeSpan>()));
            _transaction.Verify(x => x.ExpireHash(_consoleId.GetOldConsoleKey(), It.IsAny <TimeSpan>()));
        }
Esempio n. 4
0
        public void OnStateApplied(ApplyStateContext context, IWriteOnlyTransaction transaction)
        {
            if (!_options.FollowJobRetentionPolicy)
            {
                // Console sessions use their own expiration timeout.
                // Do not expire here, will be expired by ConsoleServerFilter.
                return;
            }

            var jobDetails = context.Storage.GetMonitoringApi().JobDetails(context.BackgroundJob.Id);

            if (jobDetails == null || jobDetails.History == null)
            {
                // WTF?!
                return;
            }

            var expiration = new ConsoleExpirationTransaction((JobStorageTransaction)transaction);

            foreach (var state in jobDetails.History.Where(x => x.StateName == ProcessingState.StateName))
            {
                var consoleId = new ConsoleId(context.BackgroundJob.Id, JobHelper.DeserializeDateTime(state.Data["StartedAt"]));

                if (context.NewState.IsFinal)
                {
                    // Job in final state is a subject for expiration.
                    // To keep storage clean, its console sessions should also be expired.
                    expiration.Expire(consoleId, context.JobExpirationTimeout);
                }
                else
                {
                    // Job will be persisted, so should its console sessions.
                    expiration.Persist(consoleId);
                }
            }
        }
Esempio n. 5
0
        public void Persist_ThrowsException_IfConsoleIdIsNull()
        {
            var expiration = new ConsoleExpirationTransaction(_transaction.Object);

            Assert.Throws <ArgumentNullException>("consoleId", () => expiration.Persist(null));
        }
Esempio n. 6
0
        public void Expire_ThrowsException_IfConsoleIdIsNull()
        {
            var expiration = new ConsoleExpirationTransaction(_transaction.Object);

            Assert.Throws <ArgumentNullException>("consoleId", () => expiration.Expire(null, TimeSpan.FromHours(1)));
        }