Skip to content

Commit 306eda8

Browse files
authored
Add sqlite persistence tests (#2681)
* Add sqlite persistence tests * fix up a test * Remove limit on prune operation for sql plugin
1 parent ad56ef2 commit 306eda8

File tree

10 files changed

+314
-15
lines changed

10 files changed

+314
-15
lines changed

.vscode/launch.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,19 @@
5151
"start",
5252
]
5353
},
54+
{
55+
"name": "Debug Server with SQLite",
56+
"type": "go",
57+
"request": "launch",
58+
"mode": "debug",
59+
"program": "${workspaceFolder}/cmd/server",
60+
"cwd": "${workspaceFolder}",
61+
"args": [
62+
"--env",
63+
"development_sqlite",
64+
"start",
65+
]
66+
},
5467
{
5568
"name": "Debug CLI Namespace Describe",
5669
"type": "go",

common/backoff/retry_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,21 +123,22 @@ func (s *RetrySuite) TestIsRetryableSuccess() {
123123

124124
func (s *RetrySuite) TestIsRetryableFailure() {
125125
i := 0
126+
theErr := someError{}
126127
op := func() error {
127128
i++
128129

129130
if i == 5 {
130131
return nil
131132
}
132133

133-
return &someError{}
134+
return &theErr
134135
}
135136

136137
policy := NewExponentialRetryPolicy(1 * time.Millisecond)
137138
policy.SetMaximumInterval(5 * time.Millisecond)
138139
policy.SetMaximumAttempts(10)
139140

140-
err := Retry(op, policy, IgnoreErrors([]error{&someError{}}))
141+
err := Retry(op, policy, IgnoreErrors([]error{&theErr}))
141142
s.Error(err)
142143
s.Equal(1, i)
143144
}

common/persistence/persistence-tests/setup.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ const (
4444
testSQLiteUser = ""
4545
testSQLitePassword = ""
4646
testSQLiteMode = "memory"
47-
testSQLiteSchemaDir = "" // specify if mode is not "memory"
47+
testSQLiteCache = "private"
48+
testSQLiteSchemaDir = "schema/sqlite/v3" // specify if mode is not "memory"
4849
)
4950

5051
// GetMySQLTestClusterOption return test options
@@ -81,8 +82,8 @@ func GetSQLiteTestClusterOption() *TestBaseOptions {
8182
DBPassword: testSQLitePassword,
8283
DBHost: environment.Localhost,
8384
DBPort: 0,
84-
SchemaDir: testSQLiteSchemaDir,
85+
SchemaDir: "",
8586
StoreType: config.StoreTypeSQL,
86-
ConnectAttributes: map[string]string{"mode": testSQLiteMode},
87+
ConnectAttributes: map[string]string{"mode": testSQLiteMode, "cache": testSQLiteCache},
8788
}
8889
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// The MIT License
2+
//
3+
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
4+
//
5+
// Copyright (c) 2020 Uber Technologies, Inc.
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files (the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions:
13+
//
14+
// The above copyright notice and this permission notice shall be included in
15+
// all copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
// THE SOFTWARE.
24+
25+
package persistencetests
26+
27+
import (
28+
"testing"
29+
30+
"github.com/stretchr/testify/suite"
31+
)
32+
33+
func TestSQLiteHistoryV2PersistenceSuite(t *testing.T) {
34+
s := new(HistoryV2PersistenceSuite)
35+
s.TestBase = NewTestBaseWithSQL(GetSQLiteTestClusterOption())
36+
s.TestBase.Setup(nil)
37+
suite.Run(t, s)
38+
}
39+
40+
func TestSQLiteMetadataPersistenceSuiteV2(t *testing.T) {
41+
s := new(MetadataPersistenceSuiteV2)
42+
s.TestBase = NewTestBaseWithSQL(GetSQLiteTestClusterOption())
43+
s.TestBase.Setup(nil)
44+
suite.Run(t, s)
45+
}
46+
47+
func TestSQLiteShardPersistenceSuite(t *testing.T) {
48+
s := new(ShardPersistenceSuite)
49+
s.TestBase = NewTestBaseWithSQL(GetSQLiteTestClusterOption())
50+
s.TestBase.Setup(nil)
51+
suite.Run(t, s)
52+
}
53+
54+
func TestSQLiteExecutionManagerSuite(t *testing.T) {
55+
s := new(ExecutionManagerSuite)
56+
s.TestBase = NewTestBaseWithSQL(GetSQLiteTestClusterOption())
57+
s.TestBase.Setup(nil)
58+
suite.Run(t, s)
59+
}
60+
61+
func TestSQLiteExecutionManagerWithEventsV2(t *testing.T) {
62+
s := new(ExecutionManagerSuiteForEventsV2)
63+
s.TestBase = NewTestBaseWithSQL(GetSQLiteTestClusterOption())
64+
s.TestBase.Setup(nil)
65+
suite.Run(t, s)
66+
}
67+
68+
func TestSQLiteClusterMetadataPersistence(t *testing.T) {
69+
s := new(ClusterMetadataManagerSuite)
70+
s.TestBase = NewTestBaseWithSQL(GetSQLiteTestClusterOption())
71+
s.TestBase.Setup(nil)
72+
suite.Run(t, s)
73+
}
74+
75+
func TestSQLiteQueuePersistence(t *testing.T) {
76+
s := new(QueuePersistenceSuite)
77+
s.TestBase = NewTestBaseWithSQL(GetSQLiteTestClusterOption())
78+
s.TestBase.Setup(nil)
79+
suite.Run(t, s)
80+
}

common/persistence/sql/cluster_metadata.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,11 @@ func (s *sqlClusterMetadataManager) PruneClusterMembership(
253253
) error {
254254
ctx, cancel := newExecutionContext()
255255
defer cancel()
256-
_, err := s.Db.PruneClusterMembership(ctx, &sqlplugin.PruneClusterMembershipFilter{
257-
PruneRecordsBefore: time.Now().UTC(),
258-
MaxRecordsAffected: request.MaxRecordsPruned})
256+
_, err := s.Db.PruneClusterMembership(
257+
ctx,
258+
&sqlplugin.PruneClusterMembershipFilter{
259+
PruneRecordsBefore: time.Now().UTC(),
260+
})
259261

260262
if err != nil {
261263
return convertCommonErrors("PruneClusterMembership", err)

common/persistence/sql/sqlplugin/cluster_metadata.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ type (
7373
// PruneClusterMembershipFilter is used for PruneClusterMembership queries
7474
PruneClusterMembershipFilter struct {
7575
PruneRecordsBefore time.Time
76-
MaxRecordsAffected int
7776
}
7877

7978
// ClusterMetadata is the SQL persistence interface for cluster metadata

common/persistence/sql/sqlplugin/mysql/cluster_metadata.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ session_start=VALUES(session_start), last_heartbeat=VALUES(last_heartbeat), reco
5959

6060
templatePruneStaleClusterMembership = `DELETE FROM
6161
cluster_membership
62-
WHERE membership_partition = ? AND record_expiry < ? LIMIT ?`
62+
WHERE membership_partition = ? AND record_expiry < ?`
6363

6464
templateGetClusterMembership = `SELECT host_id, rpc_address, rpc_port, role, session_start, last_heartbeat, record_expiry FROM
6565
cluster_membership WHERE membership_partition = ?`
@@ -262,6 +262,5 @@ func (mdb *db) PruneClusterMembership(
262262
templatePruneStaleClusterMembership,
263263
constMembershipPartition,
264264
mdb.converter.ToMySQLDateTime(filter.PruneRecordsBefore),
265-
filter.MaxRecordsAffected,
266265
)
267266
}

common/persistence/sql/sqlplugin/postgresql/cluster_metadata.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ membership_partition = $1, host_id = $2, rpc_address = $3, rpc_port = $4, role =
6363
templatePruneStaleClusterMembership = `DELETE FROM
6464
cluster_membership
6565
WHERE host_id = ANY(ARRAY(
66-
SELECT host_id FROM cluster_membership WHERE membership_partition = $1 AND record_expiry < $2 LIMIT $3))`
66+
SELECT host_id FROM cluster_membership WHERE membership_partition = $1 AND record_expiry < $2))`
6767

6868
templateGetClusterMembership = `SELECT host_id, rpc_address, rpc_port, role, session_start, last_heartbeat, record_expiry FROM
6969
cluster_membership WHERE membership_partition = $`
@@ -281,6 +281,5 @@ func (pdb *db) PruneClusterMembership(
281281
templatePruneStaleClusterMembership,
282282
constMembershipPartition,
283283
filter.PruneRecordsBefore,
284-
filter.MaxRecordsAffected,
285284
)
286285
}

common/persistence/sql/sqlplugin/sqlite/cluster_metadata.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ VALUES(?, ?, ?, ?, ?, ?, ?, ?) `
6161

6262
templatePruneStaleClusterMembership = `DELETE FROM
6363
cluster_membership
64-
WHERE membership_partition = ? AND record_expiry < ? LIMIT ?`
64+
WHERE membership_partition = ? AND record_expiry < ?`
6565

6666
templateGetClusterMembership = `SELECT host_id, rpc_address, rpc_port, role, session_start, last_heartbeat, record_expiry FROM
6767
cluster_membership WHERE membership_partition = ?`
@@ -264,6 +264,5 @@ func (mdb *db) PruneClusterMembership(
264264
templatePruneStaleClusterMembership,
265265
constMembershipPartition,
266266
mdb.converter.ToSQLiteDateTime(filter.PruneRecordsBefore),
267-
filter.MaxRecordsAffected,
268267
)
269268
}

0 commit comments

Comments
 (0)