forked from IBM/sarama
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsticky_assignor_user_data_test.go
51 lines (43 loc) · 1.73 KB
/
sticky_assignor_user_data_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
package sarama
import (
"encoding/base64"
"testing"
)
func TestStickyAssignorUserDataV0(t *testing.T) {
// Single topic with deterministic ordering across encode-decode
req := &StickyAssignorUserDataV0{}
data := decodeUserDataBytes(t, "AAAAAQADdDAzAAAAAQAAAAU=")
testDecodable(t, "", req, data)
testEncodable(t, "", req, data)
// Multiple partitions
req = &StickyAssignorUserDataV0{}
data = decodeUserDataBytes(t, "AAAAAQADdDE4AAAAEgAAAAAAAAABAAAAAgAAAAMAAAAEAAAABQAAAAYAAAAHAAAACAAAAAkAAAAKAAAACwAAAAwAAAANAAAADgAAAA8AAAAQAAAAEQ==")
testDecodable(t, "", req, data)
// Multiple topics and partitions
req = &StickyAssignorUserDataV0{}
data = decodeUserDataBytes(t, "AAAABQADdDEyAAAAAgAAAAIAAAAKAAN0MTEAAAABAAAABAADdDE0AAAAAQAAAAgAA3QxMwAAAAEAAAANAAN0MDkAAAABAAAABQ==")
testDecodable(t, "", req, data)
}
func TestStickyAssignorUserDataV1(t *testing.T) {
// Single topic with deterministic ordering across encode-decode
req := &StickyAssignorUserDataV1{}
data := decodeUserDataBytes(t, "AAAAAQADdDA2AAAAAgAAAAAAAAAE/////w==")
testDecodable(t, "", req, data)
testEncodable(t, "", req, data)
// Multiple topics and partitions
req = &StickyAssignorUserDataV1{}
data = decodeUserDataBytes(t, "AAAABgADdDEwAAAAAgAAAAIAAAAJAAN0MTIAAAACAAAAAwAAAAsAA3QxNAAAAAEAAAAEAAN0MTMAAAABAAAACwADdDE1AAAAAQAAAAwAA3QwOQAAAAEAAAAG/////w==")
testDecodable(t, "", req, data)
// Generation is populated
req = &StickyAssignorUserDataV1{}
data = decodeUserDataBytes(t, "AAAAAQAHdG9waWMwMQAAAAMAAAAAAAAAAQAAAAIAAAAB")
testDecodable(t, "", req, data)
}
func decodeUserDataBytes(t *testing.T, base64Data string) []byte {
data, err := base64.StdEncoding.DecodeString(base64Data)
if err != nil {
t.Errorf("Error decoding data: %v", err)
t.FailNow()
}
return data
}