public void Test_CanCompare_ExpectedNotEqual_Cancelled() { Faker faker = new Faker(); TaskExecutionResultInfo cancelledInfo1 = TaskExecutionResultInfo.Cancelled(); TimeSpan sampleDuration1 = faker.Date.Timespan(); DateTimeOffset sampleRetryAt1 = faker.Date.RecentOffset(); int sampleFaultErrorThresholdCount1 = faker.Random.Int(1, 5); TaskExecutionResultInfo cancelledInfo2 = TaskExecutionResultInfo.Cancelled(); TimeSpan sampleDuration2 = faker.Date.Timespan(); DateTimeOffset sampleRetry2 = faker.Date.PastOffset(); int sampleFaultErrorThresholdCount2 = faker.Random.Int(1, 5); TaskExecutionResult cancelled1 = new TaskExecutionResult(cancelledInfo1, duration: sampleDuration1, retryAt: sampleRetryAt1, faultErrorThresholdCount: sampleFaultErrorThresholdCount1); TaskExecutionResult cancelled2 = new TaskExecutionResult(cancelledInfo2, duration: sampleDuration2, retryAt: sampleRetry2, faultErrorThresholdCount: sampleFaultErrorThresholdCount2); Assert.AreNotEqual(cancelled1, cancelled2); }
public void Test_CanCompare_ExpectedNotEqual_WithError(bool isRecoverable) { Faker faker = new Faker(); Exception exc = faker.System.Exception(); TaskExecutionResultInfo failedWithErrorInfo1 = TaskExecutionResultInfo .ExecutedWithError(new QueuedTaskError(exc), isRecoverable); TaskExecutionResultInfo failedWithErrorInfo2 = TaskExecutionResultInfo .ExecutedWithError(new QueuedTaskError(exc), isRecoverable); TimeSpan sampleDuration1 = faker.Date.Timespan(); DateTimeOffset sampleRetryAt1 = faker.Date.SoonOffset(); int sampleFaultErrorThresholdCount1 = faker.Random.Int(1, 5); TimeSpan sampleDuration2 = faker.Date.Timespan(); DateTimeOffset sampleRetryAt2 = faker.Date.SoonOffset(); int sampleFaultErrorThresholdCount2 = faker.Random.Int(1, 5); TaskExecutionResult failedWithError1 = new TaskExecutionResult(failedWithErrorInfo1, duration: sampleDuration1, retryAt: sampleRetryAt1, faultErrorThresholdCount: sampleFaultErrorThresholdCount1); TaskExecutionResult failedWithError2 = new TaskExecutionResult(failedWithErrorInfo2, duration: sampleDuration2, retryAt: sampleRetryAt2, faultErrorThresholdCount: sampleFaultErrorThresholdCount2); Assert.AreNotEqual(failedWithError1, failedWithError2); }
public void Test_CanCreate_WithError(bool isRecoverable) { Faker faker = new Faker(); Exception exc = faker.System.Exception(); TaskExecutionResultInfo failedWithErrorInfo = TaskExecutionResultInfo .ExecutedWithError(new QueuedTaskError(exc), isRecoverable); TimeSpan sampleDuration = faker.Date.Timespan(); DateTimeOffset sampleRetryAt = faker.Date.RecentOffset(); int sampleFaultErrorThresholdCount = faker.Random.Int(1, 5); TaskExecutionResult failedWithError = new TaskExecutionResult(failedWithErrorInfo, duration: sampleDuration, retryAt: sampleRetryAt, faultErrorThresholdCount: sampleFaultErrorThresholdCount); Assert.IsFalse(failedWithError.ExecutedSuccessfully); Assert.IsFalse(failedWithError.ExecutionCancelled); Assert.IsTrue(failedWithError.ExecutionFailed); Assert.NotNull(failedWithError.Error); Assert.AreEqual(failedWithErrorInfo.Error, failedWithError.Error); Assert.AreEqual(( long )(Math.Ceiling(sampleDuration.TotalMilliseconds)), failedWithError.ProcessingTimeMilliseconds); Assert.AreEqual(sampleRetryAt, failedWithError.RetryAt); Assert.AreEqual(sampleFaultErrorThresholdCount, failedWithError.FaultErrorThresholdCount); }
public void Test_CanCompare_ExpectedNotEqual_Successful() { Faker faker = new Faker(); TaskExecutionResultInfo successfulInfo1 = TaskExecutionResultInfo.Successful(); TimeSpan sampleDuration1 = faker.Date.Timespan(); DateTimeOffset sampleRetryAt1 = faker.Date.RecentOffset(); int sampleFaultErrorThresholdCount1 = faker.Random.Int(1, 5); TaskExecutionResultInfo successfulInfo2 = TaskExecutionResultInfo.Successful(); TimeSpan sampleDuration2 = faker.Date.Timespan(); DateTimeOffset sampleRetryAt2 = faker.Date.RecentOffset(); int sampleFaultErrorThresholdCount2 = faker.Random.Int(1, 5); TaskExecutionResult successful1 = new TaskExecutionResult(successfulInfo1, duration: sampleDuration1, retryAt: sampleRetryAt1, faultErrorThresholdCount: sampleFaultErrorThresholdCount1); TaskExecutionResult successful2 = new TaskExecutionResult(successfulInfo2, duration: sampleDuration2, retryAt: sampleRetryAt2, faultErrorThresholdCount: sampleFaultErrorThresholdCount2); Assert.AreNotEqual(successful1, successful2); }
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_CanCompare_Successful() { TaskExecutionResultInfo successful1 = TaskExecutionResultInfo.Successful(); TaskExecutionResultInfo successful2 = TaskExecutionResultInfo.Successful(); Assert.AreEqual(successful1, successful2); Assert.AreEqual(successful1, successful1); Assert.AreNotSame(successful1, successful2); }
public void Test_CanConstruct_Cancelled() { TaskExecutionResultInfo cancelled = TaskExecutionResultInfo.Cancelled(); Assert.NotNull(cancelled); Assert.IsFalse(cancelled.ExecutedSuccessfully); Assert.IsTrue(cancelled.ExecutionCancelled); Assert.IsFalse(cancelled.ExecutionFailed); Assert.IsNull(cancelled.Error); }
public void Test_CanConstruct_Successful() { TaskExecutionResultInfo successful = TaskExecutionResultInfo.Successful(); Assert.NotNull(successful); Assert.IsTrue(successful.ExecutedSuccessfully); Assert.IsFalse(successful.ExecutionCancelled); Assert.IsFalse(successful.ExecutionFailed); Assert.IsNull(successful.Error); }
public void Test_CanCompare_Cancelled() { TaskExecutionResultInfo cancelled1 = TaskExecutionResultInfo.Cancelled(); TaskExecutionResultInfo cancelled2 = TaskExecutionResultInfo.Cancelled(); Assert.AreEqual(cancelled1, cancelled2); Assert.AreEqual(cancelled1, cancelled1); Assert.AreNotSame(cancelled1, cancelled2); }
public async Task Test_CanPostResult_SuccessfulResults_SerialCalls() { Faker faker = new Faker(); Func <TaskExecutionResult> rsFactory = () => new TaskExecutionResult(TaskExecutionResultInfo.Successful(), duration: faker.Date.Timespan(), retryAt: DateTimeOffset.UtcNow, faultErrorThresholdCount: mDataSource.QueueFaultErrorThresholdCount); await Run_PostResultTests(rsFactory); }
public async Task Test_CanPostResult_FailedResults_SerialCalls() { Faker faker = new Faker(); Func <TaskExecutionResult> rsFactory = () => new TaskExecutionResult(TaskExecutionResultInfo .ExecutedWithError(new QueuedTaskError(faker.System.Exception()), isRecoverable: faker.Random.Bool()), duration: TimeSpan.Zero, retryAt: DateTimeOffset.UtcNow, faultErrorThresholdCount: mDataSource.QueueFaultErrorThresholdCount); await Run_PostResultTests(rsFactory); }
public void Test_CanCompare_WithError_ExpectedEqual(bool isRecoverable) { Faker faker = new Faker(); Exception exc = faker.System.Exception(); TaskExecutionResultInfo failedWithError1 = TaskExecutionResultInfo .ExecutedWithError(new QueuedTaskError(exc), isRecoverable); TaskExecutionResultInfo failedWithError2 = TaskExecutionResultInfo .ExecutedWithError(new QueuedTaskError(exc), isRecoverable); Assert.AreEqual(failedWithError1, failedWithError2); Assert.AreEqual(failedWithError1, failedWithError1); Assert.AreNotSame(failedWithError1, failedWithError2); }
public TaskExecutionResult(TaskExecutionResultInfo resultInfo, TimeSpan duration, DateTimeOffset retryAt, int faultErrorThresholdCount) { if (resultInfo == null) { throw new ArgumentNullException(nameof(resultInfo)); } mResultInfo = resultInfo; mFaultErrorThresholdCount = faultErrorThresholdCount; mProcessingTimeMilliseconds = ( long )Math.Ceiling(duration.TotalMilliseconds); mRetryAt = retryAt; }
public void Test_CanConstruct_WithError(bool isRecoverable) { Faker faker = new Faker(); Exception exc = faker.System.Exception(); TaskExecutionResultInfo failedWithError = TaskExecutionResultInfo .ExecutedWithError(new QueuedTaskError(exc), isRecoverable); Assert.NotNull(failedWithError); Assert.IsFalse(failedWithError.ExecutedSuccessfully); Assert.IsFalse(failedWithError.ExecutionCancelled); Assert.IsTrue(failedWithError.ExecutionFailed); Assert.NotNull(failedWithError.Error); Assert.AreEqual(isRecoverable, failedWithError.IsRecoverable); }
public void Test_CanCompare_WithError_ExpectedNotEqual() { Faker faker = new Faker(); Exception exc = faker.System.Exception(); TaskExecutionResultInfo failedWithError1 = TaskExecutionResultInfo .ExecutedWithError(new QueuedTaskError(exc), true); TaskExecutionResultInfo failedWithError2 = TaskExecutionResultInfo .ExecutedWithError(new QueuedTaskError(exc), false); Assert.AreNotEqual(failedWithError1, failedWithError2); TaskExecutionResultInfo failedWithError3 = TaskExecutionResultInfo .ExecutedWithError(new QueuedTaskError("t1", "m1", "s1"), true); TaskExecutionResultInfo failedWithError4 = TaskExecutionResultInfo .ExecutedWithError(new QueuedTaskError("t2", "m2", "s2"), true); Assert.AreNotEqual(failedWithError3, failedWithError4); }
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_CanCompare_ExpectedEquals_Cancelled() { Faker faker = new Faker(); TaskExecutionResultInfo cancelledInfo = TaskExecutionResultInfo.Cancelled(); TimeSpan sampleDuration = faker.Date.Timespan(); DateTimeOffset sampleRetryAt = faker.Date.RecentOffset(); int sampleFaultErrorThresholdCount = faker.Random.Int(1, 5); TaskExecutionResult cancelled1 = new TaskExecutionResult(cancelledInfo, duration: sampleDuration, retryAt: sampleRetryAt, faultErrorThresholdCount: sampleFaultErrorThresholdCount); TaskExecutionResult cancelled2 = new TaskExecutionResult(cancelledInfo, duration: sampleDuration, retryAt: sampleRetryAt, faultErrorThresholdCount: sampleFaultErrorThresholdCount); Assert.AreEqual(cancelled1, cancelled2); Assert.AreEqual(cancelled1, cancelled1); }
public void Test_CanCompare_ExpectedEquals_Successful() { Faker faker = new Faker(); TaskExecutionResultInfo successfulInfo = TaskExecutionResultInfo.Successful(); TimeSpan sampleDuration = faker.Date.Timespan(); DateTimeOffset sampleRetryAt = faker.Date.RecentOffset(); int sampleFaultErrorThresholdCount = faker.Random.Int(1, 5); TaskExecutionResult successful1 = new TaskExecutionResult(successfulInfo, duration: sampleDuration, retryAt: sampleRetryAt, faultErrorThresholdCount: sampleFaultErrorThresholdCount); TaskExecutionResult successful2 = new TaskExecutionResult(successfulInfo, duration: sampleDuration, retryAt: sampleRetryAt, faultErrorThresholdCount: sampleFaultErrorThresholdCount); Assert.AreEqual(successful1, successful2); Assert.AreEqual(successful1, successful1); }
public void Test_CanCreate_Cancelled() { Faker faker = new Faker(); TaskExecutionResultInfo cancelledInfo = TaskExecutionResultInfo.Cancelled(); TimeSpan sampleDuration = faker.Date.Timespan(); DateTimeOffset sampleRetryAt = faker.Date.RecentOffset(); int sampleFaultErrorThresholdCount = faker.Random.Int(1, 5); TaskExecutionResult cancelled = new TaskExecutionResult(cancelledInfo, duration: sampleDuration, retryAt: sampleRetryAt, faultErrorThresholdCount: sampleFaultErrorThresholdCount); Assert.IsFalse(cancelled.ExecutedSuccessfully); Assert.IsTrue(cancelled.ExecutionCancelled); Assert.IsFalse(cancelled.ExecutionFailed); Assert.IsNull(cancelled.Error); Assert.AreEqual(( long )(Math.Ceiling(sampleDuration.TotalMilliseconds)), cancelled.ProcessingTimeMilliseconds); Assert.AreEqual(sampleRetryAt, cancelled.RetryAt); Assert.AreEqual(sampleFaultErrorThresholdCount, cancelled.FaultErrorThresholdCount); }
public void Test_CanCompare_ExpectedEquals_WithError(bool isRecoverable) { Faker faker = new Faker(); Exception exc = faker.System.Exception(); TaskExecutionResultInfo failedWithErrorInfo = TaskExecutionResultInfo .ExecutedWithError(new QueuedTaskError(exc), isRecoverable); TimeSpan sampleDuration = faker.Date.Timespan(); DateTimeOffset sampleRetryAt = faker.Date.RecentOffset(); int sampleFaultErrorThresholdCount = faker.Random.Int(1, 5); TaskExecutionResult failedWithError1 = new TaskExecutionResult(failedWithErrorInfo, duration: sampleDuration, retryAt: sampleRetryAt, faultErrorThresholdCount: sampleFaultErrorThresholdCount); TaskExecutionResult failedWithError2 = new TaskExecutionResult(failedWithErrorInfo, duration: sampleDuration, retryAt: sampleRetryAt, faultErrorThresholdCount: sampleFaultErrorThresholdCount); Assert.AreEqual(failedWithError1, failedWithError2); Assert.AreEqual(failedWithError1, failedWithError1); }
public void NotifyTaskCompleted() { mResult = TaskExecutionResultInfo.Successful(); }
public void NotifyTaskErrored(QueuedTaskError error, bool isRecoverable) { mResult = TaskExecutionResultInfo.ExecutedWithError(error, isRecoverable); }
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); }
public void NotifyCancellationObserved() { mResult = TaskExecutionResultInfo.Cancelled(); }