forked from colinmarc/cdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmmap_test.go
43 lines (31 loc) · 856 Bytes
/
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
package cdb_test
import (
"math/rand"
"testing"
"time"
"github.com/colinmarc/cdb"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestGetMmap(t *testing.T) {
db, err := cdb.OpenMmap("./test/test.cdb")
require.NoError(t, err)
require.NotNil(t, db)
records := append(append(expectedRecords, expectedRecords...), expectedRecords...)
shuffle(records)
for _, record := range records {
msg := "while fetching " + string(record[0])
value, err := db.Get(record[0])
require.NoError(t, err, msg)
assert.Equal(t, string(record[1]), string(value), msg)
}
}
func BenchmarkGetMmap(b *testing.B) {
db, _ := cdb.OpenMmap("./test/test.cdb")
b.ResetTimer()
rand.Seed(time.Now().UnixNano())
for i := 0; i < b.N; i++ {
record := expectedRecords[rand.Intn(len(expectedRecords))]
db.Get(record[0])
}
}