コード例 #1
0
ファイル: fsm_test.go プロジェクト: ryanwalls/workflow-demo
func testDecisionTask(prevStarted int, events []*swf.HistoryEvent) *swf.PollForDecisionTaskOutput {
	d := &swf.PollForDecisionTaskOutput{
		Events:                 events,
		PreviousStartedEventId: sugar.I(prevStarted),
		StartedEventId:         sugar.I(prevStarted + len(events)),
		WorkflowExecution:      testWorkflowExecution,
		WorkflowType:           testWorkflowType,
	}
	for i, e := range d.Events {
		if e.EventId == nil {
			e.EventId = sugar.L(*d.StartedEventId - int64(i))
		}
		e.EventTimestamp = aws.Time(time.Unix(0, 0))
		d.Events[i] = e
	}
	return d
}
コード例 #2
0
ファイル: fsm_test.go プロジェクト: ryanwalls/workflow-demo
func TestFSMWhenInPreprocStateAndPreprocSuccessfullyCompletesExpectsWorkflowComplete(t *testing.T) {
	// arrange
	simulationStateManager := &simulationStateManager{}
	simulationStateManager.FSM = simulationStateManager.setupFSM()

	serializedState := &fsm.SerializedState{}
	serializedState.StateName = "preproc"
	serializedState.StateData = simulationStateManager.FSM.Serialize(testData)
	serializedState.StateVersion = 1

	markerRecordedEvent := sugar.EventFromPayload(5, &swf.MarkerRecordedEventAttributes{
		MarkerName: sugar.S(fsm.StateMarker),
		Details:    sugar.S(simulationStateManager.FSM.Serialize(serializedState)),
	})

	preprocResult := `{"CustomerId":1,"SimulationResultId":172,"S3SimulationFolder":"Customer_1/simulation172_2016-01-22","FileLocation":"Customer_1/simulation172_2016-01-22/b308147a-a73c-493f-bf10-478219419057_scanpattern.zip","ZoxFileLocation":"Customer_1/simulation172_2016-01-22/035c0f01-d53a-4b36-bbaa-21650a0e2a64_voxel.zip","CoarseZoxFileLocation":"Customer_1/simulation172_2016-01-22/035c0f01-d53a-4b36-bbaa-21650a0e2a64_voxel.zip","MediumZoxFileLocation":"Customer_1/simulation172_2016-01-22/035c0f01-d53a-4b36-bbaa-21650a0e2a64_voxel.zip","FineZoxFileLocation":"Customer_1/simulation172_2016-01-22/035c0f01-d53a-4b36-bbaa-21650a0e2a64_voxel.zip","sizeX":0.001,"sizeY":0.001,"sizeZ":0.001}`
	events := []*swf.HistoryEvent{
		&swf.HistoryEvent{EventType: sugar.S("DecisionTaskStarted"), EventId: sugar.I(9)},
		&swf.HistoryEvent{EventType: sugar.S("DecisionTaskScheduled"), EventId: sugar.I(8)},
		sugar.EventFromPayload(7, &swf.ActivityTaskCompletedEventAttributes{
			ScheduledEventId: sugar.I(6),
			Result:           sugar.S(preprocResult),
		}),
		sugar.EventFromPayload(6, &swf.ActivityTaskScheduledEventAttributes{
			ActivityId:   sugar.S(testActivityInfo.ActivityId),
			ActivityType: testActivityInfo.ActivityType,
		}),
		markerRecordedEvent,
	}
	first := testDecisionTask(5, events)

	// act
	_, decisions, _, err := simulationStateManager.Tick(first)

	// assert
	assert.Nil(t, err, "Should be no errors")
	assert.NotNil(t, decisions, "Should have returned some decisions")
	assert.True(t, Find(decisions, workflowCompletedPredicate), "Should have completed the workflow")
	workflowCopmletedDecision := FindDecision(decisions, workflowCompletedPredicate)
	assert.Equal(t, preprocResult, *workflowCopmletedDecision.CompleteWorkflowExecutionDecisionAttributes.Result, "Should have passed the result from preproc onto next decision")
}
コード例 #3
0
ファイル: fsm_test.go プロジェクト: ryanwalls/workflow-demo
func TestFSMWhenStartingNewWorkflowExpectsPreprocScheduled(t *testing.T) {
	// arrange
	// {"CustomerId": 1, "SimulationResultId": 172, "S3SimulationFolder": "Customer_1/simulation172_2016-01-22"}

	simulationStateManager := &simulationStateManager{}
	simulationStateManager.FSM = simulationStateManager.setupFSM()
	events := []*swf.HistoryEvent{
		&swf.HistoryEvent{EventType: sugar.S("DecisionTaskStarted"), EventId: sugar.I(3)},
		&swf.HistoryEvent{EventType: sugar.S("DecisionTaskScheduled"), EventId: sugar.I(2)},
		sugar.EventFromPayload(1, &swf.WorkflowExecutionStartedEventAttributes{
			Input: fsm.StartFSMWorkflowInput(simulationStateManager.FSM, testData),
		}),
	}
	firstDecisionTask := testDecisionTask(0, events)

	// act
	_, decisions, _, err := simulationStateManager.Tick(firstDecisionTask)

	// assert
	assert.Nil(t, err, "Should be no errors")
	assert.NotNil(t, decisions, "Should have returned some decisions")
	assert.True(t, Find(decisions, scheduleActivityPredicateFunc("preproc")), "Should have scheduled preproc")
}
コード例 #4
0
ファイル: fsm_test.go プロジェクト: ryanwalls/workflow-demo
func TestFSMWhenInPreprocStateAndPreprocFailsExpectsWorkflowFailed(t *testing.T) {
	// arrange
	simulationStateManager := &simulationStateManager{}
	simulationStateManager.FSM = simulationStateManager.setupFSM()

	serializedState := &fsm.SerializedState{}
	serializedState.StateName = "preproc"
	serializedState.StateData = simulationStateManager.FSM.Serialize(testData)
	serializedState.StateVersion = 1

	markerRecordedEvent := sugar.EventFromPayload(5, &swf.MarkerRecordedEventAttributes{
		MarkerName: sugar.S(fsm.StateMarker),
		Details:    sugar.S(simulationStateManager.FSM.Serialize(serializedState)),
	})

	events := []*swf.HistoryEvent{
		&swf.HistoryEvent{EventType: sugar.S("DecisionTaskStarted"), EventId: sugar.I(9)},
		&swf.HistoryEvent{EventType: sugar.S("DecisionTaskScheduled"), EventId: sugar.I(8)},
		sugar.EventFromPayload(7, &swf.ActivityTaskFailedEventAttributes{
			ScheduledEventId: sugar.I(6),
		}),
		sugar.EventFromPayload(6, &swf.ActivityTaskScheduledEventAttributes{
			ActivityId:   sugar.S(testActivityInfo.ActivityId),
			ActivityType: testActivityInfo.ActivityType,
		}),
		markerRecordedEvent,
	}
	first := testDecisionTask(5, events)

	// act
	_, decisions, _, err := simulationStateManager.Tick(first)

	// assert
	assert.Nil(t, err, "Should be no errors")
	assert.NotNil(t, decisions, "Should have returned some decisions")
	assert.True(t, Find(decisions, workflowCancelledPredicate), "Should have failed the workflow because preproc failed")
}
コード例 #5
0
ファイル: fsm_test.go プロジェクト: ryanwalls/workflow-demo
func DecisionsToEvents(decisions []*swf.Decision) []*swf.HistoryEvent {
	var events []*swf.HistoryEvent
	for _, d := range decisions {
		if scheduleActivityPredicate(d) {
			event := &swf.HistoryEvent{
				EventType: sugar.S("ActivityTaskCompleted"),
				EventId:   sugar.I(7),
				ActivityTaskCompletedEventAttributes: &swf.ActivityTaskCompletedEventAttributes{
					ScheduledEventId: sugar.I(6),
				},
			}
			events = append(events, event)
			event = &swf.HistoryEvent{
				EventType: sugar.S("ActivityTaskScheduled"),
				EventId:   sugar.I(6),
				ActivityTaskScheduledEventAttributes: &swf.ActivityTaskScheduledEventAttributes{
					ActivityId:   sugar.S(testActivityInfo.ActivityId),
					ActivityType: testActivityInfo.ActivityType,
				},
			}
			events = append(events, event)
		}
		if stateMarkerPredicate(d) {
			event := &swf.HistoryEvent{
				EventType: sugar.S("MarkerRecorded"),
				EventId:   sugar.I(5),
				MarkerRecordedEventAttributes: &swf.MarkerRecordedEventAttributes{
					MarkerName: sugar.S(fsm.StateMarker),
					Details:    d.RecordMarkerDecisionAttributes.Details,
				},
			}
			events = append(events, event)

		}
	}
	return events
}
コード例 #6
0
ファイル: deciders_test.go プロジェクト: lstoll/swfsm
func testContextWithSignal(scheduledEventId int, event *swf.SignalExternalWorkflowExecutionInitiatedEventAttributes) func() *FSMContext {
	return func() *FSMContext {
		correlator := &EventCorrelator{}
		correlator.Track(&swf.HistoryEvent{
			EventId:   s.I(scheduledEventId),
			EventType: s.S(swf.EventTypeSignalExternalWorkflowExecutionInitiated),
			SignalExternalWorkflowExecutionInitiatedEventAttributes: event,
		})

		return NewFSMContext(nil,
			swf.WorkflowType{Name: s.S("foo"), Version: s.S("1")},
			swf.WorkflowExecution{WorkflowId: s.S("id"), RunId: s.S("runid")},
			correlator, "state", nil, 1)
	}
}