forked from giautm/eh-kafka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eventbus_test.go
105 lines (88 loc) · 2.29 KB
/
eventbus_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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package kafka_test
import (
"context"
"os"
"strings"
"testing"
"time"
kfbus "github.com/giautm/eh-kafka"
kitlog "github.com/go-kit/kit/log"
"github.com/google/uuid"
"github.com/looplab/eventhorizon/eventbus"
"github.com/rcrowley/go-metrics"
"go.uber.org/goleak"
)
func init() {
// Disable metrics, it cause goroutine leaks
metrics.UseNilMetrics = true
}
func TestEventBus(t *testing.T) {
defer goleak.VerifyNoLeaks(t)
logger := kitlog.NewLogfmtLogger(os.Stdout)
logger = kitlog.With(logger, "TestEventBus", os.Getegid())
kfbus.Logger = logger
brokers := strings.Split(os.Getenv("KAFKA_BROKERS"), ",")
topic := uuid.New()
timeout := time.Second * 60
ctx := context.Background()
bus1, err := kfbus.NewEventBus(
ctx,
brokers,
kfbus.DefaultTopicProducer(topic.String()),
kfbus.DefaultTopicsConsumer(topic.String()),
kfbus.WithTimeout(timeout),
)
if err != nil {
t.Fatal("there should be no error:", err)
}
bus1.SetWaitConsumer(true)
defer bus1.Close()
bus2, err := kfbus.NewEventBus(
ctx,
brokers,
kfbus.DefaultTopicProducer(topic.String()),
kfbus.DefaultTopicsConsumer(topic.String()),
kfbus.WithTimeout(timeout),
)
if err != nil {
t.Fatal("there should be no error:", err)
}
bus2.SetWaitConsumer(true)
defer bus2.Close()
eventbus.AcceptanceTest(t, bus1, bus2, timeout)
}
func TestBatchProducerEventBus(t *testing.T) {
defer goleak.VerifyNoLeaks(t)
logger := kitlog.NewLogfmtLogger(os.Stdout)
logger = kitlog.With(logger, "TestEventBus", os.Getegid())
kfbus.Logger = logger
brokers := strings.Split("uat-kafka-1.svr.tiki.services:9092", ",")
topic := uuid.New()
timeout := time.Second * 60
ctx := context.Background()
bus1, err := kfbus.NewEventBus(
ctx,
brokers,
kfbus.DefaultTopicProducer(topic.String()),
kfbus.DefaultTopicsConsumer(topic.String()),
kfbus.WithTimeout(timeout),
)
if err != nil {
t.Fatal("there should be no error:", err)
}
bus1.SetWaitConsumer(true)
defer bus1.Close()
bus2, err := kfbus.NewEventBusWithBatchProducer(
ctx,
brokers,
kfbus.DefaultTopicProducer(topic.String()),
kfbus.DefaultTopicsConsumer(topic.String()),
kfbus.WithTimeout(timeout),
)
if err != nil {
t.Fatal("there should be no error:", err)
}
bus2.SetWaitConsumer(true)
defer bus2.Close()
eventbus.AcceptanceTest(t, bus1, bus2, timeout)
}