flow

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2020 License: Apache-2.0 Imports: 9 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCancelled = errors.New("flow cancelled")

Functions

func Pulse

func TestContextWithPulse

func TestContextWithPulse(ctx context.Context, pn insolar.PulseNumber) context.Context

Types

type Flow

type Flow interface {
	// Handle gives control to another handle and waits for its return. Consider it "calling" another dispatcher.
	Handle(context.Context, Handle) error

	// Procedure starts a routine and blocks Handle execution until cancellation happens or routine returns.
	// If cancellation happens first, ErrCancelled will immediately be returned to the Handle. The Procedure
	// continues to execute in the background, but it's state must be discarded by the Handle as invalid.
	// If Routine returns first, Procedure error (if any) will be returned.
	// Procedure can figure out whether it's execution was canceled and there is no point to continue
	// the execution by reading from context.Done()
	Procedure(ctx context.Context, proc Procedure, cancelable bool) error

	// Migrate blocks caller execution until cancellation happens then runs provided Handle in a new flow.
	// Note that this method can be called after cancellation. Use it to migrate processing after Handle or Procedure
	// returned ErrCancelled.
	//
	// IMPORTANT: Migrate can be called only once per flow. Calling it the second time will result in error.
	Migrate(context.Context, Handle) error

	// Continue blocks caller execution until cancellation happens then updates 'cancel' and returns control to caller.
	// It might be called multiple times, but each time it will wait for cancellation.
	// Might be used to continue processing in Handle after Procedure returns ErrCancelled
	Continue(context.Context)
}

Flow will be pasted to all Handles to control execution. This is very important not to blow this interface. Keep it minimal.

type FlowMock

type FlowMock struct {
	ContinueMock mFlowMockContinue

	HandleMock mFlowMockHandle

	MigrateMock mFlowMockMigrate

	ProcedureMock mFlowMockProcedure
	// contains filtered or unexported fields
}

FlowMock implements Flow

func NewFlowMock

func NewFlowMock(t minimock.Tester) *FlowMock

NewFlowMock returns a mock for Flow

func (*FlowMock) Continue

func (mmContinue *FlowMock) Continue(ctx context.Context)

Continue implements Flow

func (*FlowMock) ContinueAfterCounter

func (mmContinue *FlowMock) ContinueAfterCounter() uint64

ContinueAfterCounter returns a count of finished FlowMock.Continue invocations

func (*FlowMock) ContinueBeforeCounter

func (mmContinue *FlowMock) ContinueBeforeCounter() uint64

ContinueBeforeCounter returns a count of FlowMock.Continue invocations

func (*FlowMock) Handle

func (mmHandle *FlowMock) Handle(ctx context.Context, h1 Handle) (err error)

Handle implements Flow

func (*FlowMock) HandleAfterCounter

func (mmHandle *FlowMock) HandleAfterCounter() uint64

HandleAfterCounter returns a count of finished FlowMock.Handle invocations

func (*FlowMock) HandleBeforeCounter

func (mmHandle *FlowMock) HandleBeforeCounter() uint64

HandleBeforeCounter returns a count of FlowMock.Handle invocations

func (*FlowMock) Migrate

func (mmMigrate *FlowMock) Migrate(ctx context.Context, h1 Handle) (err error)

Migrate implements Flow

func (*FlowMock) MigrateAfterCounter

func (mmMigrate *FlowMock) MigrateAfterCounter() uint64

MigrateAfterCounter returns a count of finished FlowMock.Migrate invocations

func (*FlowMock) MigrateBeforeCounter

func (mmMigrate *FlowMock) MigrateBeforeCounter() uint64

MigrateBeforeCounter returns a count of FlowMock.Migrate invocations

func (*FlowMock) MinimockContinueDone

func (m *FlowMock) MinimockContinueDone() bool

MinimockContinueDone returns true if the count of the Continue invocations corresponds the number of defined expectations

func (*FlowMock) MinimockContinueInspect

func (m *FlowMock) MinimockContinueInspect()

MinimockContinueInspect logs each unmet expectation

func (*FlowMock) MinimockFinish

func (m *FlowMock) MinimockFinish()

MinimockFinish checks that all mocked methods have been called the expected number of times

func (*FlowMock) MinimockHandleDone

func (m *FlowMock) MinimockHandleDone() bool

MinimockHandleDone returns true if the count of the Handle invocations corresponds the number of defined expectations

func (*FlowMock) MinimockHandleInspect

func (m *FlowMock) MinimockHandleInspect()

MinimockHandleInspect logs each unmet expectation

func (*FlowMock) MinimockMigrateDone

func (m *FlowMock) MinimockMigrateDone() bool

MinimockMigrateDone returns true if the count of the Migrate invocations corresponds the number of defined expectations

func (*FlowMock) MinimockMigrateInspect

func (m *FlowMock) MinimockMigrateInspect()

MinimockMigrateInspect logs each unmet expectation

func (*FlowMock) MinimockProcedureDone

func (m *FlowMock) MinimockProcedureDone() bool

MinimockProcedureDone returns true if the count of the Procedure invocations corresponds the number of defined expectations

func (*FlowMock) MinimockProcedureInspect

func (m *FlowMock) MinimockProcedureInspect()

MinimockProcedureInspect logs each unmet expectation

func (*FlowMock) MinimockWait

func (m *FlowMock) MinimockWait(timeout mm_time.Duration)

MinimockWait waits for all mocked methods to be called the expected number of times

func (*FlowMock) Procedure

func (mmProcedure *FlowMock) Procedure(ctx context.Context, proc Procedure, cancelable bool) (err error)

Procedure implements Flow

func (*FlowMock) ProcedureAfterCounter

func (mmProcedure *FlowMock) ProcedureAfterCounter() uint64

ProcedureAfterCounter returns a count of finished FlowMock.Procedure invocations

func (*FlowMock) ProcedureBeforeCounter

func (mmProcedure *FlowMock) ProcedureBeforeCounter() uint64

ProcedureBeforeCounter returns a count of FlowMock.Procedure invocations

type FlowMockContinueExpectation

type FlowMockContinueExpectation struct {
	Counter uint64
	// contains filtered or unexported fields
}

FlowMockContinueExpectation specifies expectation struct of the Flow.Continue

type FlowMockContinueParams

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

FlowMockContinueParams contains parameters of the Flow.Continue

type FlowMockHandleExpectation

type FlowMockHandleExpectation struct {
	Counter uint64
	// contains filtered or unexported fields
}

FlowMockHandleExpectation specifies expectation struct of the Flow.Handle

func (*FlowMockHandleExpectation) Then

Then sets up Flow.Handle return parameters for the expectation previously defined by the When method

type FlowMockHandleParams

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

FlowMockHandleParams contains parameters of the Flow.Handle

type FlowMockHandleResults

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

FlowMockHandleResults contains results of the Flow.Handle

type FlowMockMigrateExpectation

type FlowMockMigrateExpectation struct {
	Counter uint64
	// contains filtered or unexported fields
}

FlowMockMigrateExpectation specifies expectation struct of the Flow.Migrate

func (*FlowMockMigrateExpectation) Then

Then sets up Flow.Migrate return parameters for the expectation previously defined by the When method

type FlowMockMigrateParams

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

FlowMockMigrateParams contains parameters of the Flow.Migrate

type FlowMockMigrateResults

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

FlowMockMigrateResults contains results of the Flow.Migrate

type FlowMockProcedureExpectation

type FlowMockProcedureExpectation struct {
	Counter uint64
	// contains filtered or unexported fields
}

FlowMockProcedureExpectation specifies expectation struct of the Flow.Procedure

func (*FlowMockProcedureExpectation) Then

Then sets up Flow.Procedure return parameters for the expectation previously defined by the When method

type FlowMockProcedureParams

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

FlowMockProcedureParams contains parameters of the Flow.Procedure

type FlowMockProcedureResults

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

FlowMockProcedureResults contains results of the Flow.Procedure

type Handle

type Handle func(context.Context, Flow) error

Handle is a one-function synchronous process that can call routines to do long processing. IMPORTANT: Asynchronous code is NOT ALLOWED here. To create a new Handle of a given message use dispatcher.NewHandler procedure. You can find an example in insolar/ladger/artifactmanager/dispatcher.go

type MakeHandle

type MakeHandle func(*message.Message) Handle

MakeHandle is a function that constructs new Handle.

type Procedure

type Procedure interface {
	// Proceed is called when Procedure is given control. When it returns, control will be given back to Handle.
	Proceed(context.Context) error
}

Procedure is a task that can execute itself. Please note that the Procedure is marked as canceled if a pulse happens during it's execution. This means that it continues to execute in the background, though it's return value will be discarded. Thus if you have multiple steps that can be executed in different pulses split them into separate Procedures. Otherwise join the steps into a single Procedure. It's a good idea to keep Procedures in a separate package to hide internal state from Handle.

type ProcedureMock

type ProcedureMock struct {
	ProceedMock mProcedureMockProceed
	// contains filtered or unexported fields
}

ProcedureMock implements Procedure

func NewProcedureMock

func NewProcedureMock(t minimock.Tester) *ProcedureMock

NewProcedureMock returns a mock for Procedure

func (*ProcedureMock) MinimockFinish

func (m *ProcedureMock) MinimockFinish()

MinimockFinish checks that all mocked methods have been called the expected number of times

func (*ProcedureMock) MinimockProceedDone

func (m *ProcedureMock) MinimockProceedDone() bool

MinimockProceedDone returns true if the count of the Proceed invocations corresponds the number of defined expectations

func (*ProcedureMock) MinimockProceedInspect

func (m *ProcedureMock) MinimockProceedInspect()

MinimockProceedInspect logs each unmet expectation

func (*ProcedureMock) MinimockWait

func (m *ProcedureMock) MinimockWait(timeout mm_time.Duration)

MinimockWait waits for all mocked methods to be called the expected number of times

func (*ProcedureMock) Proceed

func (mmProceed *ProcedureMock) Proceed(ctx context.Context) (err error)

Proceed implements Procedure

func (*ProcedureMock) ProceedAfterCounter

func (mmProceed *ProcedureMock) ProceedAfterCounter() uint64

ProceedAfterCounter returns a count of finished ProcedureMock.Proceed invocations

func (*ProcedureMock) ProceedBeforeCounter

func (mmProceed *ProcedureMock) ProceedBeforeCounter() uint64

ProceedBeforeCounter returns a count of ProcedureMock.Proceed invocations

type ProcedureMockProceedExpectation

type ProcedureMockProceedExpectation struct {
	Counter uint64
	// contains filtered or unexported fields
}

ProcedureMockProceedExpectation specifies expectation struct of the Procedure.Proceed

func (*ProcedureMockProceedExpectation) Then

Then sets up Procedure.Proceed return parameters for the expectation previously defined by the When method

type ProcedureMockProceedParams

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

ProcedureMockProceedParams contains parameters of the Procedure.Proceed

type ProcedureMockProceedResults

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

ProcedureMockProceedResults contains results of the Procedure.Proceed

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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