-
Notifications
You must be signed in to change notification settings - Fork 1
/
bdb_test.go
102 lines (82 loc) · 1.69 KB
/
bdb_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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package bdb
import "time"
import "fmt"
import "testing"
import "runtime"
import "io/ioutil"
func init() {
runtime.GOMAXPROCS(2)
}
var (
key = []byte("key")
value = []byte("value")
)
func Test(t *testing.T) {
e := OpenEnv("db", Create | InitMPool); defer e.Close()
db := e.OpenDb("db", BTree, Create); defer db.Close()
fmt.Println(db)
// var all [][]byte
n := 1000
for i := 0; i < n; i++ {
db.Put(key, value)
gotValue := db.Get(key)
// all = append(all, gotValue)
if string(value) != string(gotValue) { t.Fatal("") }
}
println("done")
time.Sleep(15 * 1000000000)
return
// all = nil
println("niled")
runtime.GC()
time.Sleep(15 * 1000000000)
}
func TestManyKeys(t *testing.T) {
go func() {
for {
println("1")
time.Sleep(10 * 1000000)
}
}()
e := OpenEnv("db", Create | InitMPool); defer e.Close()
db := e.OpenDb("db", BTree, Create); defer db.Close()
n := 10000
var all [][]byte
for i := 0; i < n; i++ {
key := []byte(fmt.Sprint("key", i))
value := []byte(fmt.Sprint("value", i))
println("value =", string(value))
db.Put(key, value)
gotValue := db.Get(key)
println("gotValue =", string(gotValue))
all = append(all, gotValue)
if string(value) != string(gotValue) { t.Fatal("") }
}
println("done")
for _, value := range all {
println(string(value))
}
}
func Test2(t *testing.T) {
ch1, ch2 := make(chan bool), make(chan bool)
go func() {
for {
bytes, _ := ioutil.ReadFile("bigfile")
println("2", len(bytes))
}
ch2 <- true
}()
i := 0
go func() {
for {
i++
// time.Sleep(1000000)
if i == 1000000000 { println("tick"); i = 0 }
}
ch1 <- true
}()
println("i =", i)
println("grc =", runtime.Goroutines())
<-ch1
<-ch2
}