Skip to content

Commit

Permalink
Write tests for resource impl (#6452)
Browse files Browse the repository at this point in the history
  • Loading branch information
taylanisikdemir authored Oct 31, 2024
1 parent 13312ea commit e170bd0
Show file tree
Hide file tree
Showing 11 changed files with 618 additions and 177 deletions.
2 changes: 1 addition & 1 deletion common/persistence/client/bean.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func NewBeanFromFactory(
factory Factory,
params *Params,
serviceConfig *service.Config,
) (*BeanImpl, error) {
) (Bean, error) {

metadataMgr, err := factory.NewDomainManager()
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions common/pprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

package common

//go:generate mockgen -package $GOPACKAGE -source $GOFILE -destination pprof_mock.go -package common github.com/uber/cadence/common PProfInitializer

type (
// PProfInitializer initialize the pprof based on config
PProfInitializer interface {
Expand Down
70 changes: 70 additions & 0 deletions common/pprof_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions common/resource/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ import (
"github.com/uber/cadence/common/messaging"
"github.com/uber/cadence/common/metrics"
"github.com/uber/cadence/common/partition"
persistenceClient "github.com/uber/cadence/common/persistence/client"
"github.com/uber/cadence/common/pinot"
"github.com/uber/cadence/common/rpc"
"github.com/uber/cadence/common/service"
)

type (
Expand Down Expand Up @@ -89,5 +91,7 @@ type (
TimeSource clock.TimeSource
// HistoryClientFn is used by integration tests to mock a history client
HistoryClientFn func() history.Client
// NewPersistenceBeanFn can be used to override the default persistence bean creation in unit tests to avoid DB setup
NewPersistenceBeanFn func(persistenceClient.Factory, *persistenceClient.Params, *service.Config) (persistenceClient.Bean, error)
}
)
123 changes: 58 additions & 65 deletions common/resource/resourceImpl.go → common/resource/resource_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,89 +70,80 @@ func NewResourceFactory() ResourceFactory {

type resourceImplFactory struct{}

func (*resourceImplFactory) NewResource(params *Params,
func (*resourceImplFactory) NewResource(
params *Params,
serviceName string,
serviceConfig *service.Config,
) (resource Resource, err error) {
return New(params, serviceName, serviceConfig)
}

type (
// Impl contains all common resources shared across frontend / matching / history / worker
type Impl struct {
status int32

// VisibilityManagerInitializer is the function each service should implement
// for visibility manager initialization
VisibilityManagerInitializer func(
persistenceBean persistenceClient.Bean,
logger log.Logger,
) (persistence.VisibilityManager, error)
// static infos
numShards int
serviceName string
hostInfo membership.HostInfo
metricsScope tally.Scope
clusterMetadata cluster.Metadata

// Impl contains all common resources shared across frontend / matching / history / worker
Impl struct {
status int32
// other common resources

// static infos
numShards int
serviceName string
hostInfo membership.HostInfo
metricsScope tally.Scope
clusterMetadata cluster.Metadata
domainCache cache.DomainCache
domainMetricsScopeCache cache.DomainMetricsScopeCache
timeSource clock.TimeSource
payloadSerializer persistence.PayloadSerializer
metricsClient metrics.Client
messagingClient messaging.Client
blobstoreClient blobstore.Client
archivalMetadata archiver.ArchivalMetadata
archiverProvider provider.ArchiverProvider
domainReplicationQueue domain.ReplicationQueue

// other common resources
// membership infos

domainCache cache.DomainCache
domainMetricsScopeCache cache.DomainMetricsScopeCache
timeSource clock.TimeSource
payloadSerializer persistence.PayloadSerializer
metricsClient metrics.Client
messagingClient messaging.Client
blobstoreClient blobstore.Client
archivalMetadata archiver.ArchivalMetadata
archiverProvider provider.ArchiverProvider
domainReplicationQueue domain.ReplicationQueue
membershipResolver membership.Resolver

// membership infos
// internal services clients

membershipResolver membership.Resolver
sdkClient workflowserviceclient.Interface
frontendRawClient frontend.Client
frontendClient frontend.Client
matchingRawClient matching.Client
matchingClient matching.Client
historyRawClient history.Client
historyClient history.Client
clientBean client.Bean

// internal services clients
// persistence clients
persistenceBean persistenceClient.Bean

sdkClient workflowserviceclient.Interface
frontendRawClient frontend.Client
frontendClient frontend.Client
matchingRawClient matching.Client
matchingClient matching.Client
historyRawClient history.Client
historyClient history.Client
clientBean client.Bean
// hostName
hostName string

// persistence clients
persistenceBean persistenceClient.Bean
// loggers
logger log.Logger
throttledLogger log.Logger

// hostName
hostName string
// for registering handlers
dispatcher *yarpc.Dispatcher

// loggers
logger log.Logger
throttledLogger log.Logger
// internal vars

// for registering handlers
dispatcher *yarpc.Dispatcher
pprofInitializer common.PProfInitializer
runtimeMetricsReporter *metrics.RuntimeMetricsReporter
rpcFactory rpc.Factory

// internal vars

pprofInitializer common.PProfInitializer
runtimeMetricsReporter *metrics.RuntimeMetricsReporter
rpcFactory rpc.Factory
isolationGroups isolationgroup.State
isolationGroupConfigStore configstore.Client
partitioner partition.Partitioner

isolationGroups isolationgroup.State
isolationGroupConfigStore configstore.Client
partitioner partition.Partitioner
asyncWorkflowQueueProvider queue.Provider

asyncWorkflowQueueProvider queue.Provider

ratelimiterAggregatorClient qrpc.Client
}
)
ratelimiterAggregatorClient qrpc.Client
}

var _ Resource = (*Impl)(nil)

Expand Down Expand Up @@ -195,7 +186,11 @@ func New(
return nil, err
}

persistenceBean, err := persistenceClient.NewBeanFromFactory(persistenceClient.NewFactory(
newPersistenceBeanFn := persistenceClient.NewBeanFromFactory
if params.NewPersistenceBeanFn != nil {
newPersistenceBeanFn = params.NewPersistenceBeanFn
}
persistenceBean, err := newPersistenceBeanFn(persistenceClient.NewFactory(
&params.PersistenceConfig,
func() float64 {
return permember.PerMember(
Expand Down Expand Up @@ -613,9 +608,7 @@ func (h *Impl) GetHistoryManager() persistence.HistoryManager {
}

// GetExecutionManager return execution manager for given shard ID
func (h *Impl) GetExecutionManager(
shardID int,
) (persistence.ExecutionManager, error) {
func (h *Impl) GetExecutionManager(shardID int) (persistence.ExecutionManager, error) {

return h.persistenceBean.GetExecutionManager(shardID)
}
Expand Down
Loading

0 comments on commit e170bd0

Please sign in to comment.