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.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +20 -11
- data/CHANGELOG.md +6 -0
- data/Gemfile +5 -2
- data/Rakefile +2 -1
- data/avro_turf.gemspec +16 -16
- data/lib/avro_turf/cached_confluent_schema_registry.rb +9 -8
- data/lib/avro_turf/cached_schema_registry.rb +3 -1
- data/lib/avro_turf/confluent_schema_registry.rb +23 -17
- data/lib/avro_turf/core_ext/date.rb +2 -0
- data/lib/avro_turf/core_ext/enumerable.rb +2 -0
- data/lib/avro_turf/core_ext/false_class.rb +2 -0
- data/lib/avro_turf/core_ext/hash.rb +4 -2
- data/lib/avro_turf/core_ext/nil_class.rb +2 -0
- data/lib/avro_turf/core_ext/numeric.rb +2 -0
- data/lib/avro_turf/core_ext/string.rb +2 -0
- data/lib/avro_turf/core_ext/symbol.rb +2 -0
- data/lib/avro_turf/core_ext/time.rb +2 -0
- data/lib/avro_turf/core_ext/true_class.rb +2 -0
- data/lib/avro_turf/core_ext.rb +12 -10
- data/lib/avro_turf/disk_cache.rb +13 -12
- data/lib/avro_turf/in_memory_cache.rb +2 -0
- data/lib/avro_turf/messaging.rb +22 -14
- data/lib/avro_turf/mutable_schema_store.rb +25 -4
- data/lib/avro_turf/schema_registry.rb +3 -1
- data/lib/avro_turf/schema_store.rb +3 -2
- data/lib/avro_turf/schema_to_avro_patch.rb +14 -12
- data/lib/avro_turf/test/fake_confluent_schema_registry_server.rb +24 -23
- data/lib/avro_turf/test/fake_prefixed_confluent_schema_registry_server.rb +12 -10
- data/lib/avro_turf/test/fake_schema_registry_server.rb +3 -1
- data/lib/avro_turf/version.rb +3 -1
- data/lib/avro_turf.rb +15 -13
- data/perf/encoding_size.rb +4 -2
- data/perf/encoding_speed.rb +4 -2
- data/spec/avro_turf_spec.rb +24 -23
- data/spec/cached_confluent_schema_registry_spec.rb +9 -7
- data/spec/confluent_schema_registry_spec.rb +31 -10
- data/spec/core_ext/date_spec.rb +2 -0
- data/spec/core_ext/enumerable_spec.rb +2 -0
- data/spec/core_ext/false_class_spec.rb +2 -0
- data/spec/core_ext/hash_spec.rb +3 -1
- data/spec/core_ext/nil_class_spec.rb +2 -0
- data/spec/core_ext/numeric_spec.rb +2 -0
- data/spec/core_ext/string_spec.rb +2 -0
- data/spec/core_ext/symbol_spec.rb +2 -0
- data/spec/core_ext/time_spec.rb +2 -0
- data/spec/core_ext/true_class_spec.rb +2 -0
- data/spec/disk_cached_confluent_schema_registry_spec.rb +23 -21
- data/spec/messaging_spec.rb +124 -99
- data/spec/mutable_schema_store_spec.rb +134 -0
- data/spec/schema_store_spec.rb +23 -21
- data/spec/schema_to_avro_patch_spec.rb +8 -7
- data/spec/spec_helper.rb +9 -9
- data/spec/support/authorized_fake_confluent_schema_registry_server.rb +4 -2
- data/spec/support/authorized_fake_prefixed_confluent_schema_registry_server.rb +4 -2
- data/spec/support/confluent_schema_registry_context.rb +32 -30
- data/spec/test/fake_confluent_schema_registry_server_spec.rb +97 -94
- metadata +5 -26
data/spec/core_ext/time_spec.rb
CHANGED
@@ -1,18 +1,20 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
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)
|
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: [{
|
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: [{
|
26
|
+
fields: [{name: "name", type: "string"}]
|
25
27
|
}.to_json
|
26
28
|
end
|
27
29
|
|
28
|
-
let(: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: {
|
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
|
-
|
52
|
+
id.to_s => schema.to_s
|
51
53
|
}
|
52
54
|
end
|
53
55
|
let(:cache_after) do
|
54
56
|
{
|
55
|
-
|
56
|
-
|
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
|
-
|
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"),
|
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"),
|
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
|
|