forked from segmentio/kafka-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
listoffset_test.go
76 lines (61 loc) · 1.95 KB
/
listoffset_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package kafka
import (
"context"
"testing"
"time"
)
func TestClientListOffsets(t *testing.T) {
client, topic, shutdown := newLocalClientAndTopic()
defer shutdown()
now := time.Now()
_, err := client.Produce(context.Background(), &ProduceRequest{
Topic: topic,
Partition: 0,
RequiredAcks: -1,
Records: NewRecordReader(
Record{Time: now, Value: NewBytes([]byte(`hello-1`))},
Record{Time: now, Value: NewBytes([]byte(`hello-2`))},
Record{Time: now, Value: NewBytes([]byte(`hello-3`))},
),
})
if err != nil {
t.Fatal(err)
}
res, err := client.ListOffsets(context.Background(), &ListOffsetsRequest{
Topics: map[string][]OffsetRequest{
topic: {FirstOffsetOf(0), LastOffsetOf(0)},
},
})
if err != nil {
t.Fatal(err)
}
if len(res.Topics) != 1 {
t.Fatal("invalid number of topics found in list offsets response:", len(res.Topics))
}
partitions, ok := res.Topics[topic]
if !ok {
t.Fatal("missing topic in the list offsets response:", topic)
}
if len(partitions) != 1 {
t.Fatal("invalid number of partitions found in list offsets response:", len(partitions))
}
partition := partitions[0]
if partition.Partition != 0 {
t.Error("invalid partition id found in list offsets response:", partition.Partition)
}
if partition.FirstOffset != 0 {
t.Error("invalid first offset found in list offsets response:", partition.FirstOffset)
}
if partition.LastOffset != 3 {
t.Error("invalid last offset found in list offsets response:", partition.LastOffset)
}
if firstOffsetTime := partition.Offsets[partition.FirstOffset]; !firstOffsetTime.IsZero() {
t.Error("unexpected first offset time in list offsets response:", partition.Offsets)
}
if lastOffsetTime := partition.Offsets[partition.LastOffset]; !lastOffsetTime.IsZero() {
t.Error("unexpected last offset time in list offsets response:", partition.Offsets)
}
if partition.Error != nil {
t.Error("unexpected error in list offsets response:", partition.Error)
}
}