Пример #1
0
// implements ExplorePolicy interface
func (p *MyPolicy) QueueNextEvent(event signal.Event) {
	// Possible events:
	//  - JavaFunctionEvent
	//  - PacketEvent
	//  - FilesystemEvent
	//  - ProcSetEvent (Linux procfs)
	//  - LogEvent
	fmt.Printf("Event: %s\n", event)
	// You can also inject fault actions
	//  - PacketFaultAction
	//  - FilesystemFaultAction
	//  - ProcSetSchedAction
	//  - ShellAction
	action, err := event.DefaultAction()
	if err != nil {
		panic(err)
	}
	// send in a goroutine so as to make the function non-blocking.
	// (Note that earthquake/util/queue/TimeBoundedQueue provides
	// better semantics and determinism, this is just an example.)
	go func() {
		fmt.Printf("Action ready: %s\n", action)
		p.nextActionChan <- action
		fmt.Printf("Action passed: %s\n", action)
	}()
}
Пример #2
0
// for dequeueRoutine()
func (r *Random) makeActionForEvent(event signal.Event) (signal.Action, error) {
	switch event.(type) {
	case *signal.ProcSetEvent:
		return r.makeActionForProcSetEvent(event.(*signal.ProcSetEvent))
	}
	defaultAction, defaultActionErr := event.DefaultAction()
	faultAction, faultActionErr := event.DefaultFaultAction()
	if faultAction == nil {
		return defaultAction, defaultActionErr
	}
	if rand.Intn(999) < int(r.FaultActionProbability*1000.0) {
		log.Debugf("Injecting fault %s for %s", faultAction, event)
		return faultAction, faultActionErr
	} else {
		return defaultAction, defaultActionErr
	}
}