Example #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldSortAndAddMultipleEntriesInLastBlock() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldSortAndAddMultipleEntriesInLastBlock()
        {
            // given
            TrackingMonitor monitor   = new TrackingMonitor();
            int             blockSize = 1_000;
            IList <BlockEntry <MutableLong, MutableLong> > expected = new List <BlockEntry <MutableLong, MutableLong> >();

            using (BlockStorage <MutableLong, MutableLong> storage = new BlockStorage <MutableLong, MutableLong>(_layout, heapBufferFactory(blockSize), _fileSystem, _file, monitor))
            {
                // when
                for (int i = 0; i < 10; i++)
                {
                    long        keyNumber = Random.nextLong(10_000_000);
                    MutableLong key       = new MutableLong(keyNumber);
                    MutableLong value     = new MutableLong(i);
                    storage.Add(key, value);
                    expected.Add(new BlockEntry <>(key, value));
                }
                storage.DoneAdding();

                // then
                Sort(expected);
                AssertContents(_layout, storage, singletonList(expected));
            }
        }
Example #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldStartPopulationAgainIfNotCompletedFirstTime()
        public virtual void ShouldStartPopulationAgainIfNotCompletedFirstTime()
        {
            // given
            // label scan store init but no start
            LifeSupport     life    = new LifeSupport();
            TrackingMonitor monitor = new TrackingMonitor();

            life.Add(CreateLabelScanStore(FileSystemRule.get(), TestDirectory.databaseLayout(), EMPTY, true, false, monitor));
            life.Init();
            assertTrue(monitor.NoIndexCalled);
            monitor.Reset();
            life.Shutdown();

            // when
            // starting label scan store again
            life = new LifeSupport();
            life.Add(CreateLabelScanStore(FileSystemRule.get(), TestDirectory.databaseLayout(), EMPTY, true, false, monitor));
            life.Init();

            // then
            // label scan store should recognize it still needs to be rebuilt
            assertTrue(monitor.CorruptedIndex);
            life.Start();
            assertTrue(monitor.RebuildingCalled);
            assertTrue(monitor.RebuiltCalled);
            life.Shutdown();
        }
Example #3
0
        private void Start(IList <NodeLabelUpdate> existingData, bool usePersistentStore, bool readOnly)
        {
            _life    = new LifeSupport();
            _monitor = new TrackingMonitor();

            _store = CreateLabelScanStore(FileSystemRule.get(), TestDirectory.databaseLayout(), asStream(existingData), usePersistentStore, readOnly, _monitor);
            _life.add(_store);

            _life.start();
            assertTrue(_monitor.initCalled);
        }
Example #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldNotFlushAnythingOnEmptyBufferInDoneAdding() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldNotFlushAnythingOnEmptyBufferInDoneAdding()
        {
            // given
            TrackingMonitor monitor = new TrackingMonitor();

            using (BlockStorage <MutableLong, MutableLong> storage = new BlockStorage <MutableLong, MutableLong>(_layout, heapBufferFactory(100), _fileSystem, _file, monitor))
            {
                // when
                storage.DoneAdding();

                // then
                assertEquals(0, monitor.BlockFlushedCallCount);
            }
        }
Example #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldSortAndAddMultipleEntriesInMultipleBlocks() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldSortAndAddMultipleEntriesInMultipleBlocks()
        {
            // given
            TrackingMonitor monitor   = new TrackingMonitor();
            int             blockSize = 1_000;

            using (BlockStorage <MutableLong, MutableLong> storage = new BlockStorage <MutableLong, MutableLong>(_layout, heapBufferFactory(blockSize), _fileSystem, _file, monitor))
            {
                // when
                IList <IList <BlockEntry <MutableLong, MutableLong> > > expectedBlocks = AddACoupleOfBlocksOfEntries(monitor, storage, 3);

                // then
                AssertContents(_layout, storage, expectedBlocks);
            }
        }
Example #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldMergeWhenEmpty() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldMergeWhenEmpty()
        {
            // given
            TrackingMonitor monitor   = new TrackingMonitor();
            int             blockSize = 1_000;

            using (BlockStorage <MutableLong, MutableLong> storage = new BlockStorage <MutableLong, MutableLong>(_layout, heapBufferFactory(blockSize), _fileSystem, _file, monitor))
            {
                // when
                storage.Merge(RandomMergeFactor(), NOT_CANCELLABLE);

                // then
                assertEquals(0, monitor.MergeIterationCallCount);
                AssertContents(_layout, storage, emptyList());
            }
        }
Example #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRestartPopulationIfIndexFileWasNeverFullyInitialized() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRestartPopulationIfIndexFileWasNeverFullyInitialized()
        {
            // given
            File labelScanStoreFile = NativeLabelScanStore.GetLabelScanStoreFile(TestDirectory.databaseLayout());

            FileSystemRule.create(labelScanStoreFile).close();
            TrackingMonitor monitor = new TrackingMonitor();
            LifeSupport     life    = new LifeSupport();

            // when
            life.Add(CreateLabelScanStore(FileSystemRule.get(), TestDirectory.databaseLayout(), EMPTY, true, false, monitor));
            life.Start();

            // then
            assertTrue(monitor.CorruptedIndex);
            assertTrue(monitor.RebuildingCalled);
            life.Shutdown();
        }
Example #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldOnlyLeaveSingleFileAfterMerge() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldOnlyLeaveSingleFileAfterMerge()
        {
            TrackingMonitor monitor   = new TrackingMonitor();
            int             blockSize = 1_000;

            using (BlockStorage <MutableLong, MutableLong> storage = new BlockStorage <MutableLong, MutableLong>(_layout, heapBufferFactory(blockSize), _fileSystem, _file, monitor))
            {
                int numberOfBlocks = Random.Next(100) + 2;
                AddACoupleOfBlocksOfEntries(monitor, storage, numberOfBlocks);
                storage.DoneAdding();

                // when
                storage.Merge(2, NOT_CANCELLABLE);

                // then
                File[] files = _fileSystem.listFiles(Directory.directory());
                assertEquals(1, Files.Length, "Expected only a single file to exist after merge.");
            }
        }
Example #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldMergeSingleBlock() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldMergeSingleBlock()
        {
            // given
            TrackingMonitor monitor   = new TrackingMonitor();
            int             blockSize = 1_000;

            using (BlockStorage <MutableLong, MutableLong> storage = new BlockStorage <MutableLong, MutableLong>(_layout, heapBufferFactory(blockSize), _fileSystem, _file, monitor))
            {
                IList <IList <BlockEntry <MutableLong, MutableLong> > > expectedBlocks = singletonList(AddEntries(storage, 4));
                storage.DoneAdding();

                // when
                storage.Merge(RandomMergeFactor(), NOT_CANCELLABLE);

                // then
                assertEquals(0, monitor.MergeIterationCallCount);
                AssertContents(_layout, storage, expectedBlocks);
            }
        }
Example #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldMergeMultipleBlocks() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldMergeMultipleBlocks()
        {
            // given
            TrackingMonitor monitor   = new TrackingMonitor();
            int             blockSize = 1_000;

            using (BlockStorage <MutableLong, MutableLong> storage = new BlockStorage <MutableLong, MutableLong>(_layout, heapBufferFactory(blockSize), _fileSystem, _file, monitor))
            {
                int numberOfBlocks = Random.Next(100) + 2;
                IList <IList <BlockEntry <MutableLong, MutableLong> > > expectedBlocks = AddACoupleOfBlocksOfEntries(monitor, storage, numberOfBlocks);
                storage.DoneAdding();

                // when
                storage.Merge(RandomMergeFactor(), NOT_CANCELLABLE);

                // then
                AssertContents(_layout, storage, AsOneBigBlock(expectedBlocks));
                assertThat(monitor.TotalEntriesToMerge, greaterThanOrEqualTo(monitor.EntryAddedCallCount));
                assertEquals(monitor.TotalEntriesToMerge, monitor.EntriesMergedConflict);
            }
        }
Example #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldAddSingleEntryInLastBlock() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldAddSingleEntryInLastBlock()
        {
            // given
            TrackingMonitor monitor   = new TrackingMonitor();
            int             blockSize = 100;
            MutableLong     key       = new MutableLong(10);
            MutableLong     value     = new MutableLong(20);

            using (BlockStorage <MutableLong, MutableLong> storage = new BlockStorage <MutableLong, MutableLong>(_layout, heapBufferFactory(blockSize), _fileSystem, _file, monitor))
            {
                // when
                storage.Add(key, value);
                storage.DoneAdding();

                // then
                assertEquals(1, monitor.BlockFlushedCallCount);
                assertEquals(1, monitor.LastKeyCount);
                assertEquals(BlockStorage.BlockHeaderSize + monitor.TotalEntrySize, monitor.LastNumberOfBytes);
                assertEquals(blockSize, monitor.LastPositionAfterFlush);
                assertThat(monitor.LastNumberOfBytes, lessThan(blockSize));
                AssertContents(_layout, storage, singletonList(singletonList(new BlockEntry <>(key, value))));
            }
        }
Example #12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private java.util.List<java.util.List<BlockEntry<org.apache.commons.lang3.mutable.MutableLong,org.apache.commons.lang3.mutable.MutableLong>>> addACoupleOfBlocksOfEntries(TrackingMonitor monitor, BlockStorage<org.apache.commons.lang3.mutable.MutableLong,org.apache.commons.lang3.mutable.MutableLong> storage, int numberOfBlocks) throws java.io.IOException
        private IList <IList <BlockEntry <MutableLong, MutableLong> > > AddACoupleOfBlocksOfEntries(TrackingMonitor monitor, BlockStorage <MutableLong, MutableLong> storage, int numberOfBlocks)
        {
            Debug.Assert(numberOfBlocks != 1);

            MutableLongSet uniqueKeys = LongSets.mutable.empty();
            IList <IList <BlockEntry <MutableLong, MutableLong> > > expected        = new List <IList <BlockEntry <MutableLong, MutableLong> > >();
            IList <BlockEntry <MutableLong, MutableLong> >          currentExpected = new List <BlockEntry <MutableLong, MutableLong> >();
            long currentBlock = 0;

            while (monitor.BlockFlushedCallCount < numberOfBlocks - 1)
            {
                MutableLong key   = UniqueKey(uniqueKeys);
                MutableLong value = new MutableLong(Random.nextLong(10_000_000));

                storage.Add(key, value);
                if (monitor.BlockFlushedCallCount > currentBlock)
                {
                    Sort(currentExpected);
                    expected.Add(currentExpected);
                    currentExpected = new List <BlockEntry <MutableLong, MutableLong> >();
                    currentBlock    = monitor.BlockFlushedCallCount;
                }
                currentExpected.Add(new BlockEntry <>(key, value));
            }
            storage.DoneAdding();
            if (currentExpected.Count > 0)
            {
                expected.Add(currentExpected);
            }
            return(expected);
        }