MCPcopy Create free account
hub / github.com/IBM/sarama / consumeKeyedFromPartition

Function consumeKeyedFromPartition

functional_java_interop_test.go:370–397  ·  view source on GitHub ↗

consumeKeyedFromPartition consumes up to count messages from a specific partition, returning them as key+value pairs.

(t *testing.T, topic string, partition int32, startOffset int64, count int)

Source from the content-addressed store, hash-verified

368// consumeKeyedFromPartition consumes up to count messages from a specific partition,
369// returning them as key+value pairs.
370func consumeKeyedFromPartition(t *testing.T, topic string, partition int32, startOffset int64, count int) map[string]string {
371 t.Helper()
372 config := NewFunctionalTestConfig()
373 consumer, err := NewConsumer(FunctionalTestEnv.KafkaBrokerAddrs, config)
374 require.NoError(t, err)
375 defer consumer.Close()
376
377 pc, err := consumer.ConsumePartition(topic, partition, startOffset)
378 require.NoError(t, err)
379 defer pc.Close()
380
381 result := make(map[string]string, count)
382 ctx, cancel := context.WithTimeout(t.Context(), 15*time.Second)
383 defer cancel()
384
385 for len(result) < count {
386 select {
387 case msg := <-pc.Messages():
388 require.NotNil(t, msg)
389 result[string(msg.Key)] = string(msg.Value)
390 case err := <-pc.Errors():
391 require.NoError(t, err)
392 case <-ctx.Done():
393 return result
394 }
395 }
396 return result
397}
398
399// TestJavaMurmur2PartitionerInterop verifies that Sarama's NewMurmur2Partitioner
400// routes keyed messages to the same partitions as the Apache Kafka Java client's

Callers 1

Calls 10

CloseMethod · 0.95
ConsumePartitionMethod · 0.95
NewFunctionalTestConfigFunction · 0.85
HelperMethod · 0.80
NewConsumerFunction · 0.70
CloseMethod · 0.65
ContextMethod · 0.65
MessagesMethod · 0.65
ErrorsMethod · 0.65
DoneMethod · 0.65

Tested by

no test coverage detected