MCPcopy
hub / github.com/etcd-io/bbolt / TestTx_RecursivelyCheckPages_MisplacedPage

Function TestTx_RecursivelyCheckPages_MisplacedPage

internal/tests/tx_check_test.go:15–52  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestTx_RecursivelyCheckPages_MisplacedPage(t *testing.T) {
16 db := btesting.MustCreateDB(t)
17 db.ForceDisableStrictMode()
18 require.NoError(t,
19 db.Fill([]byte("data"), 1, 10000,
20 func(tx int, k int) []byte { return []byte(fmt.Sprintf("%04d", k)) },
21 func(tx int, k int) []byte { return make([]byte, 100) },
22 ))
23 require.NoError(t, db.Close())
24
25 xRay := surgeon.NewXRay(db.Path())
26
27 path1, err := xRay.FindPathsToKey([]byte("0451"))
28 require.NoError(t, err, "cannot find page that contains key:'0451'")
29 require.Len(t, path1, 1, "Expected only one page that contains key:'0451'")
30
31 path2, err := xRay.FindPathsToKey([]byte("7563"))
32 require.NoError(t, err, "cannot find page that contains key:'7563'")
33 require.Len(t, path2, 1, "Expected only one page that contains key:'7563'")
34
35 srcPage := path1[0][len(path1[0])-1]
36 targetPage := path2[0][len(path2[0])-1]
37 require.NoError(t, surgeon.CopyPage(db.Path(), srcPage, targetPage))
38
39 db.MustReopen()
40 db.ForceDisableStrictMode()
41 require.NoError(t, db.Update(func(tx *bolt.Tx) error {
42 // Collect all the errors.
43 var errors []error
44 for err := range tx.Check() {
45 errors = append(errors, err)
46 }
47 require.Len(t, errors, 1)
48 require.ErrorContains(t, errors[0], fmt.Sprintf("leaf page(%v) needs to be >= the key in the ancestor", targetPage))
49 return nil
50 }))
51 require.NoError(t, db.Close())
52}
53
54func TestTx_RecursivelyCheckPages_CorruptedLeaf(t *testing.T) {
55 db := btesting.MustCreateDB(t)

Callers

nothing calls this directly

Calls 12

FindPathsToKeyMethod · 0.95
MustCreateDBFunction · 0.92
NewXRayFunction · 0.92
CopyPageFunction · 0.92
FillMethod · 0.80
MustReopenMethod · 0.80
UpdateMethod · 0.80
CheckMethod · 0.80
CloseMethod · 0.45
PathMethod · 0.45
LenMethod · 0.45

Tested by

no test coverage detected