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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
package fetch_test
import (
"testing"
"time"
"github.com/segmentio/kafka-go/protocol"
"github.com/segmentio/kafka-go/protocol/fetch"
"github.com/segmentio/kafka-go/protocol/prototest"
)
const (
v0 = 0
v11 = 11
)
func TestFetchRequest(t *testing.T) {
prototest.TestRequest(t, v0, &fetch.Request{
ReplicaID: -1,
MaxWaitTime: 500,
MinBytes: 1024,
Topics: []fetch.RequestTopic{
{
Topic: "topic-1",
Partitions: []fetch.RequestPartition{
{
Partition: 1,
FetchOffset: 2,
PartitionMaxBytes: 1024,
},
},
},
},
})
}
func TestFetchResponse(t *testing.T) {
t0 := time.Now().Truncate(time.Millisecond)
t1 := t0.Add(1 * time.Millisecond)
t2 := t0.Add(2 * time.Millisecond)
prototest.TestResponse(t, v0, &fetch.Response{
Topics: []fetch.ResponseTopic{
{
Topic: "topic-1",
Partitions: []fetch.ResponsePartition{
{
Partition: 1,
HighWatermark: 1000,
RecordSet: protocol.RecordSet{
Version: 1,
Records: protocol.NewRecordReader(
protocol.Record{Offset: 0, Time: t0, Key: nil, Value: prototest.String("msg-0")},
protocol.Record{Offset: 1, Time: t1, Key: nil, Value: prototest.String("msg-1")},
protocol.Record{Offset: 2, Time: t2, Key: prototest.Bytes([]byte{1}), Value: prototest.String("msg-2")},
),
},
},
},
},
},
})
headers := []protocol.Header{
{Key: "key-1", Value: []byte("value-1")},
{Key: "key-2", Value: []byte("value-2")},
{Key: "key-3", Value: []byte("value-3")},
}
prototest.TestResponse(t, v11, &fetch.Response{
Topics: []fetch.ResponseTopic{
{
Topic: "topic-1",
Partitions: []fetch.ResponsePartition{
{
Partition: 1,
HighWatermark: 1000,
RecordSet: protocol.RecordSet{
Version: 2,
Records: protocol.NewRecordReader(
protocol.Record{Offset: 0, Time: t0, Key: nil, Value: prototest.String("msg-0"), Headers: headers},
protocol.Record{Offset: 1, Time: t1, Key: nil, Value: prototest.String("msg-1")},
protocol.Record{Offset: 2, Time: t2, Key: prototest.Bytes([]byte{1}), Value: prototest.String("msg-2")},
),
},
},
},
},
},
})
}
func BenchmarkFetchResponse(b *testing.B) {
t0 := time.Now().Truncate(time.Millisecond)
t1 := t0.Add(1 * time.Millisecond)
t2 := t0.Add(2 * time.Millisecond)
prototest.BenchmarkResponse(b, v0, &fetch.Response{
Topics: []fetch.ResponseTopic{
{
Topic: "topic-1",
Partitions: []fetch.ResponsePartition{
{
Partition: 1,
HighWatermark: 1000,
RecordSet: protocol.RecordSet{
Version: 1,
Records: protocol.NewRecordReader(
protocol.Record{Offset: 0, Time: t0, Key: nil, Value: prototest.String("msg-0")},
protocol.Record{Offset: 1, Time: t1, Key: nil, Value: prototest.String("msg-1")},
protocol.Record{Offset: 2, Time: t2, Key: prototest.Bytes([]byte{1}), Value: prototest.String("msg-2")},
),
},
},
},
},
},
})
headers := []protocol.Header{
{Key: "key-1", Value: []byte("value-1")},
{Key: "key-2", Value: []byte("value-2")},
{Key: "key-3", Value: []byte("value-3")},
}
prototest.BenchmarkResponse(b, v11, &fetch.Response{
Topics: []fetch.ResponseTopic{
{
Topic: "topic-1",
Partitions: []fetch.ResponsePartition{
{
Partition: 1,
HighWatermark: 1000,
RecordSet: protocol.RecordSet{
Version: 2,
Records: protocol.NewRecordReader(
protocol.Record{Offset: 0, Time: t0, Key: nil, Value: prototest.String("msg-0"), Headers: headers},
protocol.Record{Offset: 1, Time: t1, Key: nil, Value: prototest.String("msg-1")},
protocol.Record{Offset: 2, Time: t2, Key: prototest.Bytes([]byte{1}), Value: prototest.String("msg-2")},
),
},
},
},
},
},
})
}
|