public void PersistInCatch() { TestBlockingActivity blocking = new TestBlockingActivity("Bookmark"); TestTryCatch tcf = new TestTryCatch { Try = new TestThrow <Exception>() { ExpectedOutcome = Outcome.CaughtException() }, Catches = { { new TestCatch <Exception> { Body = blocking } } } }; JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(tcf, null, jsonStore, PersistableIdleAction.None)) { testWorkflowRuntime.ExecuteWorkflow(); testWorkflowRuntime.WaitForActivityStatusChange(blocking.DisplayName, TestActivityInstanceState.Executing); testWorkflowRuntime.PersistWorkflow(); testWorkflowRuntime.ResumeBookMark("Bookmark", null); testWorkflowRuntime.WaitForCompletion(); } }
public void PersistAfterCatchBeforeRethrow() { TestTryCatch root = new TestTryCatch("parent TryCatch") { Try = new TestSequence { Activities = { new TestProductWriteline("W1"), new TestThrow <TAC.ApplicationException> { ExceptionExpression = (context => new TAC.ApplicationException("abcd")), ExpectedOutcome = Outcome.CaughtException(typeof(TAC.ApplicationException)), } } }, Catches = { new TestCatch <TAC.ApplicationException> { Body = new TestSequence { Activities = { new TestBlockingActivity("Blocking1", "B1"), new TestRethrow { ExpectedOutcome = Outcome.UncaughtException(typeof(TAC.ApplicationException)), } } } } } }; JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(root, null, jsonStore, CoreWf.PersistableIdleAction.None)) { testWorkflowRuntime.ExecuteWorkflow(); testWorkflowRuntime.WaitForActivityStatusChange("Blocking1", TestActivityInstanceState.Executing); testWorkflowRuntime.PersistWorkflow(); testWorkflowRuntime.ResumeBookMark("Blocking1", null); Exception resultedException; testWorkflowRuntime.WaitForAborted(out resultedException); if (!(resultedException is TAC.ApplicationException)) { throw resultedException; } } }
public static void PersistAndUpdate(this TestWorkflowRuntime twRuntime, WorkflowIdentity updatedIdentity) { twRuntime.PersistWorkflow(); twRuntime.UnloadWorkflow(); if (null != updatedIdentity) { twRuntime.LoadAndUpdateWorkflow(updatedIdentity.ToString()); } else { twRuntime.LoadWorkflow(); } twRuntime.ResumeWorkflow(); }
public void TestAbortLoad() { Variable <int> value = VariableHelper.Create <int>("value"); TestSequence sequence = new TestSequence() { Variables = { value }, Activities = { new TestAssign <int>() { ToVariable = value, Value = 100 }, new TestPersist(), new TestReadLine <int>("Read", "Read") { BookmarkValue = value }, new TestWriteLine("AfterAbort") { MessageExpression = (env) => value.Get(env).ToString(), HintMessage = "9999" } } }; JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(sequence, null, jsonStore, PersistableIdleAction.Persist); runtime.ExecuteWorkflow(); runtime.WaitForActivityStatusChange("Read", TestActivityInstanceState.Executing); runtime.PersistWorkflow(); runtime.AbortWorkflow("Abort Workflow"); //Wait Sometime to Handle to free Thread.CurrentThread.Join((int)TimeSpan.FromSeconds(4).TotalMilliseconds); //Load Workflow from Last Persistence Point runtime.LoadWorkflow(); runtime.ResumeBookMark("Read", 9999); runtime.WaitForActivityStatusChange("AfterAbort", TestActivityInstanceState.Closed); //Wait for the second completion trace TestTraceManager.Instance.WaitForTrace(runtime.CurrentWorkflowInstanceId, new SynchronizeTrace(RemoteWorkflowRuntime.CompletedOrAbortedHandlerCalled), 1); //Call Abort on Completed Workflow, this should not throw exception runtime.AbortWorkflow("Abort on Completed Workflow"); }
public void PersistInTry() { TestBlockingActivity blocking = new TestBlockingActivity("Bookmark"); TestTryCatch tryCatch = new TestTryCatch("TryCatchTest") { Try = new TestSequence("TrySeq") { Activities = { blocking, new TestThrow <ArgumentException>("TryException") { ExpectedOutcome = Outcome.CaughtException() }, }, }, Catches = { new TestCatch <ArgumentException>() { Body = new TestWriteLine("Caught", "Caught") } }, Finally = new TestWriteLine("Finally", "Finally") }; JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(tryCatch, null, jsonStore, PersistableIdleAction.None)) { testWorkflowRuntime.ExecuteWorkflow(); testWorkflowRuntime.WaitForActivityStatusChange(blocking.DisplayName, TestActivityInstanceState.Executing); testWorkflowRuntime.PersistWorkflow(); testWorkflowRuntime.ResumeBookMark("Bookmark", null); testWorkflowRuntime.WaitForCompletion(); } }
public void IfInWhileWithPersistence() { // Test case description: // Above scenario with persistence to see if there will be any change in the behavior and if we are able // tp preserve the state and the rules fine. Variable <int> count = new Variable <int> { Name = "Counter", Default = 0 }; TestWhile whileAct = new TestWhile { Variables = { count }, Body = new TestSequence { Activities = { new TestIf(HintThenOrElse.Then) { Condition = true, ThenActivity = new TestBlockingActivity("Bookmark"), }, new TestIncrement { CounterVariable = count, IncrementCount = 1 } } }, ConditionExpression = (e => count.Get(e) < 1), HintIterationCount = 1 }; JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); using (TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(whileAct, null, jsonStore, PersistableIdleAction.None)) { runtime.ExecuteWorkflow(); runtime.WaitForIdle(); runtime.PersistWorkflow(); runtime.ResumeBookMark("Bookmark", null); runtime.WaitForCompletion(); } }
public void DoWhilePersisted() { Variable <int> counter = new Variable <int>("Counter", 0); TestBlockingActivity blocking = new TestBlockingActivity("B"); TestDoWhile doWhile = new TestDoWhile { Variables = { counter }, ConditionExpression = (env) => counter.Get(env) < 1, Body = new TestSequence { Activities = { blocking, new TestIncrement { IncrementCount = 1, CounterVariable = counter } } }, HintIterationCount = 1 }; JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); using (TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(doWhile, null, jsonStore, PersistableIdleAction.None)) { runtime.ExecuteWorkflow(); runtime.WaitForActivityStatusChange(blocking.DisplayName, TestActivityInstanceState.Executing); runtime.PersistWorkflow(); runtime.ResumeBookMark("B", null); runtime.WaitForCompletion(); } }
public void WhilePersisted() { Variable <int> count = new Variable <int> { Name = "Counter", Default = 0 }; TestWhile whileAct = new TestWhile { Variables = { count }, Body = new TestSequence { Activities = { new TestBlockingActivity("Bookmark"), new TestIncrement { CounterVariable = count, IncrementCount= 1 } } }, ConditionExpression = (e => count.Get(e) < 1), HintIterationCount = 1 }; JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); using (TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(whileAct, null, jsonStore, PersistableIdleAction.None)) { runtime.ExecuteWorkflow(); runtime.WaitForIdle(); runtime.PersistWorkflow(); runtime.ResumeBookMark("Bookmark", null); runtime.WaitForCompletion(); } }
public static void TestResumeWithDelay() { var testSequence = new TestSequence() { Activities = { new TestDelay() { Duration = TimeSpan.FromMilliseconds(100) }, } }; JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); TestWorkflowRuntime workflowRuntime = TestRuntime.CreateTestWorkflowRuntime(testSequence, null, jsonStore, PersistableIdleAction.Unload); workflowRuntime.ExecuteWorkflow(); workflowRuntime.PersistWorkflow(); workflowRuntime.WaitForUnloaded(); workflowRuntime.LoadWorkflow(); workflowRuntime.ResumeWorkflow(); workflowRuntime.WaitForCompletion(false); }
public void CancelSequenceInTheMiddle() { TestSequence seq = new TestSequence { Activities = { new TestWriteLine("W1", "I should be printed"), new TestBlockingActivity("BookMark1") { ExpectedOutcome = Outcome.Canceled }, new TestWriteLine("W2", "I should not be printed") { ExpectedOutcome = Outcome.Canceled }, new TestWriteLine("W3", "I should not be printed") { ExpectedOutcome = Outcome.Canceled }, } }; JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); using (TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(seq, null, jsonStore, PersistableIdleAction.None)) { runtime.ExecuteWorkflow(); runtime.WaitForIdle(); runtime.PersistWorkflow(); runtime.CancelWorkflow(); runtime.WaitForCanceled(); } }
public static void TestPersistDuringResumeBookmark() { bool isSync = true; Variable <int> value = VariableHelper.Create <int>("value"); Variable <string> persist = VariableHelper.Create <string>("persist"); const string WaitMessage = "Continue the WaitActivity"; TestSequence testSequence = new TestSequence() { Variables = { value, persist }, Activities = { new TestWriteLine() { Message = "Workflow Started" }, new TestWaitForTrace() { DisplayName = "WaitActivity", TraceToWait = WaitMessage, DelayDuration = TimeSpan.FromMilliseconds(10) }, new TestWaitReadLine <int>("Read", "Read") { BookmarkValue = value, WaitTime = TimeSpan.FromSeconds(1) }, new TestReadLine <string>("PersistBookmark", "PersistBookmark") { BookmarkValue = persist }, new TestWriteLine() { MessageExpression = ((env) => value.Get(env).ToString()), HintMessage = "9999" } } }; JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); TestWorkflowRuntime workflowRuntime = TestRuntime.CreateTestWorkflowRuntime(testSequence, null, jsonStore, PersistableIdleAction.Unload); workflowRuntime.ExecuteWorkflow(); workflowRuntime.WaitForActivityStatusChange("WaitActivity", TestActivityInstanceState.Executing); TestTraceManager.Instance.AddTrace(workflowRuntime.CurrentWorkflowInstanceId, new SynchronizeTrace(WaitMessage)); SynchronizeTrace.Trace(workflowRuntime.CurrentWorkflowInstanceId, WaitMessage); if (isSync) { workflowRuntime.ResumeBookMark("Read", 9999); workflowRuntime.PersistWorkflow(); } else { TestWorkflowRuntimeAsyncResult asyncResultResume = workflowRuntime.BeginResumeBookMark("Read", 9999, null, null); TestWorkflowRuntimeAsyncResult asyncResultPersist = workflowRuntime.BeginPersistWorkflow(null, null); workflowRuntime.EndResumeBookMark(asyncResultResume); workflowRuntime.EndPersistWorkflow(asyncResultPersist); } workflowRuntime.WaitForActivityStatusChange("PersistBookmark", TestActivityInstanceState.Executing); workflowRuntime.WaitForUnloaded(1); workflowRuntime.LoadWorkflow(); workflowRuntime.ResumeBookMark("PersistBookmark", "Yes"); workflowRuntime.WaitForCompletion(false); }
public void PersistParallelForEach() { DelegateInArgument <string> _currentVariable = new DelegateInArgument <string>() { Name = "_currentVariable" }; TestParallelForEach <string> parallelForEach = new TestParallelForEach <string>("Parallel for each") { HintValues = new string[] { "Hi", "There" }, ValuesExpression = (context => new string[] { "Hi", "There" }), CurrentVariable = _currentVariable, Body = new TestSequence("Sequence") { Activities = { new TestWriteLine("Writeline") { Message = "Hi" }, new TestSequence("inner seq") { Activities = { new TestIf(HintThenOrElse.Else, HintThenOrElse.Then) { DisplayName = "Test if", ConditionExpression = (env) => (bool)(_currentVariable.Get(env).Equals("Hi")), ThenActivity = new TestBlockingActivity("Block Hi"), ElseActivity = new TestBlockingActivity("Block There") } } }, new TestWriteLine("Writeline act") { Message = "After blocking activty" }, } } }; JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(parallelForEach, null, jsonStore, PersistableIdleAction.None)) { testWorkflowRuntime.ExecuteWorkflow(); testWorkflowRuntime.WaitForActivityStatusChange("Block Hi", TestActivityInstanceState.Executing); testWorkflowRuntime.PersistWorkflow(); System.Threading.Thread.Sleep(2000); testWorkflowRuntime.ResumeBookMark("Block Hi", null); testWorkflowRuntime.WaitForActivityStatusChange("Block There", TestActivityInstanceState.Executing); testWorkflowRuntime.PersistWorkflow(); System.Threading.Thread.Sleep(2000); testWorkflowRuntime.ResumeBookMark("Block There", null); testWorkflowRuntime.WaitForCompletion(); } }