This commit is contained in:
2026-06-14 07:57:01 +03:00
parent 685c48f94f
commit 181031a753
14 changed files with 626 additions and 591 deletions

View File

@@ -868,82 +868,49 @@ func TestWritePreparer(t *testing.T) {
}
}
func TestWriteReadSnapshot(t *testing.T) {
metrics := make(map[uint32]*_metric)
metrics[1] = &_metric{
metricType: qb.Cumulative,
fracDigits: 3,
lastPageNo: 1000,
buffer: []byte{},
}
in := WriteSnapshotIn{
SnapshotNumber: 1,
Dir: ".",
WriteBufferSize: 8 * 1024 * 1024,
Metrics: metrics,
FrozenIndexPagesCount: 7,
IndexPageNumbers: []uint32{
1, 2, 3, 4, 5,
},
FrozenDataPagesCount: 8,
DataPageNumbers: []uint32{
6, 7, 8,
},
}
err := WriteSnapshot(in)
if err != nil {
t.Fatalf("writeSnapshot: %s", err)
}
out, err := ReadSnapshot("1.snapshot")
if err != nil {
return
}
if out.FrozenIndexPagesCount != in.FrozenIndexPagesCount {
t.Fatalf("FrozenIndexPagesCount: got %d are not equal expected %d",
out.FrozenIndexPagesCount, in.FrozenIndexPagesCount)
}
if out.FrozenDataPagesCount != in.FrozenDataPagesCount {
t.Fatalf("FrozenDataPagesCount: got %d are not equal expected %d",
out.FrozenDataPagesCount, in.FrozenDataPagesCount)
}
if !slices.Equal(out.IndexPageNumbers, in.IndexPageNumbers) {
t.Fatalf("IndexPageNumbers: got %v are not equal expected %v",
out.IndexPageNumbers, in.IndexPageNumbers)
}
if !slices.Equal(out.DataPageNumbers, in.DataPageNumbers) {
t.Fatalf("DataPageNumbers: got %v are not equal expected %v",
out.DataPageNumbers, in.DataPageNumbers)
}
for metricID, replay := range out.Metrics {
origin, ok := metrics[metricID]
if !ok {
t.Fatalf("decoded metricID %d not found in metrics", metricID)
func TestWriteTimestampsWithRewind(t *testing.T) {
DataPagePayloadSize = 8
var (
payload = []byte{
0xaa, 0xbb, 0xcc,
}
err = cmpMetric(replay, origin)
if err != nil {
t.Fatalf("metric %d: %s", metricID, err)
before = []byte{
0x00, 0x00, 0x00, 0x00, 0x04, 0x03, 0x02, 0x01,
}
occupied = 4
after = []byte{
0x00, 0x00, 0x00, 0xaa, 0xbb, 0xcc, 0x02, 0x01,
}
occupiedAfter = 5
)
occupied = writeTimestampsWithRewind(before, occupied, payload, 2)
if occupied != occupiedAfter {
t.Fatalf("got occupied %d are not equal expected %d", occupied, occupiedAfter)
}
if !bytes.Equal(before, after) {
t.Fatalf("got buf % x are not equal expected % x", before, after)
}
}
func cmpMetric(replay *ReplayMetric, origin *_metric) error {
if replay.metricType != origin.metricType {
return fmt.Errorf("metricType: got %d are not equal expected %d",
replay.metricType, origin.metricType)
func TestWriteValuesWithRewind(t *testing.T) {
var (
payload = []byte{
0xaa, 0xbb, 0xcc,
}
before = []byte{
0x01, 0x02, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00,
}
occupied = 4
after = []byte{
0x01, 0x02, 0xaa, 0xbb, 0xcc, 0x00, 0x00, 0x00,
}
occupiedAfter = 5
)
occupied = writeValuesWithRewind(before, occupied, payload, 2)
if occupied != occupiedAfter {
t.Fatalf("got occupied %d are not equal expected %d", occupied, occupiedAfter)
}
if replay.fracDigits != origin.fracDigits {
return fmt.Errorf("fracDigits: got %d are not equal expected %d",
replay.fracDigits, origin.fracDigits)
if !bytes.Equal(before, after) {
t.Fatalf("got buf % x are not equal expected % x", before, after)
}
if replay.lastPageNo != origin.lastPageNo {
return fmt.Errorf("lastPageNo: got %d are not equal expected %d",
replay.lastPageNo, origin.lastPageNo)
}
// if !refect.DeepEq{
// return fmt.Errorf("lastPageNo: got %d are not equal expected %d",
// replay.lastPageNo, origin.lastPageNo)
// }
return nil
}