Beispiel #1
0
            public async Task AcknowledgesMessageOnCompletionOfInvocation()
            {
                // Arrange
                var cts        = new CancellationTokenSource();
                var runner     = new TestableJobRunner(TimeSpan.FromSeconds(5));
                var invocation = TestHelpers.CreateInvocation(Guid.NewGuid(), "test", "test", new Dictionary <string, string>());

                runner.MockDispatcher
                .Setup(d => d.Dispatch(It.IsAny <InvocationContext>()))
                .Completes(InvocationResult.Completed())
                .Verifiable();

                // Act
                await runner.Dispatch(invocation, cts.Token);

                // Assert
                runner.MockQueue.Verify(q => q.Complete(invocation, ExecutionResult.Completed, null, null));
            }
Beispiel #2
0
            public async Task DispatchesTheJobUsingTheDispatcher()
            {
                // Arrange
                var cts        = new CancellationTokenSource();
                var runner     = new TestableJobRunner(TimeSpan.FromSeconds(5));
                var invocation = TestHelpers.CreateInvocation(Guid.NewGuid(), "test", "test", new Dictionary <string, string>());

                runner.MockDispatcher
                .Setup(d => d.Dispatch(It.IsAny <InvocationContext>()))
                .Completes(InvocationResult.Completed())
                .Verifiable();

                // Act
                await runner.Dispatch(invocation, cts.Token);

                // Assert
                runner.MockDispatcher.VerifyAll();
            }
Beispiel #3
0
            public async Task EnqueuesARescheduleIfTheResultRequestsIt(ExecutionResult result)
            {
                // Arrange
                var cts        = new CancellationTokenSource();
                var runner     = new TestableJobRunner(TimeSpan.FromSeconds(5));
                var invocation = TestHelpers.CreateInvocation(Guid.NewGuid(), "test", "test", new Dictionary <string, string>());
                var repeat     = TestHelpers.CreateInvocation(Guid.NewGuid(), "test", "test", new Dictionary <string, string>());

                runner.MockDispatcher
                .Setup(d => d.Dispatch(It.IsAny <InvocationContext>()))
                .Completes(new InvocationResult(result, result == ExecutionResult.Faulted ? new Exception() : null, TimeSpan.FromDays(365)))
                .Verifiable();
                runner.MockQueue
                .Setup(q => q.Enqueue("test", Constants.Source_RepeatingJob, It.IsAny <Dictionary <string, string> >(), TimeSpan.FromDays(365), null))
                .Completes(repeat);

                // Act
                await runner.Dispatch(invocation, cts.Token);

                // Assert
                runner.MockQueue.Verify(q => q.Enqueue(invocation.Job, Constants.Source_RepeatingJob, invocation.Payload, TimeSpan.FromDays(365), null));
            }
Beispiel #4
0
            public async Task UpdatesTheStatusOfTheRequestToExecuting()
            {
                // Arrange
                var cts        = new CancellationTokenSource();
                var runner     = new TestableJobRunner(TimeSpan.FromSeconds(5));
                var invocation = TestHelpers.CreateInvocation(Guid.NewGuid(), "test", "test", new Dictionary <string, string>());

                var dispatchTCS = runner
                                  .MockDispatcher
                                  .Setup(d => d.Dispatch(It.IsAny <InvocationContext>()))
                                  .WaitsForSignal();

                // Act
                var task = runner.Dispatch(invocation, cts.Token);

                // Assert
                runner.MockQueue.Verify(q => q.UpdateStatus(invocation, InvocationStatus.Executing, ExecutionResult.Incomplete));

                dispatchTCS.SetResult(InvocationResult.Completed());

                await task;
            }
Beispiel #5
0
            public async Task SuspendsInvocationIfJobRemainsIncompleteWithAContinuation()
            {
                // Arrange
                var cts        = new CancellationTokenSource();
                var runner     = new TestableJobRunner(TimeSpan.FromSeconds(5));
                var invocation = TestHelpers.CreateInvocation(Guid.NewGuid(), "test", "test", new Dictionary <string, string>());

                var continuationPayload = new Dictionary <string, string>()
                {
                    { "foo", "bar" }
                };

                runner.MockDispatcher
                .Setup(d => d.Dispatch(It.IsAny <InvocationContext>()))
                .Completes(InvocationResult.Suspended(new JobContinuation(TimeSpan.FromDays(365), continuationPayload)))
                .Verifiable();

                // Act
                await runner.Dispatch(invocation, cts.Token);

                // Assert
                runner.MockQueue.Verify(q => q.Suspend(invocation, continuationPayload, TimeSpan.FromDays(365), null));
            }
Beispiel #6
0
            public async Task CompletesWithResultMessageIfThereIsAnException(ExecutionResult result)
            {
                // Arrange
                var cts        = new CancellationTokenSource();
                var runner     = new TestableJobRunner(TimeSpan.FromSeconds(5));
                var invocation = TestHelpers.CreateInvocation(Guid.NewGuid(), "test", "test", new Dictionary <string, string>());
                var exception  = new Exception("BORK!");

                runner.MockDispatcher
                .Setup(d => d.Dispatch(It.IsAny <InvocationContext>()))
                .Completes(() =>
                {
                    runner.VirtualClock.Advance(TimeSpan.FromDays(365));     // Wow this is a long job ;)
                    return(new InvocationResult(result, exception));
                })
                .Verifiable();

                // Act
                await runner.Dispatch(invocation, cts.Token);

                // Assert
                runner.MockQueue.Verify(q => q.Complete(invocation, result, exception.ToString(), null));
            }
            public async Task EnqueuesARescheduleIfTheResultRequestsIt(ExecutionResult result)
            {
                // Arrange
                var cts = new CancellationTokenSource();
                var runner = new TestableJobRunner(TimeSpan.FromSeconds(5));
                var invocation = TestHelpers.CreateInvocation(Guid.NewGuid(), "test", "test", new Dictionary<string, string>());
                var repeat = TestHelpers.CreateInvocation(Guid.NewGuid(), "test", "test", new Dictionary<string,string>());
                
                runner.MockDispatcher
                    .Setup(d => d.Dispatch(It.IsAny<InvocationContext>()))
                    .Completes(new InvocationResult(result, result == ExecutionResult.Faulted ? new Exception() : null, TimeSpan.FromDays(365)))
                    .Verifiable();
                runner.MockQueue
                    .Setup(q => q.Enqueue("test", Constants.Source_RepeatingJob, It.IsAny<Dictionary<string, string>>(), TimeSpan.FromDays(365), null))
                    .Completes(repeat);

                // Act
                await runner.Dispatch(invocation, cts.Token);

                // Assert
                runner.MockQueue.Verify(q => q.Enqueue(invocation.Job, Constants.Source_RepeatingJob, invocation.Payload, TimeSpan.FromDays(365), null));
            }
            public async Task SuspendsInvocationIfJobRemainsIncompleteWithAContinuation()
            {
                // Arrange
                var cts = new CancellationTokenSource();
                var runner = new TestableJobRunner(TimeSpan.FromSeconds(5));
                var invocation = TestHelpers.CreateInvocation(Guid.NewGuid(), "test", "test", new Dictionary<string, string>());
                
                var continuationPayload = new Dictionary<string, string>() { { "foo", "bar" } };
                runner.MockDispatcher
                    .Setup(d => d.Dispatch(It.IsAny<InvocationContext>()))
                    .Completes(InvocationResult.Suspended(new JobContinuation(TimeSpan.FromDays(365), continuationPayload)))
                    .Verifiable();

                // Act
                await runner.Dispatch(invocation, cts.Token);

                // Assert
                runner.MockQueue.Verify(q => q.Suspend(invocation, continuationPayload, TimeSpan.FromDays(365), null));
            }
            public async Task CompletesWithResultMessageIfThereIsAnException(ExecutionResult result)
            {
                // Arrange
                var cts = new CancellationTokenSource();
                var runner = new TestableJobRunner(TimeSpan.FromSeconds(5));
                var invocation = TestHelpers.CreateInvocation(Guid.NewGuid(), "test", "test", new Dictionary<string, string>());
                var exception = new Exception("BORK!");
                
                runner.MockDispatcher
                    .Setup(d => d.Dispatch(It.IsAny<InvocationContext>()))
                    .Completes(() =>
                    {
                        runner.VirtualClock.Advance(TimeSpan.FromDays(365)); // Wow this is a long job ;)
                        return new InvocationResult(result, exception);
                    })
                    .Verifiable();

                // Act
                await runner.Dispatch(invocation, cts.Token);

                // Assert
                runner.MockQueue.Verify(q => q.Complete(invocation, result, exception.ToString(), null));
            }
            public async Task AcknowledgesMessageOnCompletionOfInvocation()
            {
                // Arrange
                var cts = new CancellationTokenSource();
                var runner = new TestableJobRunner(TimeSpan.FromSeconds(5));
                var invocation = TestHelpers.CreateInvocation(Guid.NewGuid(), "test", "test", new Dictionary<string, string>());
                
                runner.MockDispatcher
                    .Setup(d => d.Dispatch(It.IsAny<InvocationContext>()))
                    .Completes(InvocationResult.Completed())
                    .Verifiable();

                // Act
                await runner.Dispatch(invocation, cts.Token);

                // Assert
                runner.MockQueue.Verify(q => q.Complete(invocation, ExecutionResult.Completed, null, null));
            }
            public async Task DispatchesTheJobUsingTheDispatcher()
            {
                // Arrange
                var cts = new CancellationTokenSource();
                var runner = new TestableJobRunner(TimeSpan.FromSeconds(5));
                var invocation = TestHelpers.CreateInvocation(Guid.NewGuid(), "test", "test", new Dictionary<string, string>());
                
                runner.MockDispatcher
                    .Setup(d => d.Dispatch(It.IsAny<InvocationContext>()))
                    .Completes(InvocationResult.Completed())
                    .Verifiable();

                // Act
                await runner.Dispatch(invocation, cts.Token);

                // Assert
                runner.MockDispatcher.VerifyAll();
            }
            public async Task UpdatesTheStatusOfTheRequestToExecuting()
            {
                // Arrange
                var cts = new CancellationTokenSource();
                var runner = new TestableJobRunner(TimeSpan.FromSeconds(5));
                var invocation = TestHelpers.CreateInvocation(Guid.NewGuid(), "test", "test", new Dictionary<string, string>());
                
                var dispatchTCS = runner
                    .MockDispatcher
                    .Setup(d => d.Dispatch(It.IsAny<InvocationContext>()))
                    .WaitsForSignal();

                // Act
                var task = runner.Dispatch(invocation, cts.Token);

                // Assert
                runner.MockQueue.Verify(q => q.UpdateStatus(invocation, InvocationStatus.Executing, ExecutionResult.Incomplete));

                dispatchTCS.SetResult(InvocationResult.Completed());

                await task;
            }