Skip to content

Commit e170bd0

Browse files
Write tests for resource impl (#6452)
1 parent 13312ea commit e170bd0

File tree

11 files changed

+618
-177
lines changed

11 files changed

+618
-177
lines changed

common/persistence/client/bean.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func NewBeanFromFactory(
9898
factory Factory,
9999
params *Params,
100100
serviceConfig *service.Config,
101-
) (*BeanImpl, error) {
101+
) (Bean, error) {
102102

103103
metadataMgr, err := factory.NewDomainManager()
104104
if err != nil {

common/pprof.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
package common
2222

23+
//go:generate mockgen -package $GOPACKAGE -source $GOFILE -destination pprof_mock.go -package common github.com/uber/cadence/common PProfInitializer
24+
2325
type (
2426
// PProfInitializer initialize the pprof based on config
2527
PProfInitializer interface {

common/pprof_mock.go

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

common/resource/params.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ import (
4343
"github.com/uber/cadence/common/messaging"
4444
"github.com/uber/cadence/common/metrics"
4545
"github.com/uber/cadence/common/partition"
46+
persistenceClient "github.com/uber/cadence/common/persistence/client"
4647
"github.com/uber/cadence/common/pinot"
4748
"github.com/uber/cadence/common/rpc"
49+
"github.com/uber/cadence/common/service"
4850
)
4951

5052
type (
@@ -89,5 +91,7 @@ type (
8991
TimeSource clock.TimeSource
9092
// HistoryClientFn is used by integration tests to mock a history client
9193
HistoryClientFn func() history.Client
94+
// NewPersistenceBeanFn can be used to override the default persistence bean creation in unit tests to avoid DB setup
95+
NewPersistenceBeanFn func(persistenceClient.Factory, *persistenceClient.Params, *service.Config) (persistenceClient.Bean, error)
9296
}
9397
)

common/resource/resourceImpl.go renamed to common/resource/resource_impl.go

Lines changed: 58 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -70,89 +70,80 @@ func NewResourceFactory() ResourceFactory {
7070

7171
type resourceImplFactory struct{}
7272

73-
func (*resourceImplFactory) NewResource(params *Params,
73+
func (*resourceImplFactory) NewResource(
74+
params *Params,
7475
serviceName string,
7576
serviceConfig *service.Config,
7677
) (resource Resource, err error) {
7778
return New(params, serviceName, serviceConfig)
7879
}
7980

80-
type (
81+
// Impl contains all common resources shared across frontend / matching / history / worker
82+
type Impl struct {
83+
status int32
8184

82-
// VisibilityManagerInitializer is the function each service should implement
83-
// for visibility manager initialization
84-
VisibilityManagerInitializer func(
85-
persistenceBean persistenceClient.Bean,
86-
logger log.Logger,
87-
) (persistence.VisibilityManager, error)
85+
// static infos
86+
numShards int
87+
serviceName string
88+
hostInfo membership.HostInfo
89+
metricsScope tally.Scope
90+
clusterMetadata cluster.Metadata
8891

89-
// Impl contains all common resources shared across frontend / matching / history / worker
90-
Impl struct {
91-
status int32
92+
// other common resources
9293

93-
// static infos
94-
numShards int
95-
serviceName string
96-
hostInfo membership.HostInfo
97-
metricsScope tally.Scope
98-
clusterMetadata cluster.Metadata
94+
domainCache cache.DomainCache
95+
domainMetricsScopeCache cache.DomainMetricsScopeCache
96+
timeSource clock.TimeSource
97+
payloadSerializer persistence.PayloadSerializer
98+
metricsClient metrics.Client
99+
messagingClient messaging.Client
100+
blobstoreClient blobstore.Client
101+
archivalMetadata archiver.ArchivalMetadata
102+
archiverProvider provider.ArchiverProvider
103+
domainReplicationQueue domain.ReplicationQueue
99104

100-
// other common resources
105+
// membership infos
101106

102-
domainCache cache.DomainCache
103-
domainMetricsScopeCache cache.DomainMetricsScopeCache
104-
timeSource clock.TimeSource
105-
payloadSerializer persistence.PayloadSerializer
106-
metricsClient metrics.Client
107-
messagingClient messaging.Client
108-
blobstoreClient blobstore.Client
109-
archivalMetadata archiver.ArchivalMetadata
110-
archiverProvider provider.ArchiverProvider
111-
domainReplicationQueue domain.ReplicationQueue
107+
membershipResolver membership.Resolver
112108

113-
// membership infos
109+
// internal services clients
114110

115-
membershipResolver membership.Resolver
111+
sdkClient workflowserviceclient.Interface
112+
frontendRawClient frontend.Client
113+
frontendClient frontend.Client
114+
matchingRawClient matching.Client
115+
matchingClient matching.Client
116+
historyRawClient history.Client
117+
historyClient history.Client
118+
clientBean client.Bean
116119

117-
// internal services clients
120+
// persistence clients
121+
persistenceBean persistenceClient.Bean
118122

119-
sdkClient workflowserviceclient.Interface
120-
frontendRawClient frontend.Client
121-
frontendClient frontend.Client
122-
matchingRawClient matching.Client
123-
matchingClient matching.Client
124-
historyRawClient history.Client
125-
historyClient history.Client
126-
clientBean client.Bean
123+
// hostName
124+
hostName string
127125

128-
// persistence clients
129-
persistenceBean persistenceClient.Bean
126+
// loggers
127+
logger log.Logger
128+
throttledLogger log.Logger
130129

131-
// hostName
132-
hostName string
130+
// for registering handlers
131+
dispatcher *yarpc.Dispatcher
133132

134-
// loggers
135-
logger log.Logger
136-
throttledLogger log.Logger
133+
// internal vars
137134

138-
// for registering handlers
139-
dispatcher *yarpc.Dispatcher
135+
pprofInitializer common.PProfInitializer
136+
runtimeMetricsReporter *metrics.RuntimeMetricsReporter
137+
rpcFactory rpc.Factory
140138

141-
// internal vars
142-
143-
pprofInitializer common.PProfInitializer
144-
runtimeMetricsReporter *metrics.RuntimeMetricsReporter
145-
rpcFactory rpc.Factory
139+
isolationGroups isolationgroup.State
140+
isolationGroupConfigStore configstore.Client
141+
partitioner partition.Partitioner
146142

147-
isolationGroups isolationgroup.State
148-
isolationGroupConfigStore configstore.Client
149-
partitioner partition.Partitioner
143+
asyncWorkflowQueueProvider queue.Provider
150144

151-
asyncWorkflowQueueProvider queue.Provider
152-
153-
ratelimiterAggregatorClient qrpc.Client
154-
}
155-
)
145+
ratelimiterAggregatorClient qrpc.Client
146+
}
156147

157148
var _ Resource = (*Impl)(nil)
158149

@@ -195,7 +186,11 @@ func New(
195186
return nil, err
196187
}
197188

198-
persistenceBean, err := persistenceClient.NewBeanFromFactory(persistenceClient.NewFactory(
189+
newPersistenceBeanFn := persistenceClient.NewBeanFromFactory
190+
if params.NewPersistenceBeanFn != nil {
191+
newPersistenceBeanFn = params.NewPersistenceBeanFn
192+
}
193+
persistenceBean, err := newPersistenceBeanFn(persistenceClient.NewFactory(
199194
&params.PersistenceConfig,
200195
func() float64 {
201196
return permember.PerMember(
@@ -613,9 +608,7 @@ func (h *Impl) GetHistoryManager() persistence.HistoryManager {
613608
}
614609

615610
// GetExecutionManager return execution manager for given shard ID
616-
func (h *Impl) GetExecutionManager(
617-
shardID int,
618-
) (persistence.ExecutionManager, error) {
611+
func (h *Impl) GetExecutionManager(shardID int) (persistence.ExecutionManager, error) {
619612

620613
return h.persistenceBean.GetExecutionManager(shardID)
621614
}

0 commit comments

Comments
 (0)