testlib

package
v2.1.0-alpha.2+incompa... Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2017 License: BSD-3-Clause Imports: 28 Imported by: 0

Documentation

Overview

Package testlib contains utility methods to include in unit tests to deal with topology common tasks, like fake tablets and action loops.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FakeTablet

type FakeTablet struct {
	// Tablet and FakeMysqlDaemon are populated at NewFakeTablet time.
	Tablet          *topodatapb.Tablet
	FakeMysqlDaemon *mysqlctl.FakeMysqlDaemon

	// The following fields are created when we start the event loop for
	// the tablet, and closed / cleared when we stop it.
	// The Listener and RPCServer are used by the gRPC server.
	Agent     *tabletmanager.ActionAgent
	Listener  net.Listener
	RPCServer *grpc.Server

	// These optional fields are used if the tablet also needs to
	// listen on the 'vt' port.
	StartHTTPServer bool
	HTTPListener    net.Listener
	HTTPServer      *http.Server
}

FakeTablet keeps track of a fake tablet in memory. It has: - a Tablet record (used for creating the tablet, kept for user's information) - a FakeMysqlDaemon (used by the fake event loop) - a 'done' channel (used to terminate the fake event loop)

func NewFakeTablet

func NewFakeTablet(t *testing.T, wr *wrangler.Wrangler, cell string, uid uint32, tabletType topodatapb.TabletType, db *fakesqldb.DB, options ...TabletOption) *FakeTablet

NewFakeTablet creates the test tablet in the topology. 'uid' has to be between 0 and 99. All the tablet info will be derived from that. Look at the implementation if you need values. Use TabletOption implementations if you need to change values at creation.

func (*FakeTablet) StartActionLoop

func (ft *FakeTablet) StartActionLoop(t *testing.T, wr *wrangler.Wrangler)

StartActionLoop will start the action loop for a fake tablet, using ft.FakeMysqlDaemon as the backing mysqld.

func (*FakeTablet) StopActionLoop

func (ft *FakeTablet) StopActionLoop(t *testing.T)

StopActionLoop will stop the Action Loop for the given FakeTablet

func (*FakeTablet) Target

func (ft *FakeTablet) Target() querypb.Target

Target returns the keyspace/shard/type info of this tablet as Target.

type TabletOption

type TabletOption func(tablet *topodatapb.Tablet)

TabletOption is an interface for changing tablet parameters. It's a way to pass multiple parameters to NewFakeTablet without making it too cumbersome.

func ForceInitTablet

func ForceInitTablet() TabletOption

ForceInitTablet is the tablet option to set the 'force' flag during InitTablet

func StartHTTPServer

func StartHTTPServer() TabletOption

StartHTTPServer is the tablet option to start the HTTP server when starting a tablet.

func TabletKeyspaceShard

func TabletKeyspaceShard(t *testing.T, keyspace, shard string) TabletOption

TabletKeyspaceShard is the option to set the tablet keyspace and shard

type VtctlPipe

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

VtctlPipe is a vtctl server based on a topo server, and a client that is connected to it via gRPC.

func NewVtctlPipe

func NewVtctlPipe(t *testing.T, ts topo.Server) *VtctlPipe

NewVtctlPipe creates a new VtctlPipe based on the given topo server.

func (*VtctlPipe) Close

func (vp *VtctlPipe) Close()

Close will stop listening and free up all resources.

func (*VtctlPipe) Run

func (vp *VtctlPipe) Run(args []string) error

Run executes the provided command remotely, logs the output in the test logs, and returns the command error.

func (*VtctlPipe) RunAndOutput

func (vp *VtctlPipe) RunAndOutput(args []string) (string, error)

RunAndOutput is similar to Run, but returns the output as a multi-line string instead of logging it.

func (*VtctlPipe) RunAndStreamOutput

func (vp *VtctlPipe) RunAndStreamOutput(args []string) (logutil.EventStream, error)

RunAndStreamOutput returns the output of the vtctl command as a channel. When the channcel is closed, the command did finish.

Jump to

Keyboard shortcuts

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