public void Test_CanUpdateFromExecutionResult_Successful()
        {
            Faker          faker = new Faker();
            DateTimeOffset now   = DateTimeOffset
                                   .UtcNow;

            Faker <QueuedTask> taskFaker =
                GetQueuedTaskFaker();

            QueuedTask task = taskFaker
                              .Generate();

            QueuedTaskResult result = new QueuedTaskResult(task);

            TaskExecutionResult successful = new TaskExecutionResult(TaskExecutionResultInfo.Successful(),
                                                                     duration: faker.Date.Timespan(),
                                                                     retryAt: faker.Date.FutureOffset(),
                                                                     faultErrorThresholdCount: faker.Random.Int(1, 5));

            QueuedTaskInfo repostWithInfo = result.UdpateFromExecutionResult(successful);

            Assert.Null(repostWithInfo);
            Assert.IsNull(result.LastError);
            Assert.AreEqual(QueuedTaskStatus.Processed, result.Status);
            Assert.AreEqual(successful.ProcessingTimeMilliseconds, result.ProcessingTimeMilliseconds);
            Assert.GreaterOrEqual(result.ProcessingFinalizedAtTs, now);
            Assert.GreaterOrEqual(result.FirstProcessingAttemptedAtTs, now);
            Assert.GreaterOrEqual(result.LastProcessingAttemptedAtTs, now);
        }
        public void Test_CanUpdateFromExecutionResult_WithError_NotRecoverable(int faultErrorThresholdCount)
        {
            Faker          faker = new Faker();
            DateTimeOffset now   = DateTimeOffset
                                   .UtcNow;

            Faker <QueuedTask> taskFaker =
                GetQueuedTaskFaker();

            QueuedTask task = taskFaker
                              .Generate();

            QueuedTaskResult result = new QueuedTaskResult(task);

            TaskExecutionResultInfo failedWithErrorInfo = TaskExecutionResultInfo
                                                          .ExecutedWithError(new QueuedTaskError(faker.System.Exception()),
                                                                             isRecoverable: false);

            TaskExecutionResult failedWithError = new TaskExecutionResult(failedWithErrorInfo,
                                                                          duration: faker.Date.Timespan(),
                                                                          retryAt: faker.Date.FutureOffset(),
                                                                          faultErrorThresholdCount: faultErrorThresholdCount);

            for (int i = 1; i <= faultErrorThresholdCount + 2; i++)
            {
                if (i > 1)
                {
                    Assert.Throws <InvalidOperationException>(() => result.UdpateFromExecutionResult(failedWithError));
                }
                else
                {
                    Assert.IsNull(result.UdpateFromExecutionResult(failedWithError));
                }

                Assert.AreEqual(1, result.ErrorCount);
                Assert.AreEqual(failedWithErrorInfo.Error, result.LastError);
                Assert.IsFalse(result.LastErrorIsRecoverable);
                Assert.AreEqual(QueuedTaskStatus.Fatal, result.Status);
                Assert.AreEqual(0, result.ProcessingTimeMilliseconds);
                Assert.GreaterOrEqual(result.FirstProcessingAttemptedAtTs, now);
                Assert.GreaterOrEqual(result.LastProcessingAttemptedAtTs, now);
            }
        }
        public void Test_CanUpdateFromExecutionResult_WithError_Recoverable(int faultErrorThresholdCount)
        {
            Faker          faker          = new Faker();
            QueuedTaskInfo repostWithInfo = null;

            DateTimeOffset now = DateTimeOffset
                                 .UtcNow;

            Faker <QueuedTask> taskFaker =
                GetQueuedTaskFaker();

            QueuedTask task = taskFaker
                              .Generate();

            QueuedTaskResult result = new QueuedTaskResult(task);

            TaskExecutionResultInfo failedWithErrorInfo = TaskExecutionResultInfo
                                                          .ExecutedWithError(new QueuedTaskError(faker.System.Exception()),
                                                                             isRecoverable: true);

            TaskExecutionResult failedWithError = new TaskExecutionResult(failedWithErrorInfo,
                                                                          duration: faker.Date.Timespan(),
                                                                          retryAt: faker.Date.FutureOffset(),
                                                                          faultErrorThresholdCount: faultErrorThresholdCount);

            //1 to faultErrorThresholdCount -> Error status
            for (int i = 1; i <= faultErrorThresholdCount; i++)
            {
                repostWithInfo = result.UdpateFromExecutionResult(failedWithError);
                Assert.NotNull(repostWithInfo);

                Assert.AreEqual(QueuedTaskStatus.Error, result.Status);
                Assert.AreEqual(0, result.ProcessingTimeMilliseconds);
                Assert.GreaterOrEqual(result.FirstProcessingAttemptedAtTs, now);
                Assert.GreaterOrEqual(result.LastProcessingAttemptedAtTs, now);
                Assert.AreEqual(failedWithErrorInfo.Error, result.LastError);
                Assert.AreEqual(i, result.ErrorCount);
            }

            //Antoher failure -> Faulted
            repostWithInfo = result.UdpateFromExecutionResult(failedWithError);
            Assert.NotNull(repostWithInfo);

            Assert.AreEqual(QueuedTaskStatus.Faulted, result.Status);
            Assert.AreEqual(0, result.ProcessingTimeMilliseconds);
            Assert.GreaterOrEqual(result.FirstProcessingAttemptedAtTs, now);
            Assert.GreaterOrEqual(result.LastProcessingAttemptedAtTs, now);
            Assert.AreEqual(failedWithErrorInfo.Error, result.LastError);
            Assert.AreEqual(faultErrorThresholdCount + 1, result.ErrorCount);

            //Antoher failure after that -> Fataled
            repostWithInfo = result.UdpateFromExecutionResult(failedWithError);
            Assert.Null(repostWithInfo);

            Assert.AreEqual(QueuedTaskStatus.Fatal, result.Status);
            Assert.AreEqual(0, result.ProcessingTimeMilliseconds);
            Assert.GreaterOrEqual(result.FirstProcessingAttemptedAtTs, now);
            Assert.GreaterOrEqual(result.LastProcessingAttemptedAtTs, now);
            Assert.AreEqual(failedWithErrorInfo.Error, result.LastError);
            Assert.AreEqual(faultErrorThresholdCount + 2, result.ErrorCount);
        }
Example #4
0
 public QueuedTaskInfo UdpateFromExecutionResult(TaskExecutionResult result)
 {
     return(mLastQueuedTaskResult.UdpateFromExecutionResult(result));
 }