MCPcopy
hub / github.com/wal-g/wal-g / TestTransferHandler_Handle

Function TestTransferHandler_Handle

internal/storagetools/transfer/handler_test.go:130–238  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

128}
129
130func TestTransferHandler_Handle(t *testing.T) {
131 defaultHandler := func() *Handler {
132 return &Handler{
133 source: memory.NewFolder("source/", memory.NewKVS()),
134 target: memory.NewFolder("target/", memory.NewKVS()),
135 fileLister: NewRegularFileLister("/", false, 100500),
136 cfg: &HandlerConfig{
137 FailOnFirstErr: false,
138 Concurrency: 5,
139 AppearanceChecks: 3,
140 AppearanceChecksInterval: 0,
141 },
142 fileStatuses: new(sync.Map),
143 jobRequirements: map[jobKey][]jobRequirement{},
144 }
145 }
146
147 countFiles := func(folder storage.Folder, max int) int {
148 found := 0
149 for i := 0; i < max; i++ {
150 exists, err := folder.Exists(strconv.Itoa(i))
151 assert.NoError(t, err)
152 if exists {
153 found++
154 }
155 }
156 return found
157 }
158
159 t.Run("move all nonexistent files", func(t *testing.T) {
160 h := defaultHandler()
161 h.fileLister.(*RegularFileLister).MaxFiles = 80
162
163 for i := 0; i < 100; i++ {
164 _ = h.source.PutObject(strconv.Itoa(i), &bytes.Buffer{})
165 }
166
167 for i := 0; i < 10; i++ {
168 _ = h.target.PutObject(strconv.Itoa(i), &bytes.Buffer{})
169 }
170
171 err := h.Handle()
172 assert.NoError(t, err)
173
174 assert.Equal(t, 90, countFiles(h.target, 100))
175 assert.Equal(t, 20, countFiles(h.source, 100))
176 })
177
178 t.Run("tolerate errors with some files", func(t *testing.T) {
179 targetMock := mock.NewFolder(memory.NewFolder("target/", memory.NewKVS()))
180
181 putCalls := 0
182 putCallsMux := new(sync.Mutex)
183 targetMock.PutObjectMock = func(_ context.Context, name string, content io.Reader) error {
184 putCallsMux.Lock()
185 defer putCallsMux.Unlock()
186 putCalls++
187 if putCalls%5 == 0 {

Callers

nothing calls this directly

Calls 13

NewFolderFunction · 0.92
NewKVSFunction · 0.92
NewFolderFunction · 0.92
NewRegularFileListerFunction · 0.85
LockMethod · 0.80
UnlockMethod · 0.80
ErrorfMethod · 0.80
ExistsMethod · 0.65
RunMethod · 0.65
PutObjectMethod · 0.65
HandleMethod · 0.65
DeleteObjectsMethod · 0.65

Tested by

no test coverage detected