Example #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(timeout = 5_000) public void shouldAcceptNewJobWhenRunningJobFinishes() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAcceptNewJobWhenRunningJobFinishes()
        {
            // Given
            when(_config.jobLimit()).thenReturn(1);

            JobScheduler jobScheduler = createInitialisedScheduler();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final IndexSamplingJobTracker jobTracker = new IndexSamplingJobTracker(config, jobScheduler);
            IndexSamplingJobTracker jobTracker = new IndexSamplingJobTracker(_config, jobScheduler);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.test.DoubleLatch latch = new org.neo4j.test.DoubleLatch();
            DoubleLatch latch = new DoubleLatch();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicBoolean lastJobExecuted = new java.util.concurrent.atomic.AtomicBoolean();
            AtomicBoolean lastJobExecuted = new AtomicBoolean();

            jobTracker.ScheduleSamplingJob(new IndexSamplingJobAnonymousInnerClass3(this, latch));

            // When
            Executors.newSingleThreadExecutor().execute(() =>
            {
                jobTracker.WaitUntilCanExecuteMoreSamplingJobs();
                jobTracker.ScheduleSamplingJob(new IndexSamplingJobAnonymousInnerClass4(this, latch, lastJobExecuted));
            });

            assertFalse(jobTracker.CanExecuteMoreSamplingJobs());
            latch.StartAndWaitForAllToStart();
            latch.WaitForAllToFinish();

            // Then
            assertTrue(lastJobExecuted.get());
        }
Example #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotRunASampleJobWhichIsAlreadyRunning() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotRunASampleJobWhichIsAlreadyRunning()
        {
            // given
            when(_config.jobLimit()).thenReturn(2);
            JobScheduler            jobScheduler = createInitialisedScheduler();
            IndexSamplingJobTracker jobTracker   = new IndexSamplingJobTracker(_config, jobScheduler);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.test.DoubleLatch latch = new org.neo4j.test.DoubleLatch();
            DoubleLatch latch = new DoubleLatch();

            // when
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicInteger count = new java.util.concurrent.atomic.AtomicInteger(0);
            AtomicInteger count = new AtomicInteger(0);

            assertTrue(jobTracker.CanExecuteMoreSamplingJobs());
            IndexSamplingJob job = new IndexSamplingJobAnonymousInnerClass(this, latch, count);

            jobTracker.ScheduleSamplingJob(job);
            jobTracker.ScheduleSamplingJob(job);

            latch.StartAndWaitForAllToStart();
            latch.WaitForAllToFinish();

            assertEquals(1, count.get());
        }
Example #3
0
 // 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;
 }
Example #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotAcceptMoreJobsThanAllowed() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotAcceptMoreJobsThanAllowed()
        {
            // given
            when(_config.jobLimit()).thenReturn(1);
            JobScheduler jobScheduler = createInitialisedScheduler();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final IndexSamplingJobTracker jobTracker = new IndexSamplingJobTracker(config, jobScheduler);
            IndexSamplingJobTracker jobTracker = new IndexSamplingJobTracker(_config, jobScheduler);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.test.DoubleLatch latch = new org.neo4j.test.DoubleLatch();
            DoubleLatch latch = new DoubleLatch();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.test.DoubleLatch waitingLatch = new org.neo4j.test.DoubleLatch();
            DoubleLatch waitingLatch = new DoubleLatch();

            // when
            assertTrue(jobTracker.CanExecuteMoreSamplingJobs());

            jobTracker.ScheduleSamplingJob(new IndexSamplingJobAnonymousInnerClass2(this, latch));

            // then
            latch.WaitForAllToStart();

            assertFalse(jobTracker.CanExecuteMoreSamplingJobs());

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicBoolean waiting = new java.util.concurrent.atomic.AtomicBoolean(false);
            AtomicBoolean waiting = new AtomicBoolean(false);

            (new Thread(() =>
            {
                waiting.set(true);
                waitingLatch.StartAndWaitForAllToStart();
                jobTracker.WaitUntilCanExecuteMoreSamplingJobs();
                waiting.set(false);
                waitingLatch.Finish();
            })).Start();

            waitingLatch.WaitForAllToStart();

            assertTrue(waiting.get());

            latch.Finish();

            waitingLatch.WaitForAllToFinish();

            assertFalse(waiting.get());

            // eventually we accept new jobs
            while (!jobTracker.CanExecuteMoreSamplingJobs())
            {
                Thread.yield();
            }
        }
Example #5
0
        public virtual IndexSamplingController Create(IndexMapSnapshotProvider snapshotProvider)
        {
            OnlineIndexSamplingJobFactory jobFactory = new OnlineIndexSamplingJobFactory(_storeView, _tokenNameLookup, _logProvider);

            System.Predicate <long>      samplingUpdatePredicate = CreateSamplingPredicate();
            IndexSamplingJobQueue <long> jobQueue   = new IndexSamplingJobQueue <long>(samplingUpdatePredicate);
            IndexSamplingJobTracker      jobTracker = new IndexSamplingJobTracker(_config, _scheduler);

            IndexSamplingController.RecoveryCondition indexRecoveryCondition = CreateIndexRecoveryCondition(_logProvider, _tokenNameLookup);
            return(new IndexSamplingController(_config, jobFactory, jobQueue, jobTracker, snapshotProvider, _scheduler, indexRecoveryCondition));
        }
Example #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(timeout = 5_000) public void shouldNotAllowNewJobsAfterBeingStopped()
        public virtual void ShouldNotAllowNewJobsAfterBeingStopped()
        {
            // Given
            IndexSamplingJobTracker jobTracker = new IndexSamplingJobTracker(_config, mock(typeof(JobScheduler)));

            // When
            jobTracker.StopAndAwaitAllJobs();

            // Then
            assertFalse(jobTracker.CanExecuteMoreSamplingJobs());
        }
Example #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(timeout = 5_000) public void shouldWaitForAllJobsToFinish() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldWaitForAllJobsToFinish()
        {
            // Given
            when(_config.jobLimit()).thenReturn(2);

            JobScheduler jobScheduler = createInitialisedScheduler();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final IndexSamplingJobTracker jobTracker = new IndexSamplingJobTracker(config, jobScheduler);
            IndexSamplingJobTracker jobTracker = new IndexSamplingJobTracker(_config, jobScheduler);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.CountDownLatch latch1 = new java.util.concurrent.CountDownLatch(1);
            System.Threading.CountdownEvent latch1 = new System.Threading.CountdownEvent(1);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.CountDownLatch latch2 = new java.util.concurrent.CountDownLatch(1);
            System.Threading.CountdownEvent latch2 = new System.Threading.CountdownEvent(1);

            WaitingIndexSamplingJob job1 = new WaitingIndexSamplingJob(IndexId11, latch1);
            WaitingIndexSamplingJob job2 = new WaitingIndexSamplingJob(IndexId22, latch1);

            jobTracker.ScheduleSamplingJob(job1);
            jobTracker.ScheduleSamplingJob(job2);

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.concurrent.Future<?> stopping = java.util.concurrent.Executors.newSingleThreadExecutor().submit(() ->
            Future <object> stopping = Executors.newSingleThreadExecutor().submit(() =>
            {
                latch2.Signal();
                try
                {
                    jobTracker.AwaitAllJobs(10, TimeUnit.SECONDS);
                }
                catch (InterruptedException e)
                {
                    throw new Exception(e);
                }
            });

            // When
            latch2.await();
            assertFalse(stopping.Done);
            latch1.Signal();
            stopping.get(10, SECONDS);

            // Then
            assertTrue(stopping.Done);
            assertNull(stopping.get());
            assertTrue(job1.Executed);
            assertTrue(job2.Executed);
        }
Example #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(timeout = 5_000) public void shouldDoNothingWhenUsedAfterBeingStopped()
        public virtual void ShouldDoNothingWhenUsedAfterBeingStopped()
        {
            // Given
            JobScheduler            scheduler  = mock(typeof(JobScheduler));
            IndexSamplingJobTracker jobTracker = new IndexSamplingJobTracker(_config, scheduler);

            jobTracker.StopAndAwaitAllJobs();

            // When
            jobTracker.ScheduleSamplingJob(mock(typeof(IndexSamplingJob)));

            // Then
            verifyZeroInteractions(scheduler);
        }