testutil

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 29, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package testutil provides test helpers for BeachDB.

- Model: Reference implementation for verifying database correctness - RandKey, RandValue: Random data generators for crash-loop testing

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RandKey

func RandKey(rng *rand.Rand, maxLen int) []byte

RandKey generates a random key of length 1 to maxLen bytes. Uses the provided RNG for reproducibility in tests.

func RandValue

func RandValue(rng *rand.Rand, maxLen int) []byte

RandValue generates a random value of length 0 to maxLen bytes. Uses the provided RNG for reproducibility in tests.

Types

type Model

type Model struct {
	// contains filtered or unexported fields
}

Model is a reference implementation for testing memtable correctness. It stores all versions of all keys to support snapshot reads.

func NewModel

func NewModel() *Model

NewModel creates a new empty model.

func (*Model) Delete

func (m *Model) Delete(key []byte)

Delete removes a key. Key is copied.

func (*Model) DeleteAt added in v0.0.2

func (m *Model) DeleteAt(key []byte, seqno uint64)

DeleteAt stores a tombstone at a specific sequence number.

func (*Model) Get

func (m *Model) Get(key []byte) ([]byte, bool)

Get retrieves a value. Returns (value, true) if found, (nil, false) if not.

func (*Model) GetAt added in v0.0.2

func (m *Model) GetAt(key []byte, seqno uint64) ([]byte, bool)

GetAt returns the value for key at the given seqno. Returns the newest version with seqno <= target. Returns (nil, true) if the newest visible version is a tombstone. Returns (nil, false) if no version exists for the key.

func (*Model) Keys

func (m *Model) Keys() [][]byte

Keys returns all keys in the model (for iteration in tests).

func (*Model) Len

func (m *Model) Len() int

Len returns the number of keys in the model.

func (*Model) Put

func (m *Model) Put(key, value []byte)

Put stores a key-value pair. Key & value are copied.

func (*Model) PutAt added in v0.0.2

func (m *Model) PutAt(key, value []byte, seqno uint64)

PutAt stores a key-value pair at a specific sequence number.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL