Skip to content

Commit 858a8b9

Browse files
feat(restore_test): add test for changing backup method
This commit adds TestRestoreFullChangingMethodIntegration, which verifies that changing backup method from rclone to native and so forth results in a correct restore. It also removes new task ID generation on every backup/restore run, as it shouldn't be needed and prevents from verifying retention policy behavior.
1 parent a521fe3 commit 858a8b9

File tree

2 files changed

+74
-2
lines changed

2 files changed

+74
-2
lines changed

pkg/service/restore/helper_integration_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ func defaultTestBackupProperties(loc backupspec.Location, ks string) map[string]
257257
func (h *testHelper) runBackup(t *testing.T, props map[string]any) string {
258258
Printf("Run backup with properties: %v", props)
259259
ctx := context.Background()
260-
h.srcCluster.TaskID = uuid.NewTime()
261260
h.srcCluster.RunID = uuid.NewTime()
262261

263262
rawProps, err := json.Marshal(props)
@@ -286,7 +285,6 @@ func (h *testHelper) runBackup(t *testing.T, props map[string]any) string {
286285
func (h *testHelper) runRestore(t *testing.T, props map[string]any) {
287286
Printf("Run restore with properties: %v", props)
288287
ctx := context.Background()
289-
h.dstCluster.TaskID = uuid.NewTime()
290288
h.dstCluster.RunID = uuid.NewTime()
291289

292290
rawProps, err := json.Marshal(props)

pkg/service/restore/restore_integration_test.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,6 +1454,80 @@ func TestRestoreTablesMethodIntegration(t *testing.T) {
14541454
}
14551455
}
14561456

1457+
func TestRestoreFullChangingMethodIntegration(t *testing.T) {
1458+
h := newTestHelper(t, ManagedClusterHosts(), ManagedSecondClusterHosts())
1459+
ctx := context.Background()
1460+
1461+
ni, err := h.srcCluster.Client.AnyNodeInfo(ctx)
1462+
if err != nil {
1463+
t.Fatal(err)
1464+
}
1465+
if ok, err := ni.SupportsNativeBackupAPI(); err != nil {
1466+
t.Fatal(err)
1467+
} else if !ok {
1468+
t.Skip("Test assumes native backup api support")
1469+
}
1470+
1471+
Print("Keyspace setup")
1472+
ksStmt := "CREATE KEYSPACE %q WITH replication = {'class': 'NetworkTopologyStrategy', 'dc1': %d}"
1473+
ks := randomizedName("changing_method_")
1474+
ExecStmt(t, h.srcCluster.rootSession, fmt.Sprintf(ksStmt, ks, 2))
1475+
1476+
Print("Table setup")
1477+
tabStmt := "CREATE TABLE %q.%q (id int PRIMARY KEY, data int)"
1478+
tab := randomizedName("tab_")
1479+
ExecStmt(t, h.srcCluster.rootSession, fmt.Sprintf(tabStmt, ks, tab))
1480+
1481+
Print("Location and permissions setup")
1482+
loc := testLocation("changing-method", "")
1483+
S3InitBucket(t, loc.Path)
1484+
ksFilter := []string{ks}
1485+
backupProps := defaultTestBackupProperties(loc, ks)
1486+
// Configure retention policy so that the last backup happens after purge
1487+
backupProps["retention"] = 3
1488+
backupProps["retention_days"] = 0
1489+
backupProps["retention_map"] = backup.RetentionMap{
1490+
h.srcCluster.TaskID: backup.RetentionPolicy{
1491+
RetentionDays: 0,
1492+
Retention: 3,
1493+
},
1494+
}
1495+
grantRestoreSchemaPermissions(t, h.dstCluster.rootSession, h.dstUser)
1496+
grantRestoreTablesPermissions(t, h.dstCluster.rootSession, ksFilter, h.dstUser)
1497+
1498+
type testIter struct {
1499+
backupMethod backup.Method
1500+
rowCnt int
1501+
}
1502+
testCases := []testIter{
1503+
{backupMethod: backup.MethodRclone, rowCnt: 50},
1504+
{backupMethod: backup.MethodNative, rowCnt: 100},
1505+
{backupMethod: backup.MethodRclone, rowCnt: 150},
1506+
{backupMethod: backup.MethodNative, rowCnt: 200},
1507+
{backupMethod: backup.MethodRclone, rowCnt: 250},
1508+
}
1509+
for i, tc := range testCases {
1510+
t.Log("Fill: ", i)
1511+
fillTable(t, h.srcCluster.rootSession, tc.rowCnt, ks, tab)
1512+
1513+
t.Log("Backup: ", i)
1514+
backupProps["method"] = tc.backupMethod
1515+
tag := h.runBackup(t, backupProps)
1516+
1517+
t.Log("Restore schema: ", i)
1518+
ExecStmt(t, h.dstCluster.rootSession, fmt.Sprintf("DROP KEYSPACE IF EXISTS %q", ks))
1519+
restoreProps := defaultTestProperties(loc, tag, false)
1520+
h.runRestore(t, restoreProps)
1521+
1522+
t.Log("Restore tables: ", i)
1523+
restoreProps = defaultTestProperties(loc, tag, true)
1524+
h.runRestore(t, restoreProps)
1525+
1526+
t.Log("Validate: ", i)
1527+
h.validateIdenticalTables(t, []table{{ks: ks, tab: tab}})
1528+
}
1529+
}
1530+
14571531
func TestRestoreFullAlternatorIntegration(t *testing.T) {
14581532
h := newTestHelper(t, ManagedSecondClusterHosts(), ManagedClusterHosts())
14591533

0 commit comments

Comments
 (0)