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

Bugfix: write changes back to *Persistence.DataStores #4284

Merged
merged 1 commit into from
Jun 24, 2021
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
33 changes: 33 additions & 0 deletions common/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/uber/cadence/common"
)
Expand Down Expand Up @@ -62,3 +63,35 @@ func TestFillingDefaultRpcName(t *testing.T) {
cfg.fillDefaults()
assert.Equal(t, "cadence-frontend", cfg.ClusterMetadata.ClusterInformation["clusterA"].RPCName)
}

func TestConfigFallbacks(t *testing.T) {
cfg := &Config{
Persistence: Persistence{
DefaultStore: "default",
VisibilityStore: "cass",
DataStores: map[string]DataStore{
"default": {
SQL: &SQL{
PluginName: "fake",
ConnectProtocol: "tcp",
ConnectAddr: "192.168.0.1:3306",
DatabaseName: "db1",
NumShards: 0, // default value, should be changed
},
},
"cass": {
Cassandra: &NoSQL{
Hosts: "127.0.0.1",
},
// no sql or nosql, should be populated from cassandra
},
},
},
}
err := cfg.ValidateAndFillDefaults()
require.NoError(t, err) // sanity check, must be valid or the later tests are potentially useless

assert.NotEmpty(t, cfg.Persistence.DataStores["cass"].Cassandra, "cassandra config should remain after update")
assert.NotEmpty(t, cfg.Persistence.DataStores["cass"].NoSQL, "nosql config should contain cassandra config / not be empty")
assert.NotZero(t, cfg.Persistence.DataStores["default"].SQL.NumShards, "num shards should be nonzero")
}
2 changes: 2 additions & 0 deletions common/config/persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ func (c *Persistence) Validate() error {
if ds.SQL != nil && ds.SQL.NumShards == 0 {
ds.SQL.NumShards = 1
}
// write changes back to DataStores, as ds is a value object
c.DataStores[st] = ds
}
return nil
}
Expand Down