github.com/cloudberrydb/gpbackup@v1.0.3-0.20240118031043-5410fd45eed6/restore/remote_test.go (about) 1 package restore_test 2 3 import ( 4 "os/user" 5 6 "github.com/cloudberrydb/gp-common-go-libs/cluster" 7 "github.com/cloudberrydb/gp-common-go-libs/operating" 8 "github.com/cloudberrydb/gp-common-go-libs/testhelper" 9 "github.com/cloudberrydb/gpbackup/filepath" 10 "github.com/cloudberrydb/gpbackup/history" 11 "github.com/cloudberrydb/gpbackup/options" 12 "github.com/cloudberrydb/gpbackup/restore" 13 "github.com/cloudberrydb/gpbackup/toc" 14 15 . "github.com/onsi/ginkgo/v2" 16 . "github.com/onsi/gomega" 17 ) 18 19 var _ = Describe("restore/remote tests", func() { 20 coordinatorSeg := cluster.SegConfig{ContentID: -1, Hostname: "localhost", DataDir: "/data/gpseg-1"} 21 localSegOne := cluster.SegConfig{ContentID: 0, Hostname: "localhost", DataDir: "/data/gpseg0"} 22 remoteSegOne := cluster.SegConfig{ContentID: 1, Hostname: "remotehost1", DataDir: "/data/gpseg1"} 23 var ( 24 testCluster *cluster.Cluster 25 testExecutor *testhelper.TestExecutor 26 testFPInfo filepath.FilePathInfo 27 ) 28 29 BeforeEach(func() { 30 operating.System.CurrentUser = func() (*user.User, error) { return &user.User{Username: "testUser", HomeDir: "testDir"}, nil } 31 operating.System.Hostname = func() (string, error) { return "testHost", nil } 32 testExecutor = &testhelper.TestExecutor{} 33 testCluster = cluster.NewCluster([]cluster.SegConfig{coordinatorSeg, localSegOne, remoteSegOne}) 34 testCluster.Executor = testExecutor 35 testFPInfo = filepath.NewFilePathInfo(testCluster, "", "20170101010101", "gpseg") 36 restore.SetFPInfo(testFPInfo) 37 }) 38 Describe("VerifyBackupFileCountOnSegments", func() { 39 BeforeEach(func() { 40 restore.SetBackupConfig(&history.BackupConfig{SingleDataFile: true}) 41 42 dataEntryOne := toc.CoordinatorDataEntry{} 43 dataEntryTwo := toc.CoordinatorDataEntry{} 44 globalDataEntries := []toc.CoordinatorDataEntry{dataEntryOne, dataEntryTwo} 45 restore.SetTOC(&toc.TOC{DataEntries: globalDataEntries}) 46 }) 47 It("successfully verifies that all backup file counts", func() { 48 testExecutor.ClusterOutput = &cluster.RemoteOutput{ 49 NumErrors: 0, 50 } 51 testCluster.Executor = testExecutor 52 restore.SetCluster(testCluster) 53 restore.VerifyBackupFileCountOnSegments() 54 Expect((*testExecutor).NumExecutions).To(Equal(1)) 55 }) 56 It("panics if backup file counts do not match on all segments with single-data-file", func() { 57 testExecutor.ClusterOutput = &cluster.RemoteOutput{ 58 Commands: []cluster.ShellCommand{ 59 cluster.ShellCommand{Stdout: "1"}, 60 cluster.ShellCommand{Stdout: "1"}, 61 }, 62 } 63 testCluster.Executor = testExecutor 64 restore.SetCluster(testCluster) 65 defer testhelper.ShouldPanicWithMessage("Found incorrect number of backup files on 2 segments") 66 restore.VerifyBackupFileCountOnSegments() 67 }) 68 It("panics if backup file counts do not match on all segments without single-data-file", func() { 69 testExecutor.ClusterOutput = &cluster.RemoteOutput{ 70 Commands: []cluster.ShellCommand{ 71 cluster.ShellCommand{Stdout: "1"}, 72 cluster.ShellCommand{Stdout: "1"}, 73 }, 74 } 75 restore.SetBackupConfig(&history.BackupConfig{SingleDataFile: false}) 76 testCluster.Executor = testExecutor 77 restore.SetCluster(testCluster) 78 defer testhelper.ShouldPanicWithMessage("Found incorrect number of backup files on 2 segments") 79 restore.VerifyBackupFileCountOnSegments() 80 }) 81 It("panics if backup file counts do not match on some segments", func() { 82 testExecutor.ClusterOutput = &cluster.RemoteOutput{ 83 Commands: []cluster.ShellCommand{ 84 cluster.ShellCommand{Stdout: "1"}, 85 }, 86 } 87 testCluster.Executor = testExecutor 88 restore.SetCluster(testCluster) 89 defer testhelper.ShouldPanicWithMessage("Found incorrect number of backup files on 1 segment") 90 restore.VerifyBackupFileCountOnSegments() 91 }) 92 It("panics if it cannot verify some backup file counts", func() { 93 testExecutor.ClusterOutput = &cluster.RemoteOutput{ 94 NumErrors: 1, 95 FailedCommands: []*cluster.ShellCommand{ 96 &cluster.ShellCommand{Content: 1, Stdout: "1"}, 97 }, 98 } 99 testCluster.Executor = testExecutor 100 restore.SetCluster(testCluster) 101 defer testhelper.ShouldPanicWithMessage("Could not verify backup file count on 1 segment") 102 restore.VerifyBackupFileCountOnSegments() 103 }) 104 It("verifies backup file counts match on all segments with resize-cluster", func() { 105 testExecutor.ClusterOutput = &cluster.RemoteOutput{ 106 Commands: []cluster.ShellCommand{ 107 cluster.ShellCommand{Stdout: "4"}, 108 cluster.ShellCommand{Stdout: "2"}, 109 }, 110 } 111 testCluster.Executor = testExecutor 112 restore.SetCluster(testCluster) 113 restore.SetBackupConfig(&history.BackupConfig{SingleDataFile: true, SegmentCount: 3}) 114 cmdFlags.Set(options.RESIZE_CLUSTER, "true") 115 // LogFatalError in VerifyBackupFileCountOnSegments will fail test if values are wrong 116 // Expect is implied, does not need to be explicitly called here 117 restore.VerifyBackupFileCountOnSegments() 118 }) 119 }) 120 })