-
Notifications
You must be signed in to change notification settings - Fork 0
/
visibility_test.go
66 lines (56 loc) · 1.46 KB
/
visibility_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
package lmdb
import (
"io/ioutil"
"os"
"testing"
"github.com/facebookgo/ensure"
)
func TestVisibility1(t *testing.T) {
path, err := ioutil.TempDir("", "lmdb_test")
if err != nil {
panic(err)
}
defer os.RemoveAll(path)
bucketNames := []string{testBucket}
db, err := Open(path, bucketNames)
defer db.Close()
if err != nil {
panic(err)
}
db.TransactionalRW(func(txn *ReadWriteTxn) error {
if n := txn.BucketStat(testBucket).Entries; n != 0 {
t.Fatal("bucket not empty: ", n)
}
txn.Put(testBucket, []byte("txn0"), []byte("bar0"))
{
val, exist := txn.GetNoCopy(testBucket, []byte("txn0"))
ensure.True(t, exist)
ensure.DeepEqual(t, val, []byte("bar0"))
}
// first tx
txn.TransactionalRW(func(txn *ReadWriteTxn) error {
{ // parent's change should be visiable to child
val, exist := txn.GetNoCopy(testBucket, []byte("txn0"))
ensure.True(t, exist)
ensure.DeepEqual(t, val, []byte("bar0"))
}
txn.Put(testBucket, []byte("txn00"), []byte("bar00"))
{
val, exist := txn.GetNoCopy(testBucket, []byte("txn00"))
ensure.True(t, exist)
ensure.DeepEqual(t, val, []byte("bar00"))
}
return nil
})
// second tx
txn.TransactionalRW(func(txn *ReadWriteTxn) error {
// first child's change should be visiable to the following child
val, exist := txn.GetNoCopy(testBucket, []byte("txn00"))
ensure.True(t, exist)
ensure.DeepEqual(t, val, []byte("bar00"))
return nil
})
// commit all
return nil
})
}