class CompleteWorkflowStateMachineTest(TestCase): def setUp(self) -> None: self.decision_id = DecisionId(DecisionTarget.SELF, 256) self.decision = Decision() self.state_machine = CompleteWorkflowStateMachine( self.decision_id, self.decision) def test_get_id(self): self.assertIs(self.decision_id, self.state_machine.get_id()) def test_get_decision(self): self.assertIs(self.decision, self.state_machine.get_decision()) def test_handle_initiation_failed_event(self): self.state_machine.handle_initiation_failed_event(HistoryEvent()) self.assertIsNone(self.state_machine.get_decision()) def test_get_state(self): self.assertEqual(DecisionState.CREATED, self.state_machine.get_state()) def test_is_done(self): self.assertTrue(self.state_machine.is_done()) def test_handle_decision_tast_started_event(self): self.state_machine.handle_decision_task_started_event()
def cancel_workflow_execution(self): logger.info("Canceling workflow: %s", self.execution_id) decision = Decision() attr = CancelWorkflowExecutionDecisionAttributes() attr.details = None decision.cancel_workflow_execution_decision_attributes = attr decision.decision_type = DecisionType.CancelWorkflowExecution decision_id = DecisionId(DecisionTarget.SELF, 0) self.add_decision(decision_id, CompleteWorkflowStateMachine(decision_id, decision)) self.completed = True
def complete_workflow_execution(self, ret_value): # PORT: addAllMissingVersionMarker(false, Optional.empty()); decision = Decision() attr = CompleteWorkflowExecutionDecisionAttributes() attr.result = json.dumps(ret_value) decision.complete_workflow_execution_decision_attributes = attr decision.decision_type = DecisionType.CompleteWorkflowExecution decision_id = DecisionId(DecisionTarget.SELF, 0) self.add_decision(decision_id, CompleteWorkflowStateMachine(decision_id, decision)) self.completed = True
def fail_workflow_execution(self, exception): # PORT: addAllMissingVersionMarker(false, Optional.empty()); decision = Decision() fail_attributes = FailWorkflowExecutionDecisionAttributes() fail_attributes.reason = "WorkflowFailureException" fail_attributes.details = serialize_exception(exception) decision.fail_workflow_execution_decision_attributes = fail_attributes decision.decision_type = DecisionType.FailWorkflowExecution decision_id = DecisionId(DecisionTarget.SELF, 0) self.add_decision(decision_id, CompleteWorkflowStateMachine(decision_id, decision)) self.completed = True
def setUp(self) -> None: self.decision_id = DecisionId(DecisionTarget.SELF, 256) self.decision = Decision() self.state_machine = CompleteWorkflowStateMachine( self.decision_id, self.decision)