Exemplo n.º 1
0
        public void WithBookmarkedLogAtTheEndOfFirstFile_ThenAllNextFilesAreRead()
        {
            GivenLogFilesInDirectory(files: 2);
            var initialFile     = LogFiles[0];
            var otherFile       = LogFiles[1];
            var batchCount      = Fixture.Create <int>();
            var otherFileLength = BatchPostingLimit * batchCount;

            GivenFileDeleteSucceeds(initialFile);
            GivenPersistedBookmark(initialFile, Fixture.Create <long>());

            GivenLockedFileLength(initialFile, length: CurrentLogFilePosition);
            GivenLockedFileLength(otherFile, length: otherFileLength);

            GivenLogReader(initialFile, length: CurrentLogFilePosition, maxStreams: int.MaxValue);
            GivenLogReader(otherFile, length: otherFileLength, maxStreams: int.MaxValue);

            GivenSendIsSuccessful();

            WhenLogShipperIsCalled();

            this.ShouldSatisfyAllConditions(
                () => LogFiles.ShouldBe(new[] { otherFile }, "Only one shall remain!"),
                () => CurrentLogFileName.ShouldBe(otherFile),
                () => CurrentLogFilePosition.ShouldBe(otherFileLength),
                () => SentBatches.ShouldBe(batchCount),
                () => SentRecords.ShouldBe(otherFileLength)
                );
        }
Exemplo n.º 2
0
        public void WithBookmarkedLogCannotBeOpened_ThenPreviousFilesAreDeletedButNotLast()
        {
            GivenLogFilesInDirectory();
            Array.ForEach(LogFiles.Take(LogFiles.Length - 1).ToArray(), GivenFileDeleteSucceeds);
            var bookmarkedFile     = LogFiles.Last();
            var bookmarkedPosition = Fixture.Create <long>();

            GivenPersistedBookmark(bookmarkedFile, bookmarkedPosition);
            GivenLogReaderCreateIOError(CurrentLogFileName, CurrentLogFilePosition);

            WhenLogShipperIsCalled();

            this.ShouldSatisfyAllConditions(
                () => CurrentLogFileName.ShouldBe(bookmarkedFile, "Bookmarked log file name should not change"),
                () => CurrentLogFilePosition.ShouldBe(bookmarkedPosition, "Bookmarked position should not change"),
                () => LogFiles.ShouldBe(new[] { bookmarkedFile }, "Only one shall remain!")
                );
        }
Exemplo n.º 3
0
        public void WithFailureLockingFileAndGettingLength_ThenProcessingStopsInTheEndOfTheFile()
        {
            GivenLogFilesInDirectory(files: 2);
            var initialFile     = LogFiles[0];
            var initialPosition = Fixture.Create <long>();
            var otherFile       = LogFiles[1];

            GivenPersistedBookmark(initialFile, initialPosition);
            GivenFileCannotBeLocked(initialFile);
            GivenLogReader(initialFile, length: initialPosition, maxStreams: 0);

            WhenLogShipperIsCalled();

            this.ShouldSatisfyAllConditions(
                () => LogFiles.ShouldBe(new[] { initialFile, otherFile }, "No files should be removed."),
                () => CurrentLogFileName.ShouldBe(initialFile),
                () => CurrentLogFilePosition.ShouldBe(initialPosition)
                );
        }
Exemplo n.º 4
0
        public void WithSendFailure_ThenBookmarkIsNotChanged()
        {
            GivenLogFilesInDirectory(files: 2);
            var allFiles    = LogFiles.ToArray();
            var initialFile = LogFiles[0];

            GivenPersistedBookmark(initialFile, 0);
            GivenLogReader(initialFile, length: BatchPostingLimit, maxStreams: BatchPostingLimit);
            GivenSendIsFailed();

            WhenLogShipperIsCalled();

            LogFiles.ShouldBe(allFiles, "Nothing shall be deleted.");

            this.ShouldSatisfyAllConditions(
                () => CurrentLogFileName.ShouldBe(initialFile),
                () => CurrentLogFilePosition.ShouldBe(0),
                () => SentBatches.ShouldBe(0),
                () => SentRecords.ShouldBe(0),
                () => FailedBatches.ShouldBe(1),
                () => FailedRecords.ShouldBe(BatchPostingLimit)
                );
        }