Example #1
0
//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();
        }
Example #2
0
//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);
                }
Example #3
0
//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());
        }