-
Notifications
You must be signed in to change notification settings - Fork 55
/
data_file_test.go
61 lines (55 loc) · 1.2 KB
/
data_file_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
package avro
import (
"bytes"
"testing"
)
func TestDataFileWriter(t *testing.T) {
schema := MustParseSchema(primitiveSchemaRaw)
datumWriter := NewSpecificDatumWriter()
datumWriter.SetSchema(schema)
buf := &bytes.Buffer{}
dfw, err := NewDataFileWriter(buf, schema, datumWriter)
if err != nil {
t.Fatal(err)
}
d := 5.0
// test size growth of underlying file with respect to flushes
var sizes = []int{
884, 884, 936, 936, 988, 988,
1040, 1040, 1092, 1092,
}
for i, size := range sizes {
p := primitive{
LongField: int64(i),
DoubleField: d,
}
if err = dfw.Write(&p); err != nil {
t.Fatalf("Write failed %v", err)
}
if i%2 == 0 {
if err = dfw.Flush(); err != nil {
t.Fatal(err)
}
}
assert(t, buf.Len(), size)
d *= 7
}
if err = dfw.Close(); err != nil {
t.Fatal(err)
}
encoded := buf.Bytes()
assert(t, len(encoded), 1145)
// now make sure we can decode again
datumReader := NewSpecificDatumReader()
dfr, err := newDataFileReaderBytes(encoded, datumReader)
if err != nil {
t.Fatal(err)
}
var p primitive
_, err = dfr.Next(&p)
assert(t, err, nil)
assert(t, p.LongField, int64(0))
_, err = dfr.Next(&p)
assert(t, err, nil)
assert(t, p.LongField, int64(1))
}