예제 #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());
        }
예제 #2
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();
            }
        }