serverutils

package
v0.0.0-...-4ac3ba3 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2017 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetJSONProto

func GetJSONProto(ts TestServerInterface, path string, response proto.Message) error

GetJSONProto uses the supplied client to GET the URL specified by the parameters and unmarshals the result into response.

func InitTestClusterFactory

func InitTestClusterFactory(impl TestClusterFactory)

InitTestClusterFactory should be called once to provide the implementation of the service. It will be called from a xx_test package that can import the server package.

func InitTestServerFactory

func InitTestServerFactory(impl TestServerFactory)

InitTestServerFactory should be called once to provide the implementation of the service. It will be called from a xx_test package that can import the server package.

func PostJSONProto

func PostJSONProto(ts TestServerInterface, path string, request, response proto.Message) error

PostJSONProto uses the supplied client to POST request to the URL specified by the parameters and unmarshals the result into response.

Types

type TestClusterFactory

type TestClusterFactory interface {
	// New instantiates a test server.
	StartTestCluster(t testing.TB, numNodes int, args base.TestClusterArgs) TestClusterInterface
}

TestClusterFactory encompasses the actual implementation of the shim service.

type TestClusterInterface

type TestClusterInterface interface {
	NumServers() int

	// Server returns the TestServerInterface corresponding to a specific node.
	Server(idx int) TestServerInterface

	// ServerConn returns a gosql.DB connection to a specific node.
	ServerConn(idx int) *gosql.DB

	// StopServer stops a single server.
	StopServer(idx int)

	// Stopper retrieves the stopper for this test cluster. Tests should call or
	// defer the Stop() method on this stopper after starting a test cluster.
	Stopper() *stop.Stopper

	// AddReplicas adds replicas for a range on a set of stores.
	// It's illegal to have multiple replicas of the same range on stores of a single
	// node.
	// The method blocks until a snapshot of the range has been copied to all the
	// new replicas and the new replicas become part of the Raft group.
	AddReplicas(
		startKey roachpb.Key, targets ...base.ReplicationTarget,
	) (roachpb.RangeDescriptor, error)

	// RemoveReplicas removes one or more replicas from a range.
	RemoveReplicas(
		startKey roachpb.Key, targets ...base.ReplicationTarget,
	) (roachpb.RangeDescriptor, error)

	// FindRangeLeaseHolder returns the current lease holder for the given range.
	// In particular, it returns one particular node's (the hint, if specified) view
	// of the current lease.
	// An error is returned if there's no active lease.
	//
	// Note that not all nodes have necessarily applied the latest lease,
	// particularly immediately after a TransferRangeLease() call. So specifying
	// different hints can yield different results. The one server that's guaranteed
	// to have applied the transfer is the previous lease holder.
	FindRangeLeaseHolder(
		rangeDesc roachpb.RangeDescriptor,
		hint *base.ReplicationTarget,
	) (base.ReplicationTarget, error)

	// TransferRangeLease transfers the lease for a range from whoever has it to
	// a particular store. That store must already have a replica of the range. If
	// that replica already has the (active) lease, this method is a no-op.
	//
	// When this method returns, it's guaranteed that the old lease holder has
	// applied the new lease, but that's about it. It's not guaranteed that the new
	// lease holder has applied it (so it might not know immediately that it is the
	// new lease holder).
	TransferRangeLease(
		rangeDesc roachpb.RangeDescriptor, dest base.ReplicationTarget,
	) error

	// LookupRange returns the descriptor of the range containing key.
	LookupRange(key roachpb.Key) (roachpb.RangeDescriptor, error)

	// Target returns a base.ReplicationTarget for the specified server.
	Target(serverIdx int) base.ReplicationTarget
}

TestClusterInterface defines TestCluster functionality used by tests.

func StartTestCluster

func StartTestCluster(t testing.TB, numNodes int, args base.TestClusterArgs) TestClusterInterface

StartTestCluster starts up a TestCluster made up of numNodes in-memory testing servers. The cluster should be stopped using Stopper().Stop().

type TestServerFactory

type TestServerFactory interface {
	// New instantiates a test server.
	New(params base.TestServerArgs) interface{}
}

TestServerFactory encompasses the actual implementation of the shim service.

type TestServerInterface

type TestServerInterface interface {
	Stopper() *stop.Stopper

	Start(params base.TestServerArgs) error

	// NodeID returns the ID of this node within its cluster.
	NodeID() roachpb.NodeID

	// ServingAddr returns the server's address.
	ServingAddr() string

	// KVClient() returns a *client.DB instance for talking to this KV server,
	// as an interface{}.
	KVClient() interface{}

	// KVDB() returns the *kv.DB instance as an interface{}.
	KVDB() interface{}

	// RPCContext returns the rpc context used by the test server.
	RPCContext() *rpc.Context

	// LeaseManager() returns the *sql.LeaseManager as an interface{}.
	LeaseManager() interface{}

	// Gossip returns the gossip used by the TestServer.
	Gossip() *gossip.Gossip

	// Clock returns the clock used by the TestServer.
	Clock() *hlc.Clock

	// DistSender returns the DistSender used by the TestServer.
	DistSender() *kv.DistSender

	// DistSQLServer returns the *distsqlrun.ServerImpl as an interface{}.
	DistSQLServer() interface{}

	// SetDistSQLSpanResolver changes the SpanResolver used for DistSQL inside the
	// server's executor. The argument must be a distsqlplan.SpanResolver
	// instance.
	//
	// This method exists because we cannot pass the fake span resolver with the
	// server or cluster params: the fake span resolver needs the node IDs and
	// addresses of the servers in a cluster, which are not available before we
	// start the servers.
	//
	// It is the caller's responsibility to make sure no queries are being run
	// with DistSQL at the same time.
	SetDistSQLSpanResolver(spanResolver interface{})

	// AdminURL returns the URL for the admin UI.
	AdminURL() string
	// GetHTTPClient returns an http client connected to the server. It uses the
	// context client TLS config.
	GetHTTPClient() (http.Client, error)

	// MustGetSQLCounter returns the value of a counter metric from the server's
	// SQL Executor. Runs in O(# of metrics) time, which is fine for test code.
	MustGetSQLCounter(name string) int64
	// MustGetSQLNetworkCounter returns the value of a counter metric from the
	// server's SQL server. Runs in O(# of metrics) time, which is fine for test
	// code.
	MustGetSQLNetworkCounter(name string) int64
	// WriteSummaries records summaries of time-series data, which is required for
	// any tests that query server stats.
	WriteSummaries() error

	// GetFirstStoreID is a utility function returning the StoreID of the first
	// store on this node.
	GetFirstStoreID() roachpb.StoreID

	// SplitRange splits the range containing splitKey.
	SplitRange(
		splitKey roachpb.Key,
	) (left roachpb.RangeDescriptor, right roachpb.RangeDescriptor, err error)
}

TestServerInterface defines test server functionality that tests need; it is implemented by server.TestServer.

func StartServer

func StartServer(
	t testing.TB, params base.TestServerArgs,
) (TestServerInterface, *gosql.DB, *client.DB)

StartServer creates a test server and sets up a gosql DB connection. The server should be stopped by calling server.Stopper().Stop().

func StartServerRaw

func StartServerRaw(args base.TestServerArgs) (TestServerInterface, error)

StartServerRaw creates and starts a TestServer. Generally StartServer() should be used. However this function can be used directly when opening a connection to the server is not desired.

Jump to

Keyboard shortcuts

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