• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

uber / cadence / 0187fdd2-f4a4-4c9a-97b4-6604937bf7be

09 May 2023 12:23AM UTC coverage: 57.253% (-0.002%) from 57.255%
0187fdd2-f4a4-4c9a-97b4-6604937bf7be

Pull #5252

buildkite

David Porter
Merge branch 'master' into feature/zonal-partitioning
Pull Request #5252: Feature/zonal partitioning

1460 of 1460 new or added lines in 51 files covered. (100.0%)

86909 of 151799 relevant lines covered (57.25%)

2482.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/common/persistence/persistence-tests/configStorePersistenceTest.go
1
// Copyright (c) 2017 Uber Technologies, Inc.
2
//
3
// Permission is hereby granted, free of charge, to any person obtaining a copy
4
// of this software and associated documentation files (the "Software"), to deal
5
// in the Software without restriction, including without limitation the rights
6
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
// copies of the Software, and to permit persons to whom the Software is
8
// furnished to do so, subject to the following conditions:
9
//
10
// The above copyright notice and this permission notice shall be included in
11
// all copies or substantial portions of the Software.
12
//
13
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
// THE SOFTWARE.
20

21
package persistencetests
22

23
import (
24
        "context"
25
        "encoding/json"
26
        "errors"
27
        "os"
28
        "testing"
29

30
        log "github.com/sirupsen/logrus"
31
        "github.com/stretchr/testify/require"
32

33
        "github.com/uber/cadence/common/config"
34
        p "github.com/uber/cadence/common/persistence"
35
        "github.com/uber/cadence/common/persistence/nosql/nosqlplugin/cassandra"
36
        "github.com/uber/cadence/common/persistence/nosql/nosqlplugin/mongodb"
37
        "github.com/uber/cadence/common/types"
38
)
39

40
var supportedPlugins = map[string]bool{
41
        cassandra.PluginName: true,
42
        mongodb.PluginName:   true,
43
}
44

45
// Currently you cannot clear or remove any entries in cluster_config table
46
// Therefore, Teardown and Setup of Test DB is required before every test.
47

48
type (
49
        // ConfigStorePersistenceSuite contains config store persistence tests
50
        ConfigStorePersistenceSuite struct {
51
                TestBase
52
                // override suite.Suite.Assertions with require.Assertions; this means that s.NotNil(nil) will stop the test,
53
                // not merely log an error
54
                *require.Assertions
55
        }
56
)
57

58
// SetupSuite implementation
59
func (s *ConfigStorePersistenceSuite) SetupSuite() {
×
60
        if testing.Verbose() {
×
61
                log.SetOutput(os.Stdout)
×
62
        }
×
63
}
64

65
// SetupTest implementation
66
func (s *ConfigStorePersistenceSuite) SetupTest() {
×
67
        // Have to define our overridden assertions in the test setup. If we did it earlier, s.T() will return nil
×
68
        s.Assertions = require.New(s.T())
×
69
}
×
70

71
// TearDownSuite implementation
72
func (s *ConfigStorePersistenceSuite) TearDownSuite() {
×
73
        s.TearDownWorkflowStore()
×
74
}
×
75

76
// Tests if error is returned when trying to fetch dc values from empty table
77
func (s *ConfigStorePersistenceSuite) TestFetchFromEmptyTable() {
×
78
        if !validDatabaseCheck(s.Config()) {
×
79
                s.T().Skip()
×
80
        }
×
81

82
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
83
        defer cancel()
×
84

×
85
        s.DefaultTestCluster.TearDownTestDatabase()
×
86
        s.DefaultTestCluster.SetupTestDatabase()
×
87

×
88
        snapshot, err := s.FetchDynamicConfig(ctx)
×
89
        s.Nil(snapshot)
×
90
        s.NotNil(err)
×
91
}
92

93
func (s *ConfigStorePersistenceSuite) TestUpdateSimpleSuccess() {
×
94
        if !validDatabaseCheck(s.Config()) {
×
95
                s.T().Skip()
×
96
        }
×
97

98
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
99
        defer cancel()
×
100

×
101
        s.DefaultTestCluster.TearDownTestDatabase()
×
102
        s.DefaultTestCluster.SetupTestDatabase()
×
103

×
104
        snapshot := generateRandomSnapshot(1)
×
105
        err := s.UpdateDynamicConfig(ctx, snapshot)
×
106
        s.Nil(err)
×
107

×
108
        retSnapshot, err := s.FetchDynamicConfig(ctx)
×
109
        s.NotNil(snapshot)
×
110
        s.Nil(err)
×
111
        s.Equal(snapshot.Version, retSnapshot.Version)
×
112
        s.Equal(snapshot.Values.Entries[0].Name, retSnapshot.Values.Entries[0].Name)
×
113
}
114

115
func (s *ConfigStorePersistenceSuite) TestUpdateVersionCollisionFailure() {
×
116
        if !validDatabaseCheck(s.Config()) {
×
117
                s.T().Skip()
×
118
        }
×
119

120
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
121
        defer cancel()
×
122

×
123
        s.DefaultTestCluster.TearDownTestDatabase()
×
124
        s.DefaultTestCluster.SetupTestDatabase()
×
125

×
126
        snapshot := generateRandomSnapshot(1)
×
127
        err := s.UpdateDynamicConfig(ctx, snapshot)
×
128
        s.Nil(err)
×
129

×
130
        err = s.UpdateDynamicConfig(ctx, snapshot)
×
131
        var condErr *p.ConditionFailedError
×
132
        s.True(errors.As(err, &condErr))
×
133
}
134

135
func (s *ConfigStorePersistenceSuite) TestUpdateIncrementalVersionSuccess() {
×
136
        if !validDatabaseCheck(s.Config()) {
×
137
                s.T().Skip()
×
138
        }
×
139

140
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
141
        defer cancel()
×
142

×
143
        s.DefaultTestCluster.TearDownTestDatabase()
×
144
        s.DefaultTestCluster.SetupTestDatabase()
×
145

×
146
        snapshot2 := generateRandomSnapshot(2)
×
147
        err := s.UpdateDynamicConfig(ctx, snapshot2)
×
148
        s.Nil(err)
×
149
        snapshot3 := generateRandomSnapshot(3)
×
150
        err = s.UpdateDynamicConfig(ctx, snapshot3)
×
151
        s.Nil(err)
×
152
}
153

154
func (s *ConfigStorePersistenceSuite) TestFetchLatestVersionSuccess() {
×
155
        if !validDatabaseCheck(s.Config()) {
×
156
                s.T().Skip()
×
157
        }
×
158

159
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
160
        defer cancel()
×
161

×
162
        s.DefaultTestCluster.TearDownTestDatabase()
×
163
        s.DefaultTestCluster.SetupTestDatabase()
×
164

×
165
        snapshot2 := generateRandomSnapshot(2)
×
166
        err := s.UpdateDynamicConfig(ctx, snapshot2)
×
167
        s.Nil(err)
×
168
        snapshot3 := generateRandomSnapshot(3)
×
169
        err = s.UpdateDynamicConfig(ctx, snapshot3)
×
170
        s.Nil(err)
×
171

×
172
        snapshot, err := s.FetchDynamicConfig(ctx)
×
173
        s.NotNil(snapshot)
×
174
        s.Nil(err)
×
175
        s.Equal(int64(3), snapshot.Version)
×
176
}
177

178
func generateRandomSnapshot(version int64) *p.DynamicConfigSnapshot {
×
179
        data, _ := json.Marshal("test_value")
×
180

×
181
        values := make([]*types.DynamicConfigValue, 1)
×
182
        values[0] = &types.DynamicConfigValue{
×
183
                Value: &types.DataBlob{
×
184
                        EncodingType: types.EncodingTypeJSON.Ptr(),
×
185
                        Data:         data,
×
186
                },
×
187
                Filters: nil,
×
188
        }
×
189

×
190
        entries := make([]*types.DynamicConfigEntry, 1)
×
191
        entries[0] = &types.DynamicConfigEntry{
×
192
                Name:   "test_parameter",
×
193
                Values: values,
×
194
        }
×
195

×
196
        return &p.DynamicConfigSnapshot{
×
197
                Version: version,
×
198
                Values: &types.DynamicConfigBlob{
×
199
                        SchemaVersion: 1,
×
200
                        Entries:       entries,
×
201
                },
×
202
        }
×
203
}
×
204

205
func validDatabaseCheck(cfg config.Persistence) bool {
×
206
        if datastore, ok := cfg.DataStores[cfg.DefaultStore]; ok {
×
207
                if datastore.NoSQL != nil {
×
208
                        return supportedPlugins[datastore.NoSQL.PluginName]
×
209
                }
×
210
        }
211
        return false
×
212
}
213

214
func (s *ConfigStorePersistenceSuite) FetchDynamicConfig(ctx context.Context) (*p.DynamicConfigSnapshot, error) {
×
215
        response, err := s.ConfigStoreManager.FetchDynamicConfig(ctx, p.DynamicConfig)
×
216
        if err != nil {
×
217
                return nil, err
×
218
        }
×
219
        if response == nil {
×
220
                return nil, errors.New("nil FetchDynamicConfig response")
×
221
        }
×
222
        return response.Snapshot, nil
×
223
}
224

225
func (s *ConfigStorePersistenceSuite) UpdateDynamicConfig(ctx context.Context, snapshot *p.DynamicConfigSnapshot) error {
×
226
        return s.ConfigStoreManager.UpdateDynamicConfig(ctx, &p.UpdateDynamicConfigRequest{Snapshot: snapshot}, p.DynamicConfig)
×
227
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc