-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler_test.go
52 lines (43 loc) · 1.4 KB
/
handler_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
package handler
import (
"log"
"testing"
"time"
)
type H struct{}
func (h *H) HandleMessage(v interface{}) {
log.Println(v.(string))
}
type BH struct{}
func (h *BH) HandleMessages(v []interface{}) {
log.Println(v...)
}
func TestHandlerRoutine(t *testing.T) {
routine := NewHandlerRoutine()
routine.Start()
routine.SendMessage(new(H), "Hello1")
routine.SendMessageAt(new(H), "Hello2", time.Now().Add(time.Second*5))
routine.SendMessageDelayed(new(H), "Hello3", time.Second*1)
routine.SendMessageAt(new(H), "Hello4", time.Now().Add(time.Second*2))
routine.SendMessageDelayed(new(H), "Hello5", time.Second*3)
routine.SendMessage(new(H), "Hello6")
time.Sleep(time.Second * 8)
routine.Stop()
}
func TestBatchHandlerRoutine(t *testing.T) {
routine := NewBatchHandlerRoutine(new(BH))
routine.Start()
routine.SendMessage("Hello1")
routine.SendMessageAt("Hello2", time.Now().Add(time.Second*5))
routine.SendMessageDelayed("Hello3", time.Second*1)
routine.SendMessageAt("Hello4", time.Now().Add(time.Second*2))
routine.SendMessageDelayed("Hello5", time.Second*3)
routine.SendMessage("Hello6")
routine.SendMessageAt("Hello7", time.Now().Add(time.Second*5))
routine.SendMessageDelayed("Hello8", time.Second*1)
routine.SendMessageAt("Hello9", time.Now().Add(time.Second*2))
routine.SendMessageDelayed("Hello10", time.Second*3)
routine.SendMessage("Hello11")
time.Sleep(time.Second * 8)
routine.Stop()
}