mock

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package mock provides a mock implementation of a batch handler.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Flusher

type Flusher[T any] struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Flusher is a mock implementation of a batch handler. It exposes a block and unblock method to influence the flushing behavior.

func (*Flusher[T]) BatchesFlushed

func (f *Flusher[T]) BatchesFlushed() [][]T

BatchesFlushed returns all batches that have been flushed.

func (*Flusher[T]) Block

func (f *Flusher[T]) Block()

Block any calls to the flusher.

func (*Flusher[T]) BlockForDuration

func (f *Flusher[T]) BlockForDuration(duration int)

BlockForDuration blocks the flusher for a given duration.

func (*Flusher[T]) FinishCount

func (f *Flusher[T]) FinishCount() int

FinishCount returns the number of times the flush method has finished.

func (*Flusher[T]) Flush

func (f *Flusher[T]) Flush(ctx context.Context, items []T)

Flush is the handler for flushing items. In this mock implementation, it will block until all blockers are removed.

func (*Flusher[T]) IsFlushingRightNow

func (f *Flusher[T]) IsFlushingRightNow() bool

IsFlushingRightNow returns whether the flusher is currently running.

func (*Flusher[T]) SetIgnoreContextCancellation

func (f *Flusher[T]) SetIgnoreContextCancellation(d time.Duration)

SetIgnoreContextCancellation sets the time to wait for the flusher to finish before shutting down because of a context cancellation.

func (*Flusher[T]) SetOnFlush

func (f *Flusher[T]) SetOnFlush(onFlush func(ctx context.Context, items []T))

SetOnFlush sets a callback that is called when the flush method is called.

func (*Flusher[T]) StartCount

func (f *Flusher[T]) StartCount() int

StartCount returns the number of times the flush method has been called.

func (*Flusher[T]) Unblock

func (f *Flusher[T]) Unblock()

Unblock the flusher.

func (*Flusher[T]) WaitForTotalFinished

func (f *Flusher[T]) WaitForTotalFinished(num int, timeout ...time.Duration) chan struct{}

WaitForTotalFinished returns a channel that is closed when the flusher has finished flushing a given number of times since the start of the flusher. If the flusher does not finish in the given timeout, a panic is triggered. By default the timeout is 1 second.

func (*Flusher[T]) WaitForTotalStarted

func (f *Flusher[T]) WaitForTotalStarted(num int, timeout ...time.Duration) chan struct{}

WaitForTotalStarted returns a channel that is closed when the flusher has started flushing a given number of times since the start of the flusher. If the flusher does not start in the given timeout, a panic is triggered. By default the timeout is 1 second.

func (*Flusher[T]) WasInterrupted

func (f *Flusher[T]) WasInterrupted() bool

WasInterrupted returns whether the flush was interrupted due to a context cancellation.

Jump to

Keyboard shortcuts

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