seqtest

package
v0.0.0-...-f2ec7b3 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Overview

Package seqtest provides a test fixture for instantiating sequencers and other general-purpose test helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckSequencer

func CheckSequencer(
	t *testing.T,
	pre func(t *testing.T, fixture *all.Fixture, seqFixture *Fixture) sequencer.Sequencer,
	post func(t *testing.T, check *Check),
)

CheckSequencer implements a general-purpose smoke test of a sequencer.Sequencer implementation. The sequencer must support foreign-key relationships. The post-hook may be nil.

func Fragment

func Fragment(batch *types.MultiBatch) ([]*types.MultiBatch, error)

Fragment breaks a batch up into a number of minimum-sized batches which are representative of how the bulk-transfer CDC feed delivers data (i.e. payloads per table). The data for any given table will remain in a time-ordered fashion.

Types

type Check

type Check struct {
	// The acceptor returned by [sequencer.Sequencer.Start].
	Acceptor types.MultiAcceptor
	// The total number of transactions to apply.
	Batches int
	// Populated by Check.
	Bounds notify.Var[hlc.Range]
	// Access to test services.
	Fixture *all.Fixture
	// Populated by Check.
	Generator *Generator
	// Populated by Check.
	Group *types.TableGroup
	// The Sequencer under test.
	Sequencer sequencer.Sequencer
	// If true, generated data will be loaded into staging first. This
	// is used to validate the sweeping behavior of a sequencer.
	Stage bool
}

Check implements a reusable test over a parent/child table pair.

func (*Check) Check

func (c *Check) Check(ctx *stopper.Context, t testing.TB)

Check generates data and verifies that it reaches the target tables.

type CheckFlag

type CheckFlag int

CheckFlag describes the range of configurations to be tested. See CheckFlags.

func CheckFlags

func CheckFlags() []CheckFlag

CheckFlags returns all check combinations.

func (CheckFlag) String

func (f CheckFlag) String() string

type Fixture

type Fixture struct {
	*all.Fixture

	BestEffort *besteffort.BestEffort
	Chaos      *chaos.Chaos
	Core       *core.Core
	Immediate  *immediate.Immediate
	Retire     *retire.Retire
	Script     *script.Sequencer
	Switcher   *switcher.Switcher
}

Fixture provides ready-to-use instances of sequencer types.

func NewSequencerFixture

func NewSequencerFixture(fixture *all.Fixture, config *sequencer.Config, scriptConfig *script.Config) (*Fixture, error)

func (*Fixture) SequencerFor

func (f *Fixture) SequencerFor(
	ctx *stopper.Context, mode switcher.Mode,
) (sequencer.Sequencer, error)

SequencerFor returns a Sequencer instance that corresponds to the given mode enum.

type Generator

type Generator struct {
	Fixture           *all.Fixture
	MaxTime           hlc.Time
	Parent, Child     base.TableInfo[*types.TargetPool]
	Parents, Children map[int]struct{}

	// Compare data to ensure time order is maintained.
	ParentVals, ChildVals map[int]int64

	// The keys are child ids and the value the parent id.
	ChildToParent map[int]int
	// contains filtered or unexported fields
}

Generator creates batches of test data. It assumes that there is a parent table and a child table. The parents map will be updated whenever a new parent entry is required.

func NewGenerator

func NewGenerator(
	ctx context.Context, fixture *all.Fixture,
) (*Generator, *types.TableGroup, error)

NewGenerator constructs a Generator that will create messages for parent and child tables.

func (*Generator) CheckConsistent

func (g *Generator) CheckConsistent(ctx context.Context, t testing.TB)

CheckConsistent verifies that the staging tables are empty and that the requisite number of rows exist in the target tables.

func (*Generator) GenerateInto

func (g *Generator) GenerateInto(batch *types.MultiBatch, time hlc.Time)

GenerateInto will add mutations to the batch at the requested time.

func (*Generator) Range

func (g *Generator) Range() hlc.Range

Range returns a range that includes all times at which the Generator created data.

func (*Generator) WaitForCatchUp

func (g *Generator) WaitForCatchUp(ctx context.Context, stats *notify.Var[sequencer.Stat]) error

WaitForCatchUp returns when the Stat shows all tables have advanced beyond the highest timestamp passed to Generator.GenerateInto.

Jump to

Keyboard shortcuts

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