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

Function TestConsumerShutsDownOutOfRange

consumer_test.go:599–633  ·  view source on GitHub ↗

If the initial offset passed on partition consumer creation is out of the actual offset range for the partition, then the partition consumer stops immediately closing its output channels.

(t *testing.T)

Source from the content-addressed store, hash-verified

597// actual offset range for the partition, then the partition consumer stops
598// immediately closing its output channels.
599func TestConsumerShutsDownOutOfRange(t *testing.T) {
600 // Given
601 broker0 := NewMockBroker(t, 0)
602 fetchResponse := new(FetchResponse)
603 fetchResponse.AddError("my_topic", 0, ErrOffsetOutOfRange)
604 broker0.SetHandlerByMap(map[string]MockResponse{
605 "MetadataRequest": NewMockMetadataResponse(t).
606 SetBroker(broker0.Addr(), broker0.BrokerID()).
607 SetLeader("my_topic", 0, broker0.BrokerID()),
608 "OffsetRequest": NewMockOffsetResponse(t).
609 SetOffset("my_topic", 0, OffsetNewest, 1234).
610 SetOffset("my_topic", 0, OffsetOldest, 7),
611 "FetchRequest": NewMockWrapper(fetchResponse),
612 })
613
614 master, err := NewConsumer([]string{broker0.Addr()}, NewTestConfig())
615 if err != nil {
616 t.Fatal(err)
617 }
618
619 // When
620 consumer, err := master.ConsumePartition("my_topic", 0, 101)
621 if err != nil {
622 t.Fatal(err)
623 }
624
625 // Then: consumer should shut down closing its messages and errors channels.
626 if _, ok := <-consumer.Messages(); ok {
627 t.Error("Expected the consumer to shut down")
628 }
629 safeClose(t, consumer)
630
631 safeClose(t, master)
632 broker0.Close()
633}
634
635// If a fetch response contains messages with offsets that are smaller then
636// requested, then such messages are ignored.

Callers

nothing calls this directly

Calls 15

SetHandlerByMapMethod · 0.95
AddrMethod · 0.95
BrokerIDMethod · 0.95
ConsumePartitionMethod · 0.95
CloseMethod · 0.95
NewMockBrokerFunction · 0.85
NewMockMetadataResponseFunction · 0.85
NewMockOffsetResponseFunction · 0.85
NewMockWrapperFunction · 0.85
SetLeaderMethod · 0.80
SetBrokerMethod · 0.80
FatalMethod · 0.80

Tested by

no test coverage detected