MCPcopy
hub / github.com/IBM/sarama / TestProduceSetV3RequestBuilding

Function TestProduceSetV3RequestBuilding

produce_set_test.go:221–288  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

219}
220
221func TestProduceSetV3RequestBuilding(t *testing.T) {
222 parent, ps := makeProduceSet()
223 parent.conf.Producer.RequiredAcks = WaitForAll
224 parent.conf.Producer.Timeout = 10 * time.Second
225 parent.conf.Version = V0_11_0_0
226
227 now := time.Now()
228 msg := &ProducerMessage{
229 Topic: "t1",
230 Partition: 0,
231 Key: StringEncoder(TestMessage),
232 Value: StringEncoder(TestMessage),
233 Headers: []RecordHeader{
234 {
235 Key: []byte("header-1"),
236 Value: []byte("value-1"),
237 },
238 {
239 Key: []byte("header-2"),
240 Value: []byte("value-2"),
241 },
242 {
243 Key: []byte("header-3"),
244 Value: []byte("value-3"),
245 },
246 },
247 Timestamp: now,
248 }
249 for range 10 {
250 safeAddMessage(t, ps, msg)
251 msg.Timestamp = msg.Timestamp.Add(time.Second)
252 }
253
254 req := ps.buildRequest()
255
256 if req.Version != 3 {
257 t.Error("Wrong request version")
258 }
259
260 batch := req.records["t1"][0].RecordBatch
261 if !batch.FirstTimestamp.Equal(now.Truncate(time.Millisecond)) {
262 t.Errorf("Wrong first timestamp: %v", batch.FirstTimestamp)
263 }
264 if !batch.MaxTimestamp.Equal(now.Add(9 * time.Second).Truncate(time.Millisecond)) {
265 t.Errorf("Wrong max timestamp: %v", batch.MaxTimestamp)
266 }
267 for i := range 10 {
268 rec := batch.Records[i]
269 if rec.TimestampDelta != time.Duration(i)*time.Second {
270 t.Errorf("Wrong timestamp delta: %v", rec.TimestampDelta)
271 }
272
273 if rec.OffsetDelta != int64(i) {
274 t.Errorf("Wrong relative inner offset, expected %d, got %d", i, rec.OffsetDelta)
275 }
276
277 for j, h := range batch.Records[i].Headers {
278 exp := fmt.Sprintf("header-%d", j+1)

Callers

nothing calls this directly

Calls 7

makeProduceSetFunction · 0.85
StringEncoderTypeAlias · 0.85
safeAddMessageFunction · 0.85
buildRequestMethod · 0.80
ErrorMethod · 0.65
ErrorfMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected