Skip to content

Commit f6a4b9a

Browse files
committed
Add implementation of CHASM List/Count Runs
1 parent ed4bfd4 commit f6a4b9a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1652
-417
lines changed

chasm/engine_mock.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chasm/export_test.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,16 @@ package chasm
22

33
import "reflect"
44

5-
func (r *Registry) Component(fqn string) (*RegistrableComponent, bool) {
6-
return r.component(fqn)
7-
}
8-
95
func (r *Registry) Task(fqn string) (*RegistrableTask, bool) {
106
return r.task(fqn)
117
}
128

13-
func (r *Registry) ComponentFor(componentInstance any) (*RegistrableComponent, bool) {
14-
return r.componentFor(componentInstance)
9+
func (r *Registry) Component(fqn string) (*RegistrableComponent, bool) {
10+
return r.component(fqn)
1511
}
1612

17-
func (r *Registry) ComponentOf(componentGoType reflect.Type) (*RegistrableComponent, bool) {
18-
return r.componentOf(componentGoType)
13+
func (r *Registry) ComponentFor(componentInstance any) (*RegistrableComponent, bool) {
14+
return r.componentFor(componentInstance)
1915
}
2016

2117
func (r *Registry) TaskFor(taskInstance any) (*RegistrableTask, bool) {
@@ -26,10 +22,6 @@ func (r *Registry) TaskOf(taskGoType reflect.Type) (*RegistrableTask, bool) {
2622
return r.taskOf(taskGoType)
2723
}
2824

29-
func (rc RegistrableComponent) FqType() string {
30-
return rc.fqType()
31-
}
32-
3325
func (rt RegistrableTask) FqType() string {
3426
return rt.fqType()
3527
}

chasm/field_test.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ import (
99
"github.com/stretchr/testify/suite"
1010
persistencespb "go.temporal.io/server/api/persistence/v1"
1111
"go.temporal.io/server/common/clock"
12+
"go.temporal.io/server/common/definition"
1213
"go.temporal.io/server/common/log"
14+
"go.temporal.io/server/common/primitives"
1315
"go.temporal.io/server/common/testing/protorequire"
1416
"go.temporal.io/server/common/testing/testlogger"
15-
"go.temporal.io/server/common/testing/testvars"
1617
"go.uber.org/mock/gomock"
1718
)
1819

@@ -165,11 +166,16 @@ func (s *fieldSuite) setupComponentWithTree(rootComponent *TestComponent) (*Node
165166
}
166167

167168
func (s *fieldSuite) TestDeferredPointerResolution() {
168-
tv := testvars.New(s.T())
169169
s.nodeBackend = &MockNodeBackend{
170170
HandleNextTransitionCount: func() int64 { return 1 },
171171
HandleGetCurrentVersion: func() int64 { return 1 },
172-
HandleGetWorkflowKey: tv.Any().WorkflowKey,
172+
HandleGetWorkflowKey: func() definition.WorkflowKey {
173+
return definition.NewWorkflowKey(
174+
primitives.NewUUID().String(),
175+
primitives.NewUUID().String(),
176+
primitives.NewUUID().String(),
177+
)
178+
},
173179
}
174180

175181
// Create component structure that will simulate NewEntity scenario.
@@ -239,11 +245,16 @@ func (s *fieldSuite) TestDeferredPointerResolution() {
239245
}
240246

241247
func (s *fieldSuite) TestMixedPointerScenario() {
242-
tv := testvars.New(s.T())
243248
s.nodeBackend = &MockNodeBackend{
244249
HandleNextTransitionCount: func() int64 { return 1 },
245250
HandleGetCurrentVersion: func() int64 { return 1 },
246-
HandleGetWorkflowKey: tv.Any().WorkflowKey,
251+
HandleGetWorkflowKey: func() definition.WorkflowKey {
252+
return definition.NewWorkflowKey(
253+
primitives.NewUUID().String(),
254+
primitives.NewUUID().String(),
255+
primitives.NewUUID().String(),
256+
)
257+
},
247258
}
248259

249260
existingComponent := &TestSubComponent11{
@@ -311,11 +322,16 @@ func (s *fieldSuite) TestMixedPointerScenario() {
311322
}
312323

313324
func (s *fieldSuite) TestUnresolvableDeferredPointerError() {
314-
tv := testvars.New(s.T())
315325
s.nodeBackend = &MockNodeBackend{
316326
HandleNextTransitionCount: func() int64 { return 1 },
317327
HandleGetCurrentVersion: func() int64 { return 1 },
318-
HandleGetWorkflowKey: tv.Any().WorkflowKey,
328+
HandleGetWorkflowKey: func() definition.WorkflowKey {
329+
return definition.NewWorkflowKey(
330+
primitives.NewUUID().String(),
331+
primitives.NewUUID().String(),
332+
primitives.NewUUID().String(),
333+
)
334+
},
319335
}
320336

321337
s.logger.(*testlogger.TestLogger).

chasm/lib/scheduler/helper_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ import (
1212
"go.temporal.io/server/chasm/lib/scheduler"
1313
"go.temporal.io/server/common/backoff"
1414
"go.temporal.io/server/common/clock"
15+
"go.temporal.io/server/common/definition"
16+
"go.temporal.io/server/common/primitives"
1517
"go.temporal.io/server/common/testing/testlogger"
16-
"go.temporal.io/server/common/testing/testvars"
1718
"google.golang.org/protobuf/types/known/durationpb"
1819
)
1920

@@ -84,10 +85,15 @@ func setupSchedulerForTest(t *testing.T) (*scheduler.Scheduler, chasm.MutableCon
8485
timeSource := clock.NewEventTimeSource()
8586
timeSource.Update(time.Now())
8687

87-
tv := testvars.New(t)
8888
nodeBackend.HandleNextTransitionCount = func() int64 { return 2 }
8989
nodeBackend.HandleGetCurrentVersion = func() int64 { return 1 }
90-
nodeBackend.HandleGetWorkflowKey = tv.Any().WorkflowKey
90+
nodeBackend.HandleGetWorkflowKey = func() definition.WorkflowKey {
91+
return definition.NewWorkflowKey(
92+
primitives.NewUUID().String(),
93+
primitives.NewUUID().String(),
94+
primitives.NewUUID().String(),
95+
)
96+
}
9197
nodeBackend.HandleIsWorkflow = func() bool { return false }
9298
nodeBackend.HandleCurrentVersionedTransition = func() *persistencespb.VersionedTransition {
9399
return &persistencespb.VersionedTransition{

chasm/lib/scheduler/scheduler_suite_test.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ import (
1111
"go.temporal.io/server/chasm"
1212
"go.temporal.io/server/chasm/lib/scheduler"
1313
"go.temporal.io/server/common/clock"
14+
"go.temporal.io/server/common/definition"
1415
"go.temporal.io/server/common/log"
16+
"go.temporal.io/server/common/primitives"
1517
"go.temporal.io/server/common/testing/protorequire"
1618
"go.temporal.io/server/common/testing/testlogger"
17-
"go.temporal.io/server/common/testing/testvars"
1819
"go.uber.org/mock/gomock"
1920
)
2021

@@ -59,12 +60,17 @@ func (s *schedulerSuite) SetupTest() {
5960
s.timeSource.Update(time.Now())
6061

6162
// Stub NodeBackend for NewEmptytree
62-
tv := testvars.New(s.T())
6363
s.nodeBackend = &chasm.MockNodeBackend{
6464
HandleNextTransitionCount: func() int64 { return 2 },
6565
HandleGetCurrentVersion: func() int64 { return 1 },
66-
HandleGetWorkflowKey: tv.Any().WorkflowKey,
67-
HandleIsWorkflow: func() bool { return false },
66+
HandleGetWorkflowKey: func() definition.WorkflowKey {
67+
return definition.NewWorkflowKey(
68+
primitives.NewUUID().String(),
69+
primitives.NewUUID().String(),
70+
primitives.NewUUID().String(),
71+
)
72+
},
73+
HandleIsWorkflow: func() bool { return false },
6874
HandleCurrentVersionedTransition: func() *persistencespb.VersionedTransition {
6975
return &persistencespb.VersionedTransition{
7076
NamespaceFailoverVersion: 1,

chasm/ref.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (r *ComponentRef) Archetype(
7676
return r.archetype, nil
7777
}
7878

79-
rc, ok := registry.componentOf(r.entityGoType)
79+
rc, ok := registry.ComponentOf(r.entityGoType)
8080
if !ok {
8181
return "", serviceerror.NewInternal("unknown chasm component type: " + r.entityGoType.String())
8282
}

chasm/ref_test.go

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
package chasm
22

33
import (
4+
"math/rand"
45
"reflect"
56
"testing"
67

78
"github.com/stretchr/testify/require"
89
"github.com/stretchr/testify/suite"
910
persistencespb "go.temporal.io/server/api/persistence/v1"
1011
"go.temporal.io/server/common/log"
12+
"go.temporal.io/server/common/primitives"
1113
"go.temporal.io/server/common/testing/protorequire"
12-
"go.temporal.io/server/common/testing/testvars"
1314
"go.uber.org/mock/gomock"
1415
)
1516

@@ -39,13 +40,25 @@ func (s *componentRefSuite) SetupTest() {
3940
s.NoError(err)
4041
}
4142

42-
func (s *componentRefSuite) TestArchetype() {
43-
tv := testvars.New(s.T())
44-
entityKey := EntityKey{
45-
tv.NamespaceID().String(),
46-
tv.WorkflowID(),
47-
tv.RunID(),
43+
// Test helper functions to avoid hardcoded values
44+
45+
func newRefTestEntityKey() EntityKey {
46+
return EntityKey{
47+
NamespaceID: primitives.NewUUID().String(),
48+
BusinessID: primitives.NewUUID().String(),
49+
EntityID: primitives.NewUUID().String(),
50+
}
51+
}
52+
53+
func newRefTestVersionedTransition() *persistencespb.VersionedTransition {
54+
return &persistencespb.VersionedTransition{
55+
NamespaceFailoverVersion: rand.Int63(),
56+
TransitionCount: rand.Int63(),
4857
}
58+
}
59+
60+
func (s *componentRefSuite) TestArchetype() {
61+
entityKey := newRefTestEntityKey()
4962
ref := NewComponentRef[*TestComponent](entityKey)
5063

5164
archetype, err := ref.Archetype(s.registry)
@@ -58,12 +71,7 @@ func (s *componentRefSuite) TestArchetype() {
5871
}
5972

6073
func (s *componentRefSuite) TestShardingKey() {
61-
tv := testvars.New(s.T())
62-
entityKey := EntityKey{
63-
tv.NamespaceID().String(),
64-
tv.WorkflowID(),
65-
tv.RunID(),
66-
}
74+
entityKey := newRefTestEntityKey()
6775
ref := NewComponentRef[*TestComponent](entityKey)
6876

6977
shardingKey, err := ref.ShardingKey(s.registry)
@@ -76,24 +84,13 @@ func (s *componentRefSuite) TestShardingKey() {
7684
}
7785

7886
func (s *componentRefSuite) TestSerializeDeserialize() {
79-
tv := testvars.New(s.T())
80-
entityKey := EntityKey{
81-
tv.NamespaceID().String(),
82-
tv.WorkflowID(),
83-
tv.RunID(),
84-
}
87+
entityKey := newRefTestEntityKey()
8588
ref := ComponentRef{
86-
EntityKey: entityKey,
87-
entityGoType: reflect.TypeFor[*TestComponent](),
88-
entityLastUpdateVT: &persistencespb.VersionedTransition{
89-
NamespaceFailoverVersion: tv.Namespace().FailoverVersion(),
90-
TransitionCount: tv.Any().Int64(),
91-
},
92-
componentPath: []string{tv.Any().String(), tv.Any().String()},
93-
componentInitialVT: &persistencespb.VersionedTransition{
94-
NamespaceFailoverVersion: tv.Namespace().FailoverVersion(),
95-
TransitionCount: tv.Any().Int64(),
96-
},
89+
EntityKey: entityKey,
90+
entityGoType: reflect.TypeFor[*TestComponent](),
91+
entityLastUpdateVT: newRefTestVersionedTransition(),
92+
componentPath: []string{primitives.NewUUID().String(), primitives.NewUUID().String()},
93+
componentInitialVT: newRefTestVersionedTransition(),
9794
}
9895

9996
serializedRef, err := ref.Serialize(s.registry)

chasm/registrable_component.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ func WithSearchAttributes(
9595
}
9696
}
9797

98+
// SearchAttributesMapper returns the search attributes mapper for this component.
99+
func (rc *RegistrableComponent) SearchAttributesMapper() *VisibilitySearchAttributesMapper {
100+
return rc.searchAttributesMapper
101+
}
102+
103+
// ComponentType returns the component type name.
104+
func (rc *RegistrableComponent) ComponentType() string {
105+
return rc.componentType
106+
}
107+
98108
// fqType returns the fully qualified name of the component, which is a combination of
99109
// the library name and the component type. This is used to uniquely identify
100110
// the component in the registry.
@@ -105,3 +115,8 @@ func (rc RegistrableComponent) fqType() string {
105115
}
106116
return fullyQualifiedName(rc.library.Name(), rc.componentType)
107117
}
118+
119+
// FqType returns the fully qualified name of the component.
120+
func (rc *RegistrableComponent) FqType() string {
121+
return rc.fqType()
122+
}

chasm/registry.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ func (r *Registry) taskFor(taskInstance any) (*RegistrableTask, bool) {
8989
return rt, ok
9090
}
9191

92-
func (r *Registry) componentOf(componentGoType reflect.Type) (*RegistrableComponent, bool) {
92+
// ComponentOf returns the RegistrableComponent for the given component Go type.
93+
func (r *Registry) ComponentOf(componentGoType reflect.Type) (*RegistrableComponent, bool) {
9394
rc, ok := r.componentByGoType[componentGoType]
9495
return rc, ok
9596
}

0 commit comments

Comments
 (0)