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

Function testReaderSetSpecialOffsets

reader_test.go:124–155  ·  view source on GitHub ↗
(t *testing.T, ctx context.Context, r *Reader)

Source from the content-addressed store, hash-verified

122}
123
124func testReaderSetSpecialOffsets(t *testing.T, ctx context.Context, r *Reader) {
125 prepareReader(t, ctx, r, Message{Value: []byte("first")})
126 prepareReader(t, ctx, r, makeTestSequence(3)...)
127
128 go func() {
129 time.Sleep(1 * time.Second)
130 prepareReader(t, ctx, r, Message{Value: []byte("last")})
131 }()
132
133 for _, test := range []struct {
134 off, final int64
135 want string
136 }{
137 {FirstOffset, 1, "first"},
138 {LastOffset, 5, "last"},
139 } {
140 offset := test.off
141 if err := r.SetOffset(offset); err != nil {
142 t.Error("setting offset", offset, "failed:", err)
143 }
144 m, err := r.ReadMessage(ctx)
145 if err != nil {
146 t.Error("reading at offset", offset, "failed:", err)
147 }
148 if string(m.Value) != test.want {
149 t.Error("message at offset", offset, "has wrong value:", string(m.Value))
150 }
151 if off := r.Offset(); off != test.final {
152 t.Errorf("bad final offset: got %d, want %d", off, test.final)
153 }
154 }
155}
156
157func testReaderSetRandomOffset(t *testing.T, ctx context.Context, r *Reader) {
158 const N = 10

Callers

nothing calls this directly

Calls 6

prepareReaderFunction · 0.85
makeTestSequenceFunction · 0.85
SetOffsetMethod · 0.80
ErrorMethod · 0.45
ReadMessageMethod · 0.45
OffsetMethod · 0.45

Tested by

no test coverage detected