示例#1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotAppendAtTheEndOfLogFileWithIncompleteEntries() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotAppendAtTheEndOfLogFileWithIncompleteEntries()
        {
            // Given
            // we use a RaftLog to create a raft log file and then we will chop some bits off the end
            SegmentedRaftLog raftLog = CreateRaftLog(100_000);

            raftLog.Start();

            raftLog.Append(new RaftLogEntry(4, new NewLeaderBarrier()));

            raftLog.Stop();

            // We use a temporary RecoveryProtocol to get the file to chop
            RecoveryProtocol recovery      = CreateRecoveryProtocol();
            State            recoveryState = Recovery.run();
            string           logFilename   = recoveryState.Segments.last().Filename;

            recoveryState.Segments.close();
            File         logFile     = new File(_logDirectory, logFilename);
            StoreChannel lastFile    = FsRule.get().open(logFile, OpenMode.READ_WRITE);
            long         currentSize = lastFile.size();

            lastFile.close();

            // When
            // We induce an incomplete entry at the end of the last file
            lastFile = FsRule.get().open(logFile, OpenMode.READ_WRITE);
            lastFile.Truncate(currentSize - 1);
            lastFile.close();

            // We start the raft log again, on the previous log file with truncated last entry.
            raftLog = CreateRaftLog(100_000);

            //  Recovery will run here
            raftLog.Start();

            // Append an entry
            raftLog.Append(new RaftLogEntry(4, new NewLeaderBarrier()));

            // Then
            // The log should report as containing only the last entry we've appended
            using (RaftLogCursor entryCursor = raftLog.GetEntryCursor(0))
            {
                // There should be exactly one entry, of type NewLeaderBarrier
                assertTrue(entryCursor.Next());
                RaftLogEntry raftLogEntry = entryCursor.get();
                assertEquals(typeof(NewLeaderBarrier), raftLogEntry.Content().GetType());
                assertFalse(entryCursor.Next());
            }
            raftLog.Stop();
        }
示例#2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReturnFalseOnCursorForEntryThatWasPruned() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReturnFalseOnCursorForEntryThatWasPruned()
        {
            //given
            SegmentedRaftLog segmentedRaftLog = CreateRaftLog(1, "keep_none");
            long             firstIndex       = segmentedRaftLog.Append(new RaftLogEntry(1, ReplicatedInteger.valueOf(1)));

            segmentedRaftLog.Append(new RaftLogEntry(2, ReplicatedInteger.valueOf(2)));
            long lastIndex = segmentedRaftLog.Append(new RaftLogEntry(3, ReplicatedInteger.valueOf(3)));

            //when
            segmentedRaftLog.Prune(firstIndex);
            RaftLogCursor entryCursor = segmentedRaftLog.GetEntryCursor(firstIndex);
            bool          next        = entryCursor.Next();

            //then
            assertFalse(next);
        }
示例#3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReturnFalseOnCursorForEntryThatDoesntExist() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReturnFalseOnCursorForEntryThatDoesntExist()
        {
            //given
            SegmentedRaftLog segmentedRaftLog = CreateRaftLog(1);

            segmentedRaftLog.Append(new RaftLogEntry(1, ReplicatedInteger.valueOf(1)));
            segmentedRaftLog.Append(new RaftLogEntry(2, ReplicatedInteger.valueOf(2)));
            long lastIndex = segmentedRaftLog.Append(new RaftLogEntry(3, ReplicatedInteger.valueOf(3)));

            //when
            bool next;

            using (RaftLogCursor entryCursor = segmentedRaftLog.GetEntryCursor(lastIndex + 1))
            {
                next = entryCursor.Next();
            }

            //then
            assertFalse(next);
        }