cockroach: github.com/cockroachdb/cockroach/pkg/testutils/serverutils Index | Files

package serverutils

import "github.com/cockroachdb/cockroach/pkg/testutils/serverutils"

Index

Package Files

test_cluster_shim.go test_server_shim.go

func GetJSONProto Uses

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

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

func InitTestClusterFactory Uses

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 Uses

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 Uses

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

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

type KeyAndTargets Uses

type KeyAndTargets struct {
    StartKey roachpb.Key
    Targets  []roachpb.ReplicationTarget
}

KeyAndTargets contains replica startKey and targets.

type TestClusterFactory Uses

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 Uses

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 ...roachpb.ReplicationTarget,
    ) (roachpb.RangeDescriptor, error)

    // AddReplicasMulti is the same as AddReplicas but will execute multiple jobs.
    AddReplicasMulti(
        kts ...KeyAndTargets,
    ) ([]roachpb.RangeDescriptor, []error)

    // AddReplicasOrFatal is the same as AddReplicas but will Fatal the test on
    // error.
    AddReplicasOrFatal(
        t testing.TB, startKey roachpb.Key, targets ...roachpb.ReplicationTarget,
    ) roachpb.RangeDescriptor

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

    // RemoveReplicasOrFatal is the same as RemoveReplicas but will Fatal the test on
    // error.
    RemoveReplicasOrFatal(
        t testing.TB, startKey roachpb.Key, targets ...roachpb.ReplicationTarget,
    ) roachpb.RangeDescriptor

    // 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 *roachpb.ReplicationTarget,
    ) (roachpb.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 roachpb.ReplicationTarget,
    ) error

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

    // LookupRangeOrFatal is the same as LookupRange but will Fatal the test on
    // error.
    LookupRangeOrFatal(t testing.TB, key roachpb.Key) roachpb.RangeDescriptor

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

    // ReplicationMode returns the ReplicationMode that the test cluster was
    // configured with.
    ReplicationMode() base.TestClusterReplicationMode
}

TestClusterInterface defines TestCluster functionality used by tests.

func StartTestCluster Uses

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 Uses

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

TestServerFactory encompasses the actual implementation of the shim service.

type TestServerInterface Uses

type TestServerInterface interface {
    Stopper() *stop.Stopper

    Start(params base.TestServerArgs) error

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

    // ServingRPCAddr returns the server's advertised address.
    ServingRPCAddr() string

    // ServingSQLAddr returns the server's advertised SQL address.
    ServingSQLAddr() string

    // HTTPAddr returns the server's http address.
    HTTPAddr() string

    // RPCAddr returns the server's RPC address.
    // Note: use ServingRPCAddr() instead unless specific reason not to.
    RPCAddr() string

    // SQLAddr returns the server's SQL address.
    // Note: use ServingSQLAddr() instead unless specific reason not to.
    SQLAddr() string

    // DB returns a *client.DB instance for talking to this KV server.
    DB() *client.DB

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

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

    // InternalExecutor returns a *sql.InternalExecutor as an interface{} (which
    // also implements sqlutil.InternalExecutor if the test cannot depend on sql).
    InternalExecutor() interface{}

    // ExecutorConfig returns a copy of the server's ExecutorConfig.
    // The real return type is sql.ExecutorConfig.
    ExecutorConfig() interface{}

    // GossipI returns the gossip used by the TestServer.
    // The real return type is *gossip.Gossip.
    GossipI() interface{}

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

    // DistSenderI returns the DistSender used by the TestServer.
    // The real return type is *kv.DistSender.
    DistSenderI() interface{}

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

    // JobRegistry returns the *jobs.Registry as an interface{}.
    JobRegistry() interface{}

    // SetDistSQLSpanResolver changes the SpanResolver used for DistSQL inside the
    // server's executor. The argument must be a physicalplan.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 configured with the client TLS
    // config required by the TestServer's configuration.
    GetHTTPClient() (http.Client, error)
    // GetAuthenticatedHTTPClient returns an http client which has been
    // authenticated to access Admin API methods (via a cookie).
    GetAuthenticatedHTTPClient() (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

    // GetStores returns the collection of stores from this TestServer's node.
    // The return value is of type *storage.Stores.
    GetStores() interface{}

    // ClusterSettings returns the ClusterSettings shared by all components of
    // this server.
    ClusterSettings() *cluster.Settings

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

    // MergeRanges merges the range containing leftKey with the following adjacent
    // range.
    MergeRanges(leftKey roachpb.Key) (merged roachpb.RangeDescriptor, err error)

    // ExpectedInitialRangeCount returns the expected number of ranges that should
    // be on the server after initial (asynchronous) splits have been completed,
    // assuming no additional information is added outside of the normal bootstrap
    // process.
    ExpectedInitialRangeCount() (int, error)
}

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

func StartServer Uses

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 Uses

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.

Package serverutils imports 15 packages (graph) and is imported by 15 packages. Updated 2019-09-19. Refresh now. Tools for package owners.