//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldThrowExceptionWhenReadingIncompleteHeader() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldThrowExceptionWhenReadingIncompleteHeader() { // given long prevFileLastIndex = 1; long version = 2; long prevIndex = 3; long prevTerm = 4; SegmentHeader writtenHeader = new SegmentHeader(prevFileLastIndex, version, prevIndex, prevTerm); InMemoryClosableChannel channel = new InMemoryClosableChannel(); channel.PutLong(writtenHeader.Version()); channel.PutLong(writtenHeader.PrevIndex()); // when try { _marshal.unmarshal(channel); fail(); } catch (EndOfStreamException) { // expected } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldAllowOutOfBoundsPruneIndex() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldAllowOutOfBoundsPruneIndex() { //Given a prune index of n, if the smallest value for a segment file is n+c, the pruning should not remove // any files and not result in a failure. Segments segments = new Segments(_fsa, _fileNames, _readerPool, _segmentFiles, _contentMarshal, _logProvider, -1); segments.Rotate(-1, -1, -1); segments.Last().closeWriter(); // need to close writer otherwise dispose will not be called segments.Rotate(10, 10, 2); // we will truncate this whole file away segments.Last().closeWriter(); segments.Prune(11); segments.Rotate(20, 20, 3); // we will truncate this whole file away segments.Last().closeWriter(); //when SegmentFile oldestNotDisposed = segments.Prune(-1); //then SegmentHeader header = oldestNotDisposed.Header(); assertEquals(10, header.PrevFileLastIndex()); assertEquals(10, header.PrevIndex()); assertEquals(2, header.PrevTerm()); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private int dump(String filenameOrDirectory, java.io.PrintStream out) throws java.io.IOException, DamagedLogStorageException, DisposedException private int Dump(string filenameOrDirectory, PrintStream @out) { LogProvider logProvider = NullLogProvider.Instance; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int[] logsFound = {0}; int[] logsFound = new int[] { 0 }; FileNames fileNames = new FileNames(new File(filenameOrDirectory)); ReaderPool readerPool = new ReaderPool(0, logProvider, fileNames, _fileSystem, Clocks.systemClock()); RecoveryProtocol recoveryProtocol = new RecoveryProtocol(_fileSystem, fileNames, readerPool, _marshal, logProvider); Segments segments = recoveryProtocol.Run().Segments; segments.Visit(segment => { logsFound[0]++; @out.println("=== " + segment.Filename + " ==="); SegmentHeader header = segment.header(); @out.println(header.ToString()); try { using (IOCursor <EntryRecord> cursor = segment.getCursor(header.PrevIndex() + 1)) { while (cursor.next()) { @out.println(cursor.get().ToString()); } } } catch (Exception e) when(e is DisposedException || e is IOException) { e.printStackTrace(); Environment.Exit(-1); return(true); } return(false); }); return(logsFound[0]); }