//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldThrowExceptionWhenReadingAnEntryWhichHasBeenPruned() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldThrowExceptionWhenReadingAnEntryWhichHasBeenPruned() { RaftLog log = CreateRaftLog(); log.Append(new RaftLogEntry(0, String(1024))); log.Append(new RaftLogEntry(1, String(1024))); log.Append(new RaftLogEntry(2, String(1024))); log.Append(new RaftLogEntry(3, String(1024))); log.Append(new RaftLogEntry(4, String(1024))); long pruneIndex = log.Prune(4); assertThat(pruneIndex, greaterThanOrEqualTo(2L)); long term = log.ReadEntryTerm(1); RaftLogCursor cursor = log.GetEntryCursor(1); if (cursor.Next()) { fail(); //the cursor should return false since this has been pruned. } assertEquals(-1L, term); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public static RaftLogEntry readLogEntry(ReadableRaftLog raftLog, long index) throws java.io.IOException public static RaftLogEntry ReadLogEntry(ReadableRaftLog raftLog, long index) { using (RaftLogCursor cursor = raftLog.GetEntryCursor(index)) { if (cursor.Next()) { return(cursor.get()); } } //todo: do not do this and update RaftLogContractTest to not depend on this exception. throw new IOException("Asked for raft log entry at index " + index + " but it was not found"); }
//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(); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void print(java.io.PrintStream out) throws java.io.IOException public virtual void Print(PrintStream @out) { @out.println(string.Format("{0,8} {1,5} {2,2} {3}", "Index", "Term", "C?", "Content")); long index = 0L; using (RaftLogCursor cursor = _raftLog.getEntryCursor(0)) { while (cursor.Next()) { RaftLogEntry raftLogEntry = cursor.get(); @out.printf("%8d %5d %s", index, raftLogEntry.Term(), raftLogEntry.Content()); index++; } } }
//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); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void start() throws java.io.IOException public override void Start() { this._state = _storage.InitialState; long recoverFromIndex = _recoverFromIndexSupplier.AsLong; _log.info("Membership state before recovery: " + _state); _log.info("Recovering from: " + recoverFromIndex + " to: " + _raftLog.appendIndex()); using (RaftLogCursor cursor = _raftLog.getEntryCursor(recoverFromIndex)) { while (cursor.Next()) { Append(cursor.Index(), cursor.get()); } } _log.info("Membership state after recovery: " + _state); UpdateMemberSets(); }
private void Read(RaftLog raftLog) { try { using (RaftLogCursor cursor = raftLog.GetEntryCursor(0)) { while (cursor.Next()) { RaftLogEntry entry = cursor.get(); ReplicatedString content = ( ReplicatedString )entry.Content(); assertEquals(StringForIndex(cursor.Index()), content.Value()); } } } catch (IOException e) { throw new Exception(e); } }
//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); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void startingFromIndexReturnEntries(org.neo4j.causalclustering.core.consensus.log.ReadableRaftLog raftLog, long startIndex, org.neo4j.causalclustering.core.consensus.log.RaftLogEntry entry, org.neo4j.causalclustering.core.consensus.log.RaftLogEntry... otherEntries) throws java.io.IOException private void StartingFromIndexReturnEntries(ReadableRaftLog raftLog, long startIndex, RaftLogEntry entry, params RaftLogEntry[] otherEntries) { RaftLogCursor cursor = mock(typeof(RaftLogCursor)); when(raftLog.GetEntryCursor(startIndex)).thenReturn(cursor, ( RaftLogCursor )null); bool?[] bools = new bool?[otherEntries.Length + 1]; Arrays.fill(bools, true); bools[otherEntries.Length] = false; when(cursor.Next()).thenReturn(true, bools); long?[] indexes = new long?[otherEntries.Length + 1]; for (int offset = 0; offset < indexes.Length; offset++) { indexes[offset] = startIndex + 1 + offset; } indexes[otherEntries.Length] = -1L; when(cursor.Index()).thenReturn(startIndex, indexes); RaftLogEntry[] raftLogEntries = Arrays.copyOf(otherEntries, otherEntries.Length + 1); when(cursor.get()).thenReturn(entry, raftLogEntries); }