tests

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2023 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Initial int32 = iota
	Running
	Stop
	Destroy
)

TestServer states.

Variables

View Source
var (
	// WaitLeaderReturnDelay represents the time interval of WaitLeader sleep before returning.
	WaitLeaderReturnDelay = 20 * time.Millisecond
	// WaitLeaderCheckInterval represents the time interval of WaitLeader running check.
	WaitLeaderCheckInterval = 500 * time.Millisecond
)

Functions

This section is empty.

Types

type ConfigOption

type ConfigOption func(conf *config.Config, serverName string)

ConfigOption is used to define customize settings in test. You can use serverName to customize a config for a certain server. Usually, the server name will be like `pd1`, `pd2` and so on, which determined by the number of servers you set.

type TestCluster

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

TestCluster is only for test.

func NewTestAPICluster

func NewTestAPICluster(ctx context.Context, initialServerCount int, opts ...ConfigOption) (*TestCluster, error)

NewTestAPICluster creates a new TestCluster with API service.

func NewTestCluster

func NewTestCluster(ctx context.Context, initialServerCount int, opts ...ConfigOption) (*TestCluster, error)

NewTestCluster creates a new TestCluster.

func (*TestCluster) CheckClusterDCLocation

func (c *TestCluster) CheckClusterDCLocation()

CheckClusterDCLocation will force the cluster to do the dc-location check in order to speed up the test.

func (*TestCluster) CheckTSOUnique

func (c *TestCluster) CheckTSOUnique(ts uint64) bool

CheckTSOUnique will check whether the TSO is unique among the cluster in the past and present.

func (*TestCluster) Destroy

func (c *TestCluster) Destroy()

Destroy is used to destroy a TestCluster.

func (*TestCluster) GetCluster

func (c *TestCluster) GetCluster() *metapb.Cluster

GetCluster returns PD cluster.

func (*TestCluster) GetClusterStatus

func (c *TestCluster) GetClusterStatus() (*cluster.Status, error)

GetClusterStatus returns raft cluster status.

func (*TestCluster) GetConfig

func (c *TestCluster) GetConfig() *clusterConfig

GetConfig returns the current TestCluster's configuration.

func (*TestCluster) GetEtcdClient

func (c *TestCluster) GetEtcdClient() *clientv3.Client

GetEtcdClient returns the builtin etcd client.

func (*TestCluster) GetFollower

func (c *TestCluster) GetFollower() string

GetFollower returns an follower of all servers

func (*TestCluster) GetHTTPClient

func (c *TestCluster) GetHTTPClient() *http.Client

GetHTTPClient returns the builtin http client.

func (*TestCluster) GetLeader

func (c *TestCluster) GetLeader() string

GetLeader returns the leader of all servers

func (*TestCluster) GetServer

func (c *TestCluster) GetServer(name string) *TestServer

GetServer returns a server with a given name.

func (*TestCluster) GetServers

func (c *TestCluster) GetServers() map[string]*TestServer

GetServers returns all servers.

func (*TestCluster) HandleRegionHeartbeat

func (c *TestCluster) HandleRegionHeartbeat(region *core.RegionInfo) error

HandleRegionHeartbeat processes RegionInfo reports from the client.

func (*TestCluster) Join

func (c *TestCluster) Join(ctx context.Context, opts ...ConfigOption) (*TestServer, error)

Join is used to add a new TestServer into the cluster.

func (*TestCluster) JoinAPIServer

func (c *TestCluster) JoinAPIServer(ctx context.Context, opts ...ConfigOption) (*TestServer, error)

JoinAPIServer is used to add a new TestAPIServer into the cluster.

func (*TestCluster) ResignLeader

func (c *TestCluster) ResignLeader() error

ResignLeader resigns the leader of the cluster.

func (*TestCluster) RunInitialServers

func (c *TestCluster) RunInitialServers() error

RunInitialServers starts to run servers in InitialServers.

func (*TestCluster) RunServer

func (c *TestCluster) RunServer(server *TestServer) <-chan error

RunServer starts to run TestServer.

func (*TestCluster) RunServers

func (c *TestCluster) RunServers(servers []*TestServer) error

RunServers starts to run multiple TestServer.

func (*TestCluster) StopAll

func (c *TestCluster) StopAll() error

StopAll is used to stop all servers.

func (*TestCluster) WaitAllLeaders

func (c *TestCluster) WaitAllLeaders(re *require.Assertions, dcLocations map[string]string)

WaitAllLeaders will block and wait for the election of PD leader and all Local TSO Allocator leaders.

func (*TestCluster) WaitAllocatorLeader

func (c *TestCluster) WaitAllocatorLeader(dcLocation string, ops ...WaitOption) string

WaitAllocatorLeader is used to get the Local TSO Allocator leader. If it exceeds the maximum number of loops, it will return an empty string.

func (*TestCluster) WaitLeader

func (c *TestCluster) WaitLeader(ops ...WaitOption) string

WaitLeader is used to get leader. If it exceeds the maximum number of loops, it will return an empty string.

func (*TestCluster) WaitRegionSyncerClientsReady

func (c *TestCluster) WaitRegionSyncerClientsReady(n int) bool

WaitRegionSyncerClientsReady is used to wait the region syncer clients establish the connection. n means wait n clients.

type TestServer

type TestServer struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

TestServer is only for test.

func NewTestAPIServer

func NewTestAPIServer(ctx context.Context, cfg *config.Config) (*TestServer, error)

NewTestAPIServer creates a new TestServer.

func NewTestServer

func NewTestServer(ctx context.Context, cfg *config.Config) (*TestServer, error)

NewTestServer creates a new TestServer.

func (*TestServer) BootstrapCluster

func (s *TestServer) BootstrapCluster() error

BootstrapCluster is used to bootstrap the cluster.

func (*TestServer) Destroy

func (s *TestServer) Destroy() error

Destroy is used to destroy a TestServer.

func (*TestServer) GetAddr

func (s *TestServer) GetAddr() string

GetAddr returns the address of TestCluster.

func (*TestServer) GetAdjacentRegions

func (s *TestServer) GetAdjacentRegions(region *core.RegionInfo) []*core.RegionInfo

GetAdjacentRegions returns regions' information that are adjacent with the specific region ID.

func (*TestServer) GetAllocator

func (s *TestServer) GetAllocator() id.Allocator

GetAllocator returns the current TestServer's ID allocator.

func (*TestServer) GetAllocatorLeader

func (s *TestServer) GetAllocatorLeader(dcLocation string) *pdpb.Member

GetAllocatorLeader returns current allocator leader of PD cluster for given dc-location.

func (*TestServer) GetCluster

func (s *TestServer) GetCluster() *metapb.Cluster

GetCluster returns PD cluster.

func (*TestServer) GetClusterID

func (s *TestServer) GetClusterID() uint64

GetClusterID returns the cluster ID.

func (*TestServer) GetClusterVersion

func (s *TestServer) GetClusterVersion() semver.Version

GetClusterVersion returns PD cluster version.

func (*TestServer) GetConfig

func (s *TestServer) GetConfig() *config.Config

GetConfig returns the current TestServer's configuration.

func (*TestServer) GetEtcdClient

func (s *TestServer) GetEtcdClient() *clientv3.Client

GetEtcdClient returns the builtin etcd client.

func (*TestServer) GetEtcdLeader

func (s *TestServer) GetEtcdLeader() (string, error)

GetEtcdLeader returns the builtin etcd leader.

func (*TestServer) GetEtcdLeaderID

func (s *TestServer) GetEtcdLeaderID() (uint64, error)

GetEtcdLeaderID returns the builtin etcd leader ID.

func (*TestServer) GetHTTPClient

func (s *TestServer) GetHTTPClient() *http.Client

GetHTTPClient returns the builtin http client.

func (*TestServer) GetKeyspaceManager

func (s *TestServer) GetKeyspaceManager() *keyspace.Manager

GetKeyspaceManager returns the current TestServer's Keyspace Manager.

func (*TestServer) GetLeader

func (s *TestServer) GetLeader() *pdpb.Member

GetLeader returns current leader of PD cluster.

func (*TestServer) GetPersistOptions

func (s *TestServer) GetPersistOptions() *config.PersistOptions

GetPersistOptions returns the current TestServer's schedule option.

func (*TestServer) GetRaftCluster

func (s *TestServer) GetRaftCluster() *cluster.RaftCluster

GetRaftCluster returns Raft cluster. If cluster has not been bootstrapped, return nil.

func (*TestServer) GetRangeHoles

func (s *TestServer) GetRangeHoles() [][]string

GetRangeHoles returns all range holes, i.e the key ranges without any region info.

func (*TestServer) GetRegionInfoByID

func (s *TestServer) GetRegionInfoByID(regionID uint64) *core.RegionInfo

GetRegionInfoByID returns regionInfo by regionID from cluster.

func (*TestServer) GetRegions

func (s *TestServer) GetRegions() []*core.RegionInfo

GetRegions returns all regions' information in detail.

func (*TestServer) GetServer

func (s *TestServer) GetServer() *server.Server

GetServer returns the real server of TestServer.

func (*TestServer) GetServerID

func (s *TestServer) GetServerID() uint64

GetServerID returns the unique etcd ID for this server in etcd cluster.

func (*TestServer) GetStore

func (s *TestServer) GetStore(storeID uint64) *core.StoreInfo

GetStore returns the store with a given store ID.

func (*TestServer) GetStoreRegions

func (s *TestServer) GetStoreRegions(storeID uint64) []*core.RegionInfo

GetStoreRegions returns all regions' information with a given storeID.

func (*TestServer) GetStores

func (s *TestServer) GetStores() []*metapb.Store

GetStores returns the stores of the cluster.

func (*TestServer) GetTSOAllocatorManager

func (s *TestServer) GetTSOAllocatorManager() *tso.AllocatorManager

GetTSOAllocatorManager returns the server's TSO Allocator Manager.

func (*TestServer) IsAllocatorLeader

func (s *TestServer) IsAllocatorLeader(dcLocation string) bool

IsAllocatorLeader returns whether the server is a TSO Allocator leader or not.

func (*TestServer) IsLeader

func (s *TestServer) IsLeader() bool

IsLeader returns whether the server is leader or not.

func (*TestServer) MoveEtcdLeader

func (s *TestServer) MoveEtcdLeader(old, new uint64) error

MoveEtcdLeader moves etcd leader from old to new.

func (*TestServer) ResignLeader

func (s *TestServer) ResignLeader() error

ResignLeader resigns the leader of the server.

func (*TestServer) Run

func (s *TestServer) Run() error

Run starts to run a TestServer.

func (*TestServer) SetEnableLocalTSO

func (s *TestServer) SetEnableLocalTSO(enableLocalTSO bool)

SetEnableLocalTSO sets the enable-local-tso flag of the TestServer.

func (*TestServer) State

func (s *TestServer) State() int32

State returns the current TestServer's state.

func (*TestServer) Stop

func (s *TestServer) Stop() error

Stop is used to stop a TestServer.

func (*TestServer) WaitLeader

func (s *TestServer) WaitLeader() bool

WaitLeader is used to get instant leader info in order to make a test know the PD leader has been elected as soon as possible. If it exceeds the maximum number of loops, it will return nil.

type WaitOp

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

WaitOp represent the wait configuration

type WaitOption

type WaitOption func(*WaitOp)

WaitOption represent the wait configuration

func WithRetryTimes

func WithRetryTimes(r int) WaitOption

WithRetryTimes indicates the retry times

func WithWaitInterval

func WithWaitInterval(i time.Duration) WaitOption

WithWaitInterval indicates the wait interval

Directories

Path Synopsis
integrations
mcs Module
tso Module
server

Jump to

Keyboard shortcuts

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