-
Notifications
You must be signed in to change notification settings - Fork 4
/
gogen-avro_test.go
91 lines (76 loc) · 2.4 KB
/
gogen-avro_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
package avro_benchmarks
import (
"bytes"
"testing"
"github.com/actgardner/gogen-avro/v10/compiler"
"github.com/actgardner/gogen-avro/v10/vm"
"github.com/nrwiersma/avro-benchmarks/models"
"github.com/stretchr/testify/assert"
)
//go:generate $GOPATH/bin/gogen-avro -package models ./models fixtures/superhero.avsc
func TestGoGenAvroDecode(t *testing.T) {
superhero, err := models.DeserializeSuperhero(bytes.NewReader(Payload))
want := models.Superhero{
Id: 234765,
Affiliation_id: 9867,
Name: "Wolverine",
Life: 85.25,
Energy: 32.75,
Powers: []models.Superpower{
{Id: 2345, Name: "Bone Claws", Damage: 5, Energy: 1.15, Passive: false},
{Id: 2346, Name: "Regeneration", Damage: -2, Energy: 0.55, Passive: true},
{Id: 2347, Name: "Adamant skeleton", Damage: -10, Energy: 0, Passive: true},
},
}
assert.NoError(t, err)
assert.Equal(t, want, superhero)
}
func BenchmarkGoGenAvroDecode(b *testing.B) {
deser, _ := compiler.CompileSchemaBytes([]byte(Schema), []byte(Schema))
r := bytes.NewReader(nil)
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
t := models.NewSuperhero()
r.Reset(Payload)
_ = vm.Eval(r, deser, &t)
}
}
func TestGoGenAvroEncode(t *testing.T) {
superhero := models.Superhero{
Id: 234765,
Affiliation_id: 9867,
Name: "Wolverine",
Life: 85.25,
Energy: 32.75,
Powers: []models.Superpower{
{Id: 2345, Name: "Bone Claws", Damage: 5, Energy: 1.15, Passive: false},
{Id: 2346, Name: "Regeneration", Damage: -2, Energy: 0.55, Passive: true},
{Id: 2347, Name: "Adamant skeleton", Damage: -10, Energy: 0, Passive: true},
},
}
buf := bytes.Buffer{}
err := superhero.Serialize(&buf)
assert.NoError(t, err)
// assert.Equal(t, Payload, buf.Bytes()) seems to add 2 bytes
}
func BenchmarkGoGenAvroEncode(b *testing.B) {
superhero := models.Superhero{
Id: 234765,
Affiliation_id: 9867,
Name: "Wolverine",
Life: 85.25,
Energy: 32.75,
Powers: []models.Superpower{
{Id: 2345, Name: "Bone Claws", Damage: 5, Energy: 1.15, Passive: false},
{Id: 2346, Name: "Regeneration", Damage: -2, Energy: 0.55, Passive: true},
{Id: 2347, Name: "Adamant skeleton", Damage: -10, Energy: 0, Passive: true},
},
}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
buf := bytes.Buffer{}
_ = superhero.Serialize(&buf)
}
}