예제 #1
0
 private void NotifyIfPopulationCompleted(UpdatesTracker updatesTracker)
 {
     if (IsCompletedPopulation(updatesTracker))
     {
         NotifyPopulationCompleted(updatesTracker);
     }
 }
예제 #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private UpdatesTracker internalExecuteCreationsDeletionsAndUpdates(long[] nodes, int numberOfCreations, boolean allowDeletions, boolean allowUpdates) throws org.neo4j.internal.kernel.api.exceptions.KernelException, InterruptedException
        private UpdatesTracker InternalExecuteCreationsDeletionsAndUpdates(long[] nodes, int numberOfCreations, bool allowDeletions, bool allowUpdates)
        {
            if (Random.nextBoolean())
            {
                // 50% of time await the start signal so that updater(s) race as much as possible with the populator.
                _indexOnlineMonitor.startSignal.await();
            }
            Random         random         = ThreadLocalRandom.current();
            UpdatesTracker updatesTracker = new UpdatesTracker();
            int            offset         = 0;

            while (updatesTracker.Created() < numberOfCreations)
            {
                int created = CreateNamedPeople(nodes, offset);
                offset += created;
                updatesTracker.IncreaseCreated(created);
                NotifyIfPopulationCompleted(updatesTracker);

                // delete if allowed
                if (allowDeletions && updatesTracker.Created() % 24 == 0)
                {
                    long nodeId = nodes[random.Next(nodes.Length)];
                    try
                    {
                        DeleteNode(nodeId);
                        updatesTracker.IncreaseDeleted(1);
                    }
                    catch (NotFoundException)
                    {
                        // ignore
                    }
                    NotifyIfPopulationCompleted(updatesTracker);
                }

                // update if allowed
                if (allowUpdates && updatesTracker.Created() % 24 == 0)
                {
                    int randomIndex = random.Next(nodes.Length);
                    try
                    {
                        if (ChangeName(nodes[randomIndex], _names[random.Next(_names.Length)]))
                        {
                            updatesTracker.IncreaseUpdated(1);
                        }
                    }
                    catch (NotFoundException)
                    {
                        // ignore
                    }
                    NotifyIfPopulationCompleted(updatesTracker);
                }
            }
            // make sure population complete has been notified
            NotifyPopulationCompleted(updatesTracker);
            return(updatesTracker);
        }
예제 #3
0
 public virtual void Add(UpdatesTracker updatesTracker)
 {
     Debug.Assert(PopulationCompleted);
     Debug.Assert(updatesTracker.PopulationCompleted);
     this._created += updatesTracker._created;
     this._deleted += updatesTracker._deleted;
     this._updated += updatesTracker._updated;
     this._createdDuringPopulation += updatesTracker._createdDuringPopulation;
     this._updatedDuringPopulation += updatesTracker._updatedDuringPopulation;
     this._deletedDuringPopulation += updatesTracker._deletedDuringPopulation;
 }
예제 #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldWorkWhileHavingHeavyConcurrentUpdates() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldWorkWhileHavingHeavyConcurrentUpdates()
        {
            // given some initial data
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long[] nodes = repeatCreateNamedPeopleFor(NAMES.length * CREATION_MULTIPLIER);
            long[] nodes        = RepeatCreateNamedPeopleFor(_names.Length * _creationMultiplier);
            int    initialNodes = nodes.Length;
            int    threads      = 5;

            _indexOnlineMonitor.initialize(threads);
            ExecutorService executorService = Executors.newFixedThreadPool(threads);

            // when populating while creating
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.internal.kernel.api.IndexReference index = createPersonNameIndex();
            IndexReference index = CreatePersonNameIndex();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.Collection<java.util.concurrent.Callable<UpdatesTracker>> jobs = new java.util.ArrayList<>(threads);
            ICollection <Callable <UpdatesTracker> > jobs = new List <Callable <UpdatesTracker> >(threads);

            for (int i = 0; i < threads; i++)
            {
                jobs.Add(() => ExecuteCreationsDeletionsAndUpdates(nodes, _creationMultiplier));
            }

            IList <Future <UpdatesTracker> > futures = executorService.invokeAll(jobs);
            // sum result into empty result
            UpdatesTracker result = new UpdatesTracker();

            result.NotifyPopulationCompleted();
            foreach (Future <UpdatesTracker> future in futures)
            {
                result.Add(future.get());
            }
            AwaitIndexesOnline();

            executorService.shutdown();
            assertTrue(executorService.awaitTermination(1, TimeUnit.MINUTES));

            // then
            AssertIndexedNodesMatchesStoreNodes();
            int    seenWhilePopulating = initialNodes + result.CreatedDuringPopulation() - result.DeletedDuringPopulation();
            double expectedSelectivity = UNIQUE_NAMES / seenWhilePopulating;

            AssertCorrectIndexSelectivity(expectedSelectivity, IndexSelectivity(index));
            AssertCorrectIndexSize("Tracker had " + result, seenWhilePopulating, IndexSize(index));
            int expectedIndexUpdates = result.DeletedAfterPopulation() + result.CreatedAfterPopulation() + result.UpdatedAfterPopulation();

            AssertCorrectIndexUpdates("Tracker had " + result, expectedIndexUpdates, IndexUpdates(index));
        }
예제 #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldProvideIndexStatisticsWhenIndexIsBuiltViaPopulationAndConcurrentAdditions() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldProvideIndexStatisticsWhenIndexIsBuiltViaPopulationAndConcurrentAdditions()
        {
            // given some initial data
            _indexOnlineMonitor.initialize(1);
            int initialNodes = RepeatCreateNamedPeopleFor(_names.Length * _creationMultiplier).Length;

            // when populating while creating
            IndexReference index = CreatePersonNameIndex();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final UpdatesTracker updatesTracker = executeCreations(CREATION_MULTIPLIER);
            UpdatesTracker updatesTracker = ExecuteCreations(_creationMultiplier);

            AwaitIndexesOnline();

            // then
            int    seenWhilePopulating = initialNodes + updatesTracker.CreatedDuringPopulation();
            double expectedSelectivity = UNIQUE_NAMES / seenWhilePopulating;

            AssertCorrectIndexSelectivity(expectedSelectivity, IndexSelectivity(index));
            AssertCorrectIndexSize(seenWhilePopulating, IndexSize(index));
            AssertCorrectIndexUpdates(updatesTracker.CreatedAfterPopulation(), IndexUpdates(index));
        }
예제 #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldProvideIndexStatisticsWhenIndexIsBuiltViaPopulationAndConcurrentAdditionsAndChangesAndDeletions() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldProvideIndexStatisticsWhenIndexIsBuiltViaPopulationAndConcurrentAdditionsAndChangesAndDeletions()
        {
            // given some initial data
            _indexOnlineMonitor.initialize(1);
            long[] nodes        = RepeatCreateNamedPeopleFor(_names.Length * _creationMultiplier);
            int    initialNodes = nodes.Length;

            // when populating while creating
            IndexReference index          = CreatePersonNameIndex();
            UpdatesTracker updatesTracker = ExecuteCreationsDeletionsAndUpdates(nodes, _creationMultiplier);

            AwaitIndexesOnline();

            // then
            AssertIndexedNodesMatchesStoreNodes();
            int    seenWhilePopulating  = initialNodes + updatesTracker.CreatedDuringPopulation() - updatesTracker.DeletedDuringPopulation();
            double expectedSelectivity  = UNIQUE_NAMES / seenWhilePopulating;
            int    expectedIndexUpdates = updatesTracker.DeletedAfterPopulation() + updatesTracker.CreatedAfterPopulation() + updatesTracker.UpdatedAfterPopulation();

            AssertCorrectIndexSelectivity(expectedSelectivity, IndexSelectivity(index));
            AssertCorrectIndexSize(seenWhilePopulating, IndexSize(index));
            AssertCorrectIndexUpdates(expectedIndexUpdates, IndexUpdates(index));
        }
예제 #7
0
 private bool IsCompletedPopulation(UpdatesTracker updatesTracker)
 {
     return(!updatesTracker.PopulationCompleted && _indexOnlineMonitor.IndexOnline);
 }
예제 #8
0
 private void NotifyPopulationCompleted(UpdatesTracker updatesTracker)
 {
     _indexOnlineMonitor.updatesDone();
     updatesTracker.NotifyPopulationCompleted();
 }