Example #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void attemptsPruningUntilOpenFileIsFound() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void AttemptsPruningUntilOpenFileIsFound()
        {
            /// <summary>
            /// prune stops attempting to prune files after finding one that is open.
            /// </summary>

            // Given
            Segments segments = new Segments(_fsa, _fileNames, _readerPool, Collections.emptyList(), _contentMarshal, _logProvider, -1);

            /*
             * create 0
             * create 1
             * create 2
             * create 3
             *
             * closeWriter on all
             * create reader on 1
             * prune on 3
             *
             * only 0 should be deleted
             */

            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();              // need to close writer otherwise dispose will not be called
            IOCursor <EntryRecord> reader = segments.Last().getCursor(11);

            segments.Rotate(20, 20, 3);                 // we will truncate this whole file away
            segments.Last().closeWriter();

            segments.Rotate(30, 30, 4);                 // we will truncate this whole file away
            segments.Last().closeWriter();

            segments.Prune(31);

            //when
            OpenEndRangeMap.ValueRange <long, SegmentFile> shouldBePruned        = segments.GetForIndex(5);
            OpenEndRangeMap.ValueRange <long, SegmentFile> shouldNotBePruned     = segments.GetForIndex(15);
            OpenEndRangeMap.ValueRange <long, SegmentFile> shouldAlsoNotBePruned = segments.GetForIndex(25);

            //then
            assertFalse(shouldBePruned.Value().Present);
            assertTrue(shouldNotBePruned.Value().Present);
            assertTrue(shouldAlsoNotBePruned.Value().Present);

            //when
            reader.close();
            segments.Prune(31);

            shouldBePruned        = segments.GetForIndex(5);
            shouldNotBePruned     = segments.GetForIndex(15);
            shouldAlsoNotBePruned = segments.GetForIndex(25);

            //then
            assertFalse(shouldBePruned.Value().Present);
            assertFalse(shouldNotBePruned.Value().Present);
            assertFalse(shouldAlsoNotBePruned.Value().Present);
        }
Example #2
0
//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());
        }
Example #3
0
//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()));
            }
        }
Example #4
0
//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()));
            }
        }