Documentation ¶
Index ¶
- Constants
- Variables
- type ConfigOption
- type TestCluster
- func (c *TestCluster) CheckClusterDCLocation()
- func (c *TestCluster) CheckTSOUnique(ts uint64) bool
- func (c *TestCluster) Destroy()
- func (c *TestCluster) GetCluster() *metapb.Cluster
- func (c *TestCluster) GetClusterStatus() (*cluster.Status, error)
- func (c *TestCluster) GetConfig() *clusterConfig
- func (c *TestCluster) GetEtcdClient() *clientv3.Client
- func (c *TestCluster) GetFollower() string
- func (c *TestCluster) GetHTTPClient() *http.Client
- func (c *TestCluster) GetLeader() string
- func (c *TestCluster) GetServer(name string) *TestServer
- func (c *TestCluster) GetServers() map[string]*TestServer
- func (c *TestCluster) HandleRegionHeartbeat(region *core.RegionInfo) error
- func (c *TestCluster) Join(ctx context.Context, opts ...ConfigOption) (*TestServer, error)
- func (c *TestCluster) JoinAPIServer(ctx context.Context, opts ...ConfigOption) (*TestServer, error)
- func (c *TestCluster) ResignLeader() error
- func (c *TestCluster) RunInitialServers() error
- func (c *TestCluster) RunServer(server *TestServer) <-chan error
- func (c *TestCluster) RunServers(servers []*TestServer) error
- func (c *TestCluster) StopAll() error
- func (c *TestCluster) WaitAllLeaders(re *require.Assertions, dcLocations map[string]string)
- func (c *TestCluster) WaitAllocatorLeader(dcLocation string, ops ...WaitOption) string
- func (c *TestCluster) WaitLeader(ops ...WaitOption) string
- func (c *TestCluster) WaitRegionSyncerClientsReady(n int) bool
- type TestServer
- func (s *TestServer) BootstrapCluster() error
- func (s *TestServer) Destroy() error
- func (s *TestServer) GetAddr() string
- func (s *TestServer) GetAdjacentRegions(region *core.RegionInfo) []*core.RegionInfo
- func (s *TestServer) GetAllocator() id.Allocator
- func (s *TestServer) GetAllocatorLeader(dcLocation string) *pdpb.Member
- func (s *TestServer) GetCluster() *metapb.Cluster
- func (s *TestServer) GetClusterID() uint64
- func (s *TestServer) GetClusterVersion() semver.Version
- func (s *TestServer) GetConfig() *config.Config
- func (s *TestServer) GetEtcdClient() *clientv3.Client
- func (s *TestServer) GetEtcdLeader() (string, error)
- func (s *TestServer) GetEtcdLeaderID() (uint64, error)
- func (s *TestServer) GetHTTPClient() *http.Client
- func (s *TestServer) GetKeyspaceManager() *keyspace.Manager
- func (s *TestServer) GetLeader() *pdpb.Member
- func (s *TestServer) GetPersistOptions() *config.PersistOptions
- func (s *TestServer) GetRaftCluster() *cluster.RaftCluster
- func (s *TestServer) GetRangeHoles() [][]string
- func (s *TestServer) GetRegionInfoByID(regionID uint64) *core.RegionInfo
- func (s *TestServer) GetRegions() []*core.RegionInfo
- func (s *TestServer) GetServer() *server.Server
- func (s *TestServer) GetServerID() uint64
- func (s *TestServer) GetStore(storeID uint64) *core.StoreInfo
- func (s *TestServer) GetStoreRegions(storeID uint64) []*core.RegionInfo
- func (s *TestServer) GetStores() []*metapb.Store
- func (s *TestServer) GetTSOAllocatorManager() *tso.AllocatorManager
- func (s *TestServer) IsAllocatorLeader(dcLocation string) bool
- func (s *TestServer) IsLeader() bool
- func (s *TestServer) MoveEtcdLeader(old, new uint64) error
- func (s *TestServer) ResignLeader() error
- func (s *TestServer) Run() error
- func (s *TestServer) SetEnableLocalTSO(enableLocalTSO bool)
- func (s *TestServer) State() int32
- func (s *TestServer) Stop() error
- func (s *TestServer) WaitLeader() bool
- type WaitOp
- type WaitOption
Constants ¶
const ( Initial int32 = iota Running Stop Destroy )
TestServer states.
Variables ¶
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 ¶
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 ¶
TestServer is only for test.
func NewTestAPIServer ¶
NewTestAPIServer creates a new TestServer.
func NewTestServer ¶
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) 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) 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