//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test(timeout = 10_000) public void scheduledTasksThatThrowsMustPropagateException() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ScheduledTasksThatThrowsMustPropagateException() { CentralJobScheduler scheduler = new CentralJobScheduler(); scheduler.Init(); Exception boom = new Exception("boom"); AtomicInteger triggerCounter = new AtomicInteger(); ThreadStart job = () => { triggerCounter.incrementAndGet(); throw boom; }; JobHandle handle = scheduler.ScheduleRecurring(Group.INDEX_POPULATION, job, 1, TimeUnit.MILLISECONDS); try { handle.WaitTermination(); fail("waitTermination should have failed."); } catch (ExecutionException e) { assertThat(e.InnerException, @is(boom)); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotifyCancelListeners() public virtual void ShouldNotifyCancelListeners() { // GIVEN CentralJobScheduler centralJobScheduler = new CentralJobScheduler(); centralJobScheduler.Init(); // WHEN AtomicBoolean halted = new AtomicBoolean(); ThreadStart job = () => { while (!halted.get()) { LockSupport.parkNanos(MILLISECONDS.toNanos(10)); } }; JobHandle handle = centralJobScheduler.Schedule(Group.INDEX_POPULATION, job); handle.RegisterCancelListener(mayBeInterrupted => halted.set(true)); handle.Cancel(false); // THEN assertTrue(halted.get()); centralJobScheduler.Shutdown(); }
public static JobScheduler CreateInitialisedScheduler() { CentralJobScheduler scheduler = CreateCentralScheduler(); scheduler.Init(); return(scheduler); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test(timeout = 10_000) public void shutDownMustKillCancelledJobs() public virtual void ShutDownMustKillCancelledJobs() { CentralJobScheduler scheduler = new CentralJobScheduler(); scheduler.Init(); BinaryLatch startLatch = new BinaryLatch(); BinaryLatch stopLatch = new BinaryLatch(); scheduler.Schedule(Group.INDEX_POPULATION, () => { try { startLatch.Release(); Thread.Sleep(100_000); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test(timeout = 10_000) public void waitTerminationOnDelayedJobMustWaitUntilJobCompletion() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void WaitTerminationOnDelayedJobMustWaitUntilJobCompletion() { CentralJobScheduler scheduler = new CentralJobScheduler(); scheduler.Init(); AtomicBoolean triggered = new AtomicBoolean(); ThreadStart job = () => { LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(10)); triggered.set(true); }; JobHandle handle = scheduler.Schedule(Group.INDEX_POPULATION, job, 10, TimeUnit.MILLISECONDS); handle.WaitTermination(); assertTrue(triggered.get()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test(timeout = 10_000) public void scheduledTasksThatThrowsShouldStop() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ScheduledTasksThatThrowsShouldStop() { CentralJobScheduler scheduler = new CentralJobScheduler(); scheduler.Init(); BinaryLatch triggerLatch = new BinaryLatch(); Exception boom = new Exception("boom"); AtomicInteger triggerCounter = new AtomicInteger(); ThreadStart job = () => { triggerCounter.incrementAndGet(); triggerLatch.Release(); throw boom; }; scheduler.ScheduleRecurring(Group.INDEX_POPULATION, job, 1, TimeUnit.MILLISECONDS); triggerLatch.Await(); Thread.Sleep(50); assertThat(triggerCounter.get(), @is(1)); }