karafka-rdkafka 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +2 -0
  3. data/.gitignore +8 -0
  4. data/.rspec +1 -0
  5. data/.semaphore/semaphore.yml +23 -0
  6. data/.yardopts +2 -0
  7. data/CHANGELOG.md +104 -0
  8. data/Gemfile +3 -0
  9. data/Guardfile +19 -0
  10. data/LICENSE +21 -0
  11. data/README.md +114 -0
  12. data/Rakefile +96 -0
  13. data/bin/console +11 -0
  14. data/docker-compose.yml +24 -0
  15. data/ext/README.md +18 -0
  16. data/ext/Rakefile +62 -0
  17. data/lib/rdkafka/abstract_handle.rb +82 -0
  18. data/lib/rdkafka/admin/create_topic_handle.rb +27 -0
  19. data/lib/rdkafka/admin/create_topic_report.rb +22 -0
  20. data/lib/rdkafka/admin/delete_topic_handle.rb +27 -0
  21. data/lib/rdkafka/admin/delete_topic_report.rb +22 -0
  22. data/lib/rdkafka/admin.rb +155 -0
  23. data/lib/rdkafka/bindings.rb +312 -0
  24. data/lib/rdkafka/callbacks.rb +106 -0
  25. data/lib/rdkafka/config.rb +299 -0
  26. data/lib/rdkafka/consumer/headers.rb +63 -0
  27. data/lib/rdkafka/consumer/message.rb +84 -0
  28. data/lib/rdkafka/consumer/partition.rb +49 -0
  29. data/lib/rdkafka/consumer/topic_partition_list.rb +164 -0
  30. data/lib/rdkafka/consumer.rb +565 -0
  31. data/lib/rdkafka/error.rb +86 -0
  32. data/lib/rdkafka/metadata.rb +92 -0
  33. data/lib/rdkafka/producer/client.rb +47 -0
  34. data/lib/rdkafka/producer/delivery_handle.rb +22 -0
  35. data/lib/rdkafka/producer/delivery_report.rb +26 -0
  36. data/lib/rdkafka/producer.rb +178 -0
  37. data/lib/rdkafka/version.rb +5 -0
  38. data/lib/rdkafka.rb +22 -0
  39. data/rdkafka.gemspec +36 -0
  40. data/spec/rdkafka/abstract_handle_spec.rb +113 -0
  41. data/spec/rdkafka/admin/create_topic_handle_spec.rb +52 -0
  42. data/spec/rdkafka/admin/create_topic_report_spec.rb +16 -0
  43. data/spec/rdkafka/admin/delete_topic_handle_spec.rb +52 -0
  44. data/spec/rdkafka/admin/delete_topic_report_spec.rb +16 -0
  45. data/spec/rdkafka/admin_spec.rb +203 -0
  46. data/spec/rdkafka/bindings_spec.rb +134 -0
  47. data/spec/rdkafka/callbacks_spec.rb +20 -0
  48. data/spec/rdkafka/config_spec.rb +182 -0
  49. data/spec/rdkafka/consumer/message_spec.rb +139 -0
  50. data/spec/rdkafka/consumer/partition_spec.rb +57 -0
  51. data/spec/rdkafka/consumer/topic_partition_list_spec.rb +223 -0
  52. data/spec/rdkafka/consumer_spec.rb +1008 -0
  53. data/spec/rdkafka/error_spec.rb +89 -0
  54. data/spec/rdkafka/metadata_spec.rb +78 -0
  55. data/spec/rdkafka/producer/client_spec.rb +145 -0
  56. data/spec/rdkafka/producer/delivery_handle_spec.rb +42 -0
  57. data/spec/rdkafka/producer/delivery_report_spec.rb +17 -0
  58. data/spec/rdkafka/producer_spec.rb +525 -0
  59. data/spec/spec_helper.rb +139 -0
  60. data.tar.gz.sig +0 -0
  61. metadata +277 -0
  62. metadata.gz.sig +0 -0
@@ -0,0 +1,57 @@
1
+ require "spec_helper"
2
+
3
+ describe Rdkafka::Consumer::Partition do
4
+ let(:offset) { 100 }
5
+ let(:err) { 0 }
6
+ subject { Rdkafka::Consumer::Partition.new(1, offset, err) }
7
+
8
+ it "should have a partition" do
9
+ expect(subject.partition).to eq 1
10
+ end
11
+
12
+ it "should have an offset" do
13
+ expect(subject.offset).to eq 100
14
+ end
15
+
16
+ it "should have an err code" do
17
+ expect(subject.err).to eq 0
18
+ end
19
+
20
+ describe "#to_s" do
21
+ it "should return a human readable representation" do
22
+ expect(subject.to_s).to eq "<Partition 1 offset=100>"
23
+ end
24
+ end
25
+
26
+ describe "#inspect" do
27
+ it "should return a human readable representation" do
28
+ expect(subject.to_s).to eq "<Partition 1 offset=100>"
29
+ end
30
+
31
+ context "without offset" do
32
+ let(:offset) { nil }
33
+
34
+ it "should return a human readable representation" do
35
+ expect(subject.to_s).to eq "<Partition 1>"
36
+ end
37
+ end
38
+
39
+ context "with err code" do
40
+ let(:err) { 1 }
41
+
42
+ it "should return a human readable representation" do
43
+ expect(subject.to_s).to eq "<Partition 1 offset=100 err=1>"
44
+ end
45
+ end
46
+ end
47
+
48
+ describe "#==" do
49
+ it "should equal another partition with the same content" do
50
+ expect(subject).to eq Rdkafka::Consumer::Partition.new(1, 100)
51
+ end
52
+
53
+ it "should not equal another partition with different content" do
54
+ expect(subject).not_to eq Rdkafka::Consumer::Partition.new(2, 101)
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,223 @@
1
+ require "spec_helper"
2
+
3
+ describe Rdkafka::Consumer::TopicPartitionList do
4
+ it "should create a new list and add unassigned topics" do
5
+ list = Rdkafka::Consumer::TopicPartitionList.new
6
+
7
+ expect(list.count).to eq 0
8
+ expect(list.empty?).to be true
9
+
10
+ list.add_topic("topic1")
11
+ list.add_topic("topic2")
12
+
13
+ expect(list.count).to eq 2
14
+ expect(list.empty?).to be false
15
+
16
+ hash = list.to_h
17
+ expect(hash.count).to eq 2
18
+ expect(hash).to eq ({
19
+ "topic1" => nil,
20
+ "topic2" => nil
21
+ })
22
+ end
23
+
24
+ it "should create a new list and add assigned topics as a range" do
25
+ list = Rdkafka::Consumer::TopicPartitionList.new
26
+
27
+ expect(list.count).to eq 0
28
+ expect(list.empty?).to be true
29
+
30
+ list.add_topic("topic1", (0..2))
31
+ list.add_topic("topic2", (0..1))
32
+
33
+ expect(list.count).to eq 5
34
+ expect(list.empty?).to be false
35
+
36
+ hash = list.to_h
37
+ expect(hash.count).to eq 2
38
+ expect(hash["topic1"]).to eq([
39
+ Rdkafka::Consumer::Partition.new(0, nil),
40
+ Rdkafka::Consumer::Partition.new(1, nil),
41
+ Rdkafka::Consumer::Partition.new(2, nil)
42
+ ])
43
+ expect(hash["topic2"]).to eq([
44
+ Rdkafka::Consumer::Partition.new(0, nil),
45
+ Rdkafka::Consumer::Partition.new(1, nil)
46
+ ])
47
+ end
48
+
49
+ it "should create a new list and add assigned topics as an array" do
50
+ list = Rdkafka::Consumer::TopicPartitionList.new
51
+
52
+ expect(list.count).to eq 0
53
+ expect(list.empty?).to be true
54
+
55
+ list.add_topic("topic1", [0, 1, 2])
56
+ list.add_topic("topic2", [0, 1])
57
+
58
+ expect(list.count).to eq 5
59
+ expect(list.empty?).to be false
60
+
61
+ hash = list.to_h
62
+ expect(hash.count).to eq 2
63
+ expect(hash["topic1"]).to eq([
64
+ Rdkafka::Consumer::Partition.new(0, nil),
65
+ Rdkafka::Consumer::Partition.new(1, nil),
66
+ Rdkafka::Consumer::Partition.new(2, nil)
67
+ ])
68
+ expect(hash["topic2"]).to eq([
69
+ Rdkafka::Consumer::Partition.new(0, nil),
70
+ Rdkafka::Consumer::Partition.new(1, nil)
71
+ ])
72
+ end
73
+
74
+ it "should create a new list and add assigned topics as a count" do
75
+ list = Rdkafka::Consumer::TopicPartitionList.new
76
+
77
+ expect(list.count).to eq 0
78
+ expect(list.empty?).to be true
79
+
80
+ list.add_topic("topic1", 3)
81
+ list.add_topic("topic2", 2)
82
+
83
+ expect(list.count).to eq 5
84
+ expect(list.empty?).to be false
85
+
86
+ hash = list.to_h
87
+ expect(hash.count).to eq 2
88
+ expect(hash["topic1"]).to eq([
89
+ Rdkafka::Consumer::Partition.new(0, nil),
90
+ Rdkafka::Consumer::Partition.new(1, nil),
91
+ Rdkafka::Consumer::Partition.new(2, nil)
92
+ ])
93
+ expect(hash["topic2"]).to eq([
94
+ Rdkafka::Consumer::Partition.new(0, nil),
95
+ Rdkafka::Consumer::Partition.new(1, nil)
96
+ ])
97
+ end
98
+
99
+ it "should create a new list and add topics and partitions with an offset" do
100
+ list = Rdkafka::Consumer::TopicPartitionList.new
101
+
102
+ expect(list.count).to eq 0
103
+ expect(list.empty?).to be true
104
+
105
+ list.add_topic_and_partitions_with_offsets("topic1", 0 => 5, 1 => 6, 2 => 7)
106
+
107
+ hash = list.to_h
108
+ expect(hash.count).to eq 1
109
+ expect(hash["topic1"]).to eq([
110
+ Rdkafka::Consumer::Partition.new(0, 5),
111
+ Rdkafka::Consumer::Partition.new(1, 6),
112
+ Rdkafka::Consumer::Partition.new(2, 7)
113
+ ])
114
+ end
115
+
116
+ describe "#to_s" do
117
+ it "should return a human readable representation" do
118
+ list = Rdkafka::Consumer::TopicPartitionList.new
119
+ list.add_topic("topic1", [0, 1])
120
+
121
+ expected = "<TopicPartitionList: {\"topic1\"=>[<Partition 0>, <Partition 1>]}>"
122
+
123
+ expect(list.to_s).to eq expected
124
+ end
125
+ end
126
+
127
+ describe "#==" do
128
+ subject do
129
+ Rdkafka::Consumer::TopicPartitionList.new.tap do |list|
130
+ list.add_topic("topic1", [0])
131
+ end
132
+ end
133
+
134
+ it "should equal another partition with the same content" do
135
+ other = Rdkafka::Consumer::TopicPartitionList.new.tap do |list|
136
+ list.add_topic("topic1", [0])
137
+ end
138
+ expect(subject).to eq other
139
+ end
140
+
141
+ it "should not equal another partition with different content" do
142
+ expect(subject).not_to eq Rdkafka::Consumer::TopicPartitionList.new
143
+ end
144
+ end
145
+
146
+ describe ".from_native_tpl" do
147
+ it "should create a list from an existing native list" do
148
+ pointer = Rdkafka::Bindings.rd_kafka_topic_partition_list_new(5)
149
+ Rdkafka::Bindings.rd_kafka_topic_partition_list_add(
150
+ pointer,
151
+ "topic",
152
+ -1
153
+ )
154
+ list = Rdkafka::Consumer::TopicPartitionList.from_native_tpl(pointer)
155
+
156
+ other = Rdkafka::Consumer::TopicPartitionList.new.tap do |list|
157
+ list.add_topic("topic")
158
+ end
159
+
160
+ expect(list).to eq other
161
+ end
162
+
163
+ it "should create a list from an existing native list with offsets" do
164
+ pointer = Rdkafka::Bindings.rd_kafka_topic_partition_list_new(5)
165
+ Rdkafka::Bindings.rd_kafka_topic_partition_list_add(
166
+ pointer,
167
+ "topic",
168
+ 0
169
+ )
170
+ Rdkafka::Bindings.rd_kafka_topic_partition_list_set_offset(
171
+ pointer,
172
+ "topic",
173
+ 0,
174
+ 100
175
+ )
176
+ list = Rdkafka::Consumer::TopicPartitionList.from_native_tpl(pointer)
177
+
178
+ other = Rdkafka::Consumer::TopicPartitionList.new.tap do |list|
179
+ list.add_topic_and_partitions_with_offsets("topic", 0 => 100)
180
+ end
181
+
182
+ expect(list).to eq other
183
+ end
184
+ end
185
+
186
+ describe "#to_native_tpl" do
187
+ it "should create a native list" do
188
+ list = Rdkafka::Consumer::TopicPartitionList.new.tap do |list|
189
+ list.add_topic("topic")
190
+ end
191
+
192
+ tpl = list.to_native_tpl
193
+
194
+ other = Rdkafka::Consumer::TopicPartitionList.from_native_tpl(tpl)
195
+
196
+ expect(list).to eq other
197
+ end
198
+
199
+ it "should create a native list with partitions" do
200
+ list = Rdkafka::Consumer::TopicPartitionList.new.tap do |list|
201
+ list.add_topic("topic", 0..16)
202
+ end
203
+
204
+ tpl = list.to_native_tpl
205
+
206
+ other = Rdkafka::Consumer::TopicPartitionList.from_native_tpl(tpl)
207
+
208
+ expect(list).to eq other
209
+ end
210
+
211
+ it "should create a native list with offsets" do
212
+ list = Rdkafka::Consumer::TopicPartitionList.new.tap do |list|
213
+ list.add_topic_and_partitions_with_offsets("topic", 0 => 100)
214
+ end
215
+
216
+ tpl = list.to_native_tpl
217
+
218
+ other = Rdkafka::Consumer::TopicPartitionList.from_native_tpl(tpl)
219
+
220
+ expect(list).to eq other
221
+ end
222
+ end
223
+ end