github.com/deanMdreon/kafka-go@v0.4.32/protocol/offsetcommit/offsetcommit_test.go (about) 1 package offsetcommit_test 2 3 import ( 4 "testing" 5 6 "github.com/deanMdreon/kafka-go/protocol/offsetcommit" 7 "github.com/deanMdreon/kafka-go/protocol/prototest" 8 ) 9 10 func TestOffsetCommitRequest(t *testing.T) { 11 for _, version := range []int16{0} { 12 prototest.TestRequest(t, version, &offsetcommit.Request{ 13 GroupID: "group-0", 14 Topics: []offsetcommit.RequestTopic{ 15 { 16 Name: "topic-0", 17 Partitions: []offsetcommit.RequestPartition{ 18 { 19 PartitionIndex: 0, 20 CommittedOffset: 1, 21 CommittedMetadata: "meta-0-0", 22 }, 23 { 24 PartitionIndex: 1, 25 CommittedOffset: 2, 26 CommittedMetadata: "meta-0-1", 27 }, 28 }, 29 }, 30 }, 31 }) 32 } 33 34 // Version 1 added: 35 // GenerationID 36 // MemberID 37 // RequestTopic.RequestPartition.CommitTimestamp 38 for _, version := range []int16{1} { 39 prototest.TestRequest(t, version, &offsetcommit.Request{ 40 GroupID: "group-1", 41 GenerationID: 1, 42 MemberID: "member-1", 43 Topics: []offsetcommit.RequestTopic{ 44 { 45 Name: "topic-1", 46 Partitions: []offsetcommit.RequestPartition{ 47 { 48 PartitionIndex: 0, 49 CommittedOffset: 1, 50 CommittedMetadata: "meta-1-0", 51 CommitTimestamp: 10, 52 }, 53 { 54 PartitionIndex: 1, 55 CommittedOffset: 2, 56 CommittedMetadata: "meta-1-1", 57 CommitTimestamp: 11, 58 }, 59 }, 60 }, 61 }, 62 }) 63 } 64 65 // Version 2 added: 66 // RetentionTimeMs 67 // Version 2 removed: 68 // RequestTopic.RequestPartition.CommitTimestamp 69 // Fields are the same through version 4. 70 for _, version := range []int16{2, 3, 4} { 71 prototest.TestRequest(t, version, &offsetcommit.Request{ 72 GroupID: "group-2", 73 GenerationID: 1, 74 MemberID: "member-2", 75 RetentionTimeMs: 1999, 76 Topics: []offsetcommit.RequestTopic{ 77 { 78 Name: "topic-2", 79 Partitions: []offsetcommit.RequestPartition{ 80 { 81 PartitionIndex: 0, 82 CommittedOffset: 1, 83 CommittedMetadata: "meta-2-0", 84 }, 85 { 86 PartitionIndex: 1, 87 CommittedOffset: 2, 88 CommittedMetadata: "meta-2-1", 89 }, 90 }, 91 }, 92 }, 93 }) 94 } 95 96 // Version 5 added: 97 // RequestTopic.RequestPartition.CommitedLeaderEpoc 98 // Version 5 removed: 99 // RetentionTimeMs 100 // Fields are the same through version 6. 101 for _, version := range []int16{5, 6} { 102 prototest.TestRequest(t, version, &offsetcommit.Request{ 103 GroupID: "group-3", 104 GenerationID: 1, 105 MemberID: "member-3", 106 Topics: []offsetcommit.RequestTopic{ 107 { 108 Name: "topic-3", 109 Partitions: []offsetcommit.RequestPartition{ 110 { 111 PartitionIndex: 0, 112 CommittedOffset: 1, 113 CommittedMetadata: "meta-3-0", 114 CommittedLeaderEpoch: 10, 115 }, 116 { 117 PartitionIndex: 1, 118 CommittedOffset: 2, 119 CommittedMetadata: "meta-3-1", 120 CommittedLeaderEpoch: 11, 121 }, 122 }, 123 }, 124 }, 125 }) 126 } 127 128 // Version 7 added: 129 // GroupInstanceID 130 for _, version := range []int16{7} { 131 prototest.TestRequest(t, version, &offsetcommit.Request{ 132 GroupID: "group-4", 133 GenerationID: 1, 134 MemberID: "member-4", 135 GroupInstanceID: "instance-4", 136 Topics: []offsetcommit.RequestTopic{ 137 { 138 Name: "topic-4", 139 Partitions: []offsetcommit.RequestPartition{ 140 { 141 PartitionIndex: 0, 142 CommittedOffset: 1, 143 CommittedMetadata: "meta-4-0", 144 CommittedLeaderEpoch: 10, 145 }, 146 { 147 PartitionIndex: 1, 148 CommittedOffset: 2, 149 CommittedMetadata: "meta-4-1", 150 CommittedLeaderEpoch: 11, 151 }, 152 }, 153 }, 154 }, 155 }) 156 } 157 } 158 159 func TestOffsetCommitResponse(t *testing.T) { 160 // Fields are the same through version 2. 161 for _, version := range []int16{0, 1, 2} { 162 prototest.TestResponse(t, version, &offsetcommit.Response{ 163 Topics: []offsetcommit.ResponseTopic{ 164 { 165 Name: "topic-1", 166 Partitions: []offsetcommit.ResponsePartition{ 167 { 168 PartitionIndex: 4, 169 ErrorCode: 34, 170 }, 171 }, 172 }, 173 }, 174 }) 175 } 176 177 // Version 3 added: 178 // ThrottleTimeMs 179 // Field are the same through version 7. 180 for _, version := range []int16{3, 4, 5, 6, 7} { 181 prototest.TestResponse(t, version, &offsetcommit.Response{ 182 ThrottleTimeMs: 10000, 183 Topics: []offsetcommit.ResponseTopic{ 184 { 185 Name: "topic-2", 186 Partitions: []offsetcommit.ResponsePartition{ 187 { 188 PartitionIndex: 2, 189 ErrorCode: 3, 190 }, 191 }, 192 }, 193 }, 194 }) 195 } 196 }