//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotReturnReaderExperiencingErrorToPool() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldNotReturnReaderExperiencingErrorToPool() { // given StoreChannel channel = mock(typeof(StoreChannel)); Reader reader = mock(typeof(Reader)); ReaderPool readerPool = mock(typeof(ReaderPool)); when(channel.read(any(typeof(ByteBuffer)))).thenThrow(new IOException()); when(reader.Channel()).thenReturn(channel); when(readerPool.Acquire(anyLong(), anyLong())).thenReturn(reader); using (SegmentFile segment = create(FsRule.get(), _fileNames.getForVersion(0), readerPool, 0, _contentMarshal, _logProvider, _segmentHeader)) { // given IOCursor <EntryRecord> cursor = segment.GetCursor(0); try { cursor.next(); fail(); } catch (IOException) { // expected from mocking } // when cursor.close(); // then verify(readerPool, never()).release(reader); verify(reader).close(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldBeAbleToRepeatedlyReadWrittenValues() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldBeAbleToRepeatedlyReadWrittenValues() { using (SegmentFile segment = create(FsRule.get(), _fileNames.getForVersion(0), _readerPool, 0, _contentMarshal, _logProvider, _segmentHeader)) { // given segment.Write(0, _entry1); segment.Write(1, _entry2); segment.Write(2, _entry3); segment.Flush(); for (int i = 0; i < 3; i++) { // when IOCursor <EntryRecord> cursor = segment.GetCursor(0); // then assertTrue(cursor.next()); assertEquals(_entry1, cursor.get().logEntry()); assertTrue(cursor.next()); assertEquals(_entry2, cursor.get().logEntry()); assertTrue(cursor.next()); assertEquals(_entry3, cursor.get().logEntry()); assertFalse(cursor.next()); cursor.close(); } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private boolean nextSegment() throws java.io.IOException private bool NextSegment() { _segmentRange = _segments.getForIndex(_currentIndex); Optional <SegmentFile> optionalFile = _segmentRange.value(); if (!optionalFile.Present) { _currentRecord.invalidate(); return(false); } SegmentFile file = optionalFile.get(); /* Open new reader before closing old, so that pruner cannot overtake us. */ IOCursor <EntryRecord> oldCursor = _cursor; try { _cursor = file.GetCursor(_currentIndex); } catch (DisposedException) { _currentRecord.invalidate(); return(false); } if (oldCursor != null) { oldCursor.close(); } _limit = _segmentRange.limit().GetValueOrDefault(long.MaxValue); return(true); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldReportCorrectInitialValues() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldReportCorrectInitialValues() { using (SegmentFile segment = create(FsRule.get(), _fileNames.getForVersion(0), _readerPool, _version, _contentMarshal, _logProvider, _segmentHeader)) { assertEquals(0, segment.Header().version()); IOCursor <EntryRecord> cursor = segment.GetCursor(0); assertFalse(cursor.next()); cursor.close(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldCallDisposeHandlerAfterLastReaderIsClosed() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldCallDisposeHandlerAfterLastReaderIsClosed() { using (SegmentFile segment = create(FsRule.get(), _fileNames.getForVersion(0), _readerPool, 0, _contentMarshal, _logProvider, _segmentHeader)) { // given IOCursor <EntryRecord> cursor0 = segment.GetCursor(0); IOCursor <EntryRecord> cursor1 = segment.GetCursor(0); // when segment.CloseWriter(); cursor0.close(); // then assertFalse(segment.TryClose()); // when cursor1.close(); // then assertTrue(segment.TryClose()); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldPruneReaderPoolOnClose() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldPruneReaderPoolOnClose() { using (SegmentFile segment = create(FsRule.get(), _fileNames.getForVersion(0), _readerPool, 0, _contentMarshal, _logProvider, _segmentHeader)) { segment.Write(0, _entry1); segment.Flush(); segment.CloseWriter(); IOCursor <EntryRecord> cursor = segment.GetCursor(0); cursor.next(); cursor.close(); } verify(_readerPool).prune(0); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHaveIdempotentCloseMethods() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldHaveIdempotentCloseMethods() { // given SegmentFile segment = create(FsRule.get(), _fileNames.getForVersion(0), _readerPool, 0, _contentMarshal, _logProvider, _segmentHeader); IOCursor <EntryRecord> cursor = segment.GetCursor(0); // when segment.CloseWriter(); cursor.close(); // then assertTrue(segment.TryClose()); segment.Close(); assertTrue(segment.TryClose()); segment.Close(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldBeAbleToWriteAndRead() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldBeAbleToWriteAndRead() { using (SegmentFile segment = create(FsRule.get(), _fileNames.getForVersion(0), _readerPool, 0, _contentMarshal, _logProvider, _segmentHeader)) { // given segment.Write(0, _entry1); segment.Flush(); // when IOCursor <EntryRecord> cursor = segment.GetCursor(0); // then assertTrue(cursor.next()); assertEquals(_entry1, cursor.get().logEntry()); cursor.close(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldCatchDoubleCloseReaderErrors() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldCatchDoubleCloseReaderErrors() { try { using (SegmentFile segment = create(FsRule.get(), _fileNames.getForVersion(0), _readerPool, 0, _contentMarshal, _logProvider, _segmentHeader)) { // given IOCursor <EntryRecord> cursor = segment.GetCursor(0); cursor.close(); cursor.close(); fail("Should have caught double close error"); } } catch (System.InvalidOperationException) { // expected } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHandleReaderPastEndCorrectly() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldHandleReaderPastEndCorrectly() { using (SegmentFile segment = create(FsRule.get(), _fileNames.getForVersion(0), _readerPool, 0, _contentMarshal, _logProvider, _segmentHeader)) { // given segment.Write(0, _entry1); segment.Write(1, _entry2); segment.Flush(); segment.CloseWriter(); IOCursor <EntryRecord> cursor = segment.GetCursor(3); // then assertFalse(cursor.next()); // when cursor.close(); // then assertTrue(segment.TryClose()); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: State run() throws java.io.IOException, DamagedLogStorageException, DisposedException internal virtual State Run() { State state = new State(); SortedDictionary <long, File> files = _fileNames.getAllFiles(_fileSystem, _log); if (Files.SetOfKeyValuePairs().Empty) { state.Segments = new Segments(_fileSystem, _fileNames, _readerPool, emptyList(), _contentMarshal, _logProvider, -1); state.Segments.rotate(-1, -1, -1); state.Terms = new Terms(-1, -1); return(state); } IList <SegmentFile> segmentFiles = new List <SegmentFile>(); SegmentFile segment = null; long expectedVersion = Files.firstKey(); bool mustRecoverLastHeader = false; bool skip = true; // the first file is treated the same as a skip foreach (KeyValuePair <long, File> entry in Files.SetOfKeyValuePairs()) { long fileNameVersion = entry.Key; File file = entry.Value; SegmentHeader header; CheckVersionSequence(fileNameVersion, expectedVersion); try { header = LoadHeader(_fileSystem, file); CheckVersionMatches(header.Version(), fileNameVersion); } catch (EndOfStreamException e) { if (Files.lastKey() != fileNameVersion) { throw new DamagedLogStorageException(e, "Intermediate file with incomplete or no header found: %s", file); } else if (Files.Count == 1) { throw new DamagedLogStorageException(e, "Single file with incomplete or no header found: %s", file); } /* Last file header must be recovered by scanning next-to-last file and writing a new header based on that. */ mustRecoverLastHeader = true; break; } segment = new SegmentFile(_fileSystem, file, _readerPool, fileNameVersion, _contentMarshal, _logProvider, header); segmentFiles.Add(segment); if (segment.Header().prevIndex() != segment.Header().prevFileLastIndex()) { _log.info(format("Skipping from index %d to %d.", segment.Header().prevFileLastIndex(), segment.Header().prevIndex() + 1)); skip = true; } if (skip) { state.PrevIndex = segment.Header().prevIndex(); state.PrevTerm = segment.Header().prevTerm(); skip = false; } expectedVersion++; } Debug.Assert(segment != null); state.AppendIndex = segment.Header().prevIndex(); state.Terms = new Terms(segment.Header().prevIndex(), segment.Header().prevTerm()); using (IOCursor <EntryRecord> cursor = segment.GetCursor(segment.Header().prevIndex() + 1)) { while (cursor.next()) { EntryRecord entry = cursor.get(); state.AppendIndex = entry.LogIndex(); state.Terms.append(state.AppendIndex, entry.LogEntry().term()); } } if (mustRecoverLastHeader) { SegmentHeader header = new SegmentHeader(state.AppendIndex, expectedVersion, state.AppendIndex, state.Terms.latest()); _log.warn("Recovering last file based on next-to-last file. " + header); File file = _fileNames.getForVersion(expectedVersion); WriteHeader(_fileSystem, file, header); segment = new SegmentFile(_fileSystem, file, _readerPool, expectedVersion, _contentMarshal, _logProvider, header); segmentFiles.Add(segment); } state.Segments = new Segments(_fileSystem, _fileNames, _readerPool, segmentFiles, _contentMarshal, _logProvider, segment.Header().version()); return(state); }