-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteafile_test.go
129 lines (112 loc) · 2.61 KB
/
teafile_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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package goteafiles
import (
"fmt"
"os"
"reflect"
"testing"
)
type Data struct {
Time uint64
Price uint8
Volume uint64
Prob uint8
Prib uint64
}
var data = Data{
Time: 1299229200000,
Price: 253,
Volume: 8,
Prob: 252,
Prib: 2,
}
func TestCreate(t *testing.T) {
tf, err := Create(
"test.tea",
WithDataType(reflect.TypeOf(Data{})),
WithContentDescription("prices of acme at NYSE"),
WithTimeFields(719162, 86400000, []int32{0}),
WithNameValues(map[string]interface{} {
"decimals": int32(2),
"url" : "www.acme.com",
}))
if err != nil {
t.Fatalf("error creating TeaFile: %v", err)
}
err = tf.Write(data)
if err != nil {
t.Fatalf("error writing data to TeaFile: %v", err)
}
err = tf.Write(data)
if err != nil {
t.Fatalf("error writing data to TeaFile: %v", err)
}
err = tf.Close()
if err != nil {
t.Fatalf("error closing TeaFile: %v", err)
}
tf, err = OpenRead("test.tea", reflect.TypeOf(Data{}))
if err != nil {
t.Fatalf("error closing TeaFile: %v", err)
}
// Comparing with fixture
goldTf, err := OpenRead("test-fixtures/acme.tea", reflect.TypeOf(Data{}))
if err != nil {
t.Fatalf("error opening golden TeaFile: %v", err)
}
if !reflect.DeepEqual(goldTf.itemSection, tf.itemSection) {
t.Fatalf(
"got different item section: %v, %v",
goldTf.itemSection,
tf.itemSection)
}
if !reflect.DeepEqual(goldTf.nameValueSection, tf.nameValueSection) {
t.Fatalf(
"got different item section: %v, %v",
goldTf.nameValueSection,
tf.nameValueSection)
}
if !reflect.DeepEqual(goldTf.contentDescriptionSection, tf.contentDescriptionSection) {
t.Fatalf(
"got different time section: %v, %v",
goldTf.contentDescriptionSection,
tf.contentDescriptionSection)
}
if !reflect.DeepEqual(goldTf.timeSection, tf.timeSection) {
t.Fatalf(
"got different time section: %v, %v",
goldTf.timeSection,
tf.timeSection)
}
err = os.Remove("test.tea")
if err != nil {
t.Fatalf("error deleting TeaFile: %v", err)
}
}
func TestRead(t *testing.T) {
tf, err := OpenRead("test-fixtures/acme.tea", reflect.TypeOf(Data{}))
if err != nil {
t.Fatalf("error opening TeaFile: %v", err)
}
_, err = tf.Read()
if err != nil {
t.Fatalf("error reading data: %v", err)
}
}
func TestMMapRead(t *testing.T) {
tf, err := OpenRead("test-fixtures/acme.tea", reflect.TypeOf(Data{}))
if err != nil {
t.Fatalf("error opening TeaFile: %v", err)
}
r, err := tf.OpenReadableMapping()
if err != nil {
t.Fatalf("error mmapping file: %v", err)
}
var tmp uint64
N := r.Len()
for i := 0; i < N; i++ {
ptr := r.GetItem(i)
item := (*Data)(ptr)
tmp = item.Volume
}
fmt.Println(tmp)
}