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
|
//go:build !functional
package sarama
import (
"fmt"
"reflect"
"testing"
)
var (
emptyOffsetCommitResponseV0 = []byte{
0x00, 0x00, 0x00, 0x00, // Empty topic
}
noEmptyOffsetCommitResponseV0 = []byte{
0, 0, 0, 1, // Topic Len
0, 5, 't', 'o', 'p', 'i', 'c', // Name
0, 0, 0, 1, // Partition Len
0, 0, 0, 3, // PartitionIndex
0, 0, // ErrorCode
}
noEmptyOffsetCommitResponseV3 = []byte{
0, 0, 0, 100, // ThrottleTimeMs
0, 0, 0, 1, // Topic Len
0, 5, 't', 'o', 'p', 'i', 'c', // Name
0, 0, 0, 1, // Partition Len
0, 0, 0, 3, // PartitionIndex
0, 0, // ErrorCode
}
)
func TestEmptyOffsetCommitResponse(t *testing.T) {
// groupInstanceId := "gid"
tests := []struct {
CaseName string
Version int16
MessageBytes []byte
Message *OffsetCommitResponse
}{
{
"v0-empty",
0,
emptyOffsetCommitResponseV0,
&OffsetCommitResponse{
Version: 0,
},
},
{
"v0-two-partition",
0,
noEmptyOffsetCommitResponseV0,
&OffsetCommitResponse{
Version: 0,
Errors: map[string]map[int32]KError{
"topic": {
3: ErrNoError,
},
},
},
},
{
"v3",
3,
noEmptyOffsetCommitResponseV3,
&OffsetCommitResponse{
ThrottleTimeMs: 100,
Version: 3,
Errors: map[string]map[int32]KError{
"topic": {
3: ErrNoError,
},
},
},
},
}
for _, c := range tests {
response := new(OffsetCommitResponse)
testVersionDecodable(t, c.CaseName, response, c.MessageBytes, c.Version)
if !reflect.DeepEqual(c.Message, response) {
t.Errorf("case %s decode failed, expected:%+v got %+v", c.CaseName, c.Message, response)
}
testEncodable(t, c.CaseName, c.Message, c.MessageBytes)
}
}
func TestNormalOffsetCommitResponse(t *testing.T) {
response := OffsetCommitResponse{}
response.AddError("t", 0, ErrNotLeaderForPartition)
response.Errors["m"] = make(map[int32]KError)
// The response encoded form cannot be checked for it varies due to
// unpredictable map traversal order.
testResponse(t, "normal", &response, nil)
}
func TestOffsetCommitResponseWithThrottleTime(t *testing.T) {
for version := 3; version <= 4; version++ {
response := OffsetCommitResponse{
Version: int16(version),
ThrottleTimeMs: 123,
}
response.AddError("t", 0, ErrNotLeaderForPartition)
response.Errors["m"] = make(map[int32]KError)
// The response encoded form cannot be checked for it varies due to
// unpredictable map traversal order.
testResponse(t, fmt.Sprintf("v%d with throttle time", version), &response, nil)
}
}
|