Example #1
0
        public void SimpleChoiceState()
        {
            var stateMachine = StateMachineBuilder.StateMachine()
                               .StartAt("InitialState")
                               .State("InitialState", StateMachineBuilder.ChoiceState()
                                      .Comment("My choice state")
                                      .DefaultStateName("DefaultState")
                                      .InputPath("$.input")
                                      .OutputPath("$.output")
                                      .Choice(StateMachineBuilder.Choice().Transition(StateMachineBuilder.Next("NextState"))
                                              .Condition(StateMachineBuilder.StringEquals("$.var", "value"))))
                               .State("NextState", StateMachineBuilder.SucceedState())
                               .State("DefaultState", StateMachineBuilder.SucceedState())
                               .Build();

            AssertStateMachine(stateMachine, "SimpleChoiceState.json");
        }
Example #2
0
 public void CatcherInTaskState_CatchAllIsNotLastCatcher_IsNotValid()
 {
     Assert.Throws <ValidationException>(() =>
                                         StateMachineBuilder.StateMachine()
                                         .StartAt("Initial")
                                         .State("Initial", StateMachineBuilder.TaskState()
                                                .Transition(StateMachineBuilder.End())
                                                .Catcher(StateMachineBuilder.Catcher()
                                                         .Transition(StateMachineBuilder.Next("Terminal"))
                                                         .CatchAll())
                                                .Catcher(StateMachineBuilder.Catcher()
                                                         .Transition(StateMachineBuilder.Next("Terminal"))
                                                         .ErrorEquals("Foo", "Bar"))
                                                .Resource("arn"))
                                         .State("Terminal", StateMachineBuilder.SucceedState())
                                         .Build());
 }
Example #3
0
        public void SinglePassStateWithJsonResult()
        {
            var stateMachine = StateMachineBuilder.StateMachine()
                               .StartAt("InitialState")
                               .State("InitialState", StateMachineBuilder.PassState()
                                      .Comment("Pass through state")
                                      .InputPath("$.input")
                                      .OutputPath("$.output")
                                      .ResultPath("$.result")
                                      .Parameters(JObject.Parse("{'a':1}"))
                                      .Transition(StateMachineBuilder.Next("NextState"))
                                      .Result("{\"Foo\": \"Bar\"}"))
                               .State("NextState", StateMachineBuilder.SucceedState())
                               .Build();

            AssertStateMachine(stateMachine, "SinglePassStateWithJsonResult.json");
        }
Example #4
0
        public void ChoiceStateWithMultipleChoices()
        {
            var stateMachine = StateMachineBuilder.StateMachine()
                               .StartAt("InitialState")
                               .State("InitialState", StateMachineBuilder.ChoiceState()
                                      .DefaultStateName("DefaultState")
                                      .Choices(
                                          StateMachineBuilder.Choice().Transition(StateMachineBuilder.Next("NextState"))
                                          .Condition(StateMachineBuilder.StringEquals("$.var", "value")),
                                          StateMachineBuilder.Choice().Transition(StateMachineBuilder.Next("OtherNextState"))
                                          .Condition(StateMachineBuilder.NumericGreaterThan("$.number", 10))))
                               .State("NextState", StateMachineBuilder.SucceedState())
                               .State("OtherNextState", StateMachineBuilder.SucceedState())
                               .State("DefaultState", StateMachineBuilder.SucceedState())
                               .Build();

            AssertStateMachine(stateMachine, "ChoiceStateWithMultipleChoices.json");
        }
Example #5
0
 public void ParallelState_WithCycles_IsNotValid()
 {
     Assert.Throws <ValidationException>(() =>
                                         AssertCycle(StateMachineBuilder.StateMachine()
                                                     .StartAt("Parallel")
                                                     .State("Parallel", StateMachineBuilder.ParallelState()
                                                            .Branch(StateMachineBuilder.SubStateMachine()
                                                                    .StartAt("BranchOneInitial")
                                                                    .State("BranchOneInitial", StateMachineBuilder
                                                                           .PassState()
                                                                           .Transition(StateMachineBuilder
                                                                                       .Next("CyclicState")))
                                                                    .State("CyclicState", StateMachineBuilder
                                                                           .PassState()
                                                                           .Transition(StateMachineBuilder
                                                                                       .Next("BranchOneInitial"))))
                                                            .Transition(StateMachineBuilder.End()))));
 }
Example #6
0
        public void CanSerializeStatesToJson()
        {
            var stateMachine = StateMachineBuilder.StateMachine()
                               .StartAt("InitialState")
                               .TimeoutSeconds(30)
                               .Comment("My Simple State Machine")
                               .State("InitialState", StateMachineBuilder.SucceedState()
                                      .Comment("Initial State")
                                      .InputPath("$.input")
                                      .OutputPath("$.output"))
                               .Build();

            var value = stateMachine.States["InitialState"].ToJson();

            var s = State.FromJson(value);

            Assert.True(s.Type == StateType.Succeed);
        }
Example #7
0
        public void SimpleParallelStateWithTasks()
        {
            var stateMachine = StateMachineBuilder.StateMachine()
                               .StartAt("para")
                               .State("para", StateMachineBuilder.ParallelState()
                                      .Transition(StateMachineBuilder.End())
                                      .Branches(
                                          StateMachineBuilder.SubStateMachine()
                                          .StartAt("t")
                                          .State("t",
                                                 StateMachineBuilder.TaskState().Resource("t").Transition(StateMachineBuilder.End())),
                                          StateMachineBuilder.SubStateMachine()
                                          .StartAt("u")
                                          .State("u",
                                                 StateMachineBuilder.TaskState().Resource("u").Transition(StateMachineBuilder.End()))
                                          ))
                               .Build();

            AssertStateMachine(stateMachine, "SimpleParallelStateWithTasks.json");
        }
Example #8
0
        public void SingleTaskState()
        {
            var stateMachine = StateMachineBuilder.StateMachine()
                               .StartAt("InitialState")
                               .State("InitialState", StateMachineBuilder.TaskState()
                                      .Comment("Initial State")
                                      .TimeoutSeconds(10)
                                      .HeartbeatSeconds(1)
                                      .Transition(StateMachineBuilder.Next("NextState"))
                                      .Resource("resource-arn")
                                      .InputPath("$.input")
                                      .ResultPath("$.result")
                                      .OutputPath("$.output")
                                      .Parameters(JObject.FromObject(new { value = "param" }))
                                      .ResultSelector(JObject.FromObject(new { value = "param" })))
                               .State("NextState", StateMachineBuilder.SucceedState())
                               .Build();

            AssertStateMachine(stateMachine, "SimpleTaskState.json");
        }
Example #9
0
 public void ChoiceStateWithClosedCycle_IsNotValid()
 {
     Assert.Throws <ValidationException>(() =>
                                         AssertCycle(StateMachineBuilder.StateMachine()
                                                     .StartAt("Initial")
                                                     .State("Initial", StateMachineBuilder.PassState()
                                                            .Transition(StateMachineBuilder.Next("Choice")))
                                                     .State("Choice", StateMachineBuilder.ChoiceState()
                                                            .DefaultStateName("Terminal")
                                                            .Choice(StateMachineBuilder.Choice()
                                                                    .Transition(StateMachineBuilder.Next("Terminal"))
                                                                    .Condition(StateMachineBuilder.StringEquals("$.foo", "bar")))
                                                            .Choice(StateMachineBuilder.Choice()
                                                                    .Transition(StateMachineBuilder.Next("NonTerminal"))
                                                                    .Condition(StateMachineBuilder.StringEquals("$.foo", "bar"))))
                                                     .State("Terminal", StateMachineBuilder.PassState().Transition(StateMachineBuilder.End()))
                                                     .State("NonTerminal",
                                                            StateMachineBuilder.PassState().Transition(StateMachineBuilder.Next("Cyclic")))
                                                     .State("Cyclic",
                                                            StateMachineBuilder.PassState().Transition(StateMachineBuilder.Next("NonTerminal")))));
 }
Example #10
0
 public void ChoiceStateWithPathOut_IsValid()
 {
     AssertNoCycle(
         StateMachineBuilder.StateMachine()
         .StartAt("Initial")
         .State("Initial", StateMachineBuilder.PassState()
                .Transition(StateMachineBuilder.Next("ChoiceOne")))
         .State("ChoiceOne", StateMachineBuilder.ChoiceState()
                .DefaultStateName("DefaultOne")
                .Choice(StateMachineBuilder.Choice()
                        .Transition(StateMachineBuilder.Next("ChoiceTwo"))
                        .Condition(StateMachineBuilder.StringEquals("$.foo", "bar"))))
         .State("DefaultOne", StateMachineBuilder.SucceedState())
         .State("ChoiceTwo", StateMachineBuilder.ChoiceState()
                .DefaultStateName("DefaultTwo")
                .Choice(StateMachineBuilder.Choice()
                        .Transition(StateMachineBuilder.Next("ChoiceOne"))
                        .Condition(StateMachineBuilder.StringEquals("$.foo", "bar"))))
         .State("DefaultTwo",
                StateMachineBuilder.PassState().Transition(StateMachineBuilder.Next("ChoiceTwo"))));
 }
Example #11
0
        public void SingleTaskStateWithCatchers()
        {
            var stateMachine = StateMachineBuilder.StateMachine()
                               .StartAt("InitialState")
                               .State("InitialState", StateMachineBuilder.TaskState()
                                      .Transition(StateMachineBuilder.Next("NextState"))
                                      .Resource("resource-arn")
                                      .Catchers(StateMachineBuilder.Catcher()
                                                .ErrorEquals("Foo", "Bar")
                                                .Transition(StateMachineBuilder.Next("RecoveryState"))
                                                .ResultPath("$.result-path"),
                                                StateMachineBuilder.Catcher()
                                                .CatchAll()
                                                .Transition(StateMachineBuilder.Next("OtherRecoveryState"))))
                               .State("NextState", StateMachineBuilder.SucceedState())
                               .State("RecoveryState", StateMachineBuilder.SucceedState())
                               .State("OtherRecoveryState", StateMachineBuilder.SucceedState())
                               .Build();

            AssertStateMachine(stateMachine, "SimpleTaskStateWithCatchers.json");
        }
Example #12
0
        public void SimpleMapState()
        {
            var stateMachine = StateMachineBuilder.StateMachine()
                               .StartAt("Validate-All")
                               .State("Validate-All", StateMachineBuilder.MapState()
                                      .InputPath("$.detail")
                                      .ItemPath("$.shipped")
                                      .ResultPath("$.detail.shipped")
                                      .MaxConcurrency(0)
                                      .Parameters(JObject.FromObject(new { value = "param" }))
                                      .ResultSelector(JObject.FromObject(new { value = "param" }))
                                      .Transition(StateMachineBuilder.End())
                                      .Iterator(StateMachineBuilder.SubStateMachine()
                                                .StartAt("Validate")
                                                .State("Validate", StateMachineBuilder.TaskState()
                                                       .Resource("arn:aws:lambda:us-east-1:123456789012:function:ship-val")
                                                       .Transition(StateMachineBuilder.End()))))
                               .Build();

            AssertStateMachine(stateMachine, "SimpleMapState.json");
        }
Example #13
0
        public void ChoiceStateWithComplexCondition()
        {
            var stateMachine = StateMachineBuilder.StateMachine()
                               .StartAt("InitialState")
                               .State("InitialState", StateMachineBuilder.ChoiceState()
                                      .DefaultStateName("DefaultState")
                                      .Choice(StateMachineBuilder.Choice().Transition(StateMachineBuilder.Next("NextState"))
                                              .Condition(StateMachineBuilder.And(
                                                             StateMachineBuilder.StringGreaterThanEquals("$.var", "value"),
                                                             StateMachineBuilder.StringLessThanEquals("$.other-var", "foo"),
                                                             StateMachineBuilder.Or(
                                                                 StateMachineBuilder.NumericLessThan("$.numeric", 9000.1),
                                                                 StateMachineBuilder.Not(StateMachineBuilder.NumericGreaterThanEquals("$.numeric", 42))
                                                                 )
                                                             ))))
                               .State("NextState", StateMachineBuilder.SucceedState())
                               .State("DefaultState", StateMachineBuilder.SucceedState())
                               .Build();

            AssertStateMachine(stateMachine, "ChoiceStateWithComplexCondition.json");
        }
Example #14
0
 public void ParallelState_WithChoiceThatHasNoTerminalPath_IsNotValid()
 {
     Assert.Throws <ValidationException>(() =>
                                         AssertDoesNotHaveTerminalPath(
                                             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
                                                                               .Next("Choice")))))));
 }
Example #15
0
        public void SingleTaskStateWithRetries()
        {
            var stateMachine = StateMachineBuilder.StateMachine()
                               .StartAt("InitialState")
                               .State("InitialState", StateMachineBuilder.TaskState()
                                      .Transition(StateMachineBuilder.Next("NextState"))
                                      .Resource("resource-arn")
                                      .Retriers(StateMachineBuilder.Retrier()
                                                .ErrorEquals("Foo", "Bar")
                                                .IntervalSeconds(20)
                                                .MaxAttempts(3)
                                                .BackoffRate(2.0),
                                                StateMachineBuilder.Retrier()
                                                .RetryOnAllErrors()
                                                .IntervalSeconds(30)
                                                .MaxAttempts(10)
                                                .BackoffRate(2.0)))
                               .State("NextState", StateMachineBuilder.SucceedState())
                               .Build();

            AssertStateMachine(stateMachine, "SimpleTaskStateWithRetries.json");
        }
Example #16
0
        public void ChoiceStateWithAllPrimitiveConditions()
        {
            var date         = DateTime.Parse("2016-03-14T01:59:00.000Z").ToUniversalTime();
            var stateMachine = StateMachineBuilder.StateMachine()
                               .StartAt("InitialState")
                               .State("InitialState", StateMachineBuilder.ChoiceState()
                                      .DefaultStateName("DefaultState")
                                      .Choice(StateMachineBuilder.Choice().Transition(StateMachineBuilder.Next("NextState"))
                                              .Condition(StateMachineBuilder.And(
                                                             StateMachineBuilder.StringEquals("$.string", "value"),
                                                             StateMachineBuilder.StringGreaterThan("$.string", "value"),
                                                             StateMachineBuilder.StringGreaterThanEquals("$.string", "value"),
                                                             StateMachineBuilder.StringLessThan("$.string", "value"),
                                                             StateMachineBuilder.StringLessThanEquals("$.string", "value"),
                                                             StateMachineBuilder.NumericEquals("$.integral", 42),
                                                             StateMachineBuilder.NumericGreaterThan("$.integral", 42),
                                                             StateMachineBuilder.NumericGreaterThanEquals("$.integral", 42),
                                                             StateMachineBuilder.NumericLessThan("$.integral", 42),
                                                             StateMachineBuilder.NumericLessThanEquals("$.integral", 42),
                                                             StateMachineBuilder.NumericEquals("$.double", 9000.1),
                                                             StateMachineBuilder.NumericGreaterThan("$.double", 9000.1),
                                                             StateMachineBuilder.NumericGreaterThanEquals("$.double", 9000.1),
                                                             StateMachineBuilder.NumericLessThan("$.double", 9000.1),
                                                             StateMachineBuilder.NumericLessThanEquals("$.double", 9000.1),
                                                             StateMachineBuilder.TimestampEquals("$.timestamp", date),
                                                             StateMachineBuilder.TimestampGreaterThan("$.timestamp", date),
                                                             StateMachineBuilder.TimestampGreaterThanEquals("$.timestamp", date),
                                                             StateMachineBuilder.TimestampLessThan("$.timestamp", date),
                                                             StateMachineBuilder.TimestampLessThanEquals("$.timestamp", date),
                                                             StateMachineBuilder.BooleanEquals("$.boolean", true),
                                                             StateMachineBuilder.BooleanEquals("$.boolean", false)
                                                             ))))
                               .State("NextState", StateMachineBuilder.SucceedState())
                               .State("DefaultState", StateMachineBuilder.SucceedState())
                               .Build();

            AssertStateMachine(stateMachine, "ChoiceStateWithAllPrimitiveCondition.json");
        }
Example #17
0
 public void ChoiceStateWithOnlyCycles_IsNotValid()
 {
     Assert.Throws <ValidationException>(() =>
                                         AssertDoesNotHaveTerminalPath(StateMachineBuilder.StateMachine()
                                                                       .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.Next("Choice")))));
 }
Example #18
0
 public void NothingSet_IsNotValid()
 {
     Assert.Throws <ValidationException>(() =>
                                         StateMachineBuilder.StateMachine().Build());
 }
Example #19
0
 public void SingleTerminalState_HasNoCycle_IsValid()
 {
     AssertNoCycle(StateMachineBuilder.StateMachine()
                   .StartAt("Initial")
                   .State("Initial", StateMachineBuilder.SucceedState()));
 }
Example #20
0
 public void NoStates_IsNotValid()
 {
     Assert.Throws <ValidationException>(() =>
                                         StateMachineBuilder.StateMachine().StartAt("Foo").Build());
 }