Exemple #1
0
        internal override void Release(MessageBody messageBody)
        {
            if (_logger.IsDebugEnabled)
            {
                _logger.DebugFormat("Releasing {0}.", this);
            }

            var releasedDataFile = new ReleasedDataFile(this);

            // release claim token from database and transition to ReleasedDataFile (i.e. rename data file) within a transaction scope
            using (var tx = new TransactionScope())
            {
                var result = DataFileServant.Instance.TryReleaseToken(ClaimStoreRelativePath) &&
                             DataFileServant.Instance.TryMoveFile(Path, releasedDataFile.Path);
                if (result)
                {
                    messageBody.DataFile = releasedDataFile;
                    tx.Complete();
                }
                else
                {
                    messageBody.DataFile = new AwaitingRetryDataFile(this);
                }
            }
        }
Exemple #2
0
        public void ReleaseDoesNotTransitionToNewState()
        {
            var sut             = new ReleasedDataFile("201306158F341A2D6FD7416B87073A0132DD51AE.chk.20150627111406.released");
            var messageBodyMock = new Mock <MessageBody>(sut);

            messageBodyMock.SetupAllProperties();

            sut.Release(messageBodyMock.Object);

            Assert.That(messageBodyMock.Object.DataFile, Is.SameAs(sut));
        }
        internal override void Lock(MessageBody messageBody)
        {
            if (_logger.IsDebugEnabled)
            {
                _logger.DebugFormat("Locking {0}.", this);
            }

            // take a new lock ---update timestamp while staying in released state--- so that this agent instance get
            // exclusive ownership of the data file should there be another remote agent instance working concurrently
            var releasedDataFile = new ReleasedDataFile(this);
            var result           = DataFileServant.Instance.TryMoveFile(Path, releasedDataFile.Path);

            messageBody.DataFile = result
                                ? (DataFile)releasedDataFile
                                : new AwaitingRetryDataFile(this);
        }
Exemple #4
0
        public void UnlockDeletesLocalDataFile()
        {
            var servantMock = new Mock <DataFileServant>();

            DataFileServant.Instance = servantMock.Object;

            const string filePath        = "201306158F341A2D6FD7416B87073A0132DD51AE.chk.20150627111406.released";
            var          sut             = new ReleasedDataFile(filePath);
            var          messageBodyMock = new Mock <MessageBody>(sut);

            servantMock.Setup(s => s.TryDeleteFile(filePath)).Returns(true).Verifiable();

            sut.Unlock(messageBodyMock.Object);

            servantMock.VerifyAll();
        }
Exemple #5
0
        public void UnlockTransitionsToAwaitingRetryDataFileWhenOperationFails()
        {
            var servantMock = new Mock <DataFileServant>();

            DataFileServant.Instance = servantMock.Object;

            const string filePath        = "201306158F341A2D6FD7416B87073A0132DD51AE.chk.20150627111406.released";
            var          sut             = new ReleasedDataFile(filePath);
            var          messageBodyMock = new Mock <MessageBody>(sut);

            servantMock.Setup(s => s.TryDeleteFile(filePath)).Returns(false);

            sut.Unlock(messageBodyMock.Object);

            Assert.That(messageBodyMock.Object.DataFile, Is.TypeOf <AwaitingRetryDataFile>());
        }
Exemple #6
0
        public void UnlockDoesNotTransitionToNewStateWhenOperationSucceeds()
        {
            var servantMock = new Mock <DataFileServant>();

            DataFileServant.Instance = servantMock.Object;

            const string filePath        = "201306158F341A2D6FD7416B87073A0132DD51AE.chk.20150627111406.released";
            var          sut             = new ReleasedDataFile(filePath);
            var          messageBodyMock = new Mock <MessageBody>(sut);

            servantMock.Setup(s => s.TryDeleteFile(filePath)).Returns(true);

            sut.Unlock(messageBodyMock.Object);

            Assert.That(messageBodyMock.Object.DataFile, Is.SameAs(sut));
        }
Exemple #7
0
        public void LockTransitionsToNewReleasedDataFileWhenOperationSucceeds()
        {
            var servantMock = new Mock <DataFileServant>();

            DataFileServant.Instance = servantMock.Object;

            const string filePath        = "201306158F341A2D6FD7416B87073A0132DD51AE.chk.20150627111406.released";
            var          sut             = new ReleasedDataFile(filePath);
            var          messageBodyMock = new Mock <MessageBody>(sut);

            messageBodyMock.SetupAllProperties();

            servantMock.Setup(s => s.TryMoveFile(filePath, It.IsAny <string>())).Returns(true);

            sut.Lock(messageBodyMock.Object);

            Assert.That(messageBodyMock.Object.DataFile, Is.TypeOf <ReleasedDataFile>());
            Assert.That(messageBodyMock.Object.DataFile, Is.Not.SameAs(sut));
            Assert.That(sut.Path.Tokenize().LockTime < messageBodyMock.Object.DataFile.Path.Tokenize().LockTime);
        }