mongo

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2019 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertJSONtoBSON

func ConvertJSONtoBSON(document string) interface{}

ConvertJSONtoBSON converts a JSON string to a BSON object

func ObjectIDToString

func ObjectIDToString(oid primitive.ObjectID) string

ObjectIDToString converts a mongo ObjectID to a string representation of the hex value.

func ObjectIDsToString

func ObjectIDsToString(oids []interface{}) []string

ObjectIDsToString converts an array of ObjectID primitives to their string representations.

Types

type MongoDocument

type MongoDocument struct {
	Id        string
	Hostname  string
	Timestamp int64
}

MongoDocument is the structure we stuff in a queue to read it later

type MongoLoad

type MongoLoad struct {
	// contains filtered or unexported fields
}

MongoLoad type for managing load tests to a mongo cluster

func (*MongoLoad) Init

func (m *MongoLoad) Init(ctx context.Context, opts *MongoLoadOptions) error

Init Initialize a new connection to mongo and set the database If Init fails to initialize a database then all other mongo operations will fail.

func (*MongoLoad) InsertDocument

func (m *MongoLoad) InsertDocument(document interface{}) (string, bool)

InsertDocument attempts to insert a single document into a mongo collection.

The method returns an OperationResult and string with the object id of the inserted document. If the operation was unsuccessful the string will be an empty string.

document is expected to be a BSON object

func (*MongoLoad) InsertDocuments

func (m *MongoLoad) InsertDocuments(documents []interface{}) ([]string, bool)

InsertDocuments attempts to insert a batch of documents as a single operation. This method uses the mongo InsertMany operation.

The document argument is expected to be a slice of BSON objects.

This method returns an OperationResult and slice of ObjectsIDs if the operation was successful. If the operation failed the slice will be nil. ObjectIDs are converted to hex and represented as strings if the _id is an ObjectID

func (*MongoLoad) InsertOneRoutine

func (m *MongoLoad) InsertOneRoutine(docs chan interface{}, waitGroup *sync.WaitGroup)

InsertOneRoutine writes documents in a loop until the duration has expired or a request to exit.

InsertOne expects a document channel

func (*MongoLoad) ReadDocument

func (m *MongoLoad) ReadDocument(id string) bson.Raw

ReadDocument finds a document by _id and returns the result

func (*MongoLoad) ReadOneRoutine

func (m *MongoLoad) ReadOneRoutine(waitGroup *sync.WaitGroup)

ReadOneRoutine reads documents based on queue items until test duration has expired.

type MongoLoadOptions

type MongoLoadOptions struct {
	Version              string
	ConnectionString     string
	Database             string
	Collection           string
	SocketTimeout        time.Duration
	ServerConnectTimeout time.Duration
	ConnectionTimeout    time.Duration
	TestDuration         time.Duration
	MaxPoolSize          uint16
	ReadPreference       string
	EnableJournal        bool
	WriteAcks            int
	Queue                *queue.Queue
	PrometheusRegistry   *prometheus.Registry
}

MongoLoadOptions type for containing load testing options

Jump to

Keyboard shortcuts

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