//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldCreateNext() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldCreateNext() { // Given using (Segments segments = new Segments(_fsa, _fileNames, _readerPool, _segmentFiles, _contentMarshal, _logProvider, -1)) { // When segments.Rotate(10, 10, 12); segments.Last().closeWriter(); SegmentFile last = segments.Last(); // Then assertEquals(10, last.Header().prevFileLastIndex()); assertEquals(10, last.Header().prevIndex()); assertEquals(12, last.Header().prevTerm()); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNeverDeleteOnTruncate() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldNeverDeleteOnTruncate() { // Given using (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(); // When segments.Truncate(20, 9, 4); // Then verify(_fsa, never()).deleteFile(any()); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldDeleteOnPrune() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldDeleteOnPrune() { verifyZeroInteractions(_fsa); // Given using (Segments segments = new Segments(_fsa, _fileNames, _readerPool, _segmentFiles, _contentMarshal, _logProvider, -1)) { // this is version 0 and will be deleted on prune later SegmentFile toPrune = segments.Rotate(-1, -1, -1); segments.Last().closeWriter(); // need to close writer otherwise dispose will not be called segments.Rotate(10, 10, 2); segments.Last().closeWriter(); // ditto segments.Rotate(20, 20, 2); // When segments.Prune(11); verify(_fsa, times(_segmentFiles.Count)).deleteFile(_fileNames.getForVersion(toPrune.Header().version())); } }
//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]); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotSwallowExceptionOnClose() public virtual void ShouldNotSwallowExceptionOnClose() { // Given doThrow(new Exception()).when(_fileA).close(); doThrow(new Exception()).when(_fileB).close(); Segments segments = new Segments(_fsa, _fileNames, _readerPool, _segmentFiles, _contentMarshal, _logProvider, -1); // When try { segments.Close(); fail("should have thrown"); } catch (Exception ex) { // Then Exception[] suppressed = ex.Suppressed; assertEquals(1, suppressed.Length); assertTrue(suppressed[0] is Exception); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldDeleteTruncatedFilesOnPrune() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldDeleteTruncatedFilesOnPrune() { // Given using (Segments segments = new Segments(_fsa, _fileNames, _readerPool, _segmentFiles, _contentMarshal, _logProvider, -1)) { SegmentFile toBePruned = segments.Rotate(-1, -1, -1); segments.Last().closeWriter(); // need to close writer otherwise dispose will not be called // we will truncate this whole file away SegmentFile toBeTruncated = segments.Rotate(10, 10, 2); segments.Last().closeWriter(); // When // We truncate a whole file segments.Truncate(20, 9, 4); // And we prune all files before that file segments.Prune(10); // Then // the truncate file is part of the deletes that happen while pruning verify(_fsa, times(_segmentFiles.Count)).deleteFile(_fileNames.getForVersion(toBePruned.Header().version())); } }
internal EntryCursor(Segments segments, long logIndex) { this._segments = segments; this._currentIndex = logIndex - 1; }
internal virtual long GetIndexToPruneFrom(long safeIndex, Segments segments) { return(Math.Min(safeIndex, _pruningStrategy.getIndexToKeep(segments))); }