avro_turf 1.19.0 → 1.20.1
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 +12 -0
- data/Gemfile +5 -2
- data/Rakefile +2 -1
- data/avro_turf.gemspec +16 -17
- 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 +25 -15
- 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 +39 -37
- 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/test/fake_server.rb +186 -0
- 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 +145 -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_http_contract_spec.rb +722 -0
- data/spec/test/fake_confluent_schema_registry_server_spec.rb +97 -94
- metadata +7 -40
data/spec/avro_turf_spec.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
describe AvroTurf do
|
|
2
4
|
let(:avro) { AvroTurf.new(schemas_path: "spec/schemas/") }
|
|
3
5
|
|
|
@@ -56,7 +58,7 @@ describe AvroTurf do
|
|
|
56
58
|
end
|
|
57
59
|
end
|
|
58
60
|
|
|
59
|
-
context
|
|
61
|
+
context "when using nested schemas" do
|
|
60
62
|
before do
|
|
61
63
|
define_schema "post.avsc", <<-AVSC
|
|
62
64
|
{
|
|
@@ -138,7 +140,6 @@ describe AvroTurf do
|
|
|
138
140
|
expect(avro.decode(encoded_data)).to eq(data)
|
|
139
141
|
end
|
|
140
142
|
end
|
|
141
|
-
|
|
142
143
|
end
|
|
143
144
|
|
|
144
145
|
describe "#decode" do
|
|
@@ -179,22 +180,22 @@ describe AvroTurf do
|
|
|
179
180
|
}
|
|
180
181
|
AVSC
|
|
181
182
|
|
|
182
|
-
encoded_data = avro.encode({
|
|
183
|
+
encoded_data = avro.encode({"x" => 42, "y" => 13}, schema_name: "point")
|
|
183
184
|
reader_avro = AvroTurf.new(schemas_path: "spec/schemas/reader")
|
|
184
185
|
|
|
185
|
-
expect(reader_avro.decode(encoded_data, schema_name: "point")).to eq({
|
|
186
|
+
expect(reader_avro.decode(encoded_data, schema_name: "point")).to eq({"x" => 42})
|
|
186
187
|
end
|
|
187
188
|
end
|
|
188
189
|
|
|
189
190
|
describe "#decode_all" do
|
|
190
191
|
context "when data contains multiple entries" do
|
|
191
|
-
let(:encoded_data) {
|
|
192
|
+
let(:encoded_data) { "Obj\u0001\u0004\u0014avro.codec\bnull\u0016avro.schema\xB6\u0004[{\"type\": \"record\", \"name\": \"address\", \"fields\": [{\"type\": \"string\", \"name\": \"street\"}, {\"type\": \"string\", \"name\": \"city\"}]}, {\"type\": \"record\", \"name\": \"person\", \"fields\": [{\"type\": \"string\", \"name\": \"name\"}, {\"type\": \"int\", \"name\": \"age\"}, {\"type\": \"address\", \"name\": \"address\"}]}]\u0000\xF9u\x84\xA1c\u0010\x82B\xE2\xCF\xF1\x98\xF7\xF1JH\u0004\x96\u0001\u0002\u0014Python🐍\x80\u0004\u0018Green Street\u001ASan Francisco\u0002\u0010Mojo🐍\u0002\u0016Blue Street\u0014Saturn🪐\xF9u\x84\xA1c\u0010\x82B\xE2\xCF\xF1\x98\xF7\xF1JH" }
|
|
192
193
|
|
|
193
194
|
it "returns array of entries decoded using the inlined writer's schema " do
|
|
194
195
|
expect(avro.decode_all(encoded_data).entries).to eq(
|
|
195
196
|
[
|
|
196
|
-
{"name"=>"Python🐍", "age"=>256, "address"=>{"street"=>"Green Street", "city"=>"San Francisco"}},
|
|
197
|
-
{"name"=>"Mojo🐍", "age"=>1, "address"=>{"street"=>"Blue Street", "city"=>"Saturn🪐"}}
|
|
197
|
+
{"name" => "Python🐍", "age" => 256, "address" => {"street" => "Green Street", "city" => "San Francisco"}},
|
|
198
|
+
{"name" => "Mojo🐍", "age" => 1, "address" => {"street" => "Blue Street", "city" => "Saturn🪐"}}
|
|
198
199
|
]
|
|
199
200
|
)
|
|
200
201
|
end
|
|
@@ -219,8 +220,8 @@ describe AvroTurf do
|
|
|
219
220
|
.decode_all(encoded_data, schema_name: "person").entries
|
|
220
221
|
).to eq(
|
|
221
222
|
[
|
|
222
|
-
{"name"=>"Python🐍", "age"=>256, "fav_color"=>"red🟥"},
|
|
223
|
-
{"name"=>"Mojo🐍", "age"=>1, "fav_color"=>"red🟥"}
|
|
223
|
+
{"name" => "Python🐍", "age" => 256, "fav_color" => "red🟥"},
|
|
224
|
+
{"name" => "Mojo🐍", "age" => 1, "fav_color" => "red🟥"}
|
|
224
225
|
]
|
|
225
226
|
)
|
|
226
227
|
end
|
|
@@ -249,7 +250,7 @@ describe AvroTurf do
|
|
|
249
250
|
end
|
|
250
251
|
|
|
251
252
|
context "with a valid message" do
|
|
252
|
-
let(:message) { {
|
|
253
|
+
let(:message) { {"full_name" => "John Doe"} }
|
|
253
254
|
|
|
254
255
|
it "does not raise any error" do
|
|
255
256
|
define_schema "message.avsc", <<-AVSC
|
|
@@ -267,7 +268,7 @@ describe AvroTurf do
|
|
|
267
268
|
end
|
|
268
269
|
|
|
269
270
|
context "when message has wrong type" do
|
|
270
|
-
let(:message) { {
|
|
271
|
+
let(:message) { {"full_name" => 123} }
|
|
271
272
|
|
|
272
273
|
it "raises Avro::SchemaValidator::ValidationError with a message about type mismatch" do
|
|
273
274
|
define_schema "message.avsc", <<-AVSC
|
|
@@ -285,7 +286,7 @@ describe AvroTurf do
|
|
|
285
286
|
end
|
|
286
287
|
|
|
287
288
|
context "when message contains extra fields (typo in key)" do
|
|
288
|
-
let(:message) { {
|
|
289
|
+
let(:message) { {"fulll_name" => "John Doe"} }
|
|
289
290
|
|
|
290
291
|
it "raises Avro::SchemaValidator::ValidationError with a message about extra field" do
|
|
291
292
|
define_schema "message.avsc", <<-AVSC
|
|
@@ -303,13 +304,12 @@ describe AvroTurf do
|
|
|
303
304
|
end
|
|
304
305
|
|
|
305
306
|
context "when the `fail_on_extra_fields` validation option is disabled" do
|
|
306
|
-
let(:message) { {
|
|
307
|
+
let(:message) { {"full_name" => "John Doe", "first_name" => "John", "last_name" => "Doe"} }
|
|
307
308
|
subject(:encode_to_stream) do
|
|
308
309
|
stream = StringIO.new
|
|
309
310
|
avro.encode_to_stream(message, stream: stream, schema_name: "message",
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
)
|
|
311
|
+
validate: true,
|
|
312
|
+
validate_options: {recursive: true, encoded: false, fail_on_extra_fields: false})
|
|
313
313
|
end
|
|
314
314
|
|
|
315
315
|
it "should not raise Avro::SchemaValidator::ValidationError with a message about extra field" do
|
|
@@ -352,8 +352,8 @@ describe AvroTurf do
|
|
|
352
352
|
|
|
353
353
|
expect(avro.decode_all_from_stream(stream).entries).to eq(
|
|
354
354
|
[
|
|
355
|
-
{"name"=>"Python🐍", "age"=>256, "address"=>{"street"=>"Green Street", "city"=>"San Francisco"}},
|
|
356
|
-
{"name"=>"Mojo🐍", "age"=>1, "address"=>{"street"=>"Blue Street", "city"=>"Saturn🪐"}}
|
|
355
|
+
{"name" => "Python🐍", "age" => 256, "address" => {"street" => "Green Street", "city" => "San Francisco"}},
|
|
356
|
+
{"name" => "Mojo🐍", "age" => 1, "address" => {"street" => "Blue Street", "city" => "Saturn🪐"}}
|
|
357
357
|
]
|
|
358
358
|
)
|
|
359
359
|
end
|
|
@@ -390,7 +390,7 @@ describe AvroTurf do
|
|
|
390
390
|
}
|
|
391
391
|
AVSC
|
|
392
392
|
|
|
393
|
-
datum = {
|
|
393
|
+
datum = {message: "hello"}
|
|
394
394
|
expect(avro.valid?(datum, schema_name: "postcard")).to eq true
|
|
395
395
|
end
|
|
396
396
|
|
|
@@ -423,7 +423,7 @@ describe AvroTurf do
|
|
|
423
423
|
end
|
|
424
424
|
|
|
425
425
|
context "when message contains extra fields (typo in key)" do
|
|
426
|
-
let(:message) { {
|
|
426
|
+
let(:message) { {"fulll_name" => "John Doe"} }
|
|
427
427
|
|
|
428
428
|
before do
|
|
429
429
|
define_schema "message.avsc", <<-AVSC
|
|
@@ -438,16 +438,17 @@ describe AvroTurf do
|
|
|
438
438
|
end
|
|
439
439
|
|
|
440
440
|
it "is valid" do
|
|
441
|
-
datum = {
|
|
441
|
+
datum = {"full_name" => "John Doe", "extra" => "extra"}
|
|
442
442
|
expect(avro.valid?(datum, schema_name: "message")).to eq true
|
|
443
443
|
end
|
|
444
444
|
|
|
445
445
|
it "is invalid when passing fail_on_extra_fields" do
|
|
446
|
-
datum = {
|
|
446
|
+
datum = {"full_name" => "John Doe", "extra" => "extra"}
|
|
447
447
|
validate_options = {
|
|
448
448
|
recursive: true,
|
|
449
449
|
encoded: false,
|
|
450
|
-
fail_on_extra_fields: true
|
|
450
|
+
fail_on_extra_fields: true
|
|
451
|
+
}
|
|
451
452
|
valid = avro.valid?(datum, schema_name: "message", validate_options: validate_options)
|
|
452
453
|
expect(valid).to eq false
|
|
453
454
|
end
|
|
@@ -1,17 +1,19 @@
|
|
|
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(:registry) { described_class.new(upstream) }
|
|
8
10
|
let(:id) { rand(999) }
|
|
9
|
-
let(:subject_name) {
|
|
11
|
+
let(:subject_name) { "a_subject" }
|
|
10
12
|
let(:schema) do
|
|
11
13
|
{
|
|
12
14
|
type: "record",
|
|
13
15
|
name: "person",
|
|
14
|
-
fields: [{
|
|
16
|
+
fields: [{name: "name", type: "string"}]
|
|
15
17
|
}.to_json
|
|
16
18
|
end
|
|
17
19
|
|
|
@@ -57,7 +59,7 @@ describe AvroTurf::CachedConfluentSchemaRegistry do
|
|
|
57
59
|
end
|
|
58
60
|
end
|
|
59
61
|
|
|
60
|
-
describe
|
|
62
|
+
describe "#subject_version" do
|
|
61
63
|
let(:version) { 1 }
|
|
62
64
|
let(:schema_with_meta) do
|
|
63
65
|
{
|
|
@@ -68,7 +70,7 @@ describe AvroTurf::CachedConfluentSchemaRegistry do
|
|
|
68
70
|
}
|
|
69
71
|
end
|
|
70
72
|
|
|
71
|
-
it
|
|
73
|
+
it "caches the result of subject_version" do
|
|
72
74
|
allow(upstream).to receive(:subject_version).with(subject_name, version).and_return(schema_with_meta)
|
|
73
75
|
registry.subject_version(subject_name, version)
|
|
74
76
|
registry.subject_version(subject_name, version)
|
|
@@ -1,22 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
require
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "webmock/rspec"
|
|
4
|
+
require "avro_turf/confluent_schema_registry"
|
|
5
|
+
require "avro_turf/test/fake_confluent_schema_registry_server"
|
|
4
6
|
|
|
5
7
|
describe AvroTurf::ConfluentSchemaRegistry do
|
|
6
8
|
let(:user) { "abc" }
|
|
7
9
|
let(:password) { "xxyyzz" }
|
|
8
10
|
let(:client_cert) { "test client cert" }
|
|
11
|
+
let(:client_chain) { "test client cert chain" }
|
|
9
12
|
let(:client_key) { "test client key" }
|
|
10
13
|
let(:client_key_pass) { "test client key password" }
|
|
11
14
|
let(:connect_timeout) { 10 }
|
|
12
15
|
|
|
13
|
-
context
|
|
16
|
+
context "authenticated by cert" do
|
|
17
|
+
it_behaves_like "a confluent schema registry client" do
|
|
18
|
+
let(:registry) {
|
|
19
|
+
described_class.new(
|
|
20
|
+
registry_url,
|
|
21
|
+
logger: logger,
|
|
22
|
+
client_cert: client_cert,
|
|
23
|
+
client_key: client_key,
|
|
24
|
+
client_key_pass: client_key_pass
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
context "authenticated by cert with chain" do
|
|
14
31
|
it_behaves_like "a confluent schema registry client" do
|
|
15
32
|
let(:registry) {
|
|
16
33
|
described_class.new(
|
|
17
34
|
registry_url,
|
|
18
35
|
logger: logger,
|
|
19
36
|
client_cert: client_cert,
|
|
37
|
+
client_chain: client_chain,
|
|
20
38
|
client_key: client_key,
|
|
21
39
|
client_key_pass: client_key_pass
|
|
22
40
|
)
|
|
@@ -24,23 +42,25 @@ describe AvroTurf::ConfluentSchemaRegistry do
|
|
|
24
42
|
end
|
|
25
43
|
end
|
|
26
44
|
|
|
27
|
-
context
|
|
45
|
+
context "authenticated by basic auth" do
|
|
28
46
|
it_behaves_like "a confluent schema registry client" do
|
|
29
47
|
let(:registry) {
|
|
30
48
|
described_class.new(
|
|
31
49
|
registry_url,
|
|
50
|
+
logger: logger,
|
|
32
51
|
user: user,
|
|
33
|
-
password: password
|
|
52
|
+
password: password
|
|
34
53
|
)
|
|
35
54
|
}
|
|
36
55
|
end
|
|
37
56
|
end
|
|
38
57
|
|
|
39
|
-
context
|
|
58
|
+
context "with connect_timeout" do
|
|
40
59
|
it_behaves_like "a confluent schema registry client" do
|
|
41
60
|
let(:registry) {
|
|
42
61
|
described_class.new(
|
|
43
62
|
registry_url,
|
|
63
|
+
logger: logger,
|
|
44
64
|
user: user,
|
|
45
65
|
password: password,
|
|
46
66
|
connect_timeout: connect_timeout
|
|
@@ -49,12 +69,13 @@ describe AvroTurf::ConfluentSchemaRegistry do
|
|
|
49
69
|
end
|
|
50
70
|
end
|
|
51
71
|
|
|
52
|
-
context
|
|
53
|
-
it_behaves_like "a confluent schema registry client", schema_context:
|
|
72
|
+
context "with non default schema_context" do
|
|
73
|
+
it_behaves_like "a confluent schema registry client", schema_context: "other" do
|
|
54
74
|
let(:registry) {
|
|
55
75
|
described_class.new(
|
|
56
76
|
registry_url,
|
|
57
|
-
|
|
77
|
+
logger: logger,
|
|
78
|
+
schema_context: "other",
|
|
58
79
|
user: user,
|
|
59
80
|
password: password,
|
|
60
81
|
connect_timeout: connect_timeout
|
data/spec/core_ext/date_spec.rb
CHANGED
data/spec/core_ext/hash_spec.rb
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
describe Hash, "#as_avro" do
|
|
2
4
|
it "coerces the keys and values to Avro" do
|
|
3
5
|
x = double(as_avro: "x")
|
|
4
6
|
y = double(as_avro: "y")
|
|
5
7
|
|
|
6
|
-
expect({
|
|
8
|
+
expect({x => y}.as_avro).to eq({"x" => "y"})
|
|
7
9
|
end
|
|
8
10
|
end
|
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
|
|