Пример #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBeAbleToCloseOnlyAfterWriterIsClosed() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldBeAbleToCloseOnlyAfterWriterIsClosed()
        {
            using (SegmentFile segment = create(FsRule.get(), _fileNames.getForVersion(0), _readerPool, 0, _contentMarshal, _logProvider, _segmentHeader))
            {
                // given
                assertFalse(segment.TryClose());

                // when
                segment.CloseWriter();

                // then
                assertTrue(segment.TryClose());
            }
        }
Пример #2
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();
        }
Пример #3
0
//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());
            }
        }
Пример #4
0
        public virtual SegmentFile Prune(long pruneIndex)
        {
            lock (this)
            {
                IEnumerator <SegmentFile> itr = _allSegments.GetEnumerator();
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                SegmentFile notDisposed    = itr.next();                // we should always leave at least one segment
                int         firstRemaining = 0;

                while (itr.MoveNext())
                {
                    SegmentFile current = itr.Current;
                    if (current.Header().prevFileLastIndex() > pruneIndex)
                    {
                        break;
                    }

                    if (!notDisposed.TryClose())
                    {
                        break;
                    }

                    _log.info("Pruning %s", notDisposed);
                    if (!notDisposed.Delete())
                    {
                        _log.error("Failed to delete %s", notDisposed);
                        break;
                    }

                    // TODO: Sync the parent directory. Also consider handling fs operations under its own lock.

                    firstRemaining++;
                    notDisposed = current;
                }

                _rangeMap.remove(notDisposed.Header().prevIndex() + 1);
                _allSegments.RemoveRange(0, firstRemaining);

                return(notDisposed);
            }
        }
Пример #5
0
//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());
            }
        }