karafka-rdkafka 0.19.1 → 0.19.2.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -654,12 +654,11 @@ describe Rdkafka::Producer do
654
654
 
655
655
  context 'when the partition count value was cached but time expired' do
656
656
  before do
657
- allow(::Process).to receive(:clock_gettime).and_return(0, 30.02)
658
- producer.partition_count('example_topic')
657
+ ::Rdkafka::Producer.partitions_count_cache = Rdkafka::Producer::PartitionsCountCache.new
659
658
  allow(::Rdkafka::Metadata).to receive(:new).and_call_original
660
659
  end
661
660
 
662
- it 'expect not to query it again' do
661
+ it 'expect to query it again' do
663
662
  producer.partition_count('example_topic')
664
663
  expect(::Rdkafka::Metadata).to have_received(:new)
665
664
  end
@@ -1042,4 +1041,118 @@ describe Rdkafka::Producer do
1042
1041
  expect(message.headers['version']).to eq('2.1.3')
1043
1042
  end
1044
1043
  end
1044
+
1045
+ describe 'with active statistics callback' do
1046
+ let(:producer) do
1047
+ rdkafka_producer_config('statistics.interval.ms': 1_000).producer
1048
+ end
1049
+
1050
+ let(:count_cache_hash) { described_class.partitions_count_cache.to_h }
1051
+ let(:pre_statistics_ttl) { count_cache_hash.fetch('produce_test_topic', [])[0] }
1052
+ let(:post_statistics_ttl) { count_cache_hash.fetch('produce_test_topic', [])[0] }
1053
+
1054
+ context "when using partition key" do
1055
+ before do
1056
+ Rdkafka::Config.statistics_callback = ->(*) {}
1057
+
1058
+ # This call will make a blocking request to the metadata cache
1059
+ producer.produce(
1060
+ topic: "produce_test_topic",
1061
+ payload: "payload headers",
1062
+ partition_key: "test"
1063
+ ).wait
1064
+
1065
+ pre_statistics_ttl
1066
+
1067
+ # We wait to make sure that statistics are triggered and that there is a refresh
1068
+ sleep(1.5)
1069
+
1070
+ post_statistics_ttl
1071
+ end
1072
+
1073
+ it 'expect to update ttl on the partitions count cache via statistics' do
1074
+ expect(pre_statistics_ttl).to be < post_statistics_ttl
1075
+ end
1076
+ end
1077
+
1078
+ context "when not using partition key" do
1079
+ before do
1080
+ Rdkafka::Config.statistics_callback = ->(*) {}
1081
+
1082
+ # This call will make a blocking request to the metadata cache
1083
+ producer.produce(
1084
+ topic: "produce_test_topic",
1085
+ payload: "payload headers"
1086
+ ).wait
1087
+
1088
+ pre_statistics_ttl
1089
+
1090
+ # We wait to make sure that statistics are triggered and that there is a refresh
1091
+ sleep(1.5)
1092
+
1093
+ # This will anyhow be populated from statistic
1094
+ post_statistics_ttl
1095
+ end
1096
+
1097
+ it 'expect not to update ttl on the partitions count cache via blocking but via use stats' do
1098
+ expect(pre_statistics_ttl).to be_nil
1099
+ expect(post_statistics_ttl).not_to be_nil
1100
+ end
1101
+ end
1102
+ end
1103
+
1104
+ describe 'without active statistics callback' do
1105
+ let(:producer) do
1106
+ rdkafka_producer_config('statistics.interval.ms': 1_000).producer
1107
+ end
1108
+
1109
+ let(:count_cache_hash) { described_class.partitions_count_cache.to_h }
1110
+ let(:pre_statistics_ttl) { count_cache_hash.fetch('produce_test_topic', [])[0] }
1111
+ let(:post_statistics_ttl) { count_cache_hash.fetch('produce_test_topic', [])[0] }
1112
+
1113
+ context "when using partition key" do
1114
+ before do
1115
+ # This call will make a blocking request to the metadata cache
1116
+ producer.produce(
1117
+ topic: "produce_test_topic",
1118
+ payload: "payload headers",
1119
+ partition_key: "test"
1120
+ ).wait
1121
+
1122
+ pre_statistics_ttl
1123
+
1124
+ # We wait to make sure that statistics are triggered and that there is a refresh
1125
+ sleep(1.5)
1126
+
1127
+ post_statistics_ttl
1128
+ end
1129
+
1130
+ it 'expect not to update ttl on the partitions count cache via statistics' do
1131
+ expect(pre_statistics_ttl).to eq post_statistics_ttl
1132
+ end
1133
+ end
1134
+
1135
+ context "when not using partition key" do
1136
+ before do
1137
+ # This call will make a blocking request to the metadata cache
1138
+ producer.produce(
1139
+ topic: "produce_test_topic",
1140
+ payload: "payload headers"
1141
+ ).wait
1142
+
1143
+ pre_statistics_ttl
1144
+
1145
+ # We wait to make sure that statistics are triggered and that there is a refresh
1146
+ sleep(1.5)
1147
+
1148
+ # This should not be populated because stats are not in use
1149
+ post_statistics_ttl
1150
+ end
1151
+
1152
+ it 'expect not to update ttl on the partitions count cache via anything' do
1153
+ expect(pre_statistics_ttl).to be_nil
1154
+ expect(post_statistics_ttl).to be_nil
1155
+ end
1156
+ end
1157
+ end
1045
1158
  end
data/spec/spec_helper.rb CHANGED
@@ -18,6 +18,9 @@ def rdkafka_base_config
18
18
  :"api.version.request" => false,
19
19
  :"broker.version.fallback" => "1.0",
20
20
  :"bootstrap.servers" => "localhost:9092",
21
+ # Display statistics and refresh often just to cover those in specs
22
+ :'statistics.interval.ms' => 1_000,
23
+ :'topic.metadata.refresh.interval.ms' => 1_000
21
24
  }
22
25
  end
23
26
 
@@ -125,6 +128,12 @@ RSpec.configure do |config|
125
128
  config.filter_run focus: true
126
129
  config.run_all_when_everything_filtered = true
127
130
 
131
+ config.before(:each) do
132
+ Rdkafka::Config.statistics_callback = nil
133
+ # We need to clear it so state does not leak between specs
134
+ Rdkafka::Producer.partitions_count_cache.to_h.clear
135
+ end
136
+
128
137
  config.before(:suite) do
129
138
  admin = rdkafka_config.admin
130
139
  {
data.tar.gz.sig CHANGED
@@ -1,3 +1 @@
1
- ��Ed/�;��u'q�������ˏn)��}-^ V�l-���^@M��%b���s��{i�l�ý��-��?�L���1�l�s��c��Z$xɪW�Ƚ��l(��D�|[����)�5V̚��k%�X~�Ÿ��%
2
- ���1}kڃ��29���ؔ�1!T�ޯ[��8�� ���^�Ԥ�gk� 3�k P��o�&)�=`]c|u(�$
3
- !%������,Ȓ �������`��V�m+Y.�бt�M�������z�hc,���
1
+ %��;��lx_9|�e�5Bv77)��N^lӷ�o<`x���5��jYKFdJ��"/V 5��p�\
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: karafka-rdkafka
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.1
4
+ version: 0.19.2.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thijs Cadier
@@ -35,7 +35,7 @@ cert_chain:
35
35
  i9zWxov0mr44TWegTVeypcWGd/0nxu1+QHVNHJrpqlPBRvwQsUm7fwmRInGpcaB8
36
36
  ap8wNYvryYzrzvzUxIVFBVM5PacgkFqRmolCa8I7tdKQN+R1
37
37
  -----END CERTIFICATE-----
38
- date: 2025-04-07 00:00:00.000000000 Z
38
+ date: 1980-01-02 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: ffi
@@ -233,6 +233,7 @@ files:
233
233
  - lib/rdkafka/producer.rb
234
234
  - lib/rdkafka/producer/delivery_handle.rb
235
235
  - lib/rdkafka/producer/delivery_report.rb
236
+ - lib/rdkafka/producer/partitions_count_cache.rb
236
237
  - lib/rdkafka/version.rb
237
238
  - renovate.json
238
239
  - spec/rdkafka/abstract_handle_spec.rb
@@ -260,6 +261,8 @@ files:
260
261
  - spec/rdkafka/native_kafka_spec.rb
261
262
  - spec/rdkafka/producer/delivery_handle_spec.rb
262
263
  - spec/rdkafka/producer/delivery_report_spec.rb
264
+ - spec/rdkafka/producer/partitions_count_cache_spec.rb
265
+ - spec/rdkafka/producer/partitions_count_spec.rb
263
266
  - spec/rdkafka/producer_spec.rb
264
267
  - spec/spec_helper.rb
265
268
  licenses:
@@ -286,7 +289,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
286
289
  - !ruby/object:Gem::Version
287
290
  version: '0'
288
291
  requirements: []
289
- rubygems_version: 3.6.2
292
+ rubygems_version: 3.6.7
290
293
  specification_version: 4
291
294
  summary: The rdkafka gem is a modern Kafka client library for Ruby based on librdkafka.
292
295
  It wraps the production-ready C client using the ffi gem and targets Kafka 1.0+
@@ -317,5 +320,7 @@ test_files:
317
320
  - spec/rdkafka/native_kafka_spec.rb
318
321
  - spec/rdkafka/producer/delivery_handle_spec.rb
319
322
  - spec/rdkafka/producer/delivery_report_spec.rb
323
+ - spec/rdkafka/producer/partitions_count_cache_spec.rb
324
+ - spec/rdkafka/producer/partitions_count_spec.rb
320
325
  - spec/rdkafka/producer_spec.rb
321
326
  - spec/spec_helper.rb
metadata.gz.sig CHANGED
Binary file