public void TestPvmWaitState() { IPvmProcessDefinition processDefinition = new ProcessDefinitionBuilder() .CreateActivity("a") .Initial() .Behavior(new WaitState()) .Transition("b") .EndActivity() .CreateActivity("b") .Behavior(new WaitState()) .Transition("c") .EndActivity() .CreateActivity("c") .Behavior(new WaitState()) .EndActivity() .BuildProcessDefinition(); IPvmProcessInstance processInstance = processDefinition.CreateProcessInstance(); processInstance.Start(); IPvmExecution activityInstance = processInstance.FindExecution("a"); Assert.NotNull(activityInstance); activityInstance.Signal(null, null); activityInstance = processInstance.FindExecution("b"); Assert.NotNull(activityInstance); activityInstance.Signal(null, null); activityInstance = processInstance.FindExecution("c"); Assert.NotNull(activityInstance); }
protected internal virtual void HandleStartEvent(EventSubscriptionEntity eventSubscription, object payload, CommandContext commandContext) { var processDefinitionId = eventSubscription.Configuration; EnsureUtil.EnsureNotNull( "Configuration of signal start event subscription '" + eventSubscription.Id + "' contains no process definition id.", processDefinitionId); DeploymentCache deploymentCache = Context.ProcessEngineConfiguration.DeploymentCache; ProcessDefinitionEntity processDefinition = deploymentCache.FindDeployedProcessDefinitionById(processDefinitionId); if (processDefinition == null || processDefinition.Suspended) { // ignore event subscription Log.DebugIgnoringEventSubscription(eventSubscription, processDefinitionId); } else { ActivityImpl signalStartEvent = (ActivityImpl)processDefinition.FindActivity(eventSubscription.ActivityId); IPvmProcessInstance processInstance = processDefinition.CreateProcessInstanceForInitial(signalStartEvent); processInstance.Start(); } }
protected internal override void StartInstance(IActivityExecution execution, IVariableMap variables, string businessKey) { ProcessDefinitionImpl definition = CallableElementUtil.GetProcessDefinitionToCall(execution, CallableElement); IPvmProcessInstance processInstance = execution.CreateSubProcessInstance(definition, businessKey); processInstance.Start(variables); }
public virtual void TestSequence() { var verifier = new ActivityInstanceVerification(); IPvmProcessDefinition processDefinition = new ProcessDefinitionBuilder().CreateActivity("one") .Initial() .Behavior(new Automatic()) .ExecutionListener(ExecutionListenerFields.EventNameStart, verifier) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .Transition("two") .EndActivity() .CreateActivity("two") .Behavior(new Automatic()) .ExecutionListener(ExecutionListenerFields.EventNameStart, verifier) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .Transition("three") .EndActivity() .CreateActivity("three") .Behavior(new End()) .ExecutionListener(ExecutionListenerFields.EventNameStart, verifier) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .EndActivity() .BuildProcessDefinition(); IPvmProcessInstance processInstance = processDefinition.CreateProcessInstance(); processInstance.Start(); verifier.AssertStartInstanceCount(1, "one"); verifier.AssertStartInstanceCount(1, "two"); verifier.AssertStartInstanceCount(1, "three"); }
public virtual void TestWaitStateScope() { IPvmProcessDefinition processDefinition = new ProcessDefinitionBuilder().CreateActivity("start") .Initial() .Behavior(new Automatic()) .Transition("scopedWait") .EndActivity() .CreateActivity("scopedWait") .Scope() .Behavior(new WaitState()) .Transition("end") .EndActivity() .CreateActivity("end") .Behavior(new End()) .EndActivity() .BuildProcessDefinition(); IPvmProcessInstance processInstance = processDefinition.CreateProcessInstance(); processInstance.Start(); IPvmExecution execution = processInstance.FindExecution("scopedWait"); Assert.NotNull(execution); execution.Signal(null, null); Assert.AreEqual(new List <string>(), processInstance.FindActiveActivityIds()); Assert.True(processInstance.IsEnded); }
public virtual void TestStartInSubProcess() { var verifier = new ActivityInstanceVerification(); IPvmProcessDefinition processDefinition = new ProcessDefinitionBuilder().CreateActivity("start") .Initial() .Behavior(new Automatic()) .ExecutionListener(ExecutionListenerFields.EventNameStart, verifier) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .Transition("embeddedsubprocess") .EndActivity() .CreateActivity("embeddedsubprocess") .Scope() .Behavior(new EmbeddedSubProcess()) .ExecutionListener(ExecutionListenerFields.EventNameStart, verifier) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .CreateActivity("startInside") .Behavior(new Automatic()) .ExecutionListener(ExecutionListenerFields.EventNameStart, verifier) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .Transition("endInside") .EndActivity() .CreateActivity("endInside") .Behavior(new End()) .ExecutionListener(ExecutionListenerFields.EventNameStart, verifier) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .EndActivity() .Transition("end") .EndActivity() .ExecutionListener(ExecutionListenerFields.EventNameStart, verifier) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .CreateActivity("end") .Behavior(new End()) .ExecutionListener(ExecutionListenerFields.EventNameStart, verifier) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .EndActivity() .BuildProcessDefinition(); IPvmProcessInstance processInstance = ((ProcessDefinitionImpl)processDefinition).CreateProcessInstanceForInitial( (ActivityImpl)processDefinition.FindActivity("endInside")); processInstance.Start(); Assert.True(processInstance.IsEnded); verifier.AssertStartInstanceCount(0, "start"); verifier.AssertStartInstanceCount(1, "embeddedsubprocess"); verifier.AssertProcessInstanceParent("embeddedsubprocess", processInstance); verifier.AssertStartInstanceCount(0, "startInside"); verifier.AssertIsCompletingActivityInstance("endInside", 1); verifier.AssertStartInstanceCount(1, "end"); }
public virtual void TestNestedSubProcessBothNoEnd() { var verifier = new ActivityInstanceVerification(); IPvmProcessDefinition processDefinition = new ProcessDefinitionBuilder().CreateActivity("start") .Initial() .Behavior(new Automatic()) .ExecutionListener(ExecutionListenerFields.EventNameStart, verifier) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .Transition("embeddedsubprocess") .EndActivity() .CreateActivity("embeddedsubprocess") .Scope() .Behavior(new EmbeddedSubProcess()) .ExecutionListener(ExecutionListenerFields.EventNameStart, verifier) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .CreateActivity("startInside") .Behavior(new Automatic()) .ExecutionListener(ExecutionListenerFields.EventNameStart, verifier) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .Transition("nestedSubProcess") .EndActivity() .CreateActivity("nestedSubProcess") .Scope() .Behavior(new EmbeddedSubProcess()) .ExecutionListener(ExecutionListenerFields.EventNameStart, verifier) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .CreateActivity("startNestedInside") .Behavior(new Automatic()) .ExecutionListener(ExecutionListenerFields.EventNameStart, verifier) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .EndActivity() .EndActivity() .EndActivity() .BuildProcessDefinition(); IPvmProcessInstance processInstance = processDefinition.CreateProcessInstance(); processInstance.Start(); Assert.True(processInstance.IsEnded); verifier.AssertStartInstanceCount(1, "start"); verifier.AssertProcessInstanceParent("start", processInstance); verifier.AssertStartInstanceCount(1, "embeddedsubprocess"); verifier.AssertProcessInstanceParent("embeddedsubprocess", processInstance); verifier.AssertStartInstanceCount(1, "startInside"); verifier.AssertParent("startInside", "embeddedsubprocess"); verifier.AssertStartInstanceCount(1, "nestedSubProcess"); verifier.AssertParent("nestedSubProcess", "embeddedsubprocess"); verifier.AssertStartInstanceCount(1, "startNestedInside"); verifier.AssertParent("startNestedInside", "nestedSubProcess"); }
public void TestPvmDecision() { IPvmProcessDefinition processDefinition = new ProcessDefinitionBuilder() .CreateActivity("start") .Initial() .Behavior(new Automatic()) .Transition("checkCredit") .EndActivity() .CreateActivity("checkCredit") .Behavior(new Decision()) .Transition("askDaughterOut", "wow") .Transition("takeToGolf", "nice") .Transition("ignore", "default") .EndActivity() .CreateActivity("takeToGolf") .Behavior(new WaitState()) .EndActivity() .CreateActivity("askDaughterOut") .Behavior(new WaitState()) .EndActivity() .CreateActivity("ignore") .Behavior(new WaitState()) .EndActivity() .BuildProcessDefinition(); IPvmProcessInstance processInstance = processDefinition.CreateProcessInstance(); processInstance.SetVariable("creditRating", "Aaa-"); processInstance.Start(); Assert.NotNull(processInstance.FindExecution("takeToGolf")); processInstance = processDefinition.CreateProcessInstance(); processInstance.SetVariable("creditRating", "AAA+"); processInstance.Start(); Assert.NotNull(processInstance.FindExecution("askDaughterOut")); processInstance = processDefinition.CreateProcessInstance(); processInstance.SetVariable("creditRating", "bb-"); processInstance.Start(); Assert.NotNull(processInstance.FindExecution("ignore")); }
public virtual void TestSingleEndAfterParallelJoin() { var verifier = new ActivityInstanceVerification(); IPvmProcessDefinition processDefinition = new ProcessDefinitionBuilder().CreateActivity("start") .Initial() .Behavior(new Automatic()) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .Transition("fork") .EndActivity() .CreateActivity("fork") .Behavior(new ParallelGateway()) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .Transition("a1") .Transition("a2") .EndActivity() .CreateActivity("a1") .Behavior(new Automatic()) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .Transition("join") .EndActivity() .CreateActivity("a2") .Behavior(new Automatic()) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .Transition("join") .EndActivity() .CreateActivity("join") .Behavior(new ParallelGateway()) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .Transition("end") .EndActivity() .CreateActivity("end") .Behavior(new End()) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .EndActivity() .BuildProcessDefinition(); IPvmProcessInstance processInstance = processDefinition.CreateProcessInstance(); processInstance.Start(); verifier.AssertNonCompletingActivityInstance("start", 1); verifier.AssertNonCompletingActivityInstance("fork", 1); verifier.AssertNonCompletingActivityInstance("a1", 1); verifier.AssertNonCompletingActivityInstance("a2", 1); verifier.AssertNonCompletingActivityInstance("join", 2); verifier.AssertIsCompletingActivityInstance("end", 1); }
private void StartProcessInstances(IList <EventSubscriptionEntity> startSignalEventSubscriptions, IDictionary <string, ProcessDefinitionEntity> processDefinitions) { foreach (var signalStartEventSubscription in startSignalEventSubscriptions) { var processDefinition = processDefinitions.ContainsKey(signalStartEventSubscription.Id)? processDefinitions[signalStartEventSubscription.Id]:null; if (processDefinition != null) { ActivityImpl signalStartEvent = (ActivityImpl)processDefinition.FindActivity(signalStartEventSubscription.ActivityId); IPvmProcessInstance processInstance = processDefinition.CreateProcessInstanceForInitial(signalStartEvent); processInstance.Start(Builder.GetVariables()); } } }
public virtual void TestSimpleSubProcess() { var verifier = new ActivityInstanceVerification(); IPvmProcessDefinition processDefinition = new ProcessDefinitionBuilder().CreateActivity("start") .Initial() .Behavior(new Automatic()) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .Transition("embeddedsubprocess") .EndActivity() .CreateActivity("embeddedsubprocess") .Scope() .Behavior(new EmbeddedSubProcess()) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .CreateActivity("startInside") .Behavior(new Automatic()) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .Transition("endInside") .EndActivity() .CreateActivity("endInside") .Behavior(new End()) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .EndActivity() .Transition("end") .EndActivity() .CreateActivity("end") .Behavior(new End()) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .EndActivity() .BuildProcessDefinition(); IPvmProcessInstance processInstance = processDefinition.CreateProcessInstance(); processInstance.Start(); verifier.AssertNonCompletingActivityInstance("start", 1); verifier.AssertNonCompletingActivityInstance("embeddedsubprocess", 1); verifier.AssertNonCompletingActivityInstance("startInside", 1); verifier.AssertIsCompletingActivityInstance("endInside", 1); verifier.AssertIsCompletingActivityInstance("end", 1); }
public virtual void TestScopeActivity() { var verifier = new ActivityInstanceVerification(); IPvmProcessDefinition processDefinition = new ProcessDefinitionBuilder().CreateActivity("one") .Initial() .Behavior(new Automatic()) .ExecutionListener(ExecutionListenerFields.EventNameStart, verifier) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .Transition("two") .EndActivity() .CreateActivity("two") .Scope() .Behavior(new WaitState()) .ExecutionListener(ExecutionListenerFields.EventNameStart, verifier) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .Transition("three") .EndActivity() .CreateActivity("three") .Behavior(new End()) .ExecutionListener(ExecutionListenerFields.EventNameStart, verifier) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .EndActivity() .BuildProcessDefinition(); IPvmProcessInstance processInstance = processDefinition.CreateProcessInstance(); processInstance.Start(); IPvmExecution childExecution = processInstance.FindExecution("two"); var parentActivityInstanceId = ((ExecutionImpl)childExecution).ParentActivityInstanceId; Assert.AreEqual(((ExecutionImpl)processInstance).Id, parentActivityInstanceId); childExecution.Signal(null, null); verifier.AssertStartInstanceCount(1, "one"); verifier.AssertStartInstanceCount(1, "two"); verifier.AssertProcessInstanceParent("two", processInstance); verifier.AssertStartInstanceCount(1, "three"); }
public virtual void TestStartInScope() { IPvmProcessDefinition processDefinition = new ProcessDefinitionBuilder().CreateActivity("start") .Initial() .Behavior(new Automatic()) .Transition("embeddedsubprocess") .EndActivity() .CreateActivity("embeddedsubprocess") .Scope() .Behavior(new EmbeddedSubProcess()) .CreateActivity("startInside") .Behavior(new Automatic()) .Transition("endInside") .EndActivity() .CreateActivity("endInside") .Behavior(new End()) .EndActivity() .Transition("end") .EndActivity() .CreateActivity("end") .Behavior(new WaitState()) .EndActivity() .BuildProcessDefinition(); IPvmProcessInstance processInstance = ((ProcessDefinitionImpl)processDefinition).CreateProcessInstanceForInitial( (ActivityImpl)processDefinition.FindActivity("startInside")); processInstance.Start(); IList <string> expectedActiveActivityIds = new List <string>(); expectedActiveActivityIds.Add("end"); Assert.AreEqual(expectedActiveActivityIds, processInstance.FindActiveActivityIds()); }
public virtual void TestWhileLoop() { var verifier = new ActivityInstanceVerification(); var transitionVerifier = new TransitionInstanceVerifyer(); IPvmProcessDefinition processDefinition = new ProcessDefinitionBuilder().CreateActivity("start") .Initial() .Behavior(new Automatic()) .ExecutionListener(ExecutionListenerFields.EventNameStart, verifier) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .StartTransition("loop") .ExecutionListener(ExecutionListenerFields.EventNameTake, transitionVerifier) .EndTransition() .EndActivity() .CreateActivity("loop") .Behavior(new While("Count", 0, 10)) .ExecutionListener(ExecutionListenerFields.EventNameStart, verifier) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .StartTransition("one", "more") .ExecutionListener(ExecutionListenerFields.EventNameTake, transitionVerifier) .EndTransition() .StartTransition("end", "done") .ExecutionListener(ExecutionListenerFields.EventNameTake, transitionVerifier) .EndTransition() .EndActivity() .CreateActivity("one") .Behavior(new Automatic()) .ExecutionListener(ExecutionListenerFields.EventNameStart, verifier) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .Transition("two") .EndActivity() .CreateActivity("two") .Behavior(new Automatic()) .ExecutionListener(ExecutionListenerFields.EventNameStart, verifier) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .Transition("three") .EndActivity() .CreateActivity("three") .Behavior(new Automatic()) .ExecutionListener(ExecutionListenerFields.EventNameStart, verifier) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .Transition("loop") .EndActivity() .CreateActivity("end") .Behavior(new End()) .ExecutionListener(ExecutionListenerFields.EventNameStart, verifier) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .EndActivity() .BuildProcessDefinition(); IPvmProcessInstance processInstance = processDefinition.CreateProcessInstance(); processInstance.Start(); Assert.AreEqual(new List <string>(), processInstance.FindActiveActivityIds()); Assert.True(processInstance.IsEnded); verifier.AssertStartInstanceCount(1, "start"); verifier.AssertProcessInstanceParent("start", processInstance); verifier.AssertStartInstanceCount(11, "loop"); verifier.AssertProcessInstanceParent("loop", processInstance); verifier.AssertStartInstanceCount(10, "one"); verifier.AssertProcessInstanceParent("one", processInstance); verifier.AssertStartInstanceCount(10, "two"); verifier.AssertProcessInstanceParent("two", processInstance); verifier.AssertStartInstanceCount(10, "three"); verifier.AssertProcessInstanceParent("three", processInstance); verifier.AssertStartInstanceCount(1, "end"); verifier.AssertProcessInstanceParent("end", processInstance); }
public virtual void TestMultipleConcurrentEndsInsideEmbeddedSubProcessWithWaitState() { var verifier = new ActivityInstanceVerification(); IPvmProcessDefinition processDefinition = new ProcessDefinitionBuilder().CreateActivity("start") .Initial() .Behavior(new Automatic()) .ExecutionListener(ExecutionListenerFields.EventNameStart, verifier) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .Transition("embeddedsubprocess") .EndActivity() .CreateActivity("embeddedsubprocess") .Scope() .Behavior(new EmbeddedSubProcess()) .ExecutionListener(ExecutionListenerFields.EventNameStart, verifier) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .CreateActivity("startInside") .Behavior(new Automatic()) .ExecutionListener(ExecutionListenerFields.EventNameStart, verifier) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .Transition("fork") .EndActivity() .CreateActivity("fork") .Behavior(new ParallelGateway()) .ExecutionListener(ExecutionListenerFields.EventNameStart, verifier) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .Transition("endInside1") .Transition("Wait") .Transition("endInside3") .EndActivity() .CreateActivity("endInside1") .Behavior(new End()) .ExecutionListener(ExecutionListenerFields.EventNameStart, verifier) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .EndActivity() .CreateActivity("Wait") .Behavior(new WaitState()) .ExecutionListener(ExecutionListenerFields.EventNameStart, verifier) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .Transition("endInside2") .EndActivity() .CreateActivity("endInside2") .Behavior(new End()) .ExecutionListener(ExecutionListenerFields.EventNameStart, verifier) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .EndActivity() .CreateActivity("endInside3") .Behavior(new End()) .ExecutionListener(ExecutionListenerFields.EventNameStart, verifier) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .EndActivity() .Transition("end") .EndActivity() .CreateActivity("end") .Behavior(new End()) .ExecutionListener(ExecutionListenerFields.EventNameStart, verifier) .ExecutionListener(ExecutionListenerFields.EventNameEnd, verifier) .EndActivity() .BuildProcessDefinition(); IPvmProcessInstance processInstance = processDefinition.CreateProcessInstance(); processInstance.Start(); Assert.IsFalse(processInstance.IsEnded); IPvmExecution execution = processInstance.FindExecution("Wait"); execution.Signal(null, null); Assert.True(processInstance.IsEnded); verifier.AssertStartInstanceCount(1, "start"); verifier.AssertProcessInstanceParent("start", processInstance); verifier.AssertStartInstanceCount(1, "embeddedsubprocess"); verifier.AssertProcessInstanceParent("embeddedsubprocess", processInstance); verifier.AssertStartInstanceCount(1, "startInside"); verifier.AssertParent("startInside", "embeddedsubprocess"); verifier.AssertStartInstanceCount(1, "fork"); verifier.AssertParent("fork", "embeddedsubprocess"); verifier.AssertStartInstanceCount(1, "Wait"); verifier.AssertParent("Wait", "embeddedsubprocess"); verifier.AssertStartInstanceCount(1, "endInside1"); verifier.AssertParent("endInside1", "embeddedsubprocess"); verifier.AssertStartInstanceCount(1, "endInside2"); verifier.AssertParent("endInside2", "embeddedsubprocess"); verifier.AssertStartInstanceCount(1, "endInside3"); verifier.AssertParent("endInside3", "embeddedsubprocess"); verifier.AssertStartInstanceCount(1, "end"); verifier.AssertProcessInstanceParent("end", processInstance); }