Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests for nosql_domain_store #6378

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 6 additions & 65 deletions common/persistence/nosql/nosql_domain_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,9 @@ func (m *nosqlDomainStore) CreateDomain(
ctx context.Context,
request *persistence.InternalCreateDomainRequest,
) (*persistence.CreateDomainResponse, error) {
config, err := m.toNoSQLInternalDomainConfig(request.Config)
if err != nil {
return nil, err
}
row := &nosqlplugin.DomainRow{
Info: request.Info,
Config: config,
Config: request.Config,
ReplicationConfig: request.ReplicationConfig,
ConfigVersion: request.ConfigVersion,
FailoverVersion: request.FailoverVersion,
Expand All @@ -81,7 +77,7 @@ func (m *nosqlDomainStore) CreateDomain(
LastUpdatedTime: request.LastUpdatedTime,
}

err = m.db.InsertDomain(ctx, row)
err := m.db.InsertDomain(ctx, row)

if err != nil {
if _, ok := err.(*types.DomainAlreadyExistsError); ok {
Expand All @@ -97,14 +93,9 @@ func (m *nosqlDomainStore) UpdateDomain(
ctx context.Context,
request *persistence.InternalUpdateDomainRequest,
) error {
config, err := m.toNoSQLInternalDomainConfig(request.Config)
if err != nil {
return err
}

row := &nosqlplugin.DomainRow{
Info: request.Info,
Config: config,
Config: request.Config,
ReplicationConfig: request.ReplicationConfig,
ConfigVersion: request.ConfigVersion,
FailoverVersion: request.FailoverVersion,
Expand All @@ -115,7 +106,7 @@ func (m *nosqlDomainStore) UpdateDomain(
LastUpdatedTime: request.LastUpdatedTime,
}

err = m.db.UpdateDomain(ctx, row)
err := m.db.UpdateDomain(ctx, row)
if err != nil {
return convertCommonErrors(m.db, "UpdateDomain", err)
}
Expand Down Expand Up @@ -169,16 +160,9 @@ func (m *nosqlDomainStore) GetDomain(
row.ReplicationConfig.ActiveClusterName = cluster.GetOrUseDefaultActiveCluster(m.currentClusterName, row.ReplicationConfig.ActiveClusterName)
row.ReplicationConfig.Clusters = cluster.GetOrUseDefaultClusters(m.currentClusterName, row.ReplicationConfig.Clusters)

domainConfig, err := m.fromNoSQLInternalDomainConfig(row.Config)
if err != nil {
return nil, &types.InternalServiceError{
Message: fmt.Sprintf("cannot convert fromNoSQLInternalDomainConfig, %v ", err),
}
}

return &persistence.InternalGetDomainResponse{
Info: row.Info,
Config: domainConfig,
Config: row.Config,
ReplicationConfig: row.ReplicationConfig,
IsGlobalDomain: row.IsGlobalDomain,
ConfigVersion: row.ConfigVersion,
Expand Down Expand Up @@ -207,16 +191,9 @@ func (m *nosqlDomainStore) ListDomains(
row.ReplicationConfig.ActiveClusterName = cluster.GetOrUseDefaultActiveCluster(m.currentClusterName, row.ReplicationConfig.ActiveClusterName)
row.ReplicationConfig.Clusters = cluster.GetOrUseDefaultClusters(m.currentClusterName, row.ReplicationConfig.Clusters)

domainConfig, err := m.fromNoSQLInternalDomainConfig(row.Config)
if err != nil {
return nil, &types.InternalServiceError{
Message: fmt.Sprintf("cannot convert fromNoSQLInternalDomainConfig, %v ", err),
}
}

domains = append(domains, &persistence.InternalGetDomainResponse{
Info: row.Info,
Config: domainConfig,
Config: row.Config,
ReplicationConfig: row.ReplicationConfig,
IsGlobalDomain: row.IsGlobalDomain,
ConfigVersion: row.ConfigVersion,
Expand Down Expand Up @@ -266,39 +243,3 @@ func (m *nosqlDomainStore) GetMetadata(
}
return &persistence.GetMetadataResponse{NotificationVersion: notificationVersion}, nil
}

func (m *nosqlDomainStore) toNoSQLInternalDomainConfig(
domainConfig *persistence.InternalDomainConfig,
) (*nosqlplugin.NoSQLInternalDomainConfig, error) {
return &nosqlplugin.NoSQLInternalDomainConfig{
Retention: domainConfig.Retention,
EmitMetric: domainConfig.EmitMetric,
ArchivalBucket: domainConfig.ArchivalBucket,
ArchivalStatus: domainConfig.ArchivalStatus,
HistoryArchivalStatus: domainConfig.HistoryArchivalStatus,
HistoryArchivalURI: domainConfig.HistoryArchivalURI,
VisibilityArchivalStatus: domainConfig.VisibilityArchivalStatus,
VisibilityArchivalURI: domainConfig.VisibilityArchivalURI,
BadBinaries: domainConfig.BadBinaries,
IsolationGroups: domainConfig.IsolationGroups,
AsyncWorkflowsConfig: domainConfig.AsyncWorkflowsConfig,
}, nil
}

func (m *nosqlDomainStore) fromNoSQLInternalDomainConfig(
domainConfig *nosqlplugin.NoSQLInternalDomainConfig,
) (*persistence.InternalDomainConfig, error) {
return &persistence.InternalDomainConfig{
Retention: domainConfig.Retention,
EmitMetric: domainConfig.EmitMetric,
ArchivalBucket: domainConfig.ArchivalBucket,
ArchivalStatus: domainConfig.ArchivalStatus,
HistoryArchivalStatus: domainConfig.HistoryArchivalStatus,
HistoryArchivalURI: domainConfig.HistoryArchivalURI,
VisibilityArchivalStatus: domainConfig.VisibilityArchivalStatus,
VisibilityArchivalURI: domainConfig.VisibilityArchivalURI,
BadBinaries: domainConfig.BadBinaries,
IsolationGroups: domainConfig.IsolationGroups,
AsyncWorkflowsConfig: domainConfig.AsyncWorkflowsConfig,
}, nil
}
Loading
Loading