utils

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2018 License: Apache-2.0 Imports: 3 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CountingDecorator

type CountingDecorator interface {
	GetCount() int
	weave.Decorator
}

CountingDecorator keeps track of number of times called. 2x per call, 1x per call with panic inside

type CountingHandler

type CountingHandler interface {
	GetCount() int
	weave.Handler
}

CountingHandler keeps track of number of times called. 1x per call

type Logging

type Logging struct{}

Logging is a decorator to log messages as they pass through

func NewLogging

func NewLogging() Logging

NewLogging creates a Logging decorator

func (Logging) Check

func (r Logging) Check(ctx weave.Context, store weave.KVStore, tx weave.Tx,
	next weave.Checker) (weave.CheckResult, error)

Check logs error -> info, success -> debug

func (Logging) Deliver

func (r Logging) Deliver(ctx weave.Context, store weave.KVStore, tx weave.Tx,
	next weave.Deliverer) (weave.DeliverResult, error)

Deliver logs error -> error, success -> info

type Recovery

type Recovery struct{}

Recovery is a decorator to recover from panics in transactions, so we can log them as errors

func NewRecovery

func NewRecovery() Recovery

NewRecovery creates a Recovery decorator

func (Recovery) Check

func (r Recovery) Check(ctx weave.Context, store weave.KVStore, tx weave.Tx,
	next weave.Checker) (res weave.CheckResult, err error)

Check turns panics into normal errors

func (Recovery) Deliver

func (r Recovery) Deliver(ctx weave.Context, store weave.KVStore, tx weave.Tx,
	next weave.Deliverer) (res weave.DeliverResult, err error)

Deliver turns panics into normal errors

type Savepoint

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

Savepoint will isolate all data inside of the call, and commit/rollback to savepoint based on if error

func NewSavepoint

func NewSavepoint() Savepoint

NewSavepoint creates a Savepoint decorator, but you must call OnCheck/OnDeliver so it will be triggered

func (Savepoint) Check

func (s Savepoint) Check(ctx weave.Context, store weave.KVStore, tx weave.Tx,
	next weave.Checker) (weave.CheckResult, error)

Check will optionally set a checkpoint

func (Savepoint) Deliver

func (s Savepoint) Deliver(ctx weave.Context, store weave.KVStore, tx weave.Tx,
	next weave.Deliverer) (weave.DeliverResult, error)

Deliver will optionally set a checkpoint

func (Savepoint) OnCheck

func (s Savepoint) OnCheck() Savepoint

OnCheck returns a savepoint that will trigger on CheckTx

func (Savepoint) OnDeliver

func (s Savepoint) OnDeliver() Savepoint

OnDeliver returns a savepoint that will trigger on DeliverTx

type TestHelpers

type TestHelpers struct{}

TestHelpers returns helper objects for tests, encapsulated in one object to be easily imported in other packages

func (TestHelpers) CountingDecorator

func (TestHelpers) CountingDecorator() CountingDecorator

CountingDecorator passes tx along, and counts how many times it was called. Adds one on input down, one on output up, to differentiate panic from error

func (TestHelpers) CountingHandler

func (TestHelpers) CountingHandler() CountingHandler

Counting handler returns success and counts times called

func (TestHelpers) ErrorDecorator

func (TestHelpers) ErrorDecorator(err error) weave.Decorator

ErrorDecorator always returns the given error when called

func (TestHelpers) ErrorHandler

func (TestHelpers) ErrorHandler(err error) weave.Handler

ErrorHandler always returns the given error when called

func (TestHelpers) PanicAtHeightDecorator

func (TestHelpers) PanicAtHeightDecorator(h int64) weave.Decorator

PanicAtHeightDecorator will panic if ctx.height >= h

func (TestHelpers) PanicHandler

func (TestHelpers) PanicHandler(err error) weave.Handler

PanicHandler always pancis with the given error when called

func (TestHelpers) WriteDecorator

func (TestHelpers) WriteDecorator(key, value []byte, after bool) weave.Decorator

WriteDecorator will write the given key/value pair to the KVStore, either before or after calling down the stack. Returns (res, err) from child handler untouched

func (TestHelpers) WriteHandler

func (TestHelpers) WriteHandler(key, value []byte, err error) weave.Handler

WriteHandler will write the given key/value pair to the KVStore, and return the error (use nil for success)

Jump to

Keyboard shortcuts

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