-
Notifications
You must be signed in to change notification settings - Fork 24
/
mmap_test.go
73 lines (56 loc) · 1.19 KB
/
mmap_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
package bigqueue
import (
"os"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func Test_MmapWriteAt(t *testing.T) {
path := Tempfile() + "/test.dat"
defer os.Remove(path)
Convey("Test_MmapWriteAt", t, func() {
db := &DB{
path: path,
InitialMmapSize: 128 * 1024,
opened: true,
}
err := db.Open(0666)
So(err, ShouldBeNil)
defer db.Close()
s := "hello xiemalin"
db.file.Write([]byte(s))
v := db.data[:len(s)]
So(s, ShouldEqual, string(v))
})
}
func Test_MmapWriteAt1(t *testing.T) {
path := Tempfile() + "/test.dat"
defer os.Remove(path)
Convey("Test_MmapWriteAt1", t, func() {
db := &DB{
path: path,
InitialMmapSize: 128 * 1024,
opened: true,
}
err := db.Open(0666)
So(err, ShouldBeNil)
s := "hello xiemalin"
bb := []byte(s)
// for i := 0; i < len(bb); i++ {
// db.data[i] = bb[i]
// }
copy(db.data[:len(bb)], bb)
db.Close()
db = &DB{
path: path,
InitialMmapSize: 128 * 1024,
opened: true,
}
//re-open
err = db.Open(0666)
So(err, ShouldBeNil)
defer db.Close()
s = "hello xiemalin"
v := db.data[:len(s)]
So(s, ShouldEqual, string(v))
})
}