Documentation
¶
Overview ¶
Package admintest holds an in-memory segmentadmin.Store with failure injection, for tests of the code that writes segments (the import and the commands of the CLI) that must not need a server.
Index ¶
- Variables
- type Fake
- func (f *Fake) AfterCall(op string, fn func())
- func (f *Fake) Calls() []string
- func (f *Fake) Claim(ctx context.Context, lock, last, stale, tmp, token string) (bool, error)
- func (*Fake) Close()
- func (f *Fake) Commit(ctx context.Context, commit *segmentadmin.Commit) (segmentadmin.CommitResult, bool, error)
- func (f *Fake) CountKeys(ctx context.Context, prefix string, limit int) (int, bool, error)
- func (f *Fake) Delete(keys ...string)
- func (f *Fake) EditSet(ctx context.Context, lock, key string, members []string, remove bool) (int64, bool, error)
- func (f *Fake) Fail(op string, nth int)
- func (f *Fake) FailFrom(op string, nth int)
- func (f *Fake) KeyTTL(ctx context.Context, key string) (bool, time.Duration, error)
- func (f *Fake) Keys() []string
- func (f *Fake) Lock(ctx context.Context, key, token string, ttl time.Duration) (bool, error)
- func (f *Fake) LoseReply(op string, nth int, always bool)
- func (f *Fake) Members(key string) []string
- func (f *Fake) Ping(ctx context.Context) error
- func (f *Fake) Put(key, value string)
- func (f *Fake) SAdd(ctx context.Context, key string, members []string, ttl time.Duration) (int64, error)
- func (f *Fake) SCard(ctx context.Context, key string) (int64, error)
- func (f *Fake) SRem(ctx context.Context, key string, members []string) (int64, error)
- func (f *Fake) SetKeys(ctx context.Context, keys []string) (int64, error)
- func (f *Fake) SetValue(ctx context.Context, key, value string) error
- func (f *Fake) StageAdd(ctx context.Context, lock, tmp, token string, members []string, ...) (int64, segmentadmin.StageResult, error)
- func (f *Fake) TTLOf(key string) time.Duration
- func (f *Fake) Unlink(ctx context.Context, keys ...string) (int64, bool, error)
- func (f *Fake) Unlock(ctx context.Context, lock, last, committed, token string) error
- func (f *Fake) Value(ctx context.Context, key string) (string, bool, error)
- func (f *Fake) WithoutUnlink()
- type Objects
- func (o *Objects) BreakAfter(key string, n int)
- func (o *Objects) Calls() []string
- func (o *Objects) FailHeads(n int)
- func (o *Objects) Get(ctx context.Context, key, etag string) (segmentadmin.Object, error)
- func (o *Objects) Head(ctx context.Context, key string) (segmentadmin.ObjectInfo, error)
- func (o *Objects) List(ctx context.Context, prefix, token string) (segmentadmin.ObjectPage, error)
- func (o *Objects) OnGet(fn func(key string))
- func (o *Objects) Put(key string, data []byte, gzip bool)
- func (o *Objects) Remove(key string)
- func (o *Objects) WithoutETag(key string)
Constants ¶
This section is empty.
Variables ¶
var ErrCrossSlot = errors.New("CROSSSLOT keys in request don't hash to the same slot")
ErrCrossSlot is the failure of a swap whose keys are not in one cluster slot.
var ErrInjected = errors.New("injected failure")
ErrInjected is the failure that Fake.Fail returns.
var ErrLostReply = errors.New("the reply was lost")
ErrLostReply is the failure of a call that was applied and whose reply was lost.
var ErrReadFailed = errors.New("the connection broke")
ErrReadFailed is the failure that an Objects body gives after the bytes that Objects.BreakAfter allows.
Functions ¶
This section is empty.
Types ¶
type Fake ¶
type Fake struct {
// contains filtered or unexported fields
}
Fake is an in-memory store. It is safe for concurrent use. It records every call as "<OP> <key>" (never a member).
func (*Fake) AfterCall ¶
AfterCall runs fn once the call of an operation ("SWAP", "EDIT") has been applied and answered, without the lock of the fake held: it may use the fake, or cancel a context.
func (*Fake) Claim ¶
Claim implements segmentadmin.Store: it removes the stale key and records the last one only for the lock holder.
func (*Fake) Commit ¶
func (f *Fake) Commit(ctx context.Context, commit *segmentadmin.Commit) (segmentadmin.CommitResult, bool, error)
Commit implements segmentadmin.Store: the conditional swap, in one step as the script does it.
func (*Fake) CountKeys ¶
CountKeys implements segmentadmin.Store.
func (*Fake) Delete ¶
Delete removes keys without a command and without a record, as an expiry would.
func (*Fake) EditSet ¶
func (f *Fake) EditSet(ctx context.Context, lock, key string, members []string, remove bool) (int64, bool, error)
EditSet implements segmentadmin.Store: refused while the import lock exists.
func (*Fake) Fail ¶
Fail makes the nth next call of an operation ("SADD", "SWAP", "UNLINK", "SET" ...) fail with ErrInjected; n is 1 for the next call.
func (*Fake) FailFrom ¶
FailFrom makes every call of an operation from the nth on fail with ErrInjected, as a store that stays down does.
func (*Fake) KeyTTL ¶
KeyTTL implements segmentadmin.Store.
func (*Fake) Lock ¶
Lock implements segmentadmin.Store: idempotent by the token, as the script is.
func (*Fake) LoseReply ¶
LoseReply makes the nth call of an operation ("SADD" of a batch, "SWAP", "EDIT") apply and then fail with ErrLostReply, as a call whose reply never came back. With always, every call from the nth on does.
func (*Fake) Ping ¶
Ping implements segmentadmin.Store.
func (*Fake) Put ¶
Put sets a string key without a command and without a record: another run that took a lock, say.
func (*Fake) SAdd ¶
func (f *Fake) SAdd(ctx context.Context, key string, members []string, ttl time.Duration) (int64, error)
SAdd implements segmentadmin.Store.
func (*Fake) SCard ¶
SCard implements segmentadmin.Store.
func (*Fake) SRem ¶
SRem implements segmentadmin.Store.
func (*Fake) SetKeys ¶
SetKeys implements segmentadmin.Store.
func (*Fake) SetValue ¶
SetValue implements segmentadmin.Store.
func (*Fake) StageAdd ¶
func (f *Fake) StageAdd( ctx context.Context, lock, tmp, token string, members []string, ttl time.Duration, first bool, ) (int64, segmentadmin.StageResult, error)
StageAdd implements segmentadmin.Store: the batch is written only while the lock holds the token, and only the first batch may create the temporary key.
func (*Fake) Unlink ¶
Unlink implements segmentadmin.Store.
func (*Fake) Unlock ¶
Unlock implements segmentadmin.Store: the compare and delete.
func (*Fake) Value ¶
Value implements segmentadmin.Store.
func (*Fake) WithoutUnlink ¶
func (f *Fake) WithoutUnlink()
WithoutUnlink makes UNLINK an unknown command, as on a server that predates it.
type Objects ¶
type Objects struct {
// contains filtered or unexported fields
}
Objects is an in-memory bucket that implements segmentadmin.ObjectAPI. It is safe for concurrent use. The ETag of an object is the hash of its bytes.
func NewObjects ¶
NewObjects returns an empty bucket whose listing pages hold pageSize objects (3 when zero).
func (*Objects) BreakAfter ¶
BreakAfter makes the GET of key fail with ErrReadFailed after n bytes of its body.
func (*Objects) FailHeads ¶
FailHeads makes the next n HEAD and LIST calls fail with ErrReadFailed.
func (*Objects) Get ¶
Get implements segmentadmin.ObjectAPI.
func (*Objects) Head ¶
func (o *Objects) Head(ctx context.Context, key string) (segmentadmin.ObjectInfo, error)
Head implements segmentadmin.ObjectAPI.
func (*Objects) List ¶
func (o *Objects) List(ctx context.Context, prefix, token string) (segmentadmin.ObjectPage, error)
List implements segmentadmin.ObjectAPI. The token is the last key of the previous page.
func (*Objects) OnGet ¶
OnGet sets a function that runs at the start of every GET, before the object is read (a test replaces an object there).
func (*Objects) Put ¶
Put stores an object. With gzip, the object is served with Content-Encoding gzip (the bytes are the caller's).
func (*Objects) WithoutETag ¶
WithoutETag makes the store answer an object with an empty ETag, as some S3 compatible stores do.