test

package
v3.35.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: Apache-2.0, Apache-2.0 Imports: 30 Imported by: 0

Documentation

Overview

Copyright 2022 Molecula Corp. (DBA FeatureBase). SPDX-License-Identifier: Apache-2.0

Copyright 2022 Molecula Corp. (DBA FeatureBase). SPDX-License-Identifier: Apache-2.0

Copyright 2022 Molecula Corp. (DBA FeatureBase). SPDX-License-Identifier: Apache-2.0

Copyright 2021 Molecula Corp. All rights reserved.

Copyright 2022 Molecula Corp. (DBA FeatureBase). SPDX-License-Identifier: Apache-2.0

Copyright 2022 Molecula Corp. (DBA FeatureBase). SPDX-License-Identifier: Apache-2.0

Copyright 2022 Molecula Corp. (DBA FeatureBase). SPDX-License-Identifier: Apache-2.0

Copyright 2022 Molecula Corp. (DBA FeatureBase). SPDX-License-Identifier: Apache-2.0

Copyright 2022 Molecula Corp. (DBA FeatureBase). SPDX-License-Identifier: Apache-2.0

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckGroupBy

func CheckGroupBy(t *testing.T, expected, results []pilosa.GroupCount)

func CheckGroupByOnKey

func CheckGroupByOnKey(t *testing.T, expected, results []pilosa.GroupCount)

CheckGroupByOnKey is like CheckGroupBy, but it doen't enforce a match on the GroupBy.Group.RowID value. In cases where the Group has a RowKey, then the value of RowID is not consistently assigned. Instead, it depends on the order of key translation IDs based on shard allocation to the

func CompareTransactions

func CompareTransactions(t *testing.T, trns1, trns2 *pilosa.Transaction)

CompareTransactions errors describing how the transactions differ (if at all). The deadlines need only be close (within deadlineSkew).

func Do

func Do(t testing.TB, method, urlStr string, body string) *httpResponse

Do executes http.Do() with an http.NewRequest().

func DoProto

func DoProto(t testing.TB, method, urlStr string, body []byte) *gohttp.Response

Do executes http.Do() with an http.NewRequest().

func GetPortsGenConfigs

func GetPortsGenConfigs(tb DirCleaner, nodes []*Command) error

GetPortsGenConfigs generates etcd configs for a number of nodes, including cross-references so that every node gets an initial cluster list pointing it at the other nodes, and modifies the configs of the provided Command objects to point to these etcd configs. It uses etcd.GenEtcdConfigs, which in turn creates temporary directories and the like.

func MustMarshalJSON

func MustMarshalJSON(v interface{}) []byte

MustMarshalJSON marshals v to JSON. Panic on error.

func MustNewHTTPRequest

func MustNewHTTPRequest(method, urlStr string, body io.Reader) *gohttp.Request

MustNewHTTPRequest creates a new HTTP request. Panic on error.

func MustOpenIndex

func MustOpenIndex(tb testing.TB) (*Holder, *Index)

MustOpenIndex returns a new, opened index at a temporary path, or fails the test. It also returns the holder containing the index.

func NewWholeTestRun

func NewWholeTestRun(tb testing.TB) *wholeTestRunWrapper

NewWholeTestRun produces a wholeTestRunWrapper around TB, which overrides a couple of the TB's methods to get whole-test-friendly behaviors.

func OptAllowedOrigins

func OptAllowedOrigins(origins []string) server.CommandOption

func RetryUntil

func RetryUntil(timeout time.Duration, fn func() error) (err error)

RetryUntil repeatedly executes fn until it returns nil or timeout occurs.

Types

type Cluster

type Cluster struct {
	*ShareableCluster
	// contains filtered or unexported fields
}

Cluster represents a per-test wrapper of a "real" cluster. Individual tests which request a cluster can get one of these back, wrapped with their test name.

func MustNewCluster

func MustNewCluster(tb testing.TB, size int, opts ...[]server.CommandOption) *Cluster

MustNewCluster creates a new cluster or returns an existing one. It never shares a cluster with non-empty opts. If opts contains only one slice of command options, those options are used with every node. If it is empty, default options are used. Otherwise, it must contain size slices of command options, which are used with corresponding nodes.

func MustRunCluster

func MustRunCluster(tb testing.TB, size int, opts ...[]server.CommandOption) *Cluster

MustRunCluster creates and starts a new cluster. The opts parameter is slightly magical; see MustNewCluster.

func MustRunUnsharedCluster

func MustRunUnsharedCluster(tb testing.TB, size int, opts ...[]server.CommandOption) *Cluster

MustRunUnsharedCluster creates a new cluster. If opts contains only one slice of command options, those options are used with every node. If it is empty, default options are used. Otherwise, it must contain size slices of command options, which are used with corresponding nodes. The new cluster is always unshared. The new cluster is started automatically, or the test is failed.

func MustUnsharedCluster

func MustUnsharedCluster(tb testing.TB, size int, opts ...[]server.CommandOption) *Cluster

MustUnsharedCluster creates a new cluster. If opts contains only one slice of command options, those options are used with every node. If it is empty, default options are used. Otherwise, it must contain size slices of command options, which are used with corresponding nodes. The new cluster is always unshared.

func (*Cluster) Close

func (c *Cluster) Close() error

func (*Cluster) Format

func (c *Cluster) Format(state fmt.State, r rune)

Format implements Formatter, allowing us to use clusters in format strings to handle the extremely common problem of "I want to embed the index name in this here string". Because we are horrible criminals, we append the rune, so you can use %i and %j to get index-name-plus-i and index-name-plus-j, respectively. We do assume that the rune works as a plain byte, though.

func (*Cluster) Idx

func (c *Cluster) Idx(of ...string) string

Idx produces an index name suitable for this test's cluster, using the name itself, or the concatenation of that name and any provided strings, joined by underscores.

func (*Cluster) Start

func (c *Cluster) Start() error

type Command

type Command struct {
	*server.Command
	// contains filtered or unexported fields
}

Command represents a test wrapper for server.Command.

func NewCommandNode

func NewCommandNode(tb DirCleaner, opts ...server.CommandOption) *Command

NewCommandNode returns a new instance of Command with clustering enabled.

func RunCommand

func RunCommand(t *testing.T) *Command

RunCommand returns a new, running Main. Panic on error.

func (*Command) AssertState

func (m *Command) AssertState(t testing.TB, expectedState disco.ClusterState, timeout time.Duration)

AssertState waits for the whole cluster to reach a specified state, or fails the calling test if it can't.

func (*Command) AwaitState

func (m *Command) AwaitState(expectedState disco.ClusterState, timeout time.Duration) (err error)

AwaitState waits for the whole cluster to reach a specified state.

func (*Command) Client

func (m *Command) Client() *pilosa.InternalClient

Client returns a client to connect to the program.

func (*Command) Close

func (m *Command) Close() error

Close closes the program and removes the underlying data directory.

func (*Command) ID

func (m *Command) ID() string

ID returns the node ID used by the running program.

func (*Command) IsPrimary

func (m *Command) IsPrimary() bool

IsPrimary returns true if this is the primary.

func (*Command) MustCreateField

func (m *Command) MustCreateField(tb testing.TB, index, field string, opts ...pilosa.FieldOption) *pilosa.Field

MustCreateField uses this command's API to create the field. The index must already exist - it fails the test if there is an error.

func (*Command) MustCreateIndex

func (m *Command) MustCreateIndex(tb testing.TB, name string, opts pilosa.IndexOptions) *pilosa.Index

MustCreateIndex uses this command's API to create an index and fails the test if there is an error.

func (*Command) Query

func (m *Command) Query(t testing.TB, index, rawQuery, query string) (string, error)

Query executes a query against the program through the HTTP API.

func (*Command) QueryAPI

func (m *Command) QueryAPI(tb testing.TB, req *pilosa.QueryRequest) pilosa.QueryResponse

QueryAPI uses this command's API to execute the given query request, failing if Query returns a non-nil error, otherwise returning the QueryResponse.

func (*Command) QueryExpect

func (m *Command) QueryExpect(t *testing.T, index, rawQuery, query string, expected string)

QueryExpect executes a query against the program through the HTTP API, and confirms that it got an expected response.

func (*Command) QueryProtobuf

func (m *Command) QueryProtobuf(indexName string, query string) (*pilosa.QueryResponse, error)

func (*Command) Queryf

func (m *Command) Queryf(t *testing.T, index, rawQuery, query string, params ...interface{}) (string, error)

Queryf is like Query, but with a format string.

func (*Command) RecalculateCaches

func (m *Command) RecalculateCaches(t *testing.T) error

RecalculateCaches is deprecated. Use MustRecalculateCaches.

func (*Command) Reopen

func (m *Command) Reopen() error

Reopen closes the program and reopens it.

func (*Command) URL

func (m *Command) URL() string

URL returns the base URL string for accessing the running program.

type DirCleaner

type DirCleaner interface {
	Helper()
	Errorf(string, ...interface{})
	Fatalf(string, ...interface{})
	Fatal(...interface{})
	Logf(string, ...interface{})
	Name() string
	TempDir() string
	Cleanup(func())
	Skip(...interface{})
}

DirCleaner represents the subset of the testing.TB interface we care about, allowing us to take objects which behave like that without importing all of testing to get them.

type Field

type Field struct {
	*pilosa.Field
}

Field represents a test wrapper for pilosa.Field.

type Holder

type Holder struct {
	*pilosa.Holder
	// contains filtered or unexported fields
}

Holder is a test wrapper for pilosa.Holder.

func MustOpenHolder

func MustOpenHolder(tb testing.TB) *Holder

MustOpenHolder creates and opens a holder at a temporary path. Panic on error.

func NewHolder

func NewHolder(tb testing.TB) *Holder

NewHolder returns a new instance of Holder with a temporary path.

func (*Holder) ClearBit

func (h *Holder) ClearBit(index, field string, rowID, columnID uint64)

ClearBit clears a bit on the given field.

func (*Holder) Close

func (h *Holder) Close() error

Close closes the holder. The data should be removed by the cleanup registered when we created the initial tempdir.

func (*Holder) MustCreateIndexIfNotExists

func (h *Holder) MustCreateIndexIfNotExists(index string, opt pilosa.IndexOptions) *Index

MustCreateIndexIfNotExists returns a given index. Panic on error.

func (*Holder) MustSetBits

func (h *Holder) MustSetBits(index, field string, rowID uint64, columnIDs ...uint64)

MustSetBits sets columns on a row. Panic on error. This function does not accept a timestamp or quantum.

func (*Holder) Range

func (h *Holder) Range(index, field string, op pql.Token, predicate int64) *pilosa.Row

Range returns a Row (of column IDs) for a field based on the given range.

func (*Holder) ReadRow

func (h *Holder) ReadRow(index, field string, rowID uint64) *pilosa.Row

ReadRow returns a Row for a given field. If the field does not exist, it fails the holder's test rather than creating the field.

func (*Holder) Reopen

func (h *Holder) Reopen() error

Reopen instantiates and opens a new holder. Note that the holder must be Closed first.

func (*Holder) Row

func (h *Holder) Row(index, field string, rowID uint64) *pilosa.Row

Row returns a Row for a given field.

func (*Holder) RowTime

func (h *Holder) RowTime(index, field string, rowID uint64, t time.Time, quantum string) *pilosa.Row

func (*Holder) SetBit

func (h *Holder) SetBit(index, field string, rowID, columnID uint64)

SetBit sets a bit on the given field.

func (*Holder) SetBitTime

func (h *Holder) SetBitTime(index, field string, rowID, columnID uint64, t *time.Time)

SetBitTime sets a bit with timestamp on the given field.

func (*Holder) SetValue

func (h *Holder) SetValue(index, field string, columnID uint64, value int64) *Index

SetValue sets an integer value on the given field.

func (*Holder) Value

func (h *Holder) Value(index, field string, columnID uint64) (int64, bool)

Value returns the integer value for a given column.

type Index

type Index struct {
	*pilosa.Index
}

Index represents a test wrapper for pilosa.Index.

func (*Index) Close

func (i *Index) Close() error

Close closes the index and removes the underlying data.

func (*Index) CreateField

func (i *Index) CreateField(name string, requestUserID string, opts ...pilosa.FieldOption) (*Field, error)

CreateField creates a field with the given options.

func (*Index) CreateFieldIfNotExists

func (i *Index) CreateFieldIfNotExists(name string, requestUserID string, opts ...pilosa.FieldOption) (*Field, error)

CreateFieldIfNotExists creates a field with the given options if it doesn't exist.

func (*Index) Reopen

func (i *Index) Reopen() error

Reopen closes the index and reopens it.

type IntID

type IntID struct {
	Val int64
	ID  uint64
}

type IntKey

type IntKey struct {
	Val int64
	Key string
}

IntKey is a string key and a signed integer value.

type KeyID

type KeyID struct {
	Key string
	ID  uint64
}

KeyID represents a key and an ID for importing data into an index and field where one uses string keys and the other does not.

type Ports

type Ports struct {
	LsnC  *net.TCPListener
	PortC int

	LsnP  *net.TCPListener
	PortP int

	LsnG *net.TCPListener
	Grpc int
}

func (*Ports) Close

func (ports *Ports) Close() error

type ShareableCluster

type ShareableCluster struct {
	Nodes []*Command
	// contains filtered or unexported fields
}

ShareableCluster represents a featurebase cluster (multiple Command instances) without test-specific overhead.

func (*ShareableCluster) AwaitPrimaryState

func (c *ShareableCluster) AwaitPrimaryState(expectedState disco.ClusterState, timeout time.Duration) error

AwaitPrimaryState waits for the cluster primary to reach a specified cluster state. When this happens, we know etcd reached a combination of node states that would imply this cluster state, but some nodes may not have caught up yet; we just test that the coordinator thought the cluster was in the given state.

func (*ShareableCluster) AwaitState

func (c *ShareableCluster) AwaitState(expectedState disco.ClusterState, timeout time.Duration) (err error)

AwaitState waits for the whole cluster to reach a specified state.

func (*ShareableCluster) Close

func (c *ShareableCluster) Close() error

Close stops a Cluster

func (*ShareableCluster) CloseAndRemove

func (c *ShareableCluster) CloseAndRemove(n int) error

func (*ShareableCluster) CloseAndRemoveNonPrimary

func (c *ShareableCluster) CloseAndRemoveNonPrimary() error

func (*ShareableCluster) CreateField

func (c *ShareableCluster) CreateField(t testing.TB, index string, iopts pilosa.IndexOptions, field string, fopts ...pilosa.FieldOption) *pilosa.Field

CreateField creates the index (if necessary) and field specified.

func (*ShareableCluster) ExceptionalState

func (c *ShareableCluster) ExceptionalState(expectedState disco.ClusterState) error

ExceptionalState returns an error if any node in the cluster is not in the expected state.

func (*ShareableCluster) GetHolder

func (c *ShareableCluster) GetHolder(n int) *Holder

func (*ShareableCluster) GetIdleNode

func (c *ShareableCluster) GetIdleNode(n int) *Command

GetIdleNode gets the node at the given index. This method is used (instead of `GetNode()`) when the cluster has yet to be started. In that case, etcd has not assigned each node an ID, and therefore the nodes are not in their final, sorted order. In other words, this method can only be used to retrieve a node when order doesn't matter. An example is if you need to do something like this:

c.GetNode(0).Config.Cluster.ReplicaN = 2
c.GetNode(1).Config.Cluster.ReplicaN = 2

In this example, the test needs the replication factor to be set to 2 before starting; it's ok to reference each node by its index in the pre-sorted node list. It's also safe to use this method after `MustRunCluster()` if the cluster contains only one node.

func (*ShareableCluster) GetNode

func (c *ShareableCluster) GetNode(n int) *Command

GetNode gets the node at the given index; this method assumes the cluster has already been started. Because the node IDs are assigned randomly, they can be in an order that does not align with the test's expectations. For example, a test might create a 3-node cluster and retrieve them using `GetNode(0)`, `GetNode(1)`, and `GetNode(2)` respectively. But if the node IDs are `456`, `123`, `789`, then we actually want `GetNode(0)` to return `c.Nodes[1]`, and `GetNode(1)` to return `c.Nodes[0]`. This method looks at all the node IDs, sorts them, and then returns the node that the test expects.

func (*ShareableCluster) GetNonPrimaries

func (c *ShareableCluster) GetNonPrimaries() []*Command

GetNonPrimaries gets all nodes except the primary.

func (*ShareableCluster) GetNonPrimary

func (c *ShareableCluster) GetNonPrimary() *Command

GetNonPrimary gets first first non-primary node in the list of nodes.

func (*ShareableCluster) GetPrimary

func (c *ShareableCluster) GetPrimary() *Command

GetPrimary gets the node which has been determined to be the primary. This used to be node0 in tests, but since implementing etcd, the primary can be any node in the cluster, so we have to use this method in tests which need to act on the primary.

func (*ShareableCluster) ImportBits

func (c *ShareableCluster) ImportBits(t testing.TB, index, field string, rowcols [][2]uint64)

func (*ShareableCluster) ImportBitsWithTimestamp

func (c *ShareableCluster) ImportBitsWithTimestamp(t testing.TB, index, field string, rowcols [][2]uint64, timestamps []int64)

func (*ShareableCluster) ImportIDKey

func (c *ShareableCluster) ImportIDKey(t testing.TB, index, field string, pairs []KeyID)

ImportIDKey imports data into an unkeyed set field in a keyed index.

func (*ShareableCluster) ImportIntID

func (c *ShareableCluster) ImportIntID(t testing.TB, index, field string, pairs []IntID)

ImportIntID imports data into an int field in an unkeyed index.

func (*ShareableCluster) ImportIntKey

func (c *ShareableCluster) ImportIntKey(t testing.TB, index, field string, pairs []IntKey)

ImportIntKey imports int data into an index which uses string keys.

func (*ShareableCluster) ImportKeyKey

func (c *ShareableCluster) ImportKeyKey(t testing.TB, index, field string, valAndRecKeys [][2]string)

ImportKeyKey imports data into an index where both the index and the field are using string keys.

func (*ShareableCluster) ImportTimeQuantumKey

func (c *ShareableCluster) ImportTimeQuantumKey(t testing.TB, index, field string, entries []TimeQuantumKey)

ImportTimeQuantumKey imports data into an index where the index is keyd and the field is a time-quantum

func (*ShareableCluster) Len

func (c *ShareableCluster) Len() int

func (*ShareableCluster) Query

func (c *ShareableCluster) Query(t testing.TB, index, query string) pilosa.QueryResponse

Query executes an API.Query through one of the cluster's node's API. It fails the test if there is an error.

func (*ShareableCluster) QueryGRPC

func (c *ShareableCluster) QueryGRPC(t testing.TB, index, query string) *proto.TableResponse

QueryGRPC executes a PQL query through the GRPC endpoint. It fails the test if there is an error.

func (*ShareableCluster) QueryHTTP

func (c *ShareableCluster) QueryHTTP(t testing.TB, index, query string) (string, error)

QueryHTTP executes a PQL query through the HTTP endpoint. It fails the test for explicit errors, but returns an error which has the response body if the HTTP call returns a non-OK status.

func (*ShareableCluster) Start

func (c *ShareableCluster) Start() error

Start runs a Cluster

type TimeQuantumKey

type TimeQuantumKey struct {
	RowKey string
	ColKey string
	Ts     int64
}

TimeQuantumKey is a string key and a string+key value

Jump to

Keyboard shortcuts

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