Documentation ¶
Overview ¶
Package mockstore provides various mocks that store facts and can execute lookups against them. It's intended for testing purposes only. Use DB to manage a set of facts manually or use LogConsumer to build a fact database by appling commands from a log. You can get Snapshots from either of these, which are immutable sets of facts that you can query.
Index ¶
- type BlogReader
- type DB
- type LogConsumer
- func (consumer *LogConsumer) Consume(ctx context.Context, aLog BlogReader) error
- func (consumer *LogConsumer) Current() *Snapshot
- func (consumer *LogConsumer) LastApplied() blog.Index
- func (consumer *LogConsumer) Lookups() lookups.All
- func (consumer *LogConsumer) Snapshot(ctx context.Context, index blog.Index) (*Snapshot, error)
- type Snapshot
- func (snap *Snapshot) AllFacts() []rpc.Fact
- func (snap *Snapshot) AssertFacts(t assert.TestingT, facts string) bool
- func (snap *Snapshot) CheckInvariants(t assert.TestingT)
- func (snap *Snapshot) ExternalID(kid uint64) string
- func (snap *Snapshot) Filtered(limit blog.Index) *Snapshot
- func (snap *Snapshot) Lookups() lookups.All
- func (snap *Snapshot) MustExternalID(kid uint64) string
- func (snap *Snapshot) MustResolveXID(externalID string) uint64
- func (snap *Snapshot) ResolveXID(externalID string) uint64
- func (snap *Snapshot) Stats() planner.Stats
- func (snap *Snapshot) StoredFacts() []rpc.Fact
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BlogReader ¶
type BlogReader interface {
Read(ctx context.Context, nextIndex blog.Index, entriesCh chan<- []blog.Entry) error
}
BlogReader is the subset of blog.AkutanLog needed by LogConsumer.
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
A DB is a mutable database of facts. It is safe for concurrent access.
func (*DB) AddFact ¶
AddFact adds the given fact to the database. The fact's ID and index should be set by the caller.
func (*DB) AddSPO ¶
AddSPO adds a new fact with the given subject, predicate, and object. The fact index will be greater than anything else in the database, and the fact ID will be derived from that.
func (*DB) Lookups ¶
Lookups returns an object that can perform lookup operations against the database.
Each of the lookups takes a log index and filters out facts with a larger index from the database. If you don't have an index to use in the requests, you can use math.MaxUint64 to filter no facts out.
type LogConsumer ¶
type LogConsumer struct {
// contains filtered or unexported fields
}
A LogConsumer reads from a log and applies commands to its internal database of facts. It is safe for concurrent access.
func NewLogConsumer ¶
func NewLogConsumer() *LogConsumer
NewLogConsumer constructs an LogConsumer that contains only the well-known facts.
func (*LogConsumer) Consume ¶
func (consumer *LogConsumer) Consume(ctx context.Context, aLog BlogReader) error
Consume is a blocking call that reads from the log and applies entries. It returns errors from aLog.
func (*LogConsumer) Current ¶
func (consumer *LogConsumer) Current() *Snapshot
Current returns a snapshot of the current database state, excluding all pending transactions.
func (*LogConsumer) LastApplied ¶
func (consumer *LogConsumer) LastApplied() blog.Index
LastApplied returns the index of the last entry consumed. It returns 0 if no entries have been consumed.
func (*LogConsumer) Lookups ¶
func (consumer *LogConsumer) Lookups() lookups.All
Lookups returns an object that can perform lookup operations against the database.
Each of the lookups takes a log index. It waits until the log consumer has reached this log index and until all pending transactions have been resolved before proceeding.
type Snapshot ¶
type Snapshot struct {
// contains filtered or unexported fields
}
A Snapshot is an immutable database of facts. All Snapshots include the well-known base facts. Snapshots are safe for concurrent access.
func NewSnapshot ¶
NewSnapshot constructs a snapshot that includes the given facts as well as the wellknown base facts. The given facts must not overlap the well-known base facts. The caller is free to modify the given facts after this returns.
func (*Snapshot) AllFacts ¶
AllFacts returns a copy of all the facts in the snapshot, including the well-known base facts. The returned facts are in no particular order.
func (*Snapshot) AssertFacts ¶
AssertFacts fails the test if any of the given facts are not included in the snapshot. The given facts may use variables to capture fact IDs and express metafacts.
func (*Snapshot) CheckInvariants ¶
CheckInvariants asserts properties on the snapshot. Specifically, it checks that:
- No subject, predicate, or object is KID 0.
- No fact is duplicated.
- The same external ID does not refer to multiple KIDs.
func (*Snapshot) ExternalID ¶
ExternalID returns an arbitrary external ID for the given KID, if any exists. Otherwise, it returns the empty string.
func (*Snapshot) Filtered ¶
Filtered returns a new snapshot that excludes the facts that have an index greater than the limit provided.
func (*Snapshot) Lookups ¶
Lookups returns an object that can perform lookup operations against the snapshot.
Each of the lookups takes a log index and filters out facts with a larger index from the snapshot. If you don't have an index to use in the requests, you can use math.MaxUint64 to filter no facts out.
func (*Snapshot) MustExternalID ¶
MustExternalID returns an arbitrary external ID for the given KID. It panics if the KID has no external ID assigned.
func (*Snapshot) MustResolveXID ¶
MustResolveXID returns the KID with the given external ID. It panics if the external ID has no mapping.
func (*Snapshot) ResolveXID ¶
ResolveXID returns the KID with the given external ID, if one exists. Otherwise, it returns 0.
func (*Snapshot) Stats ¶
Stats returns statistics about the facts stored in the snapshot. These statistics also include information about a cluster with a handful of partitions.
func (*Snapshot) StoredFacts ¶
StoredFacts returns a copy of the user-created facts in the snapshot, excluding the well-known base facts. The returned facts are in no particular order.