-
Notifications
You must be signed in to change notification settings - Fork 11
/
deliver_test.go
56 lines (51 loc) · 1.28 KB
/
deliver_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
package main
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/sclasen/sarama"
"fmt"
_ "net/http/pprof"
"net/http"
"log"
"time"
"net"
)
const localKafka = "localhost:9092"
func kafkaIsUp() bool {
conn, err := net.Dial("tcp", localKafka)
if err != nil {
log.Printf("Kakfa does not appear to be up on %s, skipping this test", localKafka)
return false
} else {
conn.Close()
return true
}
}
func TestKafkaConfig(t *testing.T) {
if kafkaIsUp() {
d, err := NewKafkaDeliver(nil, "testClientId", []string{localKafka})
assert.Nil(t, err, fmt.Sprintf("%v+", err))
for i := 0; i < 10000; i++ {
err = d.producer.SendMessage("test", nil, sarama.StringEncoder("hello world"))
assert.Nil(t, err, fmt.Sprintf("%v+", err))
}
}
}
func TestNewKafkaDeliver(t *testing.T) {
if kafkaIsUp() {
store, err := OpenStore("test.db")
assert.Nil(t, err, err)
go func() {
log.Println(http.ListenAndServe("localhost:6060", nil))
}()
d, err := NewKafkaDeliver(store, "testClientId", []string{localKafka})
d.Start()
ack := make(chan bool)
d.store.EventsInChannel() <- &EventIn{ saved: ack, event: &Event{Channel:"test", Body:[]byte("{}"), } }
acked := <-ack
assert.True(t, acked, "not acked")
time.Sleep(time.Second * 5)
d.Stop()
d.Store().Close()
}
}