offline_simulator

package
v0.0.0-...-05d47a9 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2022 License: Apache-2.0 Imports: 10 Imported by: 4

Documentation

Index

Constants

View Source
const (
	ServerStateOnline  ServerState = "Online"
	ServerStateOffline ServerState = "Offline"

	// MinOnlineDuration should be a string representing a time,
	// like "1h", "30m", etc.
	MinOnlineDuration  = "MIN_ONLINE_DURATION"
	MaxOnlineDuration  = "MAX_ONLINE_DURATION"
	MinOfflineDuration = "MIN_OFFLINE_DURATION"
	MaxOfflineDuration = "MAX_OFFLINE_DURATION"
	//OfflineRatio should be a decimal between 0 and 1.
	OfflineRatio = "OFFLINE_RATIO"
)

Variables

View Source
var ErrServerOffline = fmt.Errorf("server is offline")

Functions

func IsServerOfflineErr

func IsServerOfflineErr(err error) bool

func NewOfflineSimulator

func NewOfflineSimulator() filter.Filter

Types

type OfflineSimulator

type OfflineSimulator struct {
	State              ServerState
	OfflineRatio       float64
	MinOnlineDuration  time.Duration  //default is about 1s
	MaxOnlineDuration  *time.Duration //optional
	MinOfflineDuration time.Duration  //default is about 1s
	MaxOfflineDuration *time.Duration //optional
	LastTransferTime   time.Time
	// contains filtered or unexported fields
}

func (*OfflineSimulator) Invoke

func (f *OfflineSimulator) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result

func (*OfflineSimulator) OnResponse

func (*OfflineSimulator) Run

func (f *OfflineSimulator) Run()

Run an offline simulator 1. if the duration of the current state is less than the minimum limit, sleep until greater than it; 2. if the duration is greater than the maximum limit (if set), switch the state immediately; 3. otherwise, switch the state with a certain probability every second.

type ServerState

type ServerState string

Jump to

Keyboard shortcuts

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