forked from segmentio/kafka-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
syncgroup_test.go
110 lines (98 loc) · 2.1 KB
/
syncgroup_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
package kafka
import (
"bufio"
"bytes"
"io"
"reflect"
"testing"
)
func TestGroupAssignment(t *testing.T) {
item := groupAssignment{
Version: 1,
Topics: map[string][]int32{
"a": {1, 2, 3},
"b": {4, 5},
},
UserData: []byte(`blah`),
}
b := bytes.NewBuffer(nil)
w := &writeBuffer{w: b}
item.writeTo(w)
var found groupAssignment
remain, err := (&found).readFrom(bufio.NewReader(b), b.Len())
if err != nil {
t.Error(err)
t.FailNow()
}
if remain != 0 {
t.Errorf("expected 0 remain, got %v", remain)
t.FailNow()
}
if !reflect.DeepEqual(item, found) {
t.Error("expected item and found to be the same")
t.FailNow()
}
}
func TestGroupAssignmentReadsFromZeroSize(t *testing.T) {
var item groupAssignment
remain, err := (&item).readFrom(bufio.NewReader(bytes.NewReader(nil)), 0)
if err != nil {
t.Error(err)
t.FailNow()
}
if remain != 0 {
t.Errorf("expected 0 remain, got %v", remain)
t.FailNow()
}
if item.Topics == nil {
t.Error("expected non nil Topics to be assigned")
}
}
func TestSyncGroupResponseV0(t *testing.T) {
item := syncGroupResponseV0{
ErrorCode: 2,
MemberAssignments: []byte(`blah`),
}
b := bytes.NewBuffer(nil)
w := &writeBuffer{w: b}
item.writeTo(w)
var found syncGroupResponseV0
remain, err := (&found).readFrom(bufio.NewReader(b), b.Len())
if err != nil {
t.Error(err)
t.FailNow()
}
if remain != 0 {
t.Errorf("expected 0 remain, got %v", remain)
t.FailNow()
}
if !reflect.DeepEqual(item, found) {
t.Error("expected item and found to be the same")
t.FailNow()
}
}
func BenchmarkSyncGroupResponseV0(t *testing.B) {
item := syncGroupResponseV0{
ErrorCode: 2,
MemberAssignments: []byte(`blah`),
}
b := bytes.NewBuffer(nil)
w := &writeBuffer{w: b}
item.writeTo(w)
r := bytes.NewReader(b.Bytes())
reader := bufio.NewReader(r)
size := b.Len()
for i := 0; i < t.N; i++ {
r.Seek(0, io.SeekStart)
var found syncGroupResponseV0
remain, err := (&found).readFrom(reader, size)
if err != nil {
t.Error(err)
t.FailNow()
}
if remain != 0 {
t.Errorf("expected 0 remain, got %v", remain)
t.FailNow()
}
}
}