コード例 #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)
                );
        }
コード例 #2
0
        public void WhenLogFileSizeIsLessThanBookmarkPosition_ThenFileIsReadFromTheBeginning()
        {
            GivenLogFilesInDirectory(1);
            var initialFile        = LogFiles[0];
            var batchesCount       = Fixture.Create <int>();
            var realFileLength     = batchesCount * BatchPostingLimit;
            var bookmarkedPosition = realFileLength + Fixture.Create <int>();

            GivenPersistedBookmark(initialFile, position: bookmarkedPosition);
            GivenLockedFileLength(initialFile, length: realFileLength);
            GivenLogReader(initialFile, length: realFileLength, maxStreams: int.MaxValue);
            GivenSendIsSuccessful();

            WhenLogShipperIsCalled();

            this.ShouldSatisfyAllConditions(
                () => CurrentLogFileName.ShouldBe(initialFile),
                () => CurrentLogFilePosition.ShouldBe(realFileLength),
                () => SentBatches.ShouldBe(batchesCount),
                () => SentRecords.ShouldBe(realFileLength)
                );
        }
コード例 #3
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)
                );
        }