Skip to content

Commit

Permalink
remove workflow and activity alias getters
Browse files Browse the repository at this point in the history
  • Loading branch information
ketsiambaku committed Jun 12, 2024
1 parent 4a1f460 commit d404463
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 90 deletions.
16 changes: 4 additions & 12 deletions internal/internal_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -780,24 +780,16 @@ func (aw *aggregatedWorker) GetRegisteredWorkflows() []string {
return aw.registry.GetRegisteredWorkflows()
}

func (aw *aggregatedWorker) GetWorkflowAlias(fnName string) (string, bool) {
return aw.registry.GetWorkflowAlias(fnName)
}

func (aw *aggregatedWorker) GetWorkflowFn(registerName string) (interface{}, bool) {
return aw.registry.GetWorkflowFn(registerName)
func (aw *aggregatedWorker) GetWorkflowFunc(registerName string) (interface{}, bool) {
return aw.registry.GetWorkflowFunc(registerName)
}

func (aw *aggregatedWorker) GetRegisteredActivities() []string {
return aw.registry.GetRegisteredActivities()
}

func (aw *aggregatedWorker) GetActivityAlias(fnName string) (string, bool) {
return aw.registry.GetActivityAlias(fnName)
}

func (aw *aggregatedWorker) GetActivityFn(registerName string) (interface{}, bool) {
return aw.registry.GetActivityFn(registerName)
func (aw *aggregatedWorker) GetActivityFunc(registerName string) (interface{}, bool) {
return aw.registry.GetActivityFunc(registerName)
}

func (aw *aggregatedWorker) RegisterWorkflow(w interface{}) {
Expand Down
14 changes: 2 additions & 12 deletions internal/internal_worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -853,13 +853,8 @@ func TestRegisterVariousWorkflowTypes(t *testing.T) {
assert.Contains(t, wfs, "testWorkflowReturnStructPtr")
assert.Contains(t, wfs, "testWorkflowReturnStructPtrPtr")

// sample assertion on workflow alias
alias, ok := w.GetWorkflowAlias(getFunctionName(testWorkflowSample))
assert.True(t, ok)
assert.Equal(t, "testWorkflowSample", alias)

// sample assertion on workflow func
fn, ok := w.GetWorkflowFn("testWorkflowSample")
fn, ok := w.GetWorkflowFunc("testWorkflowSample")
assert.True(t, ok)
assert.Equal(t, reflect.Func, reflect.ValueOf(fn).Kind())
assert.Equal(t, getFunctionName(testWorkflowSample), runtime.FuncForPC(reflect.ValueOf(fn).Pointer()).Name())
Expand All @@ -874,13 +869,8 @@ func TestRegisterActivityWithOptions(t *testing.T) {
assert.Equal(t, 1, len(wfs))
assert.Contains(t, wfs, "testActivityMultipleArgs")

// assert activity alias
alias, ok := w.GetActivityAlias(getFunctionName(testActivityMultipleArgs))
assert.True(t, ok)
assert.Equal(t, "testActivityMultipleArgs", alias)

// assert activity function
fn, ok := w.GetActivityFn("testActivityMultipleArgs")
fn, ok := w.GetActivityFunc("testActivityMultipleArgs")
assert.True(t, ok)
assert.Equal(t, reflect.Func, reflect.ValueOf(fn).Kind())
assert.Equal(t, getFunctionName(testActivityMultipleArgs), runtime.FuncForPC(reflect.ValueOf(fn).Pointer()).Name())
Expand Down
14 changes: 3 additions & 11 deletions internal/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,7 @@ func (r *registry) GetRegisteredWorkflows() []string {
return r.GetRegisteredWorkflowTypes()
}

func (r *registry) GetWorkflowAlias(fnName string) (string, bool) {
return r.getWorkflowAlias(fnName)
}

func (r *registry) GetWorkflowFn(registerName string) (interface{}, bool) {
func (r *registry) GetWorkflowFunc(registerName string) (interface{}, bool) {
return r.getWorkflowFn(registerName)
}

Expand All @@ -145,14 +141,10 @@ func (r *registry) GetRegisteredActivities() []string {
return activityNames
}

func (r *registry) GetActivityAlias(fnName string) (string, bool) {
return r.getActivityAlias(fnName)
}

func (r *registry) GetActivityFn(registerName string) (interface{}, bool) {
func (r *registry) GetActivityFunc(registerName string) (interface{}, bool) {
a, ok := r.GetActivity(registerName)
if !ok {
return nil, ok
return nil, false

Check warning on line 147 in internal/registry.go

View check run for this annotation

Codecov / codecov/patch

internal/registry.go#L147

Added line #L147 was not covered by tests
}
return a.GetFunction(), ok
}
Expand Down
14 changes: 3 additions & 11 deletions internal/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ func TestWorkflowRegistration(t *testing.T) {
require.Equal(t, tt.workflowType, workflowType)

// Verify workflow is resolved from workflow type
_, ok := r.GetWorkflowFn(tt.workflowType)
_, ok := r.GetWorkflowFunc(tt.workflowType)
require.True(t, ok)

// Verify workflow is resolved from alternative (backwards compatible) workflow type
if len(tt.altWorkflowType) > 0 {
_, ok = r.GetWorkflowFn(tt.altWorkflowType)
_, ok = r.GetWorkflowFunc(tt.altWorkflowType)
require.True(t, ok)
}

Expand All @@ -126,10 +126,6 @@ func TestWorkflowRegistration(t *testing.T) {
if tt.resolveByAlias != "" {
workflowType = getWorkflowFunctionName(r, tt.resolveByAlias)
require.Equal(t, tt.workflowType, workflowType)
fnName := getFunctionName(tt.resolveByFunction)
alias, ok := r.GetWorkflowAlias(fnName)
require.Equal(t, tt.resolveByAlias, alias)
require.True(t, ok)
}
})
}
Expand Down Expand Up @@ -237,7 +233,7 @@ func TestActivityRegistration(t *testing.T) {
// Verify activity is resolved from activity type
_, ok := r.GetActivity(tt.activityType)
require.True(t, ok)
_, ok = r.GetActivityFn(tt.activityType)
_, ok = r.GetActivityFunc(tt.activityType)
require.True(t, ok)

// Verify activity is resolved from alternative (backwards compatible) activity type
Expand All @@ -254,10 +250,6 @@ func TestActivityRegistration(t *testing.T) {
if tt.resolveByAlias != "" {
activityType = getActivityFunctionName(r, tt.resolveByAlias)
require.Equal(t, tt.activityType, activityType, "resolve by alias")
fnName := getFunctionName(tt.resolveByFunction)
alias, ok := r.GetActivityAlias(fnName)
require.Equal(t, tt.resolveByAlias, alias)
require.True(t, ok)
}
})
}
Expand Down
16 changes: 4 additions & 12 deletions internal/workflow_replayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,24 +135,16 @@ func (r *WorkflowReplayer) GetRegisteredWorkflows() []string {
return r.registry.GetRegisteredWorkflows()
}

func (r *WorkflowReplayer) GetWorkflowAlias(fnName string) (string, bool) {
return r.registry.GetWorkflowAlias(fnName)
}

func (r *WorkflowReplayer) GetWorkflowFn(registerName string) (interface{}, bool) {
return r.registry.GetWorkflowFn(registerName)
func (r *WorkflowReplayer) GetWorkflowFunc(registerName string) (interface{}, bool) {
return r.registry.GetWorkflowFunc(registerName)
}

func (r *WorkflowReplayer) GetRegisteredActivities() []string {
return r.registry.GetRegisteredActivities()
}

func (r *WorkflowReplayer) GetActivityAlias(fnName string) (string, bool) {
return r.registry.GetActivityAlias(fnName)
}

func (r *WorkflowReplayer) GetActivityFn(registerName string) (interface{}, bool) {
return r.registry.GetActivityFn(registerName)
func (r *WorkflowReplayer) GetActivityFunc(registerName string) (interface{}, bool) {
return r.registry.GetActivityFunc(registerName)
}

// ReplayWorkflowHistory executes a single decision task for the given history.
Expand Down
6 changes: 1 addition & 5 deletions internal/workflow_replayer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,7 @@ func (s *workflowReplayerSuite) TestActivityRegistration() {
a := s.replayer.GetRegisteredActivities()[0]
s.Equal(name, a)

alias, ok := s.replayer.GetActivityAlias(getFunctionName(testActivityFunction))
s.True(ok)
s.Equal(name, alias)

fn, ok := s.replayer.GetActivityFn(a)
fn, ok := s.replayer.GetActivityFunc(a)
s.True(ok)
s.Equal(reflect.Func, reflect.ValueOf(fn).Kind())
s.Equal(getFunctionName(testActivityFunction), runtime.FuncForPC(reflect.ValueOf(fn).Pointer()).Name())
Expand Down
9 changes: 2 additions & 7 deletions internal/workflow_shadower.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,9 @@ func (s *WorkflowShadower) GetRegisteredWorkflows() []string {
return s.replayer.GetRegisteredWorkflows()
}

// GetWorkflowAlias returns the workflow alias and true if the alias was found.
func (s *WorkflowShadower) GetWorkflowAlias(fnName string) (string, bool) {
return s.replayer.GetWorkflowAlias(fnName)
}

// GetWorkflowFn returns the workflow function corresponding to the provided registerName
func (s *WorkflowShadower) GetWorkflowFn(registerName string) (interface{}, bool) {
return s.replayer.GetWorkflowFn(registerName)
func (s *WorkflowShadower) GetWorkflowFunc(registerName string) (interface{}, bool) {
return s.replayer.GetWorkflowFunc(registerName)
}

func (s *WorkflowShadower) shadowWorker() error {
Expand Down
5 changes: 1 addition & 4 deletions internal/workflow_shadower_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,10 +444,7 @@ func (s *workflowShadowerSuite) TestWorkflowRegistration() {
fnName := getFunctionName(testReplayWorkflow)
s.Equal(fnName, wfName)

_, ok := s.testShadower.GetWorkflowAlias(wfName)
s.False(ok)

fn, ok := s.testShadower.GetWorkflowFn(wfName)
fn, ok := s.testShadower.GetWorkflowFunc(wfName)
s.True(ok)
s.Equal(fnName, runtime.FuncForPC(reflect.ValueOf(fn).Pointer()).Name())
}
Expand Down
20 changes: 4 additions & 16 deletions worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,12 @@ type (
// instance to the global registry. In this case, the list may contain duplicate names.
GetRegisteredWorkflows() []string

// GetWorkflowAlias returns the customized workflow name recorded for the provided function name
// and a boolean value indicating whether an alias was found.
// All customization on the workflow name are provided with workflow.RegisterOptions{}.
// This method returns an empty string and false if no alias was found.
GetWorkflowAlias(fnName string) (string, bool)

// GetWorkflowFn takes a name and returns the corresponding workflow
// GetWorkflowFunc takes a name and returns the corresponding workflow
// function and a boolean value indicating whether the activity was found.
// It returns nil, false when no workflow was registered with the provided name.
// The registerName is the resolved name recorded on the registry after all options
// from workflow.RegisterOptions{} are applied.
GetWorkflowFn(registerName string) (interface{}, bool)
GetWorkflowFunc(registerName string) (interface{}, bool)
}

// ActivityRegistry exposes activity registration functions to consumers.
Expand Down Expand Up @@ -161,18 +155,12 @@ type (
// instance to the global registry. In this case, the list may contain duplicate names.
GetRegisteredActivities() []string

// GetActivityAlias returns the customized activity name recorded for the provided function name
// and a boolean value indicating whether an alias was found.
// All customization on the activity name are provided with Worker.RegisterActivityWithOptions.
// This method returns an empty string and false if no alias was found.
GetActivityAlias(fnName string) (string, bool)

// GetActivityFn takes a name and returns the corresponding activity
// GetActivityFunc takes a name and returns the corresponding activity
// function and a boolean value indicating whether the activity was found.
// It returns nil, false when no activity was registered with the provided name.
// The registerName is the resolved name recorded on the registry after all options
// from activity.RegisterOptions{} are applied.
GetActivityFn(registerName string) (interface{}, bool)
GetActivityFunc(registerName string) (interface{}, bool)
}

// WorkflowReplayer supports replaying a workflow from its event history.
Expand Down

0 comments on commit d404463

Please sign in to comment.