Files
seaweedfs/weed/mq/offset_range_test.go
T
Chris Lu f35caf8be3 mq: read a recorded offset range that ends at offset 0
The broker and the Kafka gateway each scanned a partition's files for
the high water mark and counted a maximum only when it was above 0, so
a partition holding one message still read as empty. Both now share
mq.OffsetRange, which tracks whether a range was found apart from its
value.
2026-11-30 13:45:28 -08:00

37 lines
1.1 KiB
Go

package mq
import (
"encoding/binary"
"testing"
)
func rangeAttrs(min, max int64) map[string][]byte {
attrs := map[string][]byte{ExtendedAttrOffsetMin: make([]byte, 8), ExtendedAttrOffsetMax: make([]byte, 8)}
binary.BigEndian.PutUint64(attrs[ExtendedAttrOffsetMin], uint64(min))
binary.BigEndian.PutUint64(attrs[ExtendedAttrOffsetMax], uint64(max))
return attrs
}
func TestOffsetRangeBounds(t *testing.T) {
for _, tc := range []struct {
name string
files []map[string][]byte
earliest, hwm int64
}{
{"no files", nil, 0, 0},
{"no ranges", []map[string][]byte{{}}, 0, 0},
{"one message", []map[string][]byte{rangeAttrs(0, 0)}, 0, 1},
{"first window", []map[string][]byte{rangeAttrs(0, 199)}, 0, 200},
{"two windows", []map[string][]byte{rangeAttrs(200, 399), rangeAttrs(0, 199)}, 0, 400},
{"trimmed head", []map[string][]byte{rangeAttrs(500, 599)}, 500, 600},
} {
var r OffsetRange
for _, f := range tc.files {
r.Add(f)
}
if earliest, hwm := r.Bounds(); earliest != tc.earliest || hwm != tc.hwm {
t.Errorf("%s: Bounds() = %d, %d; want %d, %d", tc.name, earliest, hwm, tc.earliest, tc.hwm)
}
}
}