public void ReleasingLockedDataFileIsInvalid() { var sut = new LockedDataFile("201306158F341A2D6FD7416B87073A0132DD51AE.chk.20150627111406.locked"); var messageBodyMock = new Mock <MessageBody>(sut); Invoking(() => sut.Release(messageBodyMock.Object)).Should().Throw <InvalidOperationException>(); }
public void UnlockingLockedDataFileIsInvalid() { const string filePath = "201306158F341A2D6FD7416B87073A0132DD51AE.chk.20150627111406.locked"; var sut = new LockedDataFile(filePath); var messageBodyMock = new Mock <MessageBody>(sut); Invoking(() => sut.Unlock(messageBodyMock.Object)).Should().Throw <InvalidOperationException>(); }
internal override void Lock(MessageBody messageBody) { // take a new lock ---update timestamp while staying in locked state--- so that this agent instance get // exclusive ownership of the data file should there be another remote agent instance working concurrently var lockedDataFile = new LockedDataFile(this); var result = DataFileServant.Instance.TryMoveFile(Path, lockedDataFile.Path); messageBody.DataFile = result ? lockedDataFile : new AwaitingRetryDataFile(this); }
internal override void Lock(MessageBody messageBody) { if (_logger.IsDebugEnabled) { _logger.Debug($"Locking {this}."); } // try to add a .timestamp.locked extension to file name to get exclusive ownership should there be another // Claim Store Agent working concurrently from another computer var lockedDataFile = new LockedDataFile(this); var result = DataFileServant.Instance.TryMoveFile(Path, lockedDataFile.Path); messageBody.DataFile = result ? lockedDataFile : new AwaitingRetryDataFile(this); }
public void LockTransitionsToAwaitingRetryDataFileWhenOperationFails() { var servantMock = new Mock <DataFileServant>(); DataFileServant.Instance = servantMock.Object; const string filePath = "201306158F341A2D6FD7416B87073A0132DD51AE.chk.20150627111406.locked"; var sut = new LockedDataFile(filePath); var messageBodyMock = new Mock <MessageBody>(sut); messageBodyMock.SetupAllProperties(); servantMock.Setup(s => s.TryMoveFile(filePath, It.IsAny <string>())).Returns(false); sut.Lock(messageBodyMock.Object); messageBodyMock.Object.DataFile.Should().BeOfType <AwaitingRetryDataFile>(); }
public void GatherCopiesDataFileToCentralClaimStoreAndRenamesLocalDataFile() { var servantMock = new Mock <DataFileServant>(); DataFileServant.Instance = servantMock.Object; const string filePath = "201306158F341A2D6FD7416B87073A0132DD51AE.chk.20150627111406.locked"; var sut = new LockedDataFile(filePath); var messageBodyMock = new Mock <MessageBody>(sut); servantMock.Setup(s => s.TryCreateDirectory(Path.Combine(Path.GetTempPath(), sut.ClaimStoreRelativePath))).Returns(true).Verifiable(); servantMock.Setup(s => s.TryCopyFile(filePath, It.Is <string>(path => path == Path.Combine(Path.GetTempPath(), sut.ClaimStoreRelativePath)))).Returns(true).Verifiable(); servantMock.Setup(s => s.TryMoveFile(filePath, It.Is <string>(path => path.Tokenize().State == GatheredDataFile.STATE_TOKEN))).Returns(true).Verifiable(); sut.Gather(messageBodyMock.Object, Path.GetTempPath()); servantMock.VerifyAll(); }
public void GatherTransitionsToGatheredDataFileWhenOperationSucceeds() { var servantMock = new Mock <DataFileServant>(); DataFileServant.Instance = servantMock.Object; const string filePath = "201306158F341A2D6FD7416B87073A0132DD51AE.chk.20150627111406.locked"; var sut = new LockedDataFile(filePath); var messageBodyMock = new Mock <MessageBody>(sut); messageBodyMock.SetupAllProperties(); servantMock.Setup(s => s.TryCreateDirectory(Path.Combine(Path.GetTempPath(), sut.ClaimStoreRelativePath))).Returns(true); servantMock.Setup(s => s.TryCopyFile(filePath, It.Is <string>(path => path == Path.Combine(Path.GetTempPath(), sut.ClaimStoreRelativePath)))).Returns(true); servantMock.Setup(s => s.TryMoveFile(filePath, It.Is <string>(path => path.Tokenize().State == GatheredDataFile.STATE_TOKEN))).Returns(true); sut.Gather(messageBodyMock.Object, Path.GetTempPath()); messageBodyMock.Object.DataFile.Should().BeOfType <GatheredDataFile>(); }
public void LockTransitionsToNewLockedDataFileWhenOperationSucceeds() { var servantMock = new Mock <DataFileServant>(); DataFileServant.Instance = servantMock.Object; const string filePath = "201306158F341A2D6FD7416B87073A0132DD51AE.chk.20150627111406.locked"; var sut = new LockedDataFile(filePath); var messageBodyMock = new Mock <MessageBody>(sut); messageBodyMock.SetupAllProperties(); servantMock.Setup(s => s.TryMoveFile(filePath, It.IsAny <string>())).Returns(true); sut.Lock(messageBodyMock.Object); messageBodyMock.Object.DataFile.Should().BeOfType <LockedDataFile>(); messageBodyMock.Object.DataFile.Should().NotBeSameAs(sut); (sut.Path.Tokenize().LockTime < messageBodyMock.Object.DataFile.Path.Tokenize().LockTime).Should().BeTrue(); }