//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()); }
// use IndexSamplingControllerFactory.create do not instantiate directly internal IndexSamplingController(IndexSamplingConfig config, IndexSamplingJobFactory jobFactory, IndexSamplingJobQueue <long> jobQueue, IndexSamplingJobTracker jobTracker, IndexMapSnapshotProvider indexMapSnapshotProvider, JobScheduler scheduler, RecoveryCondition indexRecoveryCondition) { this._backgroundSampling = config.BackgroundSampling(); this._jobFactory = jobFactory; this._indexMapSnapshotProvider = indexMapSnapshotProvider; this._jobQueue = jobQueue; this._jobTracker = jobTracker; this._scheduler = scheduler; this._indexRecoveryCondition = indexRecoveryCondition; }