forked from cockroachdb/pebble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleaner_test.go
111 lines (99 loc) · 2.3 KB
/
cleaner_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright 2019 The LevelDB-Go and Pebble Authors. All rights reserved. Use
// of this source code is governed by a BSD-style license that can be found in
// the LICENSE file.
package pebble
import (
"fmt"
"sort"
"strings"
"testing"
"github.com/cockroachdb/pebble/internal/datadriven"
"github.com/cockroachdb/pebble/vfs"
"github.com/stretchr/testify/require"
)
func TestArchiveCleaner(t *testing.T) {
dbs := make(map[string]*DB)
defer func() {
for _, db := range dbs {
require.NoError(t, db.Close())
}
}()
var buf syncedBuffer
mem := vfs.NewMem()
opts := &Options{
Cleaner: ArchiveCleaner{},
FS: loggingFS{mem, &buf},
WALDir: "wal",
}
datadriven.RunTest(t, "testdata/cleaner", func(td *datadriven.TestData) string {
switch td.Cmd {
case "batch":
if len(td.CmdArgs) != 1 {
return "batch <db>"
}
buf.Reset()
d := dbs[td.CmdArgs[0].String()]
b := d.NewBatch()
if err := runBatchDefineCmd(td, b); err != nil {
return err.Error()
}
if err := b.Commit(Sync); err != nil {
return err.Error()
}
return buf.String()
case "compact":
if len(td.CmdArgs) != 1 {
return "compact <db>"
}
buf.Reset()
d := dbs[td.CmdArgs[0].String()]
if err := d.Compact(nil, []byte("\xff")); err != nil {
return err.Error()
}
return buf.String()
case "flush":
if len(td.CmdArgs) != 1 {
return "flush <db>"
}
buf.Reset()
d := dbs[td.CmdArgs[0].String()]
if err := d.Flush(); err != nil {
return err.Error()
}
return buf.String()
case "list":
if len(td.CmdArgs) != 1 {
return "list <dir>"
}
paths, err := mem.List(td.CmdArgs[0].String())
if err != nil {
return err.Error()
}
sort.Strings(paths)
buf.Reset()
fmt.Fprintf(&buf, "%s\n", strings.Join(paths, "\n"))
return buf.String()
case "open":
if len(td.CmdArgs) != 1 && len(td.CmdArgs) != 2 {
return "open <dir> [readonly]"
}
opts.ReadOnly = false
if len(td.CmdArgs) == 2 {
if td.CmdArgs[1].String() != "readonly" {
return "open <dir> [readonly]"
}
opts.ReadOnly = true
}
buf.Reset()
dir := td.CmdArgs[0].String()
d, err := Open(dir, opts)
if err != nil {
return err.Error()
}
dbs[dir] = d
return buf.String()
default:
return fmt.Sprintf("unknown command: %s", td.Cmd)
}
})
}