Exemple #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCorrectlyDecideToAwaitMergeDependingOnProgress() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCorrectlyDecideToAwaitMergeDependingOnProgress()
        {
            // given
            BlockBasedIndexPopulator <GenericKey, NativeIndexValue> populator = InstantiatePopulator(NO_MONITOR);
            bool closed = false;

            try
            {
                populator.Add(BatchOfUpdates());

                // when
                Race race = new Race();
                race.AddContestant(throwing(() => populator.scanCompleted(nullInstance)));
                race.AddContestant(throwing(() => populator.close(false)));
                race.Go();
                closed = true;

                // then regardless of who wins (close/merge) after close call returns no files should still be mapped
                EphemeralFileSystemAbstraction ephemeralFileSystem = ( EphemeralFileSystemAbstraction )_fs;
                ephemeralFileSystem.AssertNoOpenFiles();
            }
            finally
            {
                if (!closed)
                {
                    populator.Close(true);
                }
            }
        }
Exemple #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReportAccurateProgressThroughoutThePhases() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReportAccurateProgressThroughoutThePhases()
        {
            // given
            TrappingMonitor monitor = new TrappingMonitor(numberOfBlocks => numberOfBlocks == 1);
            BlockBasedIndexPopulator <GenericKey, NativeIndexValue> populator = InstantiatePopulator(monitor);

            try
            {
                populator.Add(BatchOfUpdates());

                // when starting to merge (in a separate thread)
                Future <object> mergeFuture = T2.execute(command(() => populator.scanCompleted(nullInstance)));
                // and waiting for merge to get going
                monitor.Barrier.awaitUninterruptibly();
                // this is a bit fuzzy, but what we want is to assert that the scan doesn't represent 100% of the work
                assertEquals(0.5f, populator.Progress(Org.Neo4j.Storageengine.Api.schema.PopulationProgress_Fields.Done).Progress, 0.1f);
                monitor.Barrier.release();
                monitor.MergeFinishedBarrier.awaitUninterruptibly();
                assertEquals(0.7f, populator.Progress(Org.Neo4j.Storageengine.Api.schema.PopulationProgress_Fields.Done).Progress, 0.1f);
                monitor.MergeFinishedBarrier.release();
                mergeFuture.get();
                assertEquals(1f, populator.Progress(Org.Neo4j.Storageengine.Api.schema.PopulationProgress_Fields.Done).Progress, 0f);
            }
            finally
            {
                populator.Close(true);
            }
        }
Exemple #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleBeingAbortedWhileMerging() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldHandleBeingAbortedWhileMerging()
        {
            // given
            TrappingMonitor monitor = new TrappingMonitor(numberOfBlocks => numberOfBlocks == 2);
            BlockBasedIndexPopulator <GenericKey, NativeIndexValue> populator = InstantiatePopulator(monitor);
            bool closed = false;

            try
            {
                populator.Add(BatchOfUpdates());

                // when starting to merge (in a separate thread)
                Future <object> mergeFuture = T2.execute(command(() => populator.scanCompleted(nullInstance)));
                // and waiting for merge to get going
                monitor.Barrier.await();
                monitor.Barrier.release();
                monitor.MergeFinishedBarrier.awaitUninterruptibly();
                // calling close here should wait for the merge future, so that checking the merge future for "done" immediately afterwards must say true
                Future <object> closeFuture = T3.execute(command(() => populator.close(false)));
                T3.get().waitUntilWaiting();
                monitor.MergeFinishedBarrier.release();
                closeFuture.get();
                closed = true;

                // then let's make sure scanComplete was cancelled, not throwing exception or anything.
                mergeFuture.get();
            }
            finally
            {
                if (!closed)
                {
                    populator.Close(false);
                }
            }
        }
Exemple #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAwaitMergeToBeFullyAbortedBeforeLeavingCloseMethod() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAwaitMergeToBeFullyAbortedBeforeLeavingCloseMethod()
        {
            // given
            TrappingMonitor monitor = new TrappingMonitor(ignore => false);
            BlockBasedIndexPopulator <GenericKey, NativeIndexValue> populator = InstantiatePopulator(monitor);
            bool closed = false;

            try
            {
                populator.Add(BatchOfUpdates());

                // when starting to merge (in a separate thread)
                Future <object> mergeFuture = T2.execute(command(() => populator.scanCompleted(nullInstance)));
                // and waiting for merge to get going
                monitor.Barrier.awaitUninterruptibly();
                // calling close here should wait for the merge future, so that checking the merge future for "done" immediately afterwards must say true
                Future <object> closeFuture = T3.execute(command(() => populator.close(false)));
                T3.get().waitUntilWaiting();
                monitor.Barrier.release();
                closeFuture.get();
                closed = true;

                // then
                assertTrue(mergeFuture.Done);
            }
            finally
            {
                if (!closed)
                {
                    populator.Close(true);
                }
            }
        }
Exemple #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotThrowOnDuplicationsLaterFixedByExternalUpdates() throws org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotThrowOnDuplicationsLaterFixedByExternalUpdates()
        {
            // given
            BlockBasedIndexPopulator <GenericKey, NativeIndexValue> populator = InstantiatePopulator(_uniqueIndexDescriptor);
            bool closed = false;

            try
            {
                // when
                Value duplicate = Values.of("duplicate");
                Value unique    = Values.of("unique");
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.kernel.api.index.IndexEntryUpdate<?> firstScanUpdate = org.neo4j.kernel.api.index.IndexEntryUpdate.add(1, INDEX_DESCRIPTOR, duplicate);
                IndexEntryUpdate <object> firstScanUpdate = IndexEntryUpdate.add(1, _indexDescriptor, duplicate);
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.kernel.api.index.IndexEntryUpdate<?> secondScanUpdate = org.neo4j.kernel.api.index.IndexEntryUpdate.add(2, INDEX_DESCRIPTOR, duplicate);
                IndexEntryUpdate <object> secondScanUpdate = IndexEntryUpdate.add(2, _indexDescriptor, duplicate);
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.kernel.api.index.IndexEntryUpdate<?> externalUpdate = org.neo4j.kernel.api.index.IndexEntryUpdate.change(1, INDEX_DESCRIPTOR, duplicate, unique);
                IndexEntryUpdate <object> externalUpdate = IndexEntryUpdate.change(1, _indexDescriptor, duplicate, unique);
                populator.Add(singleton(firstScanUpdate));
                using (IndexUpdater updater = populator.NewPopulatingUpdater())
                {
                    updater.Process(externalUpdate);
                }
                populator.Add(singleton(secondScanUpdate));
                populator.ScanCompleted(nullInstance);

                // then
                AssertHasEntry(populator, unique, 1);
                AssertHasEntry(populator, duplicate, 2);
            }
            finally
            {
                if (!closed)
                {
                    populator.Close(true);
                }
            }
        }
Exemple #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldThrowOnDuplicatedValuesFromScan()
        public virtual void ShouldThrowOnDuplicatedValuesFromScan()
        {
            // given
            BlockBasedIndexPopulator <GenericKey, NativeIndexValue> populator = InstantiatePopulator(_uniqueIndexDescriptor);
            bool closed = false;

            try
            {
                // when
                Value duplicate = Values.of("duplicate");
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.kernel.api.index.IndexEntryUpdate<?> firstScanUpdate = org.neo4j.kernel.api.index.IndexEntryUpdate.add(1, INDEX_DESCRIPTOR, duplicate);
                IndexEntryUpdate <object> firstScanUpdate = IndexEntryUpdate.add(1, _indexDescriptor, duplicate);
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.kernel.api.index.IndexEntryUpdate<?> secondScanUpdate = org.neo4j.kernel.api.index.IndexEntryUpdate.add(2, INDEX_DESCRIPTOR, duplicate);
                IndexEntryUpdate <object> secondScanUpdate = IndexEntryUpdate.add(2, _indexDescriptor, duplicate);
                try
                {
                    populator.Add(singleton(firstScanUpdate));
                    populator.Add(singleton(secondScanUpdate));
                    populator.ScanCompleted(nullInstance);

                    fail("Expected to throw");
                }
                catch (IndexEntryConflictException)
                {
                    // then
                }
            }
            finally
            {
                if (!closed)
                {
                    populator.Close(true);
                }
            }
        }
Exemple #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDeallocateAllAllocatedMemoryOnDrop() throws org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldDeallocateAllAllocatedMemoryOnDrop()
        {
            // given
            ThreadSafePeakMemoryAllocationTracker memoryTracker = new ThreadSafePeakMemoryAllocationTracker(new LocalMemoryTracker());
            ByteBufferFactory bufferFactory = new ByteBufferFactory(() => new UnsafeDirectByteBufferAllocator(memoryTracker), 100);
            BlockBasedIndexPopulator <GenericKey, NativeIndexValue> populator = InstantiatePopulator(NO_MONITOR, bufferFactory);
            bool closed = false;

            try
            {
                // when
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.Collection<org.neo4j.kernel.api.index.IndexEntryUpdate<?>> updates = batchOfUpdates();
                ICollection <IndexEntryUpdate <object> > updates = BatchOfUpdates();
                populator.Add(updates);
                int nextId = updates.Count;
                ExternalUpdates(populator, nextId, nextId + 10);
                nextId = nextId + 10;
                long memoryBeforeScanCompleted = memoryTracker.UsedDirectMemory();
                populator.ScanCompleted(nullInstance);
                ExternalUpdates(populator, nextId, nextId + 10);

                // then
                assertTrue("expected some memory to have been temporarily allocated in scanCompleted", memoryTracker.PeakMemoryUsage() > memoryBeforeScanCompleted);
                populator.Drop();
                closed = true;
                assertEquals("expected all allocated memory to have been freed on drop", memoryBeforeScanCompleted, memoryTracker.UsedDirectMemory());

                bufferFactory.Close();
                assertEquals(0, memoryTracker.UsedDirectMemory());
            }
            finally
            {
                if (!closed)
                {
                    populator.Close(true);
                }
            }
        }
Exemple #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDeleteDirectoryOnDrop() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldDeleteDirectoryOnDrop()
        {
            // given
            TrappingMonitor monitor = new TrappingMonitor(ignore => false);
            BlockBasedIndexPopulator <GenericKey, NativeIndexValue> populator = InstantiatePopulator(monitor);
            bool closed = false;

            try
            {
                populator.Add(BatchOfUpdates());

                // when starting to merge (in a separate thread)
                Future <object> mergeFuture = T2.execute(command(() => populator.scanCompleted(nullInstance)));
                // and waiting for merge to get going
                monitor.Barrier.awaitUninterruptibly();
                // calling drop here should wait for the merge future and then delete index directory
                assertTrue(_fs.fileExists(_indexDir));
                assertTrue(_fs.isDirectory(_indexDir));
                assertTrue(_fs.listFiles(_indexDir).Length > 0);

                Future <object> dropFuture = T3.execute(command(populator.drop));
                T3.get().waitUntilWaiting();
                monitor.Barrier.release();
                dropFuture.get();
                closed = true;

                // then
                assertTrue(mergeFuture.Done);
                assertFalse(_fs.fileExists(_indexDir));
            }
            finally
            {
                if (!closed)
                {
                    populator.Close(true);
                }
            }
        }