-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathdelay.go
81 lines (67 loc) · 1.51 KB
/
delay.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
78
79
80
81
package wiremock
import (
"encoding/json"
"time"
)
type DelayInterface interface {
ParseDelay() map[string]interface{}
}
type fixedDelay struct {
milliseconds int64
}
func (d fixedDelay) ParseDelay() map[string]interface{} {
return map[string]interface{}{
"type": "fixed",
"milliseconds": d.milliseconds,
}
}
type logNormalRandomDelay struct {
median int64
sigma float64
}
func (d logNormalRandomDelay) ParseDelay() map[string]interface{} {
return map[string]interface{}{
"type": "lognormal",
"median": d.median,
"sigma": d.sigma,
}
}
type uniformRandomDelay struct {
lower int64
upper int64
}
func (d uniformRandomDelay) ParseDelay() map[string]interface{} {
return map[string]interface{}{
"type": "uniform",
"lower": d.lower,
"upper": d.upper,
}
}
type chunkedDribbleDelay struct {
numberOfChunks int64
totalDuration int64
}
func (d chunkedDribbleDelay) MarshalJSON() ([]byte, error) {
jsonMap := map[string]interface{}{
"numberOfChunks": d.numberOfChunks,
"totalDuration": d.totalDuration,
}
return json.Marshal(jsonMap)
}
func NewLogNormalRandomDelay(median time.Duration, sigma float64) DelayInterface {
return logNormalRandomDelay{
median: median.Milliseconds(),
sigma: sigma,
}
}
func NewFixedDelay(delay time.Duration) DelayInterface {
return fixedDelay{
milliseconds: delay.Milliseconds(),
}
}
func NewUniformRandomDelay(lower, upper time.Duration) DelayInterface {
return uniformRandomDelay{
lower: lower.Milliseconds(),
upper: upper.Milliseconds(),
}
}