/
consumer_test.go
70 lines (62 loc) · 1.44 KB
/
consumer_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
package haystack
import (
"fmt"
"log"
"testing"
"time"
)
const (
StreamName string = "CONSUMER_TEST"
)
// TestGetMessage gets a specific record
func TestPrint(t *testing.T) {
if k, ok := InitKinesis(); ok {
if test := CheckStream(k, StreamName); !test {
if ok := CreateStream(k, StreamName, 1); !ok {
t.Fail()
}
}
ch := make(chan bool)
for i := 0; i < 5; i++ {
tempMessage := &Message{
"1234", // uid
"test.com/testpage.html", // ref site
time.Now().String(), // timestamp
"Pageview", // event type
fmt.Sprintf("{'a': %d}", i)}
go SendMessage(k, StreamName, tempMessage, ch)
}
// Hang around for a response
select {
case resp := <-ch:
if !resp {
log.Println("Message failed to send")
t.Fail()
}
case <-time.After(10 * time.Second):
log.Println("Message send timeout")
t.Fail()
return
}
if data, ok := GetMessages(k, StreamName, "shardId-000000000000"); ok {
PrintRecords(data)
} else {
log.Println("Failed to retrieve messages from stream")
t.Fail()
}
}
}
// TestGetMessages attempts to retrieve all messages in the test stream
func TestGetMessages(t *testing.T) {
if k, ok := InitKinesis(); ok {
if _, ok := GetMessages(k, StreamName, "shardId-000000000000"); !ok {
log.Println("Failed to retrieve messages from stream")
t.Fail()
}
}
if k, ok := InitKinesis(); ok {
if ok := DeleteStream(k, StreamName); ok {
return
}
}
}