-
Notifications
You must be signed in to change notification settings - Fork 2
/
doc_test.go
144 lines (125 loc) · 3.4 KB
/
doc_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
// +build !doc
package gokafkaesque_test
import (
"fmt"
gokafkaesque "github.com/arbor/go-kafkaesque"
)
func ExampleNewClient() {
config := gokafkaesque.NewConfig().
SetURL("http://localhost:8080").
SetRetry(3).
Build()
client := gokafkaesque.NewClient(config)
a, _ := client.GetStatus()
fmt.Println(a.GetMessage())
// Output:
// Ok
}
// This example is meant to fail because the output is too verbose
// We will improve it later
func ExampleClient_GetTopics() {
config := gokafkaesque.NewConfig().
SetURL("http://localhost:8080").
SetRetry(3).
Build()
client := gokafkaesque.NewClient(config)
a, _ := client.GetTopics()
fmt.Println(a.TopicsToString())
// Output:
// [__confluent.support.metrics __consumer_offsets]
}
func ExampleClient_CreateTopic() {
config := gokafkaesque.NewConfig().
SetURL("http://localhost:8080").
SetRetry(3).
Build()
client := gokafkaesque.NewClient(config)
t := gokafkaesque.NewTopic("foo").SetPartitions("2").SetReplicationFactor("5").BuildTopic()
a, _ := client.CreateTopic(t)
fmt.Println(a.GetMessage())
// output:
// foo created.
}
func ExampleClient_CreateTopicWithConfig() {
config := gokafkaesque.NewConfig().
SetURL("http://localhost:8080").
SetRetry(3).
Build()
client := gokafkaesque.NewClient(config)
t := gokafkaesque.NewTopic("fooWithConfig").SetPartitions("2").SetReplicationFactor("5").BuildTopic()
t.Config = &gokafkaesque.Config{
RetentionMs: "1000",
SegmentBytes: "10000000",
CleanupPolicy: "delete",
MinInsyncReplicas: "1",
RetentionBytes: "10",
SegmentMs: "10",
}
a, _ := client.CreateTopic(t)
fmt.Println(a.GetMessage())
// output:
// fooWithConfig created.
}
func ExampleClient_DeleteTopicWithConfig() {
config := gokafkaesque.NewConfig().
SetURL("http://localhost:8080").
SetRetry(3).
Build()
client := gokafkaesque.NewClient(config)
a, _ := client.DeleteTopic("fooWithConfig")
fmt.Println(a.GetMessage())
// Output:
// fooWithConfig deleted.
}
func ExampleClient_GetTopic() {
config := gokafkaesque.NewConfig().
SetURL("http://localhost:8080").
SetRetry(3).
Build()
client := gokafkaesque.NewClient(config)
a, _ := client.GetTopic("foo")
fmt.Printf("partition: %s\nreplication_factor: %s\n", a.GetPartitions(), a.GetReplicationFactor())
// output:
// partition: 2
// replication_factor: 5
}
// This is a PUT request, which means it requires complete parameters set.
// To only update optional params, we need to implement PATCH request instead.
func ExampleClient_UpdateTopic() {
config := gokafkaesque.NewConfig().
SetURL("http://localhost:8080").
SetRetry(3).
Build()
client := gokafkaesque.NewClient(config)
t := gokafkaesque.NewTopic("foo").SetPartitions("2").SetReplicationFactor("5").BuildTopic()
_, err := client.CreateTopic(t)
if err != nil {
fmt.Println(err)
}
t.Config = &gokafkaesque.Config{
RetentionMs: "1000",
SegmentBytes: "10000000",
CleanupPolicy: "delete",
MinInsyncReplicas: "1",
RetentionBytes: "10",
SegmentMs: "10",
}
a, err := client.UpdateTopic(t)
if err != nil {
fmt.Println(err)
}
fmt.Println(a.GetMessage())
// output:
// foo updated.
}
func ExampleClient_DeleteTopic() {
config := gokafkaesque.NewConfig().
SetURL("http://localhost:8080").
SetRetry(3).
Build()
client := gokafkaesque.NewClient(config)
a, _ := client.DeleteTopic("foo")
fmt.Println(a.GetMessage())
// Output:
// foo deleted.
}