forked from karrick/goavro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ocf_test.go
69 lines (56 loc) · 1.52 KB
/
ocf_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
package goavro_test
import (
"bytes"
"testing"
"github.com/karrick/goavro"
)
// testOCFRoundTrip has OCFWriter write to a buffer using specified
// compression algorithm, then attempt to read it back
func testOCFRoundTrip(t *testing.T, compressionName string) {
schema := `{"type":"long"}`
bb := new(bytes.Buffer)
ocfw, err := goavro.NewOCFWriter(goavro.OCFConfig{
W: bb,
CompressionName: compressionName,
Schema: schema,
})
if err != nil {
t.Fatal(err)
}
valuesToWrite := []int64{13, 42, -12, -1234}
if err = ocfw.Append(valuesToWrite); err != nil {
t.Fatal(err)
}
ocfr, err := goavro.NewOCFReader(bb)
if err != nil {
t.Fatal(err)
}
var valuesRead []int64
for ocfr.Scan() {
value, err := ocfr.Read()
if err != nil {
t.Fatal(err)
}
valuesRead = append(valuesRead, value.(int64))
}
if err = ocfr.Err(); err != nil {
t.Fatal(err)
}
if actual, expected := len(valuesRead), len(valuesToWrite); actual != expected {
t.Errorf("Actual: %v; Expected: %v", actual, expected)
}
for i := 0; i < len(valuesRead); i++ {
if actual, expected := valuesRead[i], valuesToWrite[i]; actual != expected {
t.Errorf("Actual: %v; Expected: %v", actual, expected)
}
}
}
func TestOCFWriterCompressionNull(t *testing.T) {
testOCFRoundTrip(t, goavro.CompressionNullLabel)
}
func TestOCFWriterCompressionDeflate(t *testing.T) {
testOCFRoundTrip(t, goavro.CompressionDeflateLabel)
}
func TestOCFWriterCompressionSnappy(t *testing.T) {
testOCFRoundTrip(t, goavro.CompressionSnappyLabel)
}