forked from cockroachdb/pebble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrotation_test.go
49 lines (41 loc) · 1.16 KB
/
rotation_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
// Copyright 2023 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 record
import (
"fmt"
"strconv"
"testing"
"github.com/cockroachdb/datadriven"
)
func TestRotation(t *testing.T) {
var rh RotationHelper
datadriven.RunTest(t, "testdata/rotation", func(t *testing.T, td *datadriven.TestData) string {
oneIntArg := func() int64 {
if len(td.CmdArgs) != 1 {
td.Fatalf(t, "expected one integer argument")
}
n, err := strconv.Atoi(td.CmdArgs[0].String())
if err != nil {
td.Fatalf(t, "expected one integer argument")
}
return int64(n)
}
switch td.Cmd {
case "add":
size := oneIntArg()
rh.AddRecord(size)
case "should-rotate":
nextSnapshotSize := oneIntArg()
return fmt.Sprint(rh.ShouldRotate(nextSnapshotSize))
case "rotate":
snapshotSize := oneIntArg()
rh.Rotate(snapshotSize)
default:
td.Fatalf(t, "unknown command %s", td.Cmd)
}
// For commands with no output, show the debug info.
a, b := rh.DebugInfo()
return fmt.Sprintf("last-snapshot-size: %d\nsize-since-last-snapshot: %d", a, b)
})
}