Refactor Restore()
This commit refactors out the complexity of downloading ordered WAL files in parallel to a type called `WALDownloader`. This makes it easier to test the restore separately from the download.
This commit is contained in:
14
mock/read_closer.go
Normal file
14
mock/read_closer.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package mock
|
||||
|
||||
type ReadCloser struct {
|
||||
CloseFunc func() error
|
||||
ReadFunc func([]byte) (int, error)
|
||||
}
|
||||
|
||||
func (r *ReadCloser) Close() error {
|
||||
return r.CloseFunc()
|
||||
}
|
||||
|
||||
func (r *ReadCloser) Read(b []byte) (int, error) {
|
||||
return r.ReadFunc(b)
|
||||
}
|
||||
28
mock/snapshot_iterator.go
Normal file
28
mock/snapshot_iterator.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package mock
|
||||
|
||||
import (
|
||||
"github.com/benbjohnson/litestream"
|
||||
)
|
||||
|
||||
type SnapshotIterator struct {
|
||||
CloseFunc func() error
|
||||
NextFunc func() bool
|
||||
ErrFunc func() error
|
||||
SnapshotFunc func() litestream.SnapshotInfo
|
||||
}
|
||||
|
||||
func (itr *SnapshotIterator) Close() error {
|
||||
return itr.CloseFunc()
|
||||
}
|
||||
|
||||
func (itr *SnapshotIterator) Next() bool {
|
||||
return itr.NextFunc()
|
||||
}
|
||||
|
||||
func (itr *SnapshotIterator) Err() error {
|
||||
return itr.ErrFunc()
|
||||
}
|
||||
|
||||
func (itr *SnapshotIterator) Snapshot() litestream.SnapshotInfo {
|
||||
return itr.SnapshotFunc()
|
||||
}
|
||||
28
mock/wal_segment_iterator.go
Normal file
28
mock/wal_segment_iterator.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package mock
|
||||
|
||||
import (
|
||||
"github.com/benbjohnson/litestream"
|
||||
)
|
||||
|
||||
type WALSegmentIterator struct {
|
||||
CloseFunc func() error
|
||||
NextFunc func() bool
|
||||
ErrFunc func() error
|
||||
WALSegmentFunc func() litestream.WALSegmentInfo
|
||||
}
|
||||
|
||||
func (itr *WALSegmentIterator) Close() error {
|
||||
return itr.CloseFunc()
|
||||
}
|
||||
|
||||
func (itr *WALSegmentIterator) Next() bool {
|
||||
return itr.NextFunc()
|
||||
}
|
||||
|
||||
func (itr *WALSegmentIterator) Err() error {
|
||||
return itr.ErrFunc()
|
||||
}
|
||||
|
||||
func (itr *WALSegmentIterator) WALSegment() litestream.WALSegmentInfo {
|
||||
return itr.WALSegmentFunc()
|
||||
}
|
||||
Reference in New Issue
Block a user