Example #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void recurringJobWithExceptionShouldKeepRunning() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void RecurringJobWithExceptionShouldKeepRunning()
        {
            // given
            RobustJobSchedulerWrapper robustWrapper = new RobustJobSchedulerWrapper(_actualScheduler, _log);

            AtomicInteger count = new AtomicInteger();

            System.InvalidOperationException e = new System.InvalidOperationException();

            // when
            int       nRuns     = 100;
            JobHandle jobHandle = robustWrapper.ScheduleRecurring(Group.HZ_TOPOLOGY_REFRESH, 1, () =>
            {
                if (count.get() < nRuns)
                {
                    count.incrementAndGet();
                    throw e;
                }
            });

            // then
            assertEventually("run count", count.get, Matchers.equalTo(nRuns), _defaultTimeoutMs, MILLISECONDS);
            jobHandle.Cancel(true);
            verify(_log, timeout(_defaultTimeoutMs).times(nRuns)).warn("Uncaught exception", e);
        }
Example #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void oneOffJobWithExceptionShouldLog() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void OneOffJobWithExceptionShouldLog()
        {
            // given
            Log log = mock(typeof(Log));
            RobustJobSchedulerWrapper robustWrapper = new RobustJobSchedulerWrapper(_actualScheduler, log);

            AtomicInteger count = new AtomicInteger();

            System.InvalidOperationException e = new System.InvalidOperationException();

            // when
            JobHandle jobHandle = robustWrapper.Schedule(Group.HZ_TOPOLOGY_HEALTH, 100, () =>
            {
                count.incrementAndGet();
                throw e;
            });

            // then
            assertEventually("run count", count.get, Matchers.equalTo(1), _defaultTimeoutMs, MILLISECONDS);
            jobHandle.WaitTermination();
            verify(log, timeout(_defaultTimeoutMs).times(1)).warn("Uncaught exception", e);
        }
Example #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void recurringJobWithErrorShouldStop() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void RecurringJobWithErrorShouldStop()
        {
            // given
            RobustJobSchedulerWrapper robustWrapper = new RobustJobSchedulerWrapper(_actualScheduler, _log);

            AtomicInteger count = new AtomicInteger();
            Exception     e     = new Exception();

            // when
            JobHandle jobHandle = robustWrapper.ScheduleRecurring(Group.HZ_TOPOLOGY_REFRESH, 1, () =>
            {
                count.incrementAndGet();
                throw e;
            });

            // when
            Thread.Sleep(50);                 // should not keep increasing during this time

            // then
            assertEventually("run count", count.get, Matchers.equalTo(1), _defaultTimeoutMs, MILLISECONDS);
            jobHandle.Cancel(true);
            verify(_log, timeout(_defaultTimeoutMs).times(1)).error("Uncaught error rethrown", e);
        }