private static WorkflowApplicationInstance GetADummyWorkflowApplicationInstance() { WorkflowIdentity wfIdentity = new WorkflowIdentity("GetAWorkflowApplicationInstanceParameter", new Version(1, 0), null); TestSequence wfDefinition = new TestSequence() { Activities = { new TestWriteLine("testWriteLine1", "In TestWriteLine1"), new TestReadLine <string>("ReadLine1", "testReadLine1"), new TestWriteLine("testWriteLine2", "In TestWriteLine2") }, }; WorkflowApplicationInstance waInstance; JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); using (TestWorkflowRuntime workflowRuntime = TestRuntime.CreateTestWorkflowRuntime(wfDefinition, null, jsonStore, PersistableIdleAction.Unload)) { //PersistenceProviderHelper pphelper = new PersistenceProviderHelper(workflowRuntime.PersistenceProviderFactoryType); //InstanceStore store = pphelper.CreateWorkflowInstanceStore(); workflowRuntime.ExecuteWorkflow(); workflowRuntime.WaitForIdle(); workflowRuntime.UnloadWorkflow(); workflowRuntime.WaitForUnloaded(); Guid worklfowInstanceId = workflowRuntime.CurrentWorkflowInstanceId; waInstance = WorkflowApplication.GetInstance(worklfowInstanceId, jsonStore); waInstance.Abandon(); } return(waInstance); }
public void UnloadFlowchartWhileExecutingFlowStep() { TestFlowchart flowchart = new TestFlowchart(); TestBlockingActivity blocking = new TestBlockingActivity("Block"); flowchart.AddStartLink(blocking); JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(flowchart, null, jsonStore, PersistableIdleAction.Unload)) { testWorkflowRuntime.ExecuteWorkflow(); testWorkflowRuntime.WaitForActivityStatusChange(blocking.DisplayName, TestActivityInstanceState.Executing); testWorkflowRuntime.UnloadWorkflow(); testWorkflowRuntime.LoadWorkflow(); testWorkflowRuntime.ResumeBookMark("Block", null); testWorkflowRuntime.WaitForCompletion(); } }
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 UnloadFlowchartWhileExecutingFlowSwitchExpression() { TestFlowchart flowchart = new TestFlowchart(); TestWriteLine writeHello = new TestWriteLine("Hello", "Hello"); TestWriteLine writeStart = new TestWriteLine("Start", "Start"); TestExpressionEvaluatorWithBody <object> expressionActivity = new TestExpressionEvaluatorWithBody <object> { ExpressionResultExpression = context => "One", Body = new TestBlockingActivity("Block"), WillBodyExecute = true }; Dictionary <object, TestActivity> cases = new Dictionary <object, TestActivity>(); cases.Add("One", writeHello); cases.Add("Two", new TestWriteLine("Two", "Two will not execute")); List <int> hints = new List <int>() { 0 }; flowchart.AddStartLink(writeStart); flowchart.AddSwitchLink(writeStart, cases, hints, expressionActivity, new TestWriteLine("Default", "Will not execute")); JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(flowchart, null, jsonStore, PersistableIdleAction.Unload)) { testWorkflowRuntime.ExecuteWorkflow(); testWorkflowRuntime.WaitForActivityStatusChange(expressionActivity.DisplayName, TestActivityInstanceState.Executing); testWorkflowRuntime.UnloadWorkflow(); testWorkflowRuntime.LoadWorkflow(); testWorkflowRuntime.ResumeBookMark("Block", null); testWorkflowRuntime.WaitForCompletion(); } }
public void UnloadFlowchartWhileExecutingFlowConditionalCondition() { TestFlowchart flowchart = new TestFlowchart(); TestExpressionEvaluatorWithBody <bool> expression = new TestExpressionEvaluatorWithBody <bool>(true) { Body = new TestBlockingActivity("Block"), WillBodyExecute = true }; TestFlowConditional conditional = new TestFlowConditional(HintTrueFalse.True) { ConditionValueExpression = expression }; flowchart.AddConditionalLink(new TestWriteLine("Start", "Flowchart started"), conditional, new TestWriteLine("True", "True Action"), new TestWriteLine("False", "False Action")); JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(System.Environment.CurrentDirectory); using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(flowchart, null, jsonStore, PersistableIdleAction.Unload)) { testWorkflowRuntime.ExecuteWorkflow(); testWorkflowRuntime.WaitForActivityStatusChange(expression.DisplayName, TestActivityInstanceState.Executing); //testWorkflowRuntime.PersistWorkflow(); testWorkflowRuntime.UnloadWorkflow(); testWorkflowRuntime.LoadWorkflow(); testWorkflowRuntime.ResumeBookMark("Block", null); testWorkflowRuntime.WaitForCompletion(true); } }
public static void TestOperationsResumeBookmarkCallback(int operationId) { Variable <int> value = VariableHelper.Create <int>("value"); const string WaitMessage = "WaitActivity will wait for this trace"; TestSequence testSequence = new TestSequence() { Variables = { value }, Activities = { new TestWriteLine() { Message = "Workflow Started" }, new TestWaitForTrace() { DisplayName = "WaitActivity", TraceToWait = WaitMessage }, new TestWaitReadLine <int>("Read", "Read") { BookmarkValue = value }, new TestReadLine <int>("Read1", "Read1") { BookmarkValue = value }, new TestWriteLine() { Message = "Workflow Completed" } } }; JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); TestWorkflowRuntime workflowRuntime = TestRuntime.CreateTestWorkflowRuntime(testSequence, null, jsonStore, PersistableIdleAction.Unload); workflowRuntime.ExecuteWorkflow(); workflowRuntime.WaitForActivityStatusChange("WaitActivity", TestActivityInstanceState.Executing); TestWorkflowRuntimeAsyncResult asyncResult = workflowRuntime.BeginResumeBookMark("Read", 10, new AsyncCallback(ResumeBookmarkCallback), operationId); //Continue the WaitActivity TestTraceManager.Instance.AddTrace(workflowRuntime.CurrentWorkflowInstanceId, new SynchronizeTrace(WaitMessage)); SynchronizeTrace.Trace(workflowRuntime.CurrentWorkflowInstanceId, WaitMessage); workflowRuntime.EndResumeBookMark(asyncResult); workflowRuntime.WaitForTrace(new UserTrace("After ResumeBookmarkCallback")); if (operationId == 2) { //Do nothing } else if (operationId == 3) { workflowRuntime.UnloadWorkflow(); workflowRuntime.LoadWorkflow(); workflowRuntime.ExecuteWorkflow(); workflowRuntime.ResumeBookMark("Read1", 99); } else if (operationId == 4) { workflowRuntime.LoadWorkflow(); workflowRuntime.ExecuteWorkflow(); workflowRuntime.ResumeBookMark("Read1", 99); } ExpectedTrace expectedTrace = testSequence.GetExpectedTrace(); expectedTrace.AddIgnoreTypes(typeof(UserTrace)); workflowRuntime.WaitForCompletion(expectedTrace); }
private static void TestInstanceOperationFromResumeBookmarkCallback(int operationsId, bool isSync) { string shouldNotExecuteMsg = "Should not see this message"; Variable <int> value = VariableHelper.Create <int>("value"); TestWriteLine writeLineNotRun = new TestWriteLine("NotExecuted", shouldNotExecuteMsg) { }; TestSequence testSequence = new TestSequence() { Variables = { value }, Activities = { new TestWriteLine() { Message = "Workflow Started" }, new TestWaitReadLine <int>("Read", "Read") { BookmarkValue = value }, } }; //Get Expected Trace without TestWriteLine() if (operationsId == 2) { testSequence.ExpectedOutcome = Outcome.Canceled; } ExpectedTrace expectedTrace = testSequence.GetExpectedTrace(); if (operationsId == 4) { expectedTrace.Trace.Steps.RemoveAt(expectedTrace.Trace.Steps.Count - 1); } else if (operationsId == 3) { expectedTrace.Trace.Steps.RemoveAt(expectedTrace.Trace.Steps.Count - 1); expectedTrace.Trace.Steps.Add(new ActivityTrace(testSequence.DisplayName, ActivityInstanceState.Faulted)); } //Now Add TestWriteLine to workflow testSequence.Activities.Add(writeLineNotRun); TestWorkflowRuntimeAsyncResult asyncResultResume = null; TestWorkflowRuntimeAsyncResult asyncResultOperation = null; string message = ""; //Execute Workflow JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); // using PersistableIdleAction.None here because the idle unload was racing with the resume bookmark after the wait for the BeforeWait trace. TestWorkflowRuntime workflowRuntime = TestRuntime.CreateTestWorkflowRuntime(testSequence, null, jsonStore, PersistableIdleAction.None); workflowRuntime.ExecuteWorkflow(); workflowRuntime.WaitForActivityStatusChange("Read", TestActivityInstanceState.Executing); if (isSync) { //Log.Info("Resuming Bookmark"); if (isSync) { workflowRuntime.ResumeBookMark("Read", 9999); } else { asyncResultResume = workflowRuntime.BeginResumeBookMark("Read", 9999, null, null); } workflowRuntime.WaitForTrace(new UserTrace(WaitReadLine <int> .BeforeWait)); switch (operationsId) { case 2: //Cancel Workflow during OnResumeBookmark is executing //Log.Info("CancelWorkflow during OnResumeBookmark executing"); if (isSync) { workflowRuntime.CancelWorkflow(); } else { asyncResultOperation = workflowRuntime.BeginCancelWorkflow(null, null); workflowRuntime.EndResumeBookMark(asyncResultResume); workflowRuntime.EndCancelWorkflow(asyncResultOperation); } //Trace.WriteLine should not execute break; case 3: //Terminate Workflow during OnResumeBookmark is executing //Log.Info("TerminateWorkflow during OnResumeBookmark executing"); if (isSync) { workflowRuntime.TerminateWorkflow("Terminate Exception"); } else { asyncResultOperation = workflowRuntime.BeginTerminateWorkflow("Terminate Exception", null, null); workflowRuntime.EndResumeBookMark(asyncResultResume); workflowRuntime.EndTerminateWorkflow(asyncResultOperation); } //Trace.WriteLine should not execute. break; case 4: //Unload Workflow during OnResumeBookmark is executing //This should wait till ResumeMark finishes the work //Log.Info("UnloadWorkflow during OnResumeBookmark executing"); if (isSync) { workflowRuntime.UnloadWorkflow(); } else { asyncResultOperation = workflowRuntime.BeginUnloadWorkflow(null, null); workflowRuntime.EndResumeBookMark(asyncResultResume); workflowRuntime.EndUnloadWorkflow(asyncResultOperation); } //message = String.Format(ExceptionStrings.WorkflowInstanceUnloaded, workflowRuntime.CurrentWorkflowInstanceId); ExceptionHelpers.CheckForException(typeof(WorkflowApplicationUnloadedException), message, new ExceptionHelpers.MethodDelegate( delegate { workflowRuntime.ResumeWorkflow(); })); break; } } if (isSync) { switch (operationsId) { case 2: { workflowRuntime.WaitForCanceled(expectedTrace); break; } case 3: { Exception terminationException; workflowRuntime.WaitForTerminated(1, out terminationException, expectedTrace); break; } case 4: { // We tried to do a ResumeWorkflow without loading it after an unload, so we expected // to get a WorkflowApplicationUnloadedException. The workflow will never complete, // so don't wait for it to complete. break; } } } else { //Give some time for Workflow to execute Thread.CurrentThread.Join((int)TimeSpan.FromSeconds(1).TotalMilliseconds); } if (isSync) { expectedTrace.AddIgnoreTypes(typeof(WorkflowInstanceTrace)); workflowRuntime.ActualTrace.Validate(expectedTrace); } else { //The traces are vary in the async situations, thus we can not do a full trace valdation //validate the writeline after read activity is not executed is sufficient if (workflowRuntime.ActualTrace.ToString().Contains(shouldNotExecuteMsg)) { throw new Exception("The NotExecuted WriteLine activity has been executed, the expectation is it does not"); } } }