public void RunFailsIfTaskErrorsButContinueOnFailure()
        {
            var buildInfo = mocks.Create <BuildProgressInformation>(string.Empty, string.Empty).Object;
            var result    = mocks.Create <IIntegrationResult>().Object;

            Mock.Get(result).SetupAllProperties();
            result.Status = IntegrationStatus.Success;
            Mock.Get(result).Setup(_result => _result.Clone()).Returns(result);
            Mock.Get(result).SetupGet(_result => _result.BuildProgressInformation).Returns(buildInfo);
            var logger     = mocks.Create <ILogger>().Object;
            var childTask1 = new SleepingTask {
                SleepPeriod = 10, Result = IntegrationStatus.Success
            };
            var childTask2 = new FailingTask();
            var childTask3 = new SleepingTask {
                SleepPeriod = 10, Result = IntegrationStatus.Success
            };
            var task = new SynchronisationTask
            {
                Logger = logger,
                Tasks  = new ITask[] {
                    childTask1,
                    childTask2,
                    childTask3
                },
                ContinueOnFailure = true
            };

            task.Run(result);
            this.mocks.VerifyAll();

            Assert.AreEqual(IntegrationStatus.Failure, result.Status);
            Assert.IsNotNull(result.ExceptionResult);
            Assert.AreEqual("Task failed!", result.ExceptionResult.Message);
        }
        public void RunFailsIfTaskErrors()
        {
            var buildInfo = mocks.DynamicMock <BuildProgressInformation>(string.Empty, string.Empty);
            var result    = mocks.Stub <IIntegrationResult>();

            result.Status = IntegrationStatus.Success;
            SetupResult.For(result.Clone()).Return(result);
            SetupResult.For(result.BuildProgressInformation).Return(buildInfo);
            var logger     = mocks.DynamicMock <ILogger>();
            var childTask1 = new SleepingTask {
                SleepPeriod = 10, Result = IntegrationStatus.Success
            };
            var childTask2 = new FailingTask();
            var task       = new SynchronisationTask
            {
                Logger = logger,
                Tasks  = new ITask[] {
                    childTask1,
                    childTask2
                }
            };

            this.mocks.ReplayAll();
            task.Run(result);
            this.mocks.VerifyAll();

            Assert.AreEqual(IntegrationStatus.Failure, result.Status);
            Assert.IsNotNull(result.ExceptionResult);
            Assert.AreEqual("Task failed!", result.ExceptionResult.Message);
        }
Beispiel #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSurfaceTaskErrorInAssertHealthy() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSurfaceTaskErrorInAssertHealthy()
        {
            // GIVEN
            TaskExecutor <Void> executor  = new DynamicTaskExecutor <Void>(2, 0, 10, _park, this.GetType().Name);
            IOException         exception = new IOException("Failure");

            // WHEN
            FailingTask failingTask = new FailingTask(exception);

            executor.Submit(failingTask);
            failingTask.Latch.await();
            failingTask.Latch.release();

            // WHEN
            for (int i = 0; i < 5; i++)
            {
                try
                {
                    executor.AssertHealthy();
                    // OK, so the executor hasn't executed the finally block after task was done yet
                    Thread.Sleep(100);
                }
                catch (Exception e)
                {
                    assertTrue(Exceptions.contains(e, exception.Message, exception.GetType()));
                    return;
                }
            }
            fail("Should not be considered healthy after failing task");
        }
Beispiel #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldShutDownOnTaskFailureEvenIfOtherTasksArePending() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldShutDownOnTaskFailureEvenIfOtherTasksArePending()
        {
            // GIVEN
            TaskExecutor <Void> executor           = new DynamicTaskExecutor <Void>(2, 0, 10, _park, this.GetType().Name);
            IOException         exception          = new IOException("Test message");
            ControlledTask      firstBlockingTask  = new ControlledTask();
            ControlledTask      secondBlockingTask = new ControlledTask();

            executor.Submit(firstBlockingTask);
            executor.Submit(secondBlockingTask);
            firstBlockingTask.Latch.waitForAllToStart();
            secondBlockingTask.Latch.waitForAllToStart();

            FailingTask failingTask = new FailingTask(exception);

            executor.Submit(failingTask);

            ControlledTask thirdBlockingTask = new ControlledTask();

            executor.Submit(thirdBlockingTask);

            // WHEN
            firstBlockingTask.Latch.finish();
            failingTask.Latch.await();
            failingTask.Latch.release();

            // THEN
            AssertExceptionOnSubmit(executor, exception);
            executor.Close();               // call would block if the shutdown as part of failure doesn't complete properly

            secondBlockingTask.Latch.finish();
        }
Beispiel #5
0
    public void InitializeAndFailASingleTask()
    {
        UITaskSystem system = new UITaskSystem();
        FailingTask  task   = new FailingTask();

        system.AddTask(task);
        Assert.AreEqual(null, task.status);

        system.OnUpdate();
        Assert.AreEqual("fail", task.status);
        Assert.AreEqual(1, task.runCount);

        Assert.AreEqual(0, system.ActiveTaskCount);
    }
Beispiel #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldShutDownOnTaskFailure() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldShutDownOnTaskFailure()
        {
            // GIVEN
            TaskExecutor <Void> executor = new DynamicTaskExecutor <Void>(30, 0, 5, _park, this.GetType().Name);

            // WHEN
            IOException exception = new IOException("Test message");
            FailingTask task      = new FailingTask(exception);

            executor.Submit(task);
            task.Latch.await();
            task.Latch.release();

            // THEN
            AssertExceptionOnSubmit(executor, exception);
        }
Beispiel #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldLetShutdownCompleteInEventOfPanic() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldLetShutdownCompleteInEventOfPanic()
        {
            // GIVEN
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final TaskExecutor<Void> executor = new DynamicTaskExecutor<>(2, 0, 10, PARK, getClass().getSimpleName());
            TaskExecutor <Void> executor  = new DynamicTaskExecutor <Void>(2, 0, 10, _park, this.GetType().Name);
            IOException         exception = new IOException("Failure");

            // WHEN
            FailingTask failingTask = new FailingTask(exception);

            executor.Submit(failingTask);
            failingTask.Latch.await();

            // WHEN
            using (OtherThreadExecutor <Void> closer = new OtherThreadExecutor <Void>("closer", null))
            {
                Future <Void> shutdown = closer.ExecuteDontWait(state =>
                {
                    executor.Close();
                    return(null);
                });
                while (!closer.WaitUntilWaiting().isAt(typeof(DynamicTaskExecutor), "close"))
                {
                    Thread.Sleep(10);
                }

                // Here we've got a shutdown call stuck awaiting queue to be empty (since true was passed in)
                // at the same time we've got a FailingTask ready to throw its exception and another task
                // sitting in the queue after it. Now make the task throw that exception.
                failingTask.Latch.release();

                // Some time after throwing this, the shutdown request should have been completed.
                shutdown.get();
            }
        }
        public void RunFailsIfTaskErrors()
        {
            var buildInfo = mocks.DynamicMock<BuildProgressInformation>(string.Empty, string.Empty);
            var result = mocks.Stub<IIntegrationResult>();
            result.Status = IntegrationStatus.Success;
            SetupResult.For(result.Clone()).Return(result);
            SetupResult.For(result.BuildProgressInformation).Return(buildInfo);
            var logger = mocks.DynamicMock<ILogger>();
            var childTask1 = new SleepingTask { SleepPeriod = 10, Result = IntegrationStatus.Success };
            var childTask2 = new FailingTask();
            var task = new SynchronisationTask
            {
                Logger = logger,
                Tasks = new ITask[] {
                    childTask1,
                    childTask2
                }
            };

            this.mocks.ReplayAll();
            task.Run(result);
            this.mocks.VerifyAll();

            Assert.AreEqual(IntegrationStatus.Failure, result.Status);
            Assert.IsNotNull(result.ExceptionResult);
            Assert.AreEqual("Task failed!", result.ExceptionResult.Message);
        }
 private string CreateFailingTask()
 {
     var task = new FailingTask();
     return _taskManager.Save(task);
 }