//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotStartOtherSamplingWhenSamplingAllTheIndexes()
        public virtual void ShouldNotStartOtherSamplingWhenSamplingAllTheIndexes()
        {
            // given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicInteger totalCount = new java.util.concurrent.atomic.AtomicInteger(0);
            AtomicInteger totalCount = new AtomicInteger(0);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicInteger concurrentCount = new java.util.concurrent.atomic.AtomicInteger(0);
            AtomicInteger concurrentCount = new AtomicInteger(0);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.test.DoubleLatch jobLatch = new org.neo4j.test.DoubleLatch();
            DoubleLatch jobLatch = new DoubleLatch();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.test.DoubleLatch testLatch = new org.neo4j.test.DoubleLatch();
            DoubleLatch testLatch = new DoubleLatch();

            IndexSamplingJobFactory jobFactory = (_indexId, proxy) =>
            {
                if (!concurrentCount.compareAndSet(0, 1))
                {
                    throw new System.InvalidOperationException("count !== 0 on create");
                }
                totalCount.incrementAndGet();
                jobLatch.WaitForAllToStart();
                testLatch.StartAndWaitForAllToStart();
                jobLatch.WaitForAllToFinish();
                concurrentCount.decrementAndGet();
                testLatch.Finish();
                return(null);
            };

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final IndexSamplingController controller = new IndexSamplingController(samplingConfig, jobFactory, jobQueue, tracker, snapshotProvider, scheduler, always(true));
            IndexSamplingController controller = new IndexSamplingController(_samplingConfig, jobFactory, _jobQueue, _tracker, _snapshotProvider, _scheduler, Always(true));

            when(_tracker.canExecuteMoreSamplingJobs()).thenReturn(true);
            when(_indexProxy.State).thenReturn(ONLINE);

            // when running once
            (new Thread(RunController(controller, TRIGGER_REBUILD_UPDATED))).Start();

            jobLatch.StartAndWaitForAllToStart();
            testLatch.WaitForAllToStart();

            // then blocking on first job
            assertEquals(1, concurrentCount.get());

            // when running a second time
            controller.SampleIndexes(BACKGROUND_REBUILD_UPDATED);

            // then no concurrent job execution
            jobLatch.Finish();
            testLatch.WaitForAllToFinish();

            // and finally exactly one job has run to completion
            assertEquals(0, concurrentCount.get());
            assertEquals(1, totalCount.get());
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotRecoverOnlineIndexIfNotNeeded()
        public virtual void ShouldNotRecoverOnlineIndexIfNotNeeded()
        {
            // given
            IndexSamplingController controller = NewSamplingController(Always(false));

            when(_indexProxy.State).thenReturn(ONLINE);

            // when
            controller.RecoverIndexSamples();

            // then
            verifyNoMoreInteractions(_jobFactory, _job, _tracker);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotRecoverOfflineIndex()
        public virtual void ShouldNotRecoverOfflineIndex()
        {
            // given
            IndexSamplingController controller = NewSamplingController(Always(true));

            when(_indexProxy.State).thenReturn(FAILED);

            // when
            controller.RecoverIndexSamples();

            // then
            verifyNoMoreInteractions(_jobFactory, _job, _tracker);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotStartForSingleIndexAJobIfTheTrackerCannotHandleIt()
        public virtual void ShouldNotStartForSingleIndexAJobIfTheTrackerCannotHandleIt()
        {
            // given
            IndexSamplingController controller = NewSamplingController(Always(false));

            when(_tracker.canExecuteMoreSamplingJobs()).thenReturn(false);
            when(_indexProxy.State).thenReturn(ONLINE);

            // when
            controller.SampleIndex(_indexId, BACKGROUND_REBUILD_UPDATED);

            // then
            verify(_tracker, times(1)).canExecuteMoreSamplingJobs();
            verifyNoMoreInteractions(_jobFactory, _tracker);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRecoverOnlineIndex()
        public virtual void ShouldRecoverOnlineIndex()
        {
            // given
            IndexSamplingController controller = NewSamplingController(Always(true));

            when(_indexProxy.State).thenReturn(ONLINE);

            // when
            controller.RecoverIndexSamples();

            // then
            verify(_jobFactory).create(_indexId, _indexProxy);
            verify(_job).run();
            verifyNoMoreInteractions(_jobFactory, _job, _tracker);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotStartAJobIfTheIndexIsNotOnline()
        public virtual void ShouldNotStartAJobIfTheIndexIsNotOnline()
        {
            // given
            IndexSamplingController controller = NewSamplingController(Always(false));

            when(_tracker.canExecuteMoreSamplingJobs()).thenReturn(true);
            when(_indexProxy.State).thenReturn(POPULATING);

            // when
            controller.SampleIndexes(BACKGROUND_REBUILD_UPDATED);

            // then
            verify(_tracker, times(2)).canExecuteMoreSamplingJobs();
            verifyNoMoreInteractions(_jobFactory, _tracker);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldStartASamplingJobForEachIndexInTheDB()
        public virtual void ShouldStartASamplingJobForEachIndexInTheDB()
        {
            // given
            IndexSamplingController controller = NewSamplingController(Always(false));

            when(_tracker.canExecuteMoreSamplingJobs()).thenReturn(true);
            when(_indexProxy.State).thenReturn(ONLINE);

            // when
            controller.SampleIndexes(BACKGROUND_REBUILD_UPDATED);

            // then
            verify(_jobFactory).create(_indexId, _indexProxy);
            verify(_tracker).scheduleSamplingJob(_job);
            verify(_tracker, times(2)).canExecuteMoreSamplingJobs();
            verifyNoMoreInteractions(_jobFactory, _tracker);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSampleAllTheOnlineIndexes()
        public virtual void ShouldSampleAllTheOnlineIndexes()
        {
            // given
            IndexSamplingController controller = NewSamplingController(Always(false));

            when(_tracker.canExecuteMoreSamplingJobs()).thenReturn(true);
            when(_indexProxy.State).thenReturn(ONLINE);
            when(_anotherIndexProxy.State).thenReturn(POPULATING);
            _indexMap.putIndexProxy(_anotherIndexProxy);

            // when
            controller.SampleIndexes(TRIGGER_REBUILD_UPDATED);

            // then
            verify(_jobFactory).create(_indexId, _indexProxy);
            verify(_tracker).scheduleSamplingJob(_job);

            verify(_tracker, times(2)).waitUntilCanExecuteMoreSamplingJobs();
            verifyNoMoreInteractions(_jobFactory, _tracker);
        }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: private Runnable runController(final IndexSamplingController controller, final IndexSamplingMode mode)
        private ThreadStart RunController(IndexSamplingController controller, IndexSamplingMode mode)
        {
            return(() => controller.sampleIndexes(mode));
        }