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 NewOfflineSimulator ¶
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
Click to show internal directories.
Click to hide internal directories.