MCPcopy
hub / github.com/segmentio/kafka-go / TestBatchDontExpectEOF

Function TestBatchDontExpectEOF

batch_test.go:12–41  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func TestBatchDontExpectEOF(t *testing.T) {
13 topic := makeTopic()
14
15 broker, err := (&Dialer{
16 Resolver: &net.Resolver{},
17 }).LookupLeader(context.Background(), "tcp", "localhost:9092", topic, 0)
18 if err != nil {
19 t.Fatal("failed to open a new kafka connection:", err)
20 }
21
22 nc, err := net.Dial("tcp", net.JoinHostPort(broker.Host, strconv.Itoa(broker.Port)))
23 if err != nil {
24 t.Fatalf("cannot connect to partition leader at %s:%d: %s", broker.Host, broker.Port, err)
25 }
26
27 conn := NewConn(nc, topic, 0)
28 defer conn.Close()
29
30 nc.(*net.TCPConn).CloseRead()
31
32 batch := conn.ReadBatch(1024, 8192)
33
34 if _, err := batch.ReadMessage(); !errors.Is(err, io.ErrUnexpectedEOF) {
35 t.Error("bad error when reading message:", err)
36 }
37
38 if err := batch.Close(); !errors.Is(err, io.ErrUnexpectedEOF) {
39 t.Error("bad error when closing the batch:", err)
40 }
41}

Callers

nothing calls this directly

Calls 8

CloseMethod · 0.95
ReadBatchMethod · 0.95
LookupLeaderMethod · 0.80
makeTopicFunction · 0.70
NewConnFunction · 0.70
DialMethod · 0.45
ReadMessageMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected