rdkafka 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e665ee94b4d29ec2c4d618540ed4588a6af3cfe8
4
- data.tar.gz: 7ad4f0ca3651861441bbe6009a503105e2c7f8c7
3
+ metadata.gz: 67acc1069396798fdb93129b30145d277af826c3
4
+ data.tar.gz: 664621fc32610b18703d393c34e72d64d7f34527
5
5
  SHA512:
6
- metadata.gz: 712032c6802290695e4a4be376829c76da6d346b9af8d365e218f3edad511931526553625e7acdf588d1b71779bac2bcbcab43ac0b599ca1be3f592d0aac9759
7
- data.tar.gz: 60c30f707e2112aaa63603429208a8fb98778dd5c08d3b29f8c700e6646755fbf1803d1258cf9701ba985636f2eb0eb2eed9bf623dbf174ac85bd2a3fc1bc21a
6
+ metadata.gz: 471c14981fe5ba4c4b2a14d724236d498d483cb02b4f93c75217be5455e0c14c2bef319b5186ffd2b74504dfe5175c9727776d28493d4f9b0da2a335572b90b6
7
+ data.tar.gz: ee82ae7f498c4fbcb553df0368f9a3bcb9df1045b7b413e1cab6aff70a5f93fb57e309f5abb096cc8886b9393cda88dc444f6eed9ed828714bd6bb12933a0e5f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 0.3.2
2
+ * `add_topic` now supports using a partition count
3
+ * Add way to make errors clearer with an extra message
4
+ * Show topics in subscribe error message
5
+ * Show partition and topic in query watermark offsets error message
6
+
1
7
  # 0.3.1
2
8
  * Bump librdkafka to 0.11.1
3
9
  * Officially support ranges in `add_topic` for topic partition list.
@@ -39,7 +39,7 @@ module Rdkafka
39
39
  # Subscribe to topic partition list and check this was successful
40
40
  response = Rdkafka::Bindings.rd_kafka_subscribe(@native_kafka, tpl)
41
41
  if response != 0
42
- raise Rdkafka::RdkafkaError.new(response)
42
+ raise Rdkafka::RdkafkaError.new(response, "Error subscribing to '#{topics.join(', ')}'")
43
43
  end
44
44
  ensure
45
45
  # Clean up the topic partition list
@@ -117,7 +117,7 @@ module Rdkafka
117
117
  timeout_ms
118
118
  )
119
119
  if response != 0
120
- raise Rdkafka::RdkafkaError.new(response)
120
+ raise Rdkafka::RdkafkaError.new(response, "Error querying watermark offsets for partition #{partition} of #{topic}")
121
121
  end
122
122
 
123
123
  return low.read_int64, high.read_int64
@@ -37,11 +37,17 @@ module Rdkafka
37
37
  # @example Add a topic with assigned partitions
38
38
  # tpl.add_topic("topic", (0..8))
39
39
  #
40
+ # @example Add a topic with all topics up to a count
41
+ # tpl.add_topic("topic", 9)
42
+ #
40
43
  # @param topic [String] The topic's name
41
- # @param partition [Array<Integer>, Range<Integer>] The topic's partition's
44
+ # @param partition [Array<Integer>, Range<Integer>, Integer] The topic's partitions or partition count
42
45
  #
43
46
  # @return [nil]
44
47
  def add_topic(topic, partitions=nil)
48
+ if partitions.is_a? Integer
49
+ partitions = (0..partitions - 1)
50
+ end
45
51
  if partitions.nil?
46
52
  Rdkafka::Bindings.rd_kafka_topic_partition_list_add(
47
53
  @tpl,
data/lib/rdkafka/error.rb CHANGED
@@ -3,12 +3,13 @@ module Rdkafka
3
3
  class RdkafkaError < RuntimeError
4
4
  # The underlying raw error response
5
5
  # @return [Integer]
6
- attr_reader :rdkafka_response
6
+ attr_reader :rdkafka_response, :message
7
7
 
8
8
  # @private
9
- def initialize(response)
9
+ def initialize(response, message=nil)
10
10
  raise TypeError.new("Response has to be an integer") unless response.is_a? Integer
11
11
  @rdkafka_response = response
12
+ @message = message
12
13
  end
13
14
 
14
15
  # This error's code, for example `:partition_eof`, `:msg_size_too_large`.
@@ -25,7 +26,12 @@ module Rdkafka
25
26
  # Human readable representation of this error.
26
27
  # @return [String]
27
28
  def to_s
28
- "#{Rdkafka::Bindings.rd_kafka_err2str(@rdkafka_response)} (#{code})"
29
+ message_part = if message
30
+ "#{message} - "
31
+ else
32
+ ''
33
+ end
34
+ "#{message_part}#{Rdkafka::Bindings.rd_kafka_err2str(@rdkafka_response)} (#{code})"
29
35
  end
30
36
 
31
37
  # Whether this error indicates the partition is EOF.
@@ -1,4 +1,4 @@
1
1
  module Rdkafka
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  LIBRDKAFKA_VERSION = "0.11.1"
4
4
  end
@@ -87,6 +87,31 @@ describe Rdkafka::Consumer::TopicPartitionList do
87
87
  ])
88
88
  end
89
89
 
90
+ it "should create a new list and add assigned topics as a count" do
91
+ list = Rdkafka::Consumer::TopicPartitionList.new
92
+
93
+ expect(list.count).to eq 0
94
+ expect(list.empty?).to be true
95
+
96
+ list.add_topic("topic1", 3)
97
+ list.add_topic("topic2", 2)
98
+
99
+ expect(list.count).to eq 5
100
+ expect(list.empty?).to be false
101
+
102
+ hash = list.to_h
103
+ expect(hash.count).to eq 2
104
+ expect(hash["topic1"]).to eq([
105
+ Rdkafka::Consumer::Partition.new(0, -1001),
106
+ Rdkafka::Consumer::Partition.new(1, -1001),
107
+ Rdkafka::Consumer::Partition.new(2, -1001)
108
+ ])
109
+ expect(hash["topic2"]).to eq([
110
+ Rdkafka::Consumer::Partition.new(0, -1001),
111
+ Rdkafka::Consumer::Partition.new(1, -1001)
112
+ ])
113
+ end
114
+
90
115
  describe "#to_s" do
91
116
  it "should return a human readable representation" do
92
117
  list = Rdkafka::Consumer::TopicPartitionList.new
@@ -7,6 +7,10 @@ describe Rdkafka::RdkafkaError do
7
7
  }.to raise_error TypeError
8
8
  end
9
9
 
10
+ it "should create an error with a message" do
11
+ expect(Rdkafka::RdkafkaError.new(10, "message").message).to eq "message"
12
+ end
13
+
10
14
  describe "#code" do
11
15
  it "should handle an invalid response" do
12
16
  expect(Rdkafka::RdkafkaError.new(933975).code).to eq :err_933975?
@@ -29,6 +33,10 @@ describe Rdkafka::RdkafkaError do
29
33
  it "should return error messages from rdkafka" do
30
34
  expect(Rdkafka::RdkafkaError.new(10).to_s).to eq "Broker: Message size too large (msg_size_too_large)"
31
35
  end
36
+
37
+ it "should show the message if present" do
38
+ expect(Rdkafka::RdkafkaError.new(10, "Error explanation").to_s).to eq "Error explanation - Broker: Message size too large (msg_size_too_large)"
39
+ end
32
40
  end
33
41
 
34
42
  describe "#is_partition_eof?" do
@@ -40,4 +48,24 @@ describe Rdkafka::RdkafkaError do
40
48
  expect(Rdkafka::RdkafkaError.new(-191).is_partition_eof?).to be true
41
49
  end
42
50
  end
51
+
52
+ describe "#==" do
53
+ subject { Rdkafka::RdkafkaError.new(10, "Error explanation") }
54
+
55
+ it "should equal another error with the same content" do
56
+ expect(subject).to eq Rdkafka::RdkafkaError.new(10, "Error explanation")
57
+ end
58
+
59
+ it "should not equal another error with a different error code" do
60
+ expect(subject).to eq Rdkafka::RdkafkaError.new(20, "Error explanation")
61
+ end
62
+
63
+ it "should not equal another error with a different message" do
64
+ expect(subject).to eq Rdkafka::RdkafkaError.new(10, "Different error explanation")
65
+ end
66
+
67
+ it "should not equal another error with no message" do
68
+ expect(subject).to eq Rdkafka::RdkafkaError.new(10)
69
+ end
70
+ end
43
71
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdkafka
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thijs Cadier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-23 00:00:00.000000000 Z
11
+ date: 2017-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi