-
Notifications
You must be signed in to change notification settings - Fork 29
/
kafka_topic_acc_test.go
181 lines (151 loc) · 4.51 KB
/
kafka_topic_acc_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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package aiven
import (
"context"
"math/rand"
"os"
"strconv"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Kafka Topic", func() {
var (
projectName string
project *Project
err error
)
ctx := context.Background()
Context("Kafka Topic CRUD", func() {
It("should not error", func() {
projectName = os.Getenv("AIVEN_PROJECT_NAME")
project, err = client.Projects.Get(ctx, projectName)
Expect(err).NotTo(HaveOccurred())
})
It("should populate fields properly", func() {
Expect(project).NotTo(BeNil())
if project != nil {
Expect(project.Name).NotTo(BeEmpty())
}
})
// kafka service
var (
serviceName string
service *Service
errS error
)
It("creating service", func() {
serviceName = "test-acc-kafka-topic-sr-" + strconv.Itoa(rand.Int())
service, errS = client.Services.Create(ctx, projectName, CreateServiceRequest{
Cloud: "google-europe-west1",
Plan: "business-4",
ProjectVPCID: nil,
ServiceName: serviceName,
ServiceType: "kafka",
})
})
It("should not error", func() {
Expect(errS).NotTo(HaveOccurred())
})
It("should populate fields properly", func() {
Expect(service).NotTo(BeNil())
if service != nil {
Expect(service.Name).NotTo(BeEmpty())
Expect(service.Plan).NotTo(BeEmpty())
Expect(service.Type).Should(Equal("kafka"))
Eventually(func() string {
service, _ = client.Services.Get(ctx, projectName, serviceName)
return service.State
}, 25*time.Minute, 1*time.Minute).Should(Equal("RUNNING"))
}
})
// kafka topic
var (
errC error
topicName string
segmentJitterMs int64
)
segmentJitterMs = 10
topicName = "test1"
It("create kafka topic", func() {
time.Sleep(10 * time.Second)
errC = client.KafkaTopics.Create(ctx, projectName, serviceName, CreateKafkaTopicRequest{
TopicName: topicName,
Config: KafkaTopicConfig{
CleanupPolicy: "compact",
SegmentJitterMs: &segmentJitterMs,
},
Tags: []KafkaTopicTag{
{
Key: "tag1-key",
Value: "tag1-value",
},
},
})
Eventually(func() string {
topic, _ := client.KafkaTopics.Get(ctx, projectName, serviceName, topicName)
if topic != nil {
return topic.State
}
return ""
}, 25*time.Minute, 1*time.Minute).Should(Equal("ACTIVE"))
})
It("should not error kafka topic with config", func() {
Expect(errC).NotTo(HaveOccurred())
})
It("should populate fields properly", func() {
t, errT := client.KafkaTopics.Get(ctx, projectName, serviceName, topicName)
Expect(errT).NotTo(HaveOccurred())
if t != nil {
Expect(t.Config.CleanupPolicy.Value).NotTo(BeEmpty())
Expect(t.Config.SegmentJitterMs.Value).To(Equal(segmentJitterMs))
Expect(t.Tags).NotTo(BeEmpty())
Expect(t.Tags[0].Key).To(Equal("tag1-key"))
Expect(t.Tags[0].Value).To(Equal("tag1-value"))
}
})
It("should update topic config", func() {
var uncleanLeaderElectionEnable = true
errU := client.KafkaTopics.Update(ctx, projectName, serviceName, topicName, UpdateKafkaTopicRequest{
Config: KafkaTopicConfig{
UncleanLeaderElectionEnable: &uncleanLeaderElectionEnable,
},
Tags: []KafkaTopicTag{
{
Key: "tag1-key",
Value: "tag1-value",
},
{
Key: "tag2-key",
Value: "tag2-value",
},
},
})
Expect(errU).NotTo(HaveOccurred())
t2, errG := client.KafkaTopics.Get(ctx, projectName, serviceName, topicName)
Expect(errG).NotTo(HaveOccurred())
Expect(t2).NotTo(BeNil())
if t2 != nil {
Expect(t2.Config.UncleanLeaderElectionEnable.Value).Should(Equal(true))
Expect(t2.Tags).ShouldNot(BeEmpty())
Expect(len(t2.Tags)).To(Equal(2))
}
})
It("list v2", func() {
list, errV2 := client.KafkaTopics.V2List(ctx, projectName, serviceName, []string{topicName})
Expect(errV2).NotTo(HaveOccurred())
Expect(len(list)).Should(Equal(1))
Expect(list[0].Config.CleanupPolicy.Value).NotTo(BeEmpty())
Expect(list[0].Config.SegmentJitterMs.Value).To(Equal(segmentJitterMs))
Expect(list[0].Tags).NotTo(BeEmpty())
Expect(len(list[0].Tags)).To(Equal(2))
})
It("delete Kafka Topic and Kafka service", func() {
if errD := client.KafkaTopics.Delete(ctx, projectName, serviceName, topicName); errD != nil {
Fail("cannot delete kafka topic:" + errD.Error())
}
if errD := client.Services.Delete(ctx, projectName, serviceName); errD != nil {
Fail("cannot delete service:" + errD.Error())
}
})
})
})