-
Notifications
You must be signed in to change notification settings - Fork 0
/
breaker_data_test.go
77 lines (67 loc) · 1.75 KB
/
breaker_data_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package breaker
import (
"time"
"github.com/sirupsen/logrus"
)
type wrapper struct {
state string
exec bool
}
func (w *wrapper) CommandFunc() {
var log = logrus.New()
log.Formatter = new(logrus.JSONFormatter)
time.Sleep(1 * time.Millisecond)
log.WithFields(logrus.Fields{"Executed": w.state}).Info("task was executed")
//fmt.Println("Executing ", w.name)
w.exec = true
}
func (w *wrapper) DefaultFunc() {
log.Formatter = new(logrus.JSONFormatter)
log.WithFields(logrus.Fields{"Defaulted": w.state}).Info("task was defaulted")
//fmt.Println("Defaulting command.....")
}
func (w *wrapper) CleanupFunc() {
log.WithFields(logrus.Fields{"Cleaned": w.state}).Info("task was cleaned")
//fmt.Println("Canceling command.....")
}
func (w *wrapper) Name() string {
return "task1"
}
type wrapper2 struct {
name string
exec bool
}
func (w *wrapper2) CommandFunc() {
time.Sleep(1000 * time.Millisecond)
//fmt.Println("Executing ", w.name)
log.Formatter = new(logrus.JSONFormatter)
log.WithFields(logrus.Fields{"Executed": w.name}).Info("task was executed")
w.exec = true
}
func (w *wrapper2) DefaultFunc() {
//fmt.Println("Defaulting ", w.name)
log.Formatter = new(logrus.JSONFormatter)
log.WithFields(logrus.Fields{"Defaulted": w.name}).Info("task was defaulted")
}
func (w *wrapper2) CleanupFunc() {
log.Formatter = new(logrus.JSONFormatter)
log.WithFields(logrus.Fields{"Cleaned": w.name}).Info("task was cleaned")
//fmt.Println("Cleaning ", w.name)
}
func (w *wrapper2) Name() string {
return "task1"
}
type wrapper3 struct {
}
func (w *wrapper3) CommandFunc() {
}
func (w *wrapper3) DefaultFunc() {
}
func (w *wrapper3) CleanupFunc() {
}
func (w *wrapper3) timeout() time.Duration {
return time.Millisecond
}
func (w *wrapper3) Name() string {
return "task1"
}