예제 #1
0
func TestMigrateStreams(t *testing.T) {
	if os.Getenv("AWS_ACCESS_KEY_ID") == "" || os.Getenv("AWS_SECRET_ACCESS_KEY") == "" {
		log.Printf("WARNING: NO AWS CREDS SPECIFIED, SKIPPING MIGRATIONS TEST")
		return
	}

	config := &aws.Config{
		Credentials: credentials.NewEnvCredentials(),
		Region:      "us-east-1",
	}
	client := kinesis.New(config)

	sm := StreamMigrator{
		Streams: []kinesis.CreateStreamInput{
			kinesis.CreateStreamInput{
				StreamName: aws.String(testDomain),
				ShardCount: aws.Long(1),
			},
		},
		Client:  client,
		Timeout: 30,
	}

	sm.Migrate()
	sm.Migrate()

}
예제 #2
0
파일: kms.go 프로젝트: robot0x/heim
func New(region, keyID string) (*KMS, error) {
	config := &aws.Config{
		Credentials: credentials.NewEnvCredentials(),
		Region:      region,
	}
	kms := &KMS{
		kms:   kms.New(config),
		keyID: keyID,
	}
	return kms, nil
}
예제 #3
0
func TestMigrateWorkflowTypes(t *testing.T) {
	if os.Getenv("AWS_ACCESS_KEY_ID") == "" || os.Getenv("AWS_SECRET_ACCESS_KEY") == "" {
		log.Printf("WARNING: NO AWS CREDS SPECIFIED, SKIPPING MIGRATIONS TEST")
		return
	}
	createDomain()
	config := &aws.Config{
		Credentials: credentials.NewEnvCredentials(),
		Region:      "us-east-1",
	}
	client := swf.New(config)

	workflow := fmt.Sprintf("test-workflow-%d", time.Now().UnixNano())
	version := fmt.Sprintf("test-workflow-version-%d", time.Now().UnixNano())

	req := swf.RegisterWorkflowTypeInput{
		Name:        &workflow,
		Description: aws.String("test workflow migration"),
		Version:     &version,
		Domain:      aws.String(testDomain),
	}

	w := WorkflowTypeMigrator{
		RegisteredWorkflowTypes: []swf.RegisterWorkflowTypeInput{req},
		Client:                  client,
	}

	w.Migrate()
	w.Migrate()

	dep := swf.DeprecateWorkflowTypeInput{
		WorkflowType: &swf.WorkflowType{
			Name:    aws.String(workflow),
			Version: aws.String(version),
		},
		Domain: aws.String(testDomain),
	}

	wd := WorkflowTypeMigrator{
		DeprecatedWorkflowTypes: []swf.DeprecateWorkflowTypeInput{dep},
		Client:                  client,
	}

	wd.Migrate()
	wd.Migrate()

}
예제 #4
0
func TestMigrateActivityTypes(t *testing.T) {

	if os.Getenv("AWS_ACCESS_KEY_ID") == "" || os.Getenv("AWS_SECRET_ACCESS_KEY") == "" {
		log.Printf("WARNING: NO AWS CREDS SPECIFIED, SKIPPING MIGRATIONS TEST")
		return
	}
	createDomain()
	config := &aws.Config{
		Credentials: credentials.NewEnvCredentials(),
		Region:      "us-east-1",
	}
	client := swf.New(config)
	activity := fmt.Sprintf("test-activity-%d", time.Now().UnixNano())
	version := fmt.Sprintf("test-activity-version-%d", time.Now().UnixNano())

	req := swf.RegisterActivityTypeInput{
		Name:        &activity,
		Description: aws.String("test activity migration"),
		Version:     &version,
		Domain:      aws.String(testDomain),
	}

	a := ActivityTypeMigrator{
		RegisteredActivityTypes: []swf.RegisterActivityTypeInput{req},
		Client:                  client,
	}

	a.Migrate()
	a.Migrate()

	dep := swf.DeprecateActivityTypeInput{
		ActivityType: &swf.ActivityType{
			Name:    &activity,
			Version: &version,
		},
		Domain: aws.String(testDomain),
	}

	ad := ActivityTypeMigrator{
		DeprecatedActivityTypes: []swf.DeprecateActivityTypeInput{dep},
		Client:                  client,
	}

	ad.Migrate()
	ad.Migrate()

}
예제 #5
0
func createDomain() {
	config := &aws.Config{
		Credentials: credentials.NewEnvCredentials(),
		Region:      "us-east-1",
	}
	client := swf.New(config)
	req := swf.RegisterDomainInput{
		Name:                                   aws.String(testDomain),
		Description:                            aws.String("test domain"),
		WorkflowExecutionRetentionPeriodInDays: aws.String("30"),
	}
	w := DomainMigrator{
		RegisteredDomains: []swf.RegisterDomainInput{req},
		Client:            client,
	}

	w.Migrate()
}
예제 #6
0
func TestMigrateDomains(t *testing.T) {
	if os.Getenv("AWS_ACCESS_KEY_ID") == "" || os.Getenv("AWS_SECRET_ACCESS_KEY") == "" {
		log.Printf("WARNING: NO AWS CREDS SPECIFIED, SKIPPING MIGRATIONS TEST")
		return
	}

	config := &aws.Config{
		Credentials: credentials.NewEnvCredentials(),
		Region:      "us-east-1",
	}
	client := swf.New(config)

	domain := fmt.Sprintf("test-domain-%d", time.Now().UnixNano()) //dont use the testDomain since we deprecate this one

	req := swf.RegisterDomainInput{
		Name:                                   aws.String(domain),
		Description:                            aws.String("test domain"),
		WorkflowExecutionRetentionPeriodInDays: aws.String("30"),
	}

	d := DomainMigrator{
		RegisteredDomains: []swf.RegisterDomainInput{req},
		Client:            client,
	}

	d.Migrate()
	d.Migrate()

	dep := swf.DeprecateDomainInput{
		Name: aws.String(domain),
	}

	dd := DomainMigrator{
		DeprecatedDomains: []swf.DeprecateDomainInput{dep},
		Client:            client,
	}

	dd.Migrate()
	dd.Migrate()

}
예제 #7
0
func TestClient(t *testing.T) {
	if os.Getenv("AWS_ACCESS_KEY_ID") == "" || os.Getenv("AWS_SECRET_ACCESS_KEY") == "" {
		log.Printf("WARNING: NO AWS CREDS SPECIFIED, SKIPPING MIGRATIONS TEST")
		return
	}

	config := &aws.Config{
		Credentials: credentials.NewEnvCredentials(),
		Region:      "us-east-1",
	}
	client := swf.New(config)

	req := swf.RegisterDomainInput{
		Name:                                   aws.String("client-test"),
		Description:                            aws.String("test domain"),
		WorkflowExecutionRetentionPeriodInDays: aws.String("30"),
	}

	d := migrator.DomainMigrator{
		RegisteredDomains: []swf.RegisterDomainInput{req},
		Client:            client,
	}

	d.Migrate()

	wreq := swf.RegisterWorkflowTypeInput{
		Name:        aws.String("client-test"),
		Description: aws.String("test workflow migration"),
		Version:     aws.String("1"),
		Domain:      aws.String("client-test"),
	}

	w := migrator.WorkflowTypeMigrator{
		RegisteredWorkflowTypes: []swf.RegisterWorkflowTypeInput{wreq},
		Client:                  client,
	}

	w.Migrate()

	fsm := &FSM{
		Domain:           "client-test",
		Name:             "client-test",
		DataType:         TestData{},
		Serializer:       JSONStateSerializer{},
		systemSerializer: JSONStateSerializer{},
		allowPanics:      false,
	}

	fsm.AddInitialState(&FSMState{Name: "initial",
		Decider: func(ctx *FSMContext, h *swf.HistoryEvent, data interface{}) Outcome {
			if *h.EventType == enums.EventTypeWorkflowExecutionSignaled {
				d := data.(*TestData)
				d.States = append(d.States, *h.WorkflowExecutionSignaledEventAttributes.SignalName)
			}
			return ctx.Stay(data, ctx.EmptyDecisions())
		},
	})

	fsmClient := NewFSMClient(fsm, client)

	workflow := uuid.New()
	testData := uuid.New()
	startTemplate := swf.StartWorkflowExecutionInput{
		WorkflowType:                 &swf.WorkflowType{Name: aws.String("client-test"), Version: aws.String("1")},
		ExecutionStartToCloseTimeout: aws.String("120"),
		TaskStartToCloseTimeout:      aws.String("120"),
		ChildPolicy:                  aws.String("ABANDON"),
		TaskList:                     &swf.TaskList{Name: aws.String("task-list")},
	}
	_, err := fsmClient.Start(startTemplate, workflow, &TestData{States: []string{testData}})

	if err != nil {
		t.Fatal(err)
	}

	state, data, err := fsmClient.GetState(workflow)
	if err != nil {
		t.Fatal(err)
	}

	if data.(*TestData).States[0] != testData {
		t.Fatal(data)
	}

	if state != "initial" {
		t.Fatal("not in initial")
	}

	found := false
	err = fsmClient.WalkOpenWorkflowInfos(&swf.ListOpenWorkflowExecutionsInput{}, func(infos *swf.WorkflowExecutionInfos) error {
		for _, info := range infos.ExecutionInfos {
			if *info.Execution.WorkflowID == workflow {
				found = true
				return StopWalking()
			}
		}
		return nil
	})

	if err != nil {
		t.Fatal(err)
	}

	if !found {
		t.Fatalf("%s not found", workflow)
	}

	snapshots, err := fsmClient.GetSnapshots(workflow)
	if err != nil {
		t.Fatal(err)
	}

	if length := len(snapshots); length != 1 {
		t.Fatalf("snapshots length: %d", length)
	}

	if name := snapshots[0].Event.Name; name != "start" {
		t.Fatalf("snapshots[0].Event.Name: %s ", name)
	}

	if Type := snapshots[0].Event.Type; Type != enums.EventTypeWorkflowExecutionStarted {
		t.Fatalf("snapshots[0].Event.Type: %s ", Type)
	}

	if name := snapshots[0].State.Name; name != "initial" {
		t.Fatalf("snapshots[0].State.Name: %s ", name)
	}

	if version := snapshots[0].State.Version; version != 0 {
		t.Fatalf("snapshots[0].State.Version: %d ", version)
	}

	if id := snapshots[0].State.ID; id != 1 {
		t.Fatalf("snapshots[0].State.ID: %d ", id)
	}

}
예제 #8
0
func TestTypedActivityWorker(t *testing.T) {
	if os.Getenv("AWS_ACCESS_KEY_ID") == "" || os.Getenv("AWS_SECRET_ACCESS_KEY") == "" {
		log.Printf("WARNING: NO AWS CREDS SPECIFIED, SKIPPING MIGRATIONS TEST")
		return
	}

	config := &aws.Config{
		Credentials: credentials.NewEnvCredentials(),
		Region:      "us-east-1",
	}

	client := swf.New(config)

	domain := "worker-test-domain"

	req := swf.RegisterDomainInput{
		Name:                                   aws.String(domain),
		Description:                            aws.String("test domain"),
		WorkflowExecutionRetentionPeriodInDays: aws.String("30"),
	}

	d := migrator.DomainMigrator{
		RegisteredDomains: []swf.RegisterDomainInput{req},
		Client:            client,
	}

	d.Migrate()

	workflow := "worker-test-workflow"
	version := "worker-test-workflow-version"

	wreq := swf.RegisterWorkflowTypeInput{
		Name:            &workflow,
		Description:     aws.String("test workflow migration"),
		Version:         &version,
		Domain:          aws.String(domain),
		DefaultTaskList: &swf.TaskList{Name: S("worker-fsm")},
	}

	w := migrator.WorkflowTypeMigrator{
		RegisteredWorkflowTypes: []swf.RegisterWorkflowTypeInput{wreq},
		Client:                  client,
	}

	w.Migrate()

	one := swf.RegisterActivityTypeInput{
		Name:        aws.String("one"),
		Description: aws.String("worker test activity 1"),
		Version:     aws.String("one"),
		Domain:      aws.String(domain),
	}

	two := swf.RegisterActivityTypeInput{
		Name:        aws.String("two"),
		Description: aws.String("worker test activity 2"),
		Version:     aws.String("two"),
		Domain:      aws.String(domain),
	}

	a := migrator.ActivityTypeMigrator{
		RegisteredActivityTypes: []swf.RegisterActivityTypeInput{one, two},
		Client:                  client,
	}

	a.Migrate()

	taskList := "aTaskListSharedBetweenTaskOneAndTwo"

	worker := &ActivityWorker{
		Domain:     domain,
		Serializer: fsm.JSONStateSerializer{},
		TaskList:   taskList,
		SWF:        client,
		Identity:   "test-activity-worker",
	}

	//This is where the actual worker config code is
	var activities Activities

	activities = MockActivities{}

	worker.AddHandler(NewActivityHandler("one", activities.Task1))

	worker.AddHandler(NewActivityHandler("two", activities.Task2))

	go worker.Start()
	//yep thats all the worker config code

	done := make(chan struct{})

	go NewWorkerFSM(client, done).Start()

	_, err := client.StartWorkflowExecution(&swf.StartWorkflowExecutionInput{
		Domain:       S(domain),
		WorkflowID:   S("worker-test"),
		WorkflowType: &swf.WorkflowType{Name: S(workflow), Version: S(version)},
		Input:        S("{}"),
		ExecutionStartToCloseTimeout: S("90"),
		TaskStartToCloseTimeout:      S("10"),
		ChildPolicy:                  S("ABANDON"),
	})

	if err != nil {
		t.Fatal(err)
	}

	select {
	case <-done:
	case <-time.After(1 * time.Minute):
		t.Fatal("One Minute Elapsed, not done with workflow")
	}

}