//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldReturnLatestItems() public virtual void ShouldReturnLatestItems() { // given int capacity = 4; ConsecutiveInFlightCache cache = new ConsecutiveInFlightCache(capacity, 1000, InFlightCacheMonitor.VOID, true); // when for (int i = 0; i < 3 * capacity; i++) { cache.Put(i, Content(i)); } // then for (int i = 0; i < 3 * capacity; i++) { RaftLogEntry entry = cache.Get(i); if (i < 2 * capacity) { assertNull(entry); } else { assertTrue(entry.Content().size().HasValue); assertEquals(i, entry.Content().size().Value); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldRemovePrunedItems() public virtual void ShouldRemovePrunedItems() { // given int capacity = 20; ConsecutiveInFlightCache cache = new ConsecutiveInFlightCache(capacity, 1000, InFlightCacheMonitor.VOID, true); for (int i = 0; i < capacity; i++) { cache.Put(i, Content(i)); } // when int upToIndex = capacity / 2 - 1; cache.Prune(upToIndex); // then assertEquals(capacity / 2, cache.ElementCount()); for (int i = 0; i < capacity; i++) { RaftLogEntry entry = cache.Get(i); if (i <= upToIndex) { assertNull(entry); } else { assertTrue(entry.Content().size().HasValue); assertEquals(i, entry.Content().size().Value); } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void applyUpTo(long applyUpToIndex) throws Exception private void ApplyUpTo(long applyUpToIndex) { using (InFlightLogEntryReader logEntrySupplier = new InFlightLogEntryReader(_raftLog, _inFlightCache, true)) { for (long logIndex = _applierState.lastApplied + 1; _applierState.keepRunning && logIndex <= applyUpToIndex; logIndex++) { RaftLogEntry entry = logEntrySupplier.Get(logIndex); if (entry == null) { throw new System.InvalidOperationException(format("Committed log entry at index %d must exist.", logIndex)); } if (entry.Content() is DistributedOperation) { DistributedOperation distributedOperation = ( DistributedOperation )entry.Content(); _progressTracker.trackReplication(distributedOperation); _batcher.add(logIndex, distributedOperation); } else { _batcher.flush(); // since this last entry didn't get in the batcher we need to update the lastApplied: _applierState.lastApplied = logIndex; } } _batcher.flush(); } }
//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 WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public synchronized void write(long logIndex, org.neo4j.causalclustering.core.consensus.log.RaftLogEntry entry) throws java.io.IOException public virtual void Write(long logIndex, RaftLogEntry entry) { lock (this) { EntryRecord.write(OrCreateWriter, _contentMarshal, logIndex, entry.Term(), entry.Content()); } }
private long SizeOf(RaftLogEntry entry) { return(entry.Content().size().GetValueOrDefault(0L)); }