//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldReadOlderLogs() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldReadOlderLogs() { // GIVEN FileSystemAbstraction fs = _fileSystemRule.get(); LogFiles logFiles = LogFilesBuilder.builder(_directory.databaseLayout(), fs).withTransactionIdStore(_transactionIdStore).withLogVersionRepository(_logVersionRepository).build(); _life.start(); _life.add(logFiles); // WHEN LogFile logFile = logFiles.LogFile; FlushablePositionAwareChannel writer = logFile.Writer; LogPositionMarker positionMarker = new LogPositionMarker(); writer.GetCurrentPosition(positionMarker); LogPosition position1 = positionMarker.NewPosition(); int intValue = 45; long longValue = 4854587; sbyte[] someBytes = someBytes(40); writer.PutInt(intValue); writer.PutLong(longValue); writer.Put(someBytes, someBytes.Length); writer.PrepareForFlush().flush(); writer.GetCurrentPosition(positionMarker); LogPosition position2 = positionMarker.NewPosition(); long longValue2 = 123456789L; writer.PutLong(longValue2); writer.Put(someBytes, someBytes.Length); writer.PrepareForFlush().flush(); // THEN using (ReadableClosableChannel reader = logFile.GetReader(position1)) { assertEquals(intValue, reader.Int); assertEquals(longValue, reader.Long); assertArrayEquals(someBytes, ReadBytes(reader, 40)); } using (ReadableClosableChannel reader = logFile.GetReader(position2)) { assertEquals(longValue2, reader.Long); assertArrayEquals(someBytes, ReadBytes(reader, 40)); } }
/// <summary> /// Utility method for creating a <seealso cref="ReversedMultiFileTransactionCursor"/> with a <seealso cref="LogFile"/> as the source of /// <seealso cref="TransactionCursor"/> for each log version. /// </summary> /// <param name="logFile"> <seealso cref="LogFile"/> to supply log entries forming transactions. </param> /// <param name="backToPosition"> <seealso cref="LogPosition"/> to read backwards to. </param> /// <param name="failOnCorruptedLogFiles"> fail reading from log files as soon as first error is encountered </param> /// <param name="monitor"> reverse transaction cursor monitor </param> /// <returns> a <seealso cref="TransactionCursor"/> which returns transactions from the end of the log stream and backwards to /// and including transaction starting at <seealso cref="LogPosition"/>. </returns> /// <exception cref="IOException"> on I/O error. </exception> public static TransactionCursor FromLogFile(LogFiles logFiles, LogFile logFile, LogPosition backToPosition, bool failOnCorruptedLogFiles, ReversedTransactionCursorMonitor monitor) { long highestVersion = logFiles.HighestLogVersion; LogEntryReader <ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(); ThrowingFunction <LogPosition, TransactionCursor, IOException> factory = position => { ReadableLogChannel channel = logFile.GetReader(position, NO_MORE_CHANNELS); if (channel is ReadAheadLogChannel) { // This is a channel which can be positioned explicitly and is the typical case for such channels // Let's take advantage of this fact and use a bit smarter reverse implementation return(new ReversedSingleFileTransactionCursor(( ReadAheadLogChannel )channel, logEntryReader, failOnCorruptedLogFiles, monitor)); } // Fall back to simply eagerly reading each single log file and reversing in memory return(eagerlyReverse(new PhysicalTransactionCursor <>(channel, logEntryReader))); }; return(new ReversedMultiFileTransactionCursor(factory, highestVersion, backToPosition)); }