示例#1
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();
            }
        }
示例#2
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());
            }
        }
示例#3
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.");
            }
        }
示例#4
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);
            }
        }
示例#5
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);
            }
        }