Skip to content

Commit c2b288c

Browse files
feat(testutils/db): make alternator setup more interesting
1 parent 4c3486e commit c2b288c

File tree

4 files changed

+260
-145
lines changed

4 files changed

+260
-145
lines changed

pkg/service/backup/service_backup_integration_test.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2264,8 +2264,8 @@ func TestBackupAlternatorIntegration(t *testing.T) {
22642264

22652265
accessKeyID, secretAccessKey := GetAlternatorCreds(t, clusterSession, "")
22662266
client := CreateAlternatorClient(t, h.Client, ManagedClusterHost(), accessKeyID, secretAccessKey)
2267-
CreateAlternatorTable(t, client, testTable)
2268-
FillAlternatorTable(t, client, testTable, rowCnt)
2267+
CreateAlternatorTable(t, client, 0, testTable)
2268+
InsertAlternatorTableData(t, client, rowCnt, testTable)
22692269

22702270
Print("When: validate data insertion")
22712271
selectStmt := fmt.Sprintf("SELECT COUNT(*) FROM %q.%q", testKeyspace, testTable)
@@ -2714,13 +2714,16 @@ func TestTGetDescribeSchemaIntegration(t *testing.T) {
27142714

27152715
// Second backup with table created with Alternator
27162716
const (
2717-
tabAlt = "tab_alt"
2718-
tabAltLSI = tabAlt + "_LSI"
2719-
tabAltGSI = tabAlt + "_GSI"
2720-
tabAltTag = tabAlt + "_tag"
2721-
tabAltTTL = tabAlt + "_TTL"
2717+
tabAlt = "tab_alt_" + AlternatorProblematicTableChars
2718+
tabAltLSI = AlternatorLSIPrefix + "0"
2719+
tabAltGSI = "gsi_alt" + AlternatorProblematicTableChars
2720+
tabAltTag = "tab_alt_tag"
2721+
tabAltTTLAttr = "tab_alt_ttl_attr"
27222722
)
2723-
CreateInterestingAlternatorSchema(t, client, "tab_alt")
2723+
CreateAlternatorTable(t, client, 1, tabAlt)
2724+
CreateAlternatorGSI(t, client, tabAlt, tabAltGSI)
2725+
TagAlternatorTable(t, client, tabAlt, tabAltTag)
2726+
UpdateAlternatorTableTTL(t, client, tabAlt, tabAltTTLAttr, true)
27242727
cqlSchema2, err := query.DescribeSchemaWithInternals(clusterSession)
27252728
tag2 := makeBackup()
27262729

@@ -2838,8 +2841,8 @@ func TestTGetDescribeSchemaIntegration(t *testing.T) {
28382841
if *altTab.Tags[0].Key != tabAltTag {
28392842
t.Fatalf("Expected alternator tag: %s, got: %s", tabAltTag, *altTab.Tags[0].Key)
28402843
}
2841-
if *altTab.TTL.AttributeName != tabAltTTL {
2842-
t.Fatalf("Expected alternator TTL: %s, got: %s", tabAltTTL, *altTab.TTL.AttributeName)
2844+
if *altTab.TTL.AttributeName != tabAltTTLAttr {
2845+
t.Fatalf("Expected alternator TTL: %s, got: %s", tabAltTTLAttr, *altTab.TTL.AttributeName)
28432846
}
28442847
})
28452848
}

pkg/service/repair/service_repair_integration_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,8 +1891,8 @@ func TestServiceRepairIntegration(t *testing.T) {
18911891
Print("When: create alternator table with 1 row")
18921892
accessKeyID, secretAccessKey := GetAlternatorCreds(t, clusterSession, "")
18931893
client := CreateAlternatorClient(t, h.Client, ManagedClusterHost(), accessKeyID, secretAccessKey)
1894-
CreateAlternatorTable(t, client, testTable)
1895-
FillAlternatorTable(t, client, testTable, 100)
1894+
CreateAlternatorTable(t, client, 0, testTable)
1895+
InsertAlternatorTableData(t, client, 100, testTable)
18961896
defer dropKeyspace(t, clusterSession, testKeyspace)
18971897

18981898
h := newRepairTestHelper(t, session, defaultConfig())

pkg/service/restore/restore_integration_test.go

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package restore_test
77

88
import (
9+
"cmp"
910
"context"
1011
"encoding/json"
1112
"fmt"
@@ -21,6 +22,7 @@ import (
2122

2223
"github.com/aws/aws-sdk-go-v2/aws"
2324
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
25+
"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
2426
"github.com/pkg/errors"
2527
"github.com/scylladb/gocqlx/v2/qb"
2628
"github.com/scylladb/scylla-manager/backupspec"
@@ -136,8 +138,19 @@ func TestRestoreSchemaRoundtripIntegration(t *testing.T) {
136138
ExecStmt(t, h.srcCluster.rootSession, fmt.Sprintf(tabStmt, cqlKs, cqlTab, tabOpt))
137139

138140
Print("Prepare alternator schema")
139-
altTab := "roundtrip_Tab_le-With1.da_sh2-aNd.d33ot.-"
140-
CreateInterestingAlternatorSchema(t, h.srcCluster.altClient, altTab)
141+
altTab1 := "roundtrip_1_" + AlternatorProblematicTableChars
142+
altTab2 := "roundtrip_2_" + AlternatorProblematicTableChars
143+
altGSI1 := "gsi_1_" + AlternatorProblematicTableChars
144+
altGSI2 := "gsi_2_" + AlternatorProblematicTableChars
145+
altTag := "tag"
146+
altTTLAttr := "ttl_attr"
147+
CreateAlternatorTable(t, h.srcCluster.altClient, 2, altTab1, altTab2)
148+
CreateAlternatorGSI(t, h.srcCluster.altClient, altTab1, altGSI1, altGSI2)
149+
CreateAlternatorGSI(t, h.srcCluster.altClient, altTab2, altGSI1, altGSI2)
150+
TagAlternatorTable(t, h.srcCluster.altClient, altTab1, altTag)
151+
TagAlternatorTable(t, h.srcCluster.altClient, altTab2, altTag)
152+
UpdateAlternatorTableTTL(t, h.srcCluster.altClient, altTab1, altTTLAttr, true)
153+
UpdateAlternatorTableTTL(t, h.srcCluster.altClient, altTab2, altTTLAttr, true)
141154

142155
Print("Save src CQL schema")
143156
srcCQLSchema, err := query.DescribeSchemaWithInternals(h.srcCluster.rootSession)
@@ -160,7 +173,11 @@ func TestRestoreSchemaRoundtripIntegration(t *testing.T) {
160173
ExecStmt(t, h.srcCluster.rootSession, "DROP KEYSPACE "+cqlKs)
161174

162175
Print("Drop backed-up src cluster alternator schema")
163-
_, err = h.srcCluster.altClient.DeleteTable(context.Background(), &dynamodb.DeleteTableInput{TableName: aws.String(altTab)})
176+
_, err = h.srcCluster.altClient.DeleteTable(context.Background(), &dynamodb.DeleteTableInput{TableName: aws.String(altTab1)})
177+
if err != nil {
178+
t.Fatal(err)
179+
}
180+
_, err = h.srcCluster.altClient.DeleteTable(context.Background(), &dynamodb.DeleteTableInput{TableName: aws.String(altTab2)})
164181
if err != nil {
165182
t.Fatal(err)
166183
}
@@ -215,7 +232,7 @@ func TestRestoreSchemaRoundtripIntegration(t *testing.T) {
215232
continue
216233
}
217234
// Don't validate alternator schema CQL statements
218-
if row.Keyspace == fmt.Sprintf("%q", "alternator_"+altTab) {
235+
if strings.HasPrefix(row.Keyspace, "\"alternator_") {
219236
continue
220237
}
221238
m1[row] = struct{}{}
@@ -230,12 +247,12 @@ func TestRestoreSchemaRoundtripIntegration(t *testing.T) {
230247
t.Fatalf("Src CQL schema: %v, is missing created objects: %v", m1, objWithOpt)
231248
}
232249
for _, row := range dstCQLSchemaSrcBackup {
233-
if row.Keyspace != "" && row.Keyspace != fmt.Sprintf("%q", "alternator_"+altTab) {
250+
if row.Keyspace != "" && !strings.HasPrefix(row.Keyspace, "\"alternator_") {
234251
m2[row] = struct{}{}
235252
}
236253
}
237254
for _, row := range srcCQLSchemaDstBackup {
238-
if row.Keyspace != "" && row.Keyspace != fmt.Sprintf("%q", "alternator_"+altTab) {
255+
if row.Keyspace != "" && !strings.HasPrefix(row.Keyspace, "\"alternator_") {
239256
m3[row] = struct{}{}
240257
}
241258
}
@@ -249,6 +266,10 @@ func TestRestoreSchemaRoundtripIntegration(t *testing.T) {
249266

250267
Print("Validate alternator schema")
251268
sanitizeAltSchema := func(schema backupspec.AlternatorSchema) {
269+
// Sort so that we can compare raw json encoding later
270+
slices.SortFunc(schema.Tables, func(a, b backupspec.AlternatorTableSchema) int {
271+
return cmp.Compare(*a.Describe.TableName, *b.Describe.TableName)
272+
})
252273
for i := range schema.Tables {
253274
// Set TTL to nil as we don't restore it
254275
schema.Tables[i].TTL = nil
@@ -259,6 +280,12 @@ func TestRestoreSchemaRoundtripIntegration(t *testing.T) {
259280
schema.Tables[i].Describe.ProvisionedThroughput.LastIncreaseDateTime = nil
260281
// Set table ID to ni as it is expected to differ
261282
schema.Tables[i].Describe.TableId = nil
283+
slices.SortFunc(schema.Tables[i].Describe.GlobalSecondaryIndexes, func(a, b types.GlobalSecondaryIndexDescription) int {
284+
return cmp.Compare(*a.IndexName, *b.IndexName)
285+
})
286+
slices.SortFunc(schema.Tables[i].Describe.LocalSecondaryIndexes, func(a, b types.LocalSecondaryIndexDescription) int {
287+
return cmp.Compare(*a.IndexName, *b.IndexName)
288+
})
262289
}
263290
}
264291
sanitizeAltSchema(srcAltSchema)

0 commit comments

Comments
 (0)