Esempio n. 1
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);
        }
Esempio n. 2
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));
            }
        }
Esempio n. 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldNoticeCancelRequest() throws java.io.IOException, java.util.concurrent.ExecutionException, InterruptedException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldNoticeCancelRequest()
        {
            // given
            Org.Neo4j.Test.Barrier_Control barrier = new Org.Neo4j.Test.Barrier_Control();
            TrackingMonitor monitor     = new TrackingMonitorAnonymousInnerClass(this, barrier);
            int             blocks      = 10;
            int             mergeFactor = 2;
            MutableLongSet  uniqueKeys  = new LongHashSet();
            AtomicBoolean   cancelled   = new AtomicBoolean();

            using (BlockStorage <MutableLong, MutableLong> storage = new BlockStorage <MutableLong, MutableLong>(_layout, heapBufferFactory(100), _fileSystem, _file, monitor), OtherThreadExecutor <Void> t2 = new OtherThreadExecutor <Void>("T2", null))
            {
                while (monitor.BlockFlushedCallCount < blocks)
                {
                    storage.Add(UniqueKey(uniqueKeys), new MutableLong());
                }
                storage.DoneAdding();

                // when starting to merge
                Future <object> merge = t2.ExecuteDontWait(command(() => storage.merge(mergeFactor, cancelled.get)));
                barrier.AwaitUninterruptibly();
                // one merge iteration have now been done, set the cancellation flag
                cancelled.set(true);
                barrier.Release();
                merge.get();
            }

            // then there should not be any more merge iterations done, i.e. merge was cancelled
            assertEquals(1, monitor.MergeIterationCallCount);
        }
Esempio n. 4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void mergeScanUpdates() throws InterruptedException, java.util.concurrent.ExecutionException, java.io.IOException
        private void MergeScanUpdates()
        {
            ExecutorService executorService = Executors.newFixedThreadPool(_allScanUpdates.Count);
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.List<java.util.concurrent.Future<?>> mergeFutures = new java.util.ArrayList<>();
            IList <Future <object> > mergeFutures = new List <Future <object> >();

            foreach (ThreadLocalBlockStorage part in _allScanUpdates)
            {
                BlockStorage <KEY, VALUE> scanUpdates = part.BlockStorage;
                // Call doneAdding here so that the buffer it allocates if it needs to flush something will be shared with other indexes
                scanUpdates.DoneAdding();
                mergeFutures.Add(executorService.submit(() =>
                {
                    scanUpdates.Merge(_mergeFactor, _cancellation);
                    return(null);
                }));
            }
            executorService.shutdown();
            while (!executorService.awaitTermination(1, TimeUnit.SECONDS))
            {
                // just wait longer
            }
            // Let potential exceptions in the merge threads have a chance to propagate
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: for (java.util.concurrent.Future<?> mergeFuture : mergeFutures)
            foreach (Future <object> mergeFuture in mergeFutures)
            {
                mergeFuture.get();
            }
        }
Esempio n. 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldNotAcceptAddedEntriesAfterDoneAdding() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldNotAcceptAddedEntriesAfterDoneAdding()
        {
            // given
            using (BlockStorage <MutableLong, MutableLong> storage = new BlockStorage <MutableLong, MutableLong>(_layout, heapBufferFactory(100), _fileSystem, _file, NO_MONITOR))
            {
                // when
                storage.DoneAdding();

                // then
                assertThrows(typeof(System.InvalidOperationException), () => storage.add(new MutableLong(0), new MutableLong(1)));
            }
        }
Esempio n. 6
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);
            }
        }
Esempio n. 7
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.");
            }
        }
Esempio n. 8
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);
            }
        }
Esempio n. 9
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);
            }
        }
Esempio n. 10
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))));
            }
        }