avro_turf 1.19.0 → 1.20.0

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.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +20 -11
  3. data/CHANGELOG.md +6 -0
  4. data/Gemfile +5 -2
  5. data/Rakefile +2 -1
  6. data/avro_turf.gemspec +16 -16
  7. data/lib/avro_turf/cached_confluent_schema_registry.rb +9 -8
  8. data/lib/avro_turf/cached_schema_registry.rb +3 -1
  9. data/lib/avro_turf/confluent_schema_registry.rb +23 -17
  10. data/lib/avro_turf/core_ext/date.rb +2 -0
  11. data/lib/avro_turf/core_ext/enumerable.rb +2 -0
  12. data/lib/avro_turf/core_ext/false_class.rb +2 -0
  13. data/lib/avro_turf/core_ext/hash.rb +4 -2
  14. data/lib/avro_turf/core_ext/nil_class.rb +2 -0
  15. data/lib/avro_turf/core_ext/numeric.rb +2 -0
  16. data/lib/avro_turf/core_ext/string.rb +2 -0
  17. data/lib/avro_turf/core_ext/symbol.rb +2 -0
  18. data/lib/avro_turf/core_ext/time.rb +2 -0
  19. data/lib/avro_turf/core_ext/true_class.rb +2 -0
  20. data/lib/avro_turf/core_ext.rb +12 -10
  21. data/lib/avro_turf/disk_cache.rb +13 -12
  22. data/lib/avro_turf/in_memory_cache.rb +2 -0
  23. data/lib/avro_turf/messaging.rb +22 -14
  24. data/lib/avro_turf/mutable_schema_store.rb +25 -4
  25. data/lib/avro_turf/schema_registry.rb +3 -1
  26. data/lib/avro_turf/schema_store.rb +3 -2
  27. data/lib/avro_turf/schema_to_avro_patch.rb +14 -12
  28. data/lib/avro_turf/test/fake_confluent_schema_registry_server.rb +24 -23
  29. data/lib/avro_turf/test/fake_prefixed_confluent_schema_registry_server.rb +12 -10
  30. data/lib/avro_turf/test/fake_schema_registry_server.rb +3 -1
  31. data/lib/avro_turf/version.rb +3 -1
  32. data/lib/avro_turf.rb +15 -13
  33. data/perf/encoding_size.rb +4 -2
  34. data/perf/encoding_speed.rb +4 -2
  35. data/spec/avro_turf_spec.rb +24 -23
  36. data/spec/cached_confluent_schema_registry_spec.rb +9 -7
  37. data/spec/confluent_schema_registry_spec.rb +31 -10
  38. data/spec/core_ext/date_spec.rb +2 -0
  39. data/spec/core_ext/enumerable_spec.rb +2 -0
  40. data/spec/core_ext/false_class_spec.rb +2 -0
  41. data/spec/core_ext/hash_spec.rb +3 -1
  42. data/spec/core_ext/nil_class_spec.rb +2 -0
  43. data/spec/core_ext/numeric_spec.rb +2 -0
  44. data/spec/core_ext/string_spec.rb +2 -0
  45. data/spec/core_ext/symbol_spec.rb +2 -0
  46. data/spec/core_ext/time_spec.rb +2 -0
  47. data/spec/core_ext/true_class_spec.rb +2 -0
  48. data/spec/disk_cached_confluent_schema_registry_spec.rb +23 -21
  49. data/spec/messaging_spec.rb +124 -99
  50. data/spec/mutable_schema_store_spec.rb +134 -0
  51. data/spec/schema_store_spec.rb +23 -21
  52. data/spec/schema_to_avro_patch_spec.rb +8 -7
  53. data/spec/spec_helper.rb +9 -9
  54. data/spec/support/authorized_fake_confluent_schema_registry_server.rb +4 -2
  55. data/spec/support/authorized_fake_prefixed_confluent_schema_registry_server.rb +4 -2
  56. data/spec/support/confluent_schema_registry_context.rb +32 -30
  57. data/spec/test/fake_confluent_schema_registry_server_spec.rb +97 -94
  58. metadata +5 -26
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe Numeric, "#as_avro" do
2
4
  it "returns the number itself" do
3
5
  expect(42.as_avro).to eq 42
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe String, "#as_avro" do
2
4
  it "returns itself" do
3
5
  expect("hello".as_avro).to eq "hello"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe Symbol, "#as_avro" do
2
4
  it "returns the String representation of the Symbol" do
3
5
  expect(:hello.as_avro).to eq("hello")
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe Time, "#as_avro" do
2
4
  it "returns an ISO8601 string describing the time" do
3
5
  time = Time.now
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe TrueClass, "#as_avro" do
2
4
  it "returns itself" do
3
5
  expect(true.as_avro).to eq true
@@ -1,18 +1,20 @@
1
- require 'webmock/rspec'
2
- require 'avro_turf/cached_confluent_schema_registry'
3
- require 'avro_turf/test/fake_confluent_schema_registry_server'
1
+ # frozen_string_literal: true
2
+
3
+ require "webmock/rspec"
4
+ require "avro_turf/cached_confluent_schema_registry"
5
+ require "avro_turf/test/fake_confluent_schema_registry_server"
4
6
 
5
7
  describe AvroTurf::CachedConfluentSchemaRegistry do
6
8
  let(:upstream) { instance_double(AvroTurf::ConfluentSchemaRegistry) }
7
9
  let(:logger_io) { StringIO.new }
8
- let(:cache) { AvroTurf::DiskCache.new("spec/cache", logger: Logger.new(logger_io))}
10
+ let(:cache) { AvroTurf::DiskCache.new("spec/cache", logger: Logger.new(logger_io)) }
9
11
  let(:registry) { described_class.new(upstream, cache: cache) }
10
12
  let(:id) { rand(999) }
11
13
  let(:schema) do
12
14
  {
13
15
  type: "record",
14
16
  name: "person",
15
- fields: [{ name: "name", type: "string" }]
17
+ fields: [{name: "name", type: "string"}]
16
18
  }.to_json
17
19
  end
18
20
 
@@ -21,21 +23,21 @@ describe AvroTurf::CachedConfluentSchemaRegistry do
21
23
  {
22
24
  type: "record",
23
25
  name: "city",
24
- fields: [{ name: "name", type: "string" }]
26
+ fields: [{name: "name", type: "string"}]
25
27
  }.to_json
26
28
  end
27
29
 
28
- let(:subject) { 'subject' }
30
+ let(:subject) { "subject" }
29
31
  let(:version) { rand(999) }
30
32
  let(:subject_version_schema) do
31
33
  {
32
34
  subject: subject,
33
35
  version: version,
34
36
  id: id,
35
- schema: {
37
+ schema: {
36
38
  type: "record",
37
39
  name: "city",
38
- fields: { name: "name", type: "string" }
40
+ fields: {name: "name", type: "string"}
39
41
  }
40
42
  }.to_json
41
43
  end
@@ -47,13 +49,13 @@ describe AvroTurf::CachedConfluentSchemaRegistry do
47
49
  describe "#fetch" do
48
50
  let(:cache_before) do
49
51
  {
50
- "#{id}" => "#{schema}"
52
+ id.to_s => schema.to_s
51
53
  }
52
54
  end
53
55
  let(:cache_after) do
54
56
  {
55
- "#{id}" => "#{schema}",
56
- "#{city_id}" => "#{city_schema}"
57
+ id.to_s => schema.to_s,
58
+ city_id.to_s => city_schema.to_s
57
59
  }
58
60
  end
59
61
 
@@ -84,13 +86,13 @@ describe AvroTurf::CachedConfluentSchemaRegistry do
84
86
  describe "#fetch (zero length cache file)" do
85
87
  let(:cache_after) do
86
88
  {
87
- "#{id}" => "#{schema}"
89
+ id.to_s => schema.to_s
88
90
  }
89
91
  end
90
92
 
91
93
  before do
92
94
  # setup the disk cache with a zero length file
93
- File.write(File.join("spec/cache", "schemas_by_id.json"), '')
95
+ File.write(File.join("spec/cache", "schemas_by_id.json"), "")
94
96
  end
95
97
 
96
98
  it "skips zero length disk cache" do
@@ -107,11 +109,11 @@ describe AvroTurf::CachedConfluentSchemaRegistry do
107
109
  describe "#fetch (corrupt cache file)" do
108
110
  before do
109
111
  # setup the disk cache with a corrupt file (i.e. not json)
110
- File.write(File.join("spec/cache", "schemas_by_id.json"), 'NOTJSON')
112
+ File.write(File.join("spec/cache", "schemas_by_id.json"), "NOTJSON")
111
113
  end
112
114
 
113
115
  it "raises error on corrupt cache file" do
114
- expect{registry.fetch(id)}.to raise_error(JSON::ParserError, /unexpected token/)
116
+ expect { registry.fetch(id) }.to raise_error(JSON::ParserError, /unexpected token/)
115
117
  end
116
118
  end
117
119
 
@@ -124,7 +126,7 @@ describe AvroTurf::CachedConfluentSchemaRegistry do
124
126
  end
125
127
 
126
128
  let(:city_name) { "a_city" }
127
- let(:cache_after) do
129
+ let(:cache_after) do
128
130
  {
129
131
  "#{subject_name}#{schema}" => id,
130
132
  "#{city_name}#{city_schema}" => city_id
@@ -139,7 +141,7 @@ describe AvroTurf::CachedConfluentSchemaRegistry do
139
141
  it "uses preloaded disk cache" do
140
142
  # multiple calls return same result, with zero upstream calls
141
143
  allow(upstream).to receive(:register).with(subject_name, schema).and_return(id)
142
- expect(registry.register(subject_name, schema)).to eq(id)
144
+ expect(registry.register(subject_name, schema)).to eq(id)
143
145
  expect(registry.register(subject_name, schema)).to eq(id)
144
146
  expect(upstream).to have_received(:register).exactly(0).times
145
147
  expect(load_cache("ids_by_schema.json")).to eq cache_before
@@ -165,7 +167,7 @@ describe AvroTurf::CachedConfluentSchemaRegistry do
165
167
 
166
168
  before do
167
169
  # setup the disk cache with a zero length file
168
- File.write(File.join("spec/cache", "ids_by_schema.json"), '')
170
+ File.write(File.join("spec/cache", "ids_by_schema.json"), "")
169
171
  end
170
172
 
171
173
  it "skips zero length disk cache" do
@@ -182,11 +184,11 @@ describe AvroTurf::CachedConfluentSchemaRegistry do
182
184
  describe "#register (corrupt cache file)" do
183
185
  before do
184
186
  # setup the disk cache with a corrupt file (i.e. not json)
185
- File.write(File.join("spec/cache", "ids_by_schema.json"), 'NOTJSON')
187
+ File.write(File.join("spec/cache", "ids_by_schema.json"), "NOTJSON")
186
188
  end
187
189
 
188
190
  it "raises error on corrupt cache file" do
189
- expect{registry.register(subject_name, schema)}.to raise_error(JSON::ParserError, /unexpected token/)
191
+ expect { registry.register(subject_name, schema) }.to raise_error(JSON::ParserError, /unexpected token/)
190
192
  end
191
193
  end
192
194