-
Notifications
You must be signed in to change notification settings - Fork 0
/
env_windows_test.go
58 lines (51 loc) · 1.23 KB
/
env_windows_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
package ssdb
import (
"os"
"ssdb/util"
"testing"
)
const windowsMMapLimit = 4
func setWindowsFileLimits(mmapLimit int, t *testing.T) {
setWindowsReadOnlyMMapLimit(mmapLimit, t)
}
func setWindowsReadOnlyMMapLimit(limit int, t *testing.T) {
util.AssertTrue(e == nil, "e == nil", t)
mmapLimit = limit
}
func TestWindowsOpenOnRead(t *testing.T) {
setWindowsFileLimits(windowsMMapLimit, t)
env := DefaultEnv()
testDir, err := env.GetTestDirectory()
if err != nil {
t.Fatal(err)
}
testFile := testDir + "/open_on_read.txt"
f, err := os.OpenFile(testFile, os.O_WRONLY|os.O_CREATE, 0666)
if err != nil {
t.Fatal(err)
}
fileData := []byte("abcdefghijklmnopqrstuvwxyz")
if _, err = f.Write(fileData); err != nil {
t.Error(err)
}
_ = f.Close()
numFiles := windowsMMapLimit + 5
files := make([]RandomAccessFile, numFiles)
for i := range files {
if files[i], err = env.NewRandomAccessFile(testFile); err != nil {
t.Error(err)
}
}
read := make([]byte, 1)
var result []byte
for i, file := range files {
if result, _, err = file.Read(read, int64(i)); err != nil {
t.Error(err)
}
util.AssertEqual(fileData[i], result[0], "read file", t)
}
files = nil
if err = env.DeleteFile(testFile); err != nil {
t.Error(err)
}
}