bttest

package
v0.0.0-...-ca7ec8b Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 35 Imported by: 0

Documentation

Overview

Package bttest contains test helpers for working with the bigtable package.

To use a Server, create it, and then connect to it with no security: (The project/instance values are ignored.)

srv, err := bttest.NewServer("localhost:0")
...
conn, err := grpc.Dial(srv.Addr, grpc.WithInsecure())
...
client, err := bigtable.NewClient(ctx, proj, instance,
        option.WithGRPCConn(conn))
...

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BtreeStorage

type BtreeStorage struct {
}

BtreeStorage stores data in an in-memory btree. This implementation is here for historical reference and should not generally be used; prefer LeveldbMemStorage. BtreeStorage's row scans do not work well in the face of concurrent insertions and deletions. Although no data races occur, changes to the Btree's internal structure break iteration in surprising ways, resulting in unpredictable rowscan results.

func (BtreeStorage) Create

func (BtreeStorage) Create(_ *btapb.Table) Rows

Create a new table, destroying any existing table.

func (BtreeStorage) GetTables

func (BtreeStorage) GetTables() []*btapb.Table

GetTables returns metadata about all stored tables.

func (BtreeStorage) Open

func (BtreeStorage) Open(_ *btapb.Table) Rows

Open the given table, which must have been previously returned by GetTables().

func (BtreeStorage) SetTableMeta

func (f BtreeStorage) SetTableMeta(_ *btapb.Table)

SetTableMeta persists metadata about a table.

type LeveldbDiskStorage

type LeveldbDiskStorage struct {
	// A root directory under which all data is stored.
	Root string

	// Optional error logger.
	ErrLog func(err error, msg string)
}

LeveldbDiskStorage stores data persistently on leveldb.

func (LeveldbDiskStorage) Create

func (f LeveldbDiskStorage) Create(tbl *btapb.Table) Rows

Create a new table, destroying any existing table.

func (LeveldbDiskStorage) GetTables

func (f LeveldbDiskStorage) GetTables() []*btapb.Table

GetTables returns metadata about all stored tables.

func (LeveldbDiskStorage) Open

func (f LeveldbDiskStorage) Open(tbl *btapb.Table) Rows

Open the given table, which must have been previously returned by GetTables().

func (LeveldbDiskStorage) SetTableMeta

func (f LeveldbDiskStorage) SetTableMeta(tbl *btapb.Table)

SetTableMeta persists metadata about a table.

type LeveldbMemStorage

type LeveldbMemStorage struct {
}

LeveldbMemStorage stores data in an in-memory level db. This is the default. Unlike BtreeStorage, LeveldbMemStorage is resilient against concurrent insertions and deletions during row scans. Concurrently added and deleted rows may or may be scanned (as with real bigtable), but the general row scan semantics should hold.

func (LeveldbMemStorage) Create

func (f LeveldbMemStorage) Create(_ *btapb.Table) Rows

Create a new table, destroying any existing table.

func (LeveldbMemStorage) GetTables

func (f LeveldbMemStorage) GetTables() []*btapb.Table

GetTables returns metadata about all stored tables.

func (LeveldbMemStorage) Open

func (f LeveldbMemStorage) Open(_ *btapb.Table) Rows

Open the given table, which must have been previously returned by GetTables().

func (LeveldbMemStorage) SetTableMeta

func (f LeveldbMemStorage) SetTableMeta(_ *btapb.Table)

SetTableMeta persists metadata about a table.

type Options

type Options struct {
	// A storage layer to use; if nil, defaults to LeveldbMemStorage.
	Storage Storage
	// The clock to use use; if nil, defaults to bigtable.Now().
	Clock func() bigtable.Timestamp

	// Grpc server options.
	GrpcOpts []grpc.ServerOption
}

Options to configure the server.

type RowIterator

type RowIterator = func(r *btpb.Row) bool

RowIterator is a callback function that receives a Row.

type Rows

type Rows interface {
	// Ascend calls the iterator for every row in the table within the range
	// [first, last], until iterator returns false.
	Ascend(iterator RowIterator)

	// AscendRange calls the iterator for every row in the table within the range
	// [greaterOrEqual, lessThan), until iterator returns false.
	AscendRange(greaterOrEqual, lessThan keyType, iterator RowIterator)

	// AscendLessThan calls the iterator for every row in the table within the range
	// [first, pivot), until iterator returns false.
	AscendLessThan(lessThan keyType, iterator RowIterator)

	// AscendGreaterOrEqual calls the iterator for every row in the table within
	// the range [pivot, last], until iterator returns false.
	AscendGreaterOrEqual(greaterOrEqual keyType, iterator RowIterator)

	// Clear removes all rows from the table.
	Clear()

	// Delete removes a row whose key is equal to given key.
	Delete(key keyType)

	// Get looks for a row whose key is equal to the given key, returning it.
	// Returns nil if unable to find that row.
	Get(key keyType) *btpb.Row

	// ReplaceOrInsert adds the given row to the table.  If a row in the table
	// already equals the given one, it is removed from the table.
	//
	// nil cannot be added to the table (will panic).
	ReplaceOrInsert(r *btpb.Row)

	Close()
}

Rows implements storage algorithms per table.

type Server

type Server struct {
	Addr string
	// contains filtered or unexported fields
}

Server is an in-memory Cloud Bigtable fake. It is unauthenticated, and only a rough approximation.

func NewServer

func NewServer(laddr string, opt ...grpc.ServerOption) (*Server, error)

NewServer creates a new Server. The Server will be listening for gRPC connections, without TLS, on the provided address. The resolved address is named by the Addr field.

func NewServerWithOptions

func NewServerWithOptions(laddr string, opt Options) (*Server, error)

NewServerWithOptions creates a new Server with the given options. The Server will be listening for gRPC connections, without TLS, on the provided address. The resolved address is named by the Addr field.

func (*Server) Close

func (s *Server) Close()

Close shuts down the server.

type Storage

type Storage interface {
	// Create a new table, destroying any existing table.
	Create(tbl *btapb.Table) Rows
	// GetTables returns metadata about all stored tables.
	GetTables() []*btapb.Table
	// Open the given table, which must have been previously returned by GetTables().
	Open(tbl *btapb.Table) Rows
	// SetTableMeta persists metadata about a table.
	SetTableMeta(tbl *btapb.Table)
}

Storage implements a storage layer for all bigtable emulator data.

Jump to

Keyboard shortcuts

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