rps

package
v0.0.0-rc5 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HistoryToString

func HistoryToString(history []historyDescription) string

Types

type KV

type KV struct {
	Key      string      `bson:"_id"`
	Document interface{} `bson:"document"`
}

KV is Key-Document object for key-value database (Mongo or in-memory)

func GenerateKV

func GenerateKV(keysize, valsize int) KV

GenerateKV produces random Key-Document object with key and value as string of `keysize` and `valsize` length respectfully

func (*KV) String

func (k *KV) String() string

type RpsCallbacks

type RpsCallbacks struct {
	Tick      func(ctx context.Context, index int, rps *RpsModel) bool
	OnDelete  func(ctx context.Context, key string)
	OnCreate  func(ctx context.Context, entity KV)
	OnUpdate  func(ctx context.Context, previous KV, actual KV)
	OnReplace func(ctx context.Context, previous KV, actual KV)
}

RpsNotifier contains callbacks for different events of RPS generator

type RpsModel

type RpsModel struct {

	// we should uniformly distribute documents between this two categories:
	Persistent    map[string]interface{} // present KV
	NonPersistent map[string]struct{}    // sometimes deleted KV
	ModelHistory  map[string][]historyDescription
	// contains filtered or unexported fields
}

RpsModel is a:

  1. rate-limiter for requests
  2. in-mem KV storage

Anyone can access in-memory Persistent state, NonPersistent(deleted) state, and change history as ModelHistory

func NewRpsModel

func NewRpsModel(ctx context.Context, notifiers *RpsCallbacks) *RpsModel

NewRpsModel creates RPS model use initialSpec to set frequency and value of operations use onCreate, onDelete and onUpdate from RpsCallbacks to make actions (e.g. with database) use Delay in RpsCallbacks to reconfigure RPS in time

func (*RpsModel) CheckValid

func (r *RpsModel) CheckValid(t *testing.T, ctx context.Context, label string, coll *mongo.Collection)

func (*RpsModel) Close

func (r *RpsModel) Close()

func (*RpsModel) SetSpec

func (r *RpsModel) SetSpec(spec *RpsSpec)

SetSpec sets RPS specification

func (*RpsModel) Start

func (r *RpsModel) Start()

type RpsSpec

type RpsSpec struct {
	DeleteCount, CreateCount, UpdateCount, ReplaceCount uint
	KVConstructor                                       func() KV `json:"-"`
	Delay                                               time.Duration
}

RpsSpec defines specification of requests count per Delay applied in order: delete, create, update

Jump to

Keyboard shortcuts

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