Documentation
¶
Overview ¶
Package backendtest provides a shared conformance suite that every backend.Backend implementation must pass, proving the implementations are interchangeable (DESIGN.md §2: "backends are interchangeable behind backend.Backend").
Index ¶
- Constants
- Variables
- func AtomicConditionalPut(h http.Handler) http.Handler
- func Digest(tb testing.TB, b backend.Backend, partPrefixes []string) string
- func IsPartObject(key string) bool
- func PartDirs(ctx context.Context, tb testing.TB, b backend.Backend, enginePrefix string) []string
- func Run(t *testing.T, factory func(t *testing.T) backend.Backend)
- func WithoutCapabilities(b backend.Backend) backend.Backend
- type ByteCounter
- func (b *ByteCounter) Bytes() int64
- func (b *ByteCounter) RangesNatively(ctx context.Context, key string) bool
- func (b *ByteCounter) Read(ctx context.Context, key string) ([]byte, error)
- func (b *ByteCounter) ReadAt(ctx context.Context, key string, off, n int64) ([]byte, error)
- func (b *ByteCounter) ReadView(ctx context.Context, key string) ([]byte, error)
- func (b *ByteCounter) Reads() int64
- func (b *ByteCounter) Report() string
- func (b *ByteCounter) Reset()
- type Capacity
- type Case
- type Counting
- type Deferred
- func (d *Deferred) CreateObject(ctx context.Context, key string) (backend.ObjectWriter, error)
- func (d *Deferred) CreateObjectDeferred(ctx context.Context, key string) (backend.ObjectWriter, error)
- func (d *Deferred) Delete(ctx context.Context, key string) error
- func (d *Deferred) DeleteDeferred(ctx context.Context, key string) error
- func (d *Deferred) Deletes() []string
- func (d *Deferred) Pending(prefix string) []string
- func (d *Deferred) StreamsWrites() bool
- func (d *Deferred) SyncPrefix(_ context.Context, prefix string) error
- func (d *Deferred) WriteDeferred(ctx context.Context, key string, data []byte) error
- type SizedByteCounter
- type StreamingMemory
Constants ¶
const Unknown = int64(-1)
Unknown is the free-bytes/free-inodes value that makes a Capacity report backend.ErrSpaceUnknown for that axis, modeling a backend without the capability.
Variables ¶
var ErrInjected = errors.New("backendtest: injected write failure")
ErrInjected is the failure Counting injects into a chosen write.
Functions ¶
func AtomicConditionalPut ¶ added in v0.33.0
AtomicConditionalPut wraps an S3-compatible test server's handler, serializing every request that carries an If-None-Match or If-Match precondition. Real S3 evaluates a conditional PUT atomically; the embeddable go-faster/fs server (as of v0.3.0) checks the precondition and performs the write as two separate steps, so two concurrent "If-None-Match: *" PUTs can both observe the key absent and both succeed — a TOCTOU race the conformance suite's single-winner CAS test rightly rejects. Serializing just the conditional requests restores real-S3 semantics for the tests without patching the fake. (Worth fixing upstream; this wrapper is then a no-op.)
func Digest ¶ added in v0.49.0
Digest renders every object under each of partPrefixes as one sorted "name size sha256" line, the name relative to its part prefix, since that prefix is random. It is the golden-file form of a part set.
func IsPartObject ¶ added in v0.49.0
IsPartObject reports whether key names an object inside a part directory rather than an engine-level object (the bucket index, the series or stream index).
func PartDirs ¶ added in v0.49.0
PartDirs returns the sorted part ids that have objects under enginePrefix. Part ids are minted, so a test cannot name them up front and asserts over this set instead.
func Run ¶
Run executes the full conformance suite against a backend produced by factory — the object operations plus the conditional-write (CAS) [Backend.PutIfAbsent]. Each subtest gets a fresh, empty backend. Call it from each implementation's test package.
func WithoutCapabilities ¶ added in v0.49.0
WithoutCapabilities wraps b exposing only the backend.Backend methods: every optional capability (backend.Viewer, backend.Sizer, backend.ReaderAt, backend.ObjectCreator, backend.DeferredSyncer, backend.NodeLocal, …) is hidden, so callers take their fallback paths — the shape of a minimal embedder backend.
Types ¶
type ByteCounter ¶ added in v0.49.0
ByteCounter counts the calls and bytes of every Read, ReadView and ReadAt, in total and per key. It serves backend.Viewer and backend.ReaderAt through backend.ReadView and backend.ReadAt, so an inner backend without them falls back to a whole read, and forwards backend.RangeHinter to say so. Every other capability is hidden, backend.Sizer included: a size probe falls back to a counted Read. SizedByteCounter forwards Size.
func NewByteCounter ¶ added in v0.49.0
func NewByteCounter(b backend.Backend) *ByteCounter
NewByteCounter wraps b.
func (*ByteCounter) Bytes ¶ added in v0.49.0
func (b *ByteCounter) Bytes() int64
Bytes returns the bytes read since the last ByteCounter.Reset.
func (*ByteCounter) RangesNatively ¶ added in v0.49.0
func (b *ByteCounter) RangesNatively(ctx context.Context, key string) bool
RangesNatively forwards the inner answer, since ByteCounter.ReadAt reads whole wherever the inner backend does. Implements backend.RangeHinter.
func (*ByteCounter) Read ¶ added in v0.49.0
Read implements backend.Backend.
func (*ByteCounter) ReadAt ¶ added in v0.49.0
ReadAt implements backend.ReaderAt.
func (*ByteCounter) ReadView ¶ added in v0.49.0
ReadView implements backend.Viewer.
func (*ByteCounter) Reads ¶ added in v0.49.0
func (b *ByteCounter) Reads() int64
Reads returns the reads made since the last ByteCounter.Reset.
func (*ByteCounter) Report ¶ added in v0.49.0
func (b *ByteCounter) Report() string
Report renders the per-key byte totals, one sorted line per key, so a failure says which object was read rather than only how much.
func (*ByteCounter) Reset ¶ added in v0.49.0
func (b *ByteCounter) Reset()
Reset zeroes every count.
type Capacity ¶ added in v0.40.0
Capacity wraps a backend with a settable capacity report, so a test can put an engine on a full disk or an exhausted inode table without needing a real one. The two axes are set independently: a filesystem with terabytes free can still fail every create, and a test must be able to say so.
Like github.com/oteldb/storage/backend/faultbackend it forwards no other optional capability — each has a mandatory fallback, so a wrapped backend runs the same code, only slower.
func WithCapacity ¶ added in v0.40.0
WithCapacity wraps b reporting freeBytes bytes and freeInodes inodes available (Unknown for an axis the backend cannot report).
func (*Capacity) FreeInodes ¶ added in v0.40.0
FreeInodes implements backend.InodeReporter.
func (*Capacity) FreeSpace ¶ added in v0.40.0
FreeSpace implements backend.SpaceReporter.
func (*Capacity) SetFreeBytes ¶ added in v0.40.0
SetFreeBytes changes the reported free bytes — the disk filling up, or being emptied.
func (*Capacity) SetFreeInodes ¶ added in v0.40.0
SetFreeInodes changes the reported free inodes.
type Case ¶ added in v0.49.0
Case names a backend factory in a test or benchmark table.
func Cached ¶ added in v0.49.0
Cached is c behind a backend.Cached read cache of budget bytes, named "cached-" + c.Name.
func Dir ¶ added in v0.49.0
Dir is a case that opens a backend over a fresh tb.TempDir, failing tb when open does.
func Matrix ¶ added in v0.49.0
Matrix is every read path a backend offers: memory, file, file behind a 1 MiB read cache, s3, and WholeObject. This package cannot import the file or s3 backends, so the caller supplies them.
func WholeObject ¶ added in v0.49.0
func WholeObject() Case
WholeObject is memory behind WithoutCapabilities: every read is a whole-object Read.
type Counting ¶ added in v0.49.0
Counting counts reads per key and can fail the n-th write. It embeds the Backend interface, so it forwards no optional capability: every read, a view or a size probe included, funnels through Read and is counted.
func NewCounting ¶ added in v0.49.0
NewCounting wraps b.
func (*Counting) FailWriteAt ¶ added in v0.49.0
FailWriteAt makes the n-th write from now on fail with ErrInjected; n ≤ 0 disables injection.
func (*Counting) Read ¶ added in v0.49.0
Read implements backend.Backend.
func (*Counting) Write ¶ added in v0.49.0
Write implements backend.Backend.
func (*Counting) Writes ¶ added in v0.49.0
Writes returns how many writes have happened since the last Counting.FailWriteAt.
type Deferred ¶ added in v0.47.0
Deferred wraps a backend with a backend.DeferredSyncer that remembers which deferred writes and deletes no SyncPrefix has covered yet, so a test can assert that nothing durable names a prefix while it still has some. It also implements backend.ObjectCreator, so a streaming writer takes its streaming path over a backend that buffers — while StreamsWrites still answers for that backend, which does not.
func WithDeferred ¶ added in v0.47.0
WithDeferred wraps b.
func (*Deferred) CreateObject ¶ added in v0.47.0
CreateObject implements backend.ObjectCreator.
func (*Deferred) CreateObjectDeferred ¶ added in v0.47.0
func (d *Deferred) CreateObjectDeferred(ctx context.Context, key string) (backend.ObjectWriter, error)
CreateObjectDeferred implements backend.DeferredSyncer.
func (*Deferred) Delete ¶ added in v0.47.0
Delete implements backend.Backend.
func (*Deferred) DeleteDeferred ¶ added in v0.47.0
DeleteDeferred implements backend.DeferredSyncer.
func (*Deferred) Deletes ¶ added in v0.47.0
Deletes returns every delete in the order it happened, a deferred one marked with a "~" prefix.
func (*Deferred) Pending ¶ added in v0.47.0
Pending returns, sorted, the keys under prefix whose deferred operation is not yet synced.
func (*Deferred) StreamsWrites ¶ added in v0.48.0
StreamsWrites answers for the wrapped backend. Implements backend.ObjectCreator.
func (*Deferred) SyncPrefix ¶ added in v0.47.0
SyncPrefix implements backend.DeferredSyncer.
func (*Deferred) WriteDeferred ¶ added in v0.47.0
WriteDeferred implements backend.DeferredSyncer.
type SizedByteCounter ¶ added in v0.49.0
type SizedByteCounter struct{ *ByteCounter }
SizedByteCounter is a ByteCounter that also forwards backend.Sizer (through backend.SizeOf), so a ranged open learns an object's length without reading it whole.
func NewSizedByteCounter ¶ added in v0.49.0
func NewSizedByteCounter(b backend.Backend) SizedByteCounter
NewSizedByteCounter wraps b.
func (SizedByteCounter) Size ¶ added in v0.49.0
Size implements backend.Sizer.
type StreamingMemory ¶ added in v0.49.0
StreamingMemory is backend.Memory plus the incremental-write backend.ObjectCreator, standing in for the file backend so the streamed write path runs without a disk. Its writer buffers and commits with one Write. It embeds the Backend interface, so memory's other capabilities (backend.Viewer, backend.Sizer, …) are hidden, except ranged reads: memory serves those natively, and a merge chooses between a windowed and a whole read by backend.RangesNatively.
func NewStreamingMemory ¶ added in v0.49.0
func NewStreamingMemory() *StreamingMemory
NewStreamingMemory returns an empty StreamingMemory.
func (*StreamingMemory) CreateObject ¶ added in v0.49.0
func (b *StreamingMemory) CreateObject(_ context.Context, key string) (backend.ObjectWriter, error)
CreateObject implements backend.ObjectCreator.
func (*StreamingMemory) Creates ¶ added in v0.49.0
func (b *StreamingMemory) Creates() int64
Creates returns how many objects CreateObject has opened.
func (*StreamingMemory) ReadAt ¶ added in v0.49.0
ReadAt implements backend.ReaderAt.
func (*StreamingMemory) StreamsWrites ¶ added in v0.49.0
func (*StreamingMemory) StreamsWrites() bool
StreamsWrites implements backend.ObjectCreator.