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

Function TestPreferredReplicaFetchResponse

fetch_response_test.go:584–727  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

582}
583
584func TestPreferredReplicaFetchResponse(t *testing.T) {
585 t.Run("decodes v11", func(t *testing.T) {
586 response := FetchResponse{}
587 testVersionDecodable(
588 t, "preferred replica fetch response v11", &response,
589 preferredReplicaFetchResponseV11, 11)
590
591 if response.ErrorCode != 0x0002 {
592 t.Fatal("Decoding produced incorrect error code.")
593 }
594
595 if response.SessionID != 0x000000AC {
596 t.Fatal("Decoding produced incorrect session ID.")
597 }
598
599 if len(response.Blocks) != 1 {
600 t.Fatal("Decoding produced incorrect number of topic blocks.")
601 }
602
603 if len(response.Blocks["topic"]) != 1 {
604 t.Fatal("Decoding produced incorrect number of partition blocks for topic.")
605 }
606
607 block := response.GetBlock("topic", 5)
608 if block == nil {
609 t.Fatal("GetBlock didn't return block.")
610 }
611 if !errors.Is(block.Err, ErrOffsetOutOfRange) {
612 t.Error("Decoding didn't produce correct error code.")
613 }
614 if block.HighWaterMarkOffset != 0x10101010 {
615 t.Error("Decoding didn't produce correct high water mark offset.")
616 }
617 if block.LastStableOffset != 0x10101009 {
618 t.Error("Decoding didn't produce correct last stable offset.")
619 }
620 if block.LogStartOffset != 0x01010101 {
621 t.Error("Decoding didn't produce correct log start offset.")
622 }
623 if block.PreferredReadReplica != 0x0003 {
624 t.Error("Decoding didn't produce correct preferred read replica.")
625 }
626 partial, err := block.isPartial()
627 if err != nil {
628 t.Fatalf("Unexpected error: %v", err)
629 }
630 if partial {
631 t.Error("Decoding detected a partial trailing record where there wasn't one.")
632 }
633
634 n, err := block.numRecords()
635 if err != nil {
636 t.Fatalf("Unexpected error: %v", err)
637 }
638 if n != 1 {
639 t.Fatal("Decoding produced incorrect number of records.")
640 }
641 msgBlock := block.RecordsSet[0].MsgSet.Messages[0]

Callers

nothing calls this directly

Calls 12

GetBlockMethod · 0.95
testVersionDecodableFunction · 0.85
testResponseFunction · 0.85
versionedDecodeFunction · 0.85
RunMethod · 0.80
FatalMethod · 0.80
IsMethod · 0.80
FatalfMethod · 0.80
ErrorMethod · 0.65
isPartialMethod · 0.45
numRecordsMethod · 0.45
LenMethod · 0.45

Tested by

no test coverage detected