bsonidgenerator

package module
v0.0.0-...-f136bca Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2017 License: MIT Imports: 4 Imported by: 0

README

BSON ObjectID Generator GoDoc

A simple script to generate a lot of bson ObjectIds, mostly for use in tests.

All object ids will have the same time.

Example Usage

See the tests and the godocs for example usage.

Documentation

Overview

Package bsonidgenerator provides tools for generating sequences of bson ObjectIds for use in test fixtures.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNMachinesTooLarge        = fmt.Errorf("Can only manage up to %d unique machines", 1<<24)
	ErrNItemsPerProcessTooLarge = fmt.Errorf("Can only manage up to %d items per process", 1<<24)
)

Functions

func CreateObjectId

func CreateObjectId(t uint32, machine uint32, pid uint16, inc uint32) bson.ObjectId

Create a bson ObjectId from the set of primitives needed to seed its state. Originally from: http://bazaar.launchpad.net/+branch/mgo/v2/view/head:/bson/bson.go#L218

Types

type Config

type Config struct {
	Time                 time.Time // We only use down to the seconds
	Nmachines            uint32    // Holds 4 bytes, we only need 3
	NprocessesPerMachine uint16    // Holds 2 bytes, we need 2
	NitemsPerProcess     uint32    // Holds 4 bytes, we only need 3
}

func NewGenerator

func NewGenerator(t time.Time, nmachines uint32, nproc uint16, ninc uint32) (Config, error)

func (Config) Count

func (conf Config) Count() int

Returns the number of ObjectIds that will be produced by this Config.

func (Config) Generate

func (conf Config) Generate() ([]bson.ObjectId, error)

Creates object ids using the Config, placing them in a slice. Returns an error if the configuration doesn't validate.

func (Config) SendOnChannel

func (conf Config) SendOnChannel(oidChan chan<- bson.ObjectId) error

Generate a stream of object ids using the Config. Returns an error if the configuration doesn't validate. This function closes the channel when it has finished sending.

func (Config) Validate

func (conf Config) Validate() error

Checks that a Config is valid. A valid config has values of number of machines and number of items per process in an acceptable range.

Jump to

Keyboard shortcuts

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