mockstore

package
v0.0.0-...-6719cd2 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2019 License: Apache-2.0 Imports: 18 Imported by: 0

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

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 NewDB

func NewDB() *DB

NewDB constructs a DB that contains only the well-known facts.

func (*DB) AddFact

func (db *DB) AddFact(fact rpc.Fact)

AddFact adds the given fact to the database. The fact's ID and index should be set by the caller.

func (*DB) AddSPO

func (db *DB) AddSPO(subject uint64, predicate uint64, object rpc.KGObject) rpc.Fact

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) Current

func (db *DB) Current() *Snapshot

Current returns a snapshot of the current state of the database.

func (*DB) Lookups

func (db *DB) Lookups() lookups.All

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.

func (*DB) SkipIndex

func (db *DB) SkipIndex() blog.Index

SkipIndex returns an unused log index greater than anything else in the database. Subsequent calls to AddSPO will not use this index.

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.

func (*LogConsumer) Snapshot

func (consumer *LogConsumer) Snapshot(ctx context.Context, index blog.Index) (*Snapshot, error)

Snapshot waits until the consumer has applied the given index and all transactions up to that index have been resolved, then returns a snapshot with any facts above the given index filtered out. If the context expires first, it returns nil and a context error.

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

func NewSnapshot(stored []rpc.Fact) *Snapshot

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

func (snap *Snapshot) AllFacts() []rpc.Fact

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

func (snap *Snapshot) AssertFacts(t assert.TestingT, facts string) bool

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

func (snap *Snapshot) CheckInvariants(t assert.TestingT)

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

func (snap *Snapshot) ExternalID(kid uint64) string

ExternalID returns an arbitrary external ID for the given KID, if any exists. Otherwise, it returns the empty string.

func (*Snapshot) Filtered

func (snap *Snapshot) Filtered(limit blog.Index) *Snapshot

Filtered returns a new snapshot that excludes the facts that have an index greater than the limit provided.

func (*Snapshot) Lookups

func (snap *Snapshot) Lookups() lookups.All

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

func (snap *Snapshot) MustExternalID(kid uint64) string

MustExternalID returns an arbitrary external ID for the given KID. It panics if the KID has no external ID assigned.

func (*Snapshot) MustResolveXID

func (snap *Snapshot) MustResolveXID(externalID string) uint64

MustResolveXID returns the KID with the given external ID. It panics if the external ID has no mapping.

func (*Snapshot) ResolveXID

func (snap *Snapshot) ResolveXID(externalID string) uint64

ResolveXID returns the KID with the given external ID, if one exists. Otherwise, it returns 0.

func (*Snapshot) Stats

func (snap *Snapshot) Stats() planner.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

func (snap *Snapshot) StoredFacts() []rpc.Fact

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.

Jump to

Keyboard shortcuts

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