Beispiel #1
0
        public void ParallelStateWithCatchers()
        {
            var stateMachine = StateMachineBuilder.StateMachine()
                               .StartAt("InitialState")
                               .State("InitialState", StateMachineBuilder.ParallelState()
                                      .Transition(StateMachineBuilder.End())
                                      .Branches(
                                          StateMachineBuilder.SubStateMachine()
                                          .Comment("Branch one")
                                          .StartAt("BranchOneInitial")
                                          .State("BranchOneInitial", StateMachineBuilder.SucceedState()),
                                          StateMachineBuilder.SubStateMachine()
                                          .Comment("Branch two")
                                          .StartAt("BranchTwoInitial")
                                          .State("BranchTwoInitial", StateMachineBuilder.SucceedState())
                                          )
                                      .Catchers(StateMachineBuilder.Catcher()
                                                .ErrorEquals("Foo", "Bar")
                                                .Transition(StateMachineBuilder.Next("RecoveryState"))
                                                .ResultPath("$.result"),
                                                StateMachineBuilder.Catcher()
                                                .CatchAll()
                                                .Transition(StateMachineBuilder.Next("OtherRecoveryState"))
                                                .ResultPath("$.result")
                                                ))
                               .State("RecoveryState", StateMachineBuilder.SucceedState())
                               .State("OtherRecoveryState", StateMachineBuilder.SucceedState())
                               .Build();

            AssertStateMachine(stateMachine, "ParallelStateWithCatchers.json");
        }
Beispiel #2
0
 public void ParallelState_ChoiceStateWithTerminalPath_IsValid()
 {
     AssertHasPathToTerminal(
         StateMachineBuilder.StateMachine()
         .StartAt("Parallel")
         .State("Parallel", StateMachineBuilder.ParallelState()
                .Transition(StateMachineBuilder.End())
                .Branch(StateMachineBuilder.SubStateMachine()
                        .StartAt("Initial")
                        .State("Initial", StateMachineBuilder.PassState()
                               .Transition(StateMachineBuilder
                                           .Next("Choice")))
                        .State("Choice", StateMachineBuilder.ChoiceState()
                               .DefaultStateName("Default")
                               .Choice(StateMachineBuilder.Choice()
                                       .Transition(StateMachineBuilder
                                                   .Next("Initial"))
                                       .Condition(StateMachineBuilder
                                                  .StringEquals("$.foo",
                                                                "bar")))
                               .Choice(StateMachineBuilder.Choice()
                                       .Transition(StateMachineBuilder
                                                   .Next("Default"))
                                       .Condition(StateMachineBuilder
                                                  .StringEquals("$.foo",
                                                                "bar"))))
                        .State("Default",
                               StateMachineBuilder
                               .PassState().Transition(StateMachineBuilder.End())))));
 }
Beispiel #3
0
        public void ParallelStateWithRetriers()
        {
            var stateMachine = StateMachineBuilder.StateMachine()
                               .StartAt("InitialState")
                               .State("InitialState", StateMachineBuilder.ParallelState()
                                      .Transition(StateMachineBuilder.End())
                                      .Branches(
                                          StateMachineBuilder.SubStateMachine()
                                          .Comment("Branch one")
                                          .StartAt("BranchOneInitial")
                                          .State("BranchOneInitial", StateMachineBuilder.SucceedState()),
                                          StateMachineBuilder.SubStateMachine()
                                          .Comment("Branch two")
                                          .StartAt("BranchTwoInitial")
                                          .State("BranchTwoInitial", StateMachineBuilder.SucceedState())
                                          )
                                      .Retriers(StateMachineBuilder.Retrier()
                                                .ErrorEquals("Foo", "Bar")
                                                .IntervalSeconds(10)
                                                .BackoffRate(1.0)
                                                .MaxAttempts(3),
                                                StateMachineBuilder.Retrier()
                                                .RetryOnAllErrors()
                                                .IntervalSeconds(10)
                                                .BackoffRate(1.0)
                                                .MaxAttempts(3)
                                                ))
                               .Build();

            AssertStateMachine(stateMachine, "ParallelStateWithRetriers.json");
        }
Beispiel #4
0
 public void NoWaitForSupplied_IsNotValid()
 {
     Assert.Throws <ValidationException>(() =>
                                         StateMachineBuilder.StateMachine()
                                         .StartAt("Initial")
                                         .State("Initial", StateMachineBuilder.WaitState()
                                                .Transition(StateMachineBuilder.End()))
                                         .Build());
 }
Beispiel #5
0
 public void MissingResourceInTaskState_IsNotValid()
 {
     Assert.Throws <ValidationException>(() =>
                                         StateMachineBuilder.StateMachine()
                                         .StartAt("Initial")
                                         .State("Initial", StateMachineBuilder.TaskState()
                                                .Transition(StateMachineBuilder.End()))
                                         .Build());
 }
Beispiel #6
0
 public void MapStateWithoutIterator_IsNotValid()
 {
     Assert.Throws <ValidationException>(() =>
                                         StateMachineBuilder.StateMachine()
                                         .StartAt("Initial")
                                         .State("Initial", StateMachineBuilder.MapState()
                                                .Transition(StateMachineBuilder.End()))
                                         .Build());
 }
Beispiel #7
0
 public void ParallelStateWithNoBranches_IsNotValid()
 {
     Assert.Throws <ValidationException>(() =>
                                         StateMachineBuilder.StateMachine()
                                         .StartAt("Initial")
                                         .State("Initial", StateMachineBuilder.ParallelState()
                                                .Transition(StateMachineBuilder.End()))
                                         .Build());
 }
Beispiel #8
0
 public void WaitForSecondsPath_MissingPath_IsNotValid()
 {
     Assert.ThrowsAny <ValidationException>(() =>
                                            StateMachineBuilder.StateMachine()
                                            .StartAt("Initial")
                                            .State("Initial", StateMachineBuilder.WaitState()
                                                   .WaitFor(StateMachineBuilder.SecondsPath(null))
                                                   .Transition(StateMachineBuilder.End()))
                                            .Build());
 }
Beispiel #9
0
 public void WaitForSecondsPath_InvalidReferencePath_IsNotValid()
 {
     Assert.ThrowsAny <ValidationException>(() =>
                                            StateMachineBuilder.StateMachine()
                                            .StartAt("Initial")
                                            .State("Initial", StateMachineBuilder.WaitState()
                                                   .WaitFor(StateMachineBuilder.SecondsPath("$.Foo[*]"))
                                                   .Transition(StateMachineBuilder.End()))
                                            .Build());
 }
Beispiel #10
0
 public void InputPath_IsNotValid()
 {
     Assert.Throws <ValidationException>(() =>
                                         StateMachineBuilder.StateMachine()
                                         .StartAt("Initial")
                                         .State("Initial", StateMachineBuilder.PassState()
                                                .InputPath("['invalidPath")
                                                .Transition(StateMachineBuilder.End()))
                                         .Build());
 }
Beispiel #11
0
 public void WaitForTimestampPath_InvalidJsonPath_IsNotValid()
 {
     Assert.ThrowsAny <ValidationException>(() =>
                                            StateMachineBuilder.StateMachine()
                                            .StartAt("Initial")
                                            .State("Initial", StateMachineBuilder.WaitState()
                                                   .WaitFor(StateMachineBuilder.TimestampPath("$."))
                                                   .Transition(StateMachineBuilder.End()))
                                            .Build());
 }
Beispiel #12
0
 public void WaitForSeconds_ZeroSeconds_IsNotValid()
 {
     Assert.Throws <ValidationException>(() =>
                                         StateMachineBuilder.StateMachine()
                                         .StartAt("Initial")
                                         .State("Initial", StateMachineBuilder.WaitState()
                                                .WaitFor(StateMachineBuilder.Seconds(0))
                                                .Transition(StateMachineBuilder.End()))
                                         .Build());
 }
Beispiel #13
0
        public void SingleWaitState_WaitUntilTimestamp()
        {
            var stateMachine = StateMachineBuilder.StateMachine()
                               .StartAt("InitialState")
                               .State("InitialState", StateMachineBuilder.WaitState()
                                      .WaitFor(StateMachineBuilder.Timestamp(DateTime.Parse("2016-03-14T01:59:00Z").ToUniversalTime()))
                                      .Transition(StateMachineBuilder.End()))
                               .Build();

            AssertStateMachine(stateMachine, "SingleWaitStateWithTimestamp.json");
        }
Beispiel #14
0
 [Fact] //
 public void RetrierInTaskState_OnlyErrorEqualsSet_IsValid()
 {
     StateMachineBuilder.StateMachine()
     .StartAt("Initial")
     .State("Initial", StateMachineBuilder.TaskState()
            .Transition(StateMachineBuilder.End())
            .Retrier(StateMachineBuilder.Retrier()
                     .RetryOnAllErrors())
            .Resource("arn"))
     .Build();
 }
Beispiel #15
0
        public void SingleWaitState_WaitUntilSecondsPath()
        {
            var stateMachine = StateMachineBuilder.StateMachine()
                               .StartAt("InitialState")
                               .State("InitialState", StateMachineBuilder.WaitState()
                                      .WaitFor(StateMachineBuilder.SecondsPath("$.seconds"))
                                      .Transition(StateMachineBuilder.End()))
                               .Build();

            AssertStateMachine(stateMachine, "SingleWaitStateWithSecondsPath.json");
        }
Beispiel #16
0
        public void SingleWaitState_WaitUntilTimestampWithPath()
        {
            var stateMachine = StateMachineBuilder.StateMachine()
                               .StartAt("InitialState")
                               .State("InitialState", StateMachineBuilder.WaitState()
                                      .WaitFor(StateMachineBuilder.TimestampPath("$.timestamp"))
                                      .Transition(StateMachineBuilder.End()))
                               .Build();

            AssertStateMachine(stateMachine, "SingleWaitStateWithTimestampWithPath.json");
        }
Beispiel #17
0
        public void SinglePassStateWithObjectResult()
        {
            var stateMachine = StateMachineBuilder.StateMachine()
                               .StartAt("InitialState")
                               .State("InitialState", StateMachineBuilder.PassState()
                                      .Transition(StateMachineBuilder.End())
                                      .Result(new SimplePojo("value")))
                               .Build();

            AssertStateMachine(stateMachine, "SinglePassStateWithObjectResult.json");
        }
Beispiel #18
0
        public void TaskStateWithEnd()
        {
            var stateMachine = StateMachineBuilder.StateMachine()
                               .StartAt("InitialState")
                               .State("InitialState", StateMachineBuilder.TaskState()
                                      .Resource("resource-arn")
                                      .Transition(StateMachineBuilder.End()))
                               .Build();

            AssertStateMachine(stateMachine, "TaskStateWithEnd.json");
        }
Beispiel #19
0
 public void NegativeTimeoutSecondsInTaskState_IsNotValid()
 {
     Assert.Throws <ValidationException>(() =>
                                         StateMachineBuilder.StateMachine()
                                         .StartAt("Initial")
                                         .State("Initial", StateMachineBuilder.TaskState()
                                                .Transition(StateMachineBuilder.End())
                                                .TimeoutSeconds(-1)
                                                .Resource("arn"))
                                         .Build());
 }
Beispiel #20
0
 public void ParallelStateInvalidBranchState_IsNotValid()
 {
     Assert.Throws <ValidationException>(() =>
                                         StateMachineBuilder.StateMachine()
                                         .StartAt("Initial")
                                         .State("Initial", StateMachineBuilder.ParallelState()
                                                .Branch(StateMachineBuilder.SubStateMachine()
                                                        .StartAt("InitialBranchState")
                                                        .State("InitialBranchState", StateMachineBuilder.FailState()))
                                                .Transition(StateMachineBuilder.End()))
                                         .Build());
 }
Beispiel #21
0
        public void TaskStateWithParametersAndEnd()
        {
            var stateMachine = StateMachineBuilder.StateMachine()
                               .StartAt("InitialState")
                               .State("InitialState", StateMachineBuilder.TaskState()
                                      .Resource("resource-arn")
                                      .Parameters(JObject.FromObject(new { value = "param" }))
                                      .Transition(StateMachineBuilder.End()))
                               .Build();

            AssertStateMachine(stateMachine, "TaskStateWithParametersAndEnd.json");
        }
Beispiel #22
0
 [Fact] //
 public void RetrierInTaskState_MaxAttemptsZero_IsValid()
 {
     StateMachineBuilder.StateMachine()
     .StartAt("Initial")
     .State("Initial", StateMachineBuilder.TaskState()
            .Transition(StateMachineBuilder.End())
            .Retrier(StateMachineBuilder.Retrier()
                     .MaxAttempts(0)
                     .RetryOnAllErrors())
            .Resource("arn"))
     .Build();
 }
Beispiel #23
0
 [Fact] //
 public void RetrierInTaskState_BackoffRateGreaterThanOne_IsValid()
 {
     StateMachineBuilder.StateMachine()
     .StartAt("Initial")
     .State("Initial", StateMachineBuilder.TaskState()
            .Transition(StateMachineBuilder.End())
            .Retrier(StateMachineBuilder.Retrier()
                     .BackoffRate(1.5)
                     .RetryOnAllErrors())
            .Resource("arn"))
     .Build();
 }
Beispiel #24
0
 [Fact] //
 public void RetrierInTaskState_IntervalSecondsPositive_IsValid()
 {
     StateMachineBuilder.StateMachine()
     .StartAt("Initial")
     .State("Initial", StateMachineBuilder.TaskState()
            .Transition(StateMachineBuilder.End())
            .Retrier(StateMachineBuilder.Retrier()
                     .IntervalSeconds(10)
                     .RetryOnAllErrors())
            .Resource("arn"))
     .Build();
 }
Beispiel #25
0
 public void RetrierInTaskState_RetryAllHasOtherErrorCodes_IsNotValid()
 {
     Assert.Throws <ValidationException>(() =>
                                         StateMachineBuilder.StateMachine()
                                         .StartAt("Initial")
                                         .State("Initial", StateMachineBuilder.TaskState()
                                                .Transition(StateMachineBuilder.End())
                                                .Retrier(StateMachineBuilder.Retrier()
                                                         .ErrorEquals("Foo", "Bar", ErrorCodes.ALL))
                                                .Resource("arn"))
                                         .Build());
 }
Beispiel #26
0
        public void OutputPAthIsNull()
        {
            var stateMachine = StateMachineBuilder.StateMachine()
                               .StartAt("helloPass")
                               .State("helloPass", StateMachineBuilder.PassState()
                                      .Result(JArray.Parse("[1,2,3]"))
                                      .InputPath("$.a")
                                      .OutputPath(null)
                                      .Transition(StateMachineBuilder.End())).Build();

            AssertStateMachine(stateMachine, "PassStateNullOutputPath.json");
        }
Beispiel #27
0
 public void HeartbeatSecondsGreaterThanTimeoutSecondsInTaskState_IsNotValid()
 {
     Assert.Throws <ValidationException>(() =>
                                         StateMachineBuilder.StateMachine()
                                         .StartAt("Initial")
                                         .State("Initial", StateMachineBuilder.TaskState()
                                                .Transition(StateMachineBuilder.End())
                                                .HeartbeatSeconds(60)
                                                .TimeoutSeconds(30)
                                                .Resource("arn"))
                                         .Build());
 }
Beispiel #28
0
 [Fact] //
 public void CatcherInTaskState_ValidTransition_IsValid()
 {
     StateMachineBuilder.StateMachine()
     .StartAt("Initial")
     .State("Initial", StateMachineBuilder.TaskState()
            .Transition(StateMachineBuilder.End())
            .Catcher(StateMachineBuilder.Catcher()
                     .Transition(StateMachineBuilder.Next("Terminal"))
                     .CatchAll())
            .Resource("arn"))
     .State("Terminal", StateMachineBuilder.SucceedState())
     .Build();
 }
Beispiel #29
0
 public void RetrierInTaskState_BackoffRateLessThanOne_IsNotValid()
 {
     Assert.Throws <ValidationException>(() =>
                                         StateMachineBuilder.StateMachine()
                                         .StartAt("Initial")
                                         .State("Initial", StateMachineBuilder.TaskState()
                                                .Transition(StateMachineBuilder.End())
                                                .Retrier(StateMachineBuilder.Retrier()
                                                         .BackoffRate(0.5)
                                                         .RetryOnAllErrors())
                                                .Resource("arn"))
                                         .Build());
 }
Beispiel #30
0
 public void CatcherInTaskState_InvalidTransition_IsNotValid()
 {
     Assert.Throws <ValidationException>(() =>
                                         StateMachineBuilder.StateMachine()
                                         .StartAt("Initial")
                                         .State("Initial", StateMachineBuilder.TaskState()
                                                .Transition(StateMachineBuilder.End())
                                                .Catcher(StateMachineBuilder.Catcher()
                                                         .Transition(StateMachineBuilder.Next("NoSuchState"))
                                                         .CatchAll())
                                                .Resource("arn"))
                                         .Build());
 }