-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
72 lines (64 loc) · 1.55 KB
/
main_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
package LogAnalysis
import (
"encoding/json"
"fmt"
"math/rand"
"sync"
"testing"
"time"
)
func TestFile(t *testing.T) {
var sy sync.WaitGroup
filecontrol := &FileControl{
Path: []string{"./test.log", "./redis.log", "./testA.log", "./testC.log"},
//防止不够多的情况出现
LineChan: make(chan []byte),
}
sy.Add(1)
go filecontrol.Init()
go LogGetChan(filecontrol.LineChan, len(filecontrol.Path), &sy)
sy.Wait()
//time.Sleep(10 * time.Second)
analysis()
}
// 并测
func BenchmarkFile(b *testing.B) {
for i := 0; i < b.N; i++ {
var sy sync.WaitGroup
filecontrol := &FileControl{
Path: []string{"./test.log", "./redis.log", "./testA.log", "./testC.log"},
//防止不够多的情况出现
LineChan: make(chan []byte),
}
sy.Add(1)
go filecontrol.Init()
go LogGetChan(filecontrol.LineChan, len(filecontrol.Path), &sy)
sy.Wait()
analysis()
}
}
// 生成测试数据
func TestSetValue(t *testing.T) {
var methods = []string{"POST", "GET", "PUT", "DELETE", "PATCH"}
rand.Seed(time.Now().UnixNano())
for i := 0; i < 1000; i++ {
d := LogData{
SessionID: rand.Intn(100),
ID: rand.Intn(1000),
SeqNumber: rand.Intn(100),
Method: methods[rand.Intn(len(methods))],
Timestamp: time.Now(),
Headers: map[string]string{
"Content-Type": "application/json",
"Authorization": "test",
},
Payload: map[string]interface{}{
"param1": rand.Intn(100),
"param2": fmt.Sprintf("value-%d", i),
},
ExtraData: fmt.Sprintf("extra-data-%d", i),
}
b, _ := json.Marshal(d)
fmt.Println(string(b))
}
}