deimos-ruby 2.5.3 → 2.6.0.pre.beta1
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/CHANGELOG.md +2 -0
- data/README.md +20 -9
- data/deimos-ruby.gemspec +1 -0
- data/docs/CONFIGURATION.md +11 -4
- data/lib/deimos/active_record_consume/batch_consumption.rb +1 -1
- data/lib/deimos/active_record_consume/message_consumption.rb +2 -2
- data/lib/deimos/active_record_consumer.rb +1 -1
- data/lib/deimos/active_record_producer.rb +1 -1
- data/lib/deimos/config/configuration.rb +34 -11
- data/lib/deimos/ext/producer_middleware.rb +2 -2
- data/lib/deimos/logging.rb +9 -0
- data/lib/deimos/producer.rb +5 -5
- data/lib/deimos/schema_backends/avro_base.rb +7 -36
- data/lib/deimos/schema_class.rb +72 -0
- data/lib/deimos/transcoder.rb +6 -6
- data/lib/deimos/utils/schema_class.rb +14 -47
- data/lib/deimos/version.rb +1 -1
- data/lib/deimos.rb +3 -3
- data/lib/tasks/deimos.rake +16 -4
- data/regenerate_test_schema_classes.rb +12 -3
- data/spec/active_record_batch_consumer_association_spec.rb +1 -1
- data/spec/active_record_batch_consumer_spec.rb +1 -1
- data/spec/active_record_consume/batch_consumption_spec.rb +1 -1
- data/spec/active_record_consumer_spec.rb +3 -3
- data/spec/active_record_producer_spec.rb +1 -1
- data/spec/batch_consumer_spec.rb +2 -2
- data/spec/consumer_spec.rb +9 -9
- data/spec/schema_class_spec.rb +65 -0
- data/spec/schemas/my_namespace/generated.rb +4 -4
- data/spec/schemas/my_namespace/my_long_namespace_schema.rb +2 -2
- data/spec/schemas/my_namespace/my_nested_schema.rb +3 -3
- data/spec/schemas/my_namespace/my_schema.rb +2 -2
- data/spec/schemas/my_namespace/my_schema_compound_key.rb +2 -2
- data/spec/schemas/my_namespace/my_schema_id_key.rb +2 -2
- data/spec/schemas/my_namespace/my_schema_key.rb +2 -2
- data/spec/schemas/my_namespace/my_schema_with_boolean.rb +2 -2
- data/spec/schemas/my_namespace/my_schema_with_circular_reference.rb +3 -3
- data/spec/schemas/my_namespace/my_schema_with_complex_type.rb +6 -6
- data/spec/schemas/my_namespace/my_schema_with_date_time.rb +2 -2
- data/spec/schemas/my_namespace/my_schema_with_id.rb +2 -2
- data/spec/schemas/my_namespace/my_schema_with_title.rb +2 -2
- data/spec/schemas/my_namespace/my_schema_with_union_type.rb +6 -6
- data/spec/schemas/my_namespace/my_schema_with_unique_id.rb +2 -2
- data/spec/schemas/my_namespace/my_updated_schema.rb +1 -1
- data/spec/schemas/my_namespace/request/create_topic.rb +2 -2
- data/spec/schemas/my_namespace/request/index.rb +2 -2
- data/spec/schemas/my_namespace/request/update_request.rb +2 -2
- data/spec/schemas/my_namespace/response/create_topic.rb +2 -2
- data/spec/schemas/my_namespace/response/index.rb +2 -2
- data/spec/schemas/my_namespace/response/update_response.rb +2 -2
- data/spec/schemas/my_namespace/wibble.rb +2 -2
- data/spec/schemas/my_namespace/widget.rb +2 -2
- data/spec/schemas/my_namespace/widget_the_second.rb +2 -2
- data/spec/schemas/my_namespace/widget_the_third.rb +2 -2
- data/spec/spec_helper.rb +2 -2
- data/spec/utils/db_poller_spec.rb +1 -1
- metadata +18 -27
- data/lib/deimos/schema_class/base.rb +0 -62
- data/lib/deimos/schema_class/enum.rb +0 -49
- data/lib/deimos/schema_class/record.rb +0 -100
- data/lib/generators/deimos/schema_class/templates/schema_class.rb.tt +0 -8
- data/lib/generators/deimos/schema_class/templates/schema_enum.rb.tt +0 -13
- data/lib/generators/deimos/schema_class/templates/schema_record.rb.tt +0 -102
- data/lib/generators/deimos/schema_class_generator.rb +0 -369
- data/spec/generators/schema_class/my_schema_spec.rb +0 -16
- data/spec/generators/schema_class/my_schema_with_circular_reference_spec.rb +0 -98
- data/spec/generators/schema_class/my_schema_with_complex_types_spec.rb +0 -237
- data/spec/generators/schema_class_generator_spec.rb +0 -283
- data/spec/snapshots/consumers-no-nest.snap +0 -1740
- data/spec/snapshots/consumers.snap +0 -1720
- data/spec/snapshots/consumers_and_producers-no-nest.snap +0 -1740
- data/spec/snapshots/consumers_and_producers.snap +0 -1720
- data/spec/snapshots/consumers_circular-no-nest.snap +0 -1740
- data/spec/snapshots/consumers_circular.snap +0 -1720
- data/spec/snapshots/consumers_complex_types-no-nest.snap +0 -1740
- data/spec/snapshots/consumers_complex_types.snap +0 -1720
- data/spec/snapshots/consumers_nested-no-nest.snap +0 -1740
- data/spec/snapshots/consumers_nested.snap +0 -1720
- data/spec/snapshots/namespace_folders.snap +0 -1800
- data/spec/snapshots/namespace_map.snap +0 -1800
- data/spec/snapshots/producers_with_key-no-nest.snap +0 -1740
- data/spec/snapshots/producers_with_key.snap +0 -1720
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# For testing the generated class.
|
|
4
|
-
RSpec.describe Schemas::MyNamespace::MySchemaWithComplexType do
|
|
5
|
-
let(:payload_hash) do
|
|
6
|
-
{
|
|
7
|
-
test_id: 'test id',
|
|
8
|
-
test_float: 1.2,
|
|
9
|
-
test_string_array: %w(abc def),
|
|
10
|
-
test_int_array: [123, 456],
|
|
11
|
-
some_integer_map: { 'int_1' => 1, 'int_2' => 2 },
|
|
12
|
-
some_record: described_class::ARecord.new(a_record_field: 'field 1'),
|
|
13
|
-
some_optional_record: described_class::ARecord.new(a_record_field: 'field 2'),
|
|
14
|
-
some_record_array: [described_class::ARecord.new(a_record_field: 'field 3'),
|
|
15
|
-
described_class::ARecord.new(a_record_field: 'field 4')],
|
|
16
|
-
some_record_map: {
|
|
17
|
-
'record_1' => described_class::ARecord.new(a_record_field: 'field 5'),
|
|
18
|
-
'record_2' => described_class::ARecord.new(a_record_field: 'field 6')
|
|
19
|
-
},
|
|
20
|
-
some_enum_array: [described_class::AnEnum.new('sym1'),
|
|
21
|
-
described_class::AnEnum.new('sym2')]
|
|
22
|
-
}
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
describe 'class initialization' do
|
|
26
|
-
|
|
27
|
-
it 'should initialize the class from keyword arguments' do
|
|
28
|
-
klass = described_class.new(
|
|
29
|
-
test_id: payload_hash[:test_id],
|
|
30
|
-
test_float: payload_hash[:test_float],
|
|
31
|
-
test_string_array: payload_hash[:test_string_array],
|
|
32
|
-
some_record: payload_hash[:some_record],
|
|
33
|
-
some_optional_record: payload_hash[:some_optional_record],
|
|
34
|
-
some_record_array: payload_hash[:some_record_array],
|
|
35
|
-
some_record_map: payload_hash[:some_record_map],
|
|
36
|
-
some_enum_array: payload_hash[:some_enum_array]
|
|
37
|
-
)
|
|
38
|
-
expect(klass).to be_instance_of(described_class)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it 'should initialize the class from a hash with symbols as keys' do
|
|
42
|
-
klass = described_class.new(**payload_hash)
|
|
43
|
-
expect(klass).to be_instance_of(described_class)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it 'should initialize the class when missing attributes' do
|
|
47
|
-
payload_hash.delete(:test_id)
|
|
48
|
-
klass = described_class.new(**payload_hash)
|
|
49
|
-
expect(klass).to be_instance_of(described_class)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
describe '.tombstone' do
|
|
55
|
-
it 'should return a tombstone' do
|
|
56
|
-
record = described_class.tombstone('foo')
|
|
57
|
-
expect(record.tombstone_key).to eq('foo')
|
|
58
|
-
expect(record.to_h).to eq({ payload_key: 'foo' })
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
describe 'base class methods' do
|
|
63
|
-
let(:klass) do
|
|
64
|
-
described_class.new(**payload_hash)
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
let(:schema_fields) do
|
|
68
|
-
%w(test_id test_float test_int_array test_optional_int test_string_array some_integer_map
|
|
69
|
-
some_record some_optional_record some_record_array some_record_map some_enum_array
|
|
70
|
-
some_optional_enum some_enum_with_default union_string)
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
it 'should return the name of the schema and namespace' do
|
|
74
|
-
expect(klass.schema).to eq('MySchemaWithComplexTypes')
|
|
75
|
-
expect(klass.namespace).to eq('com.my-namespace')
|
|
76
|
-
expect(klass.full_schema).to eq('com.my-namespace.MySchemaWithComplexTypes')
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
it 'should return an array of all fields in the schema' do
|
|
80
|
-
expect(klass.schema_fields).to match_array(schema_fields)
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
it 'should return a json version of the payload' do
|
|
84
|
-
described_class.new(**payload_hash)
|
|
85
|
-
payload_h = {
|
|
86
|
-
'test_id' => 'test id',
|
|
87
|
-
'test_float' => 1.2,
|
|
88
|
-
'test_string_array' => %w(abc def),
|
|
89
|
-
'test_int_array' => [123, 456],
|
|
90
|
-
'some_optional_enum' => nil,
|
|
91
|
-
'test_optional_int' => 123,
|
|
92
|
-
'some_integer_map' => { 'int_1' => 1, 'int_2' => 2 },
|
|
93
|
-
'some_record' => { 'a_record_field' => 'field 1' },
|
|
94
|
-
'some_optional_record' => { 'a_record_field' => 'field 2' },
|
|
95
|
-
'some_record_array' => [
|
|
96
|
-
{ 'a_record_field' => 'field 3' },
|
|
97
|
-
{ 'a_record_field' => 'field 4' }
|
|
98
|
-
],
|
|
99
|
-
'some_record_map' => {
|
|
100
|
-
'record_1' => { 'a_record_field' => 'field 5' },
|
|
101
|
-
'record_2' => { 'a_record_field' => 'field 6' }
|
|
102
|
-
},
|
|
103
|
-
'some_enum_array' => %w(sym1 sym2),
|
|
104
|
-
'some_enum_with_default' => 'sym6',
|
|
105
|
-
'union_string' => ''
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
expect(klass.as_json).to eq(payload_h)
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
it 'should return a JSON string of the payload' do
|
|
112
|
-
s = '{"test_id":"test ' \
|
|
113
|
-
'id","union_string":"","test_float":1.2,"test_string_array":["abc","def"],"test_int_array":[123,456],"test_' \
|
|
114
|
-
'optional_i' \
|
|
115
|
-
'nt":123,"some_integer_map":{"int_1":1,"int_2":2},"some_record":{"a_record_field":"field ' \
|
|
116
|
-
'1"},"some_optional_record":{"a_record_field":"field 2"},"some_record_array":[{"a_record_field":"field ' \
|
|
117
|
-
'3"},{"a_record_field":"field 4"}],"some_record_map":{"record_1":{"a_record_field":"field ' \
|
|
118
|
-
'5"},"record_2":{"a_record_field":"field ' \
|
|
119
|
-
'6"}},"some_enum_array":["sym1","sym2"],"some_optional_enum":null,"some_enum_with_default":"sym6"}'
|
|
120
|
-
expect(klass.to_json).to eq(s)
|
|
121
|
-
end
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
describe 'defaults' do
|
|
125
|
-
it 'should set an_optional_int if it is not provided' do
|
|
126
|
-
payload_hash.delete(:an_optional_int)
|
|
127
|
-
klass = described_class.new(**payload_hash)
|
|
128
|
-
expect(klass.test_optional_int).to eq(123)
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
it 'should set some_record if it is not provided' do
|
|
132
|
-
payload_hash.delete(:some_record)
|
|
133
|
-
klass = described_class.new(**payload_hash)
|
|
134
|
-
expect(klass.some_record).
|
|
135
|
-
to eq(described_class::ARecord.new(a_record_field: 'Test String'))
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
it 'should set some_record to nil' do
|
|
139
|
-
klass = described_class.new(**payload_hash, some_record: nil)
|
|
140
|
-
expect(klass.some_record).to be_nil
|
|
141
|
-
end
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
describe 'getters and setters' do
|
|
145
|
-
let(:klass) do
|
|
146
|
-
described_class.new(**payload_hash)
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
context 'when getting attributes' do
|
|
150
|
-
it 'should get of values of primitive types' do
|
|
151
|
-
expect(klass.test_id).to eq('test id')
|
|
152
|
-
expect(klass.test_float).to eq(1.2)
|
|
153
|
-
expect(klass.test_string_array).to eq(%w(abc def))
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
it 'should get the value of some_record_array' do
|
|
157
|
-
some_record_array = klass.some_record_array
|
|
158
|
-
expect(some_record_array.first).to be_instance_of(described_class::ARecord)
|
|
159
|
-
expect(some_record_array.first.a_record_field).to eq('field 3')
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
it 'should get the value of some_record_map' do
|
|
163
|
-
some_record_map = klass.some_record_map
|
|
164
|
-
expect(some_record_map['record_1']).
|
|
165
|
-
to be_instance_of(described_class::ARecord)
|
|
166
|
-
expect(some_record_map['record_1'].a_record_field).to eq('field 5')
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
it 'should get the value of some_enum_array' do
|
|
170
|
-
some_enum_array = klass.some_enum_array
|
|
171
|
-
expect(some_enum_array.first).to be_instance_of(described_class::AnEnum)
|
|
172
|
-
expect(some_enum_array.first.value).to eq('sym1')
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
it 'should get the value of some_record' do
|
|
176
|
-
record = klass.some_record
|
|
177
|
-
expect(record).to be_instance_of(described_class::ARecord)
|
|
178
|
-
expect(record.a_record_field).to eq('field 1')
|
|
179
|
-
expect(record.to_h).to eq({ 'a_record_field' => 'field 1' })
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
it 'should support Hash-style element access of values' do
|
|
183
|
-
expect(klass['test_id']).to eq('test id')
|
|
184
|
-
expect(klass['test_float']).to eq(1.2)
|
|
185
|
-
expect(klass['test_string_array']).to eq(%w(abc def))
|
|
186
|
-
end
|
|
187
|
-
end
|
|
188
|
-
|
|
189
|
-
context 'when setting attributes' do
|
|
190
|
-
it 'should modify the value of test_id' do
|
|
191
|
-
expect(klass.test_id).to eq('test id')
|
|
192
|
-
|
|
193
|
-
klass.test_id = 'something different'
|
|
194
|
-
expect(klass.test_id).to eq('something different')
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
it 'should modify the value of some_optional_record' do
|
|
198
|
-
expect(klass.some_optional_record).
|
|
199
|
-
to eq(described_class::ARecord.new(a_record_field: 'field 2'))
|
|
200
|
-
klass.some_optional_record = described_class::ARecord.
|
|
201
|
-
new(a_record_field: 'new field')
|
|
202
|
-
|
|
203
|
-
expect(klass.some_optional_record).to eq(described_class::ARecord.
|
|
204
|
-
new(a_record_field: 'new field'))
|
|
205
|
-
expect(klass.some_optional_record.as_json).to eq({ 'a_record_field' => 'new field' })
|
|
206
|
-
end
|
|
207
|
-
|
|
208
|
-
it 'should accept a hash object inner records' do
|
|
209
|
-
klass.some_optional_record = { a_record_field: 'new field' }
|
|
210
|
-
expect(klass.some_optional_record).
|
|
211
|
-
to eq(described_class::ARecord.new(a_record_field: 'new field'))
|
|
212
|
-
expect(klass.some_optional_record.as_json).to eq({ 'a_record_field' => 'new field' })
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
it 'should modify the value of some_enum_array' do
|
|
216
|
-
klass.some_enum_array.first.value = 'new_sym'
|
|
217
|
-
expect(klass.some_enum_array.first).
|
|
218
|
-
to eq(described_class::AnEnum.new('new_sym'))
|
|
219
|
-
|
|
220
|
-
klass.some_enum_array.second.value = described_class::AnEnum.
|
|
221
|
-
new('other_sym')
|
|
222
|
-
expect(klass.some_enum_array.second.value).to eq('other_sym')
|
|
223
|
-
end
|
|
224
|
-
|
|
225
|
-
it 'should modify the value of some_record_map' do
|
|
226
|
-
klass.some_record_map['record_1'].a_record_field = 'new field'
|
|
227
|
-
expect(klass.some_record_map['record_1']).to eq(described_class::ARecord.
|
|
228
|
-
new(a_record_field: 'new field'))
|
|
229
|
-
|
|
230
|
-
klass.some_record_map['record_2'] = described_class::ARecord.
|
|
231
|
-
new(a_record_field: 'other field')
|
|
232
|
-
expect(klass.some_record_map['record_2']).to eq(described_class::ARecord.
|
|
233
|
-
new(a_record_field: 'other field'))
|
|
234
|
-
end
|
|
235
|
-
end
|
|
236
|
-
end
|
|
237
|
-
end
|
|
@@ -1,283 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'generators/deimos/schema_class_generator'
|
|
4
|
-
require 'fileutils'
|
|
5
|
-
|
|
6
|
-
class MultiFileSerializer
|
|
7
|
-
def process_string(str)
|
|
8
|
-
# Ruby 3.4 changes how hashes are printed
|
|
9
|
-
if Gem::Version.new(RUBY_VERSION) > Gem::Version.new('3.4.0')
|
|
10
|
-
str.gsub(/{"(.*)" => /, '{"\1"=>')
|
|
11
|
-
else
|
|
12
|
-
str
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def dump(value)
|
|
17
|
-
value.keys.sort.map { |k| "#{k}:\n#{process_string(value[k])}\n" }.join("\n")
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
RSpec.describe Deimos::Generators::SchemaClassGenerator do
|
|
22
|
-
let(:schema_class_path) { 'spec/app/lib/schema_classes' }
|
|
23
|
-
let(:files) { Dir["#{schema_class_path}/**/*.rb"].to_h { |f| [f, File.read(f)]} }
|
|
24
|
-
|
|
25
|
-
before(:each) do
|
|
26
|
-
Deimos.config.reset!
|
|
27
|
-
Deimos.configure do
|
|
28
|
-
schema.path 'spec/schemas/'
|
|
29
|
-
schema.generated_class_path 'spec/app/lib/schema_classes'
|
|
30
|
-
schema.backend :avro_local
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
after(:each) do
|
|
35
|
-
FileUtils.rm_rf('spec/app')
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
context 'with a Consumers Schema' do
|
|
39
|
-
before(:each) do
|
|
40
|
-
Karafka::App.routes.redraw do
|
|
41
|
-
topic 'MyTopic' do
|
|
42
|
-
consumer ConsumerTest::MyConsumer
|
|
43
|
-
schema 'Generated'
|
|
44
|
-
namespace 'com.my-namespace'
|
|
45
|
-
key_config field: :a_string
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
context 'nested true' do
|
|
51
|
-
it 'should generate the correct classes' do
|
|
52
|
-
Deimos.with_config('schema.nest_child_schemas' => true) do
|
|
53
|
-
described_class.start
|
|
54
|
-
expect(files).to match_snapshot('consumers', snapshot_serializer: MultiFileSerializer)
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
context 'nested false' do
|
|
60
|
-
it 'should generate the correct classes' do
|
|
61
|
-
Deimos.with_config('schema.nest_child_schemas' => false) do
|
|
62
|
-
described_class.start
|
|
63
|
-
expect(files).to match_snapshot('consumers-no-nest', snapshot_serializer: MultiFileSerializer)
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
context 'with a Consumers Schema with Complex types' do
|
|
70
|
-
before(:each) do
|
|
71
|
-
Deimos.configure do
|
|
72
|
-
consumer do
|
|
73
|
-
class_name 'ConsumerTest::MyConsumer'
|
|
74
|
-
topic 'MyTopic'
|
|
75
|
-
schema 'MySchemaWithComplexTypes'
|
|
76
|
-
namespace 'com.my-namespace'
|
|
77
|
-
key_config field: :a_string
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
context 'nested true' do
|
|
83
|
-
it 'should generate the correct classes' do
|
|
84
|
-
Deimos.with_config('schema.nest_child_schemas' => true) do
|
|
85
|
-
described_class.start
|
|
86
|
-
expect(files).to match_snapshot('consumers_complex_types', snapshot_serializer: MultiFileSerializer)
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
context 'nested false' do
|
|
92
|
-
it 'should generate the correct classes' do
|
|
93
|
-
Deimos.with_config('schema.nest_child_schemas' => false) do
|
|
94
|
-
described_class.start
|
|
95
|
-
expect(files).to match_snapshot('consumers_complex_types-no-nest', snapshot_serializer: MultiFileSerializer)
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
context 'with a Consumers Schema with a circular reference' do
|
|
102
|
-
before(:each) do
|
|
103
|
-
Deimos.configure do
|
|
104
|
-
consumer do
|
|
105
|
-
class_name 'ConsumerTest::MyConsumer'
|
|
106
|
-
topic 'MyTopic'
|
|
107
|
-
schema 'MySchemaWithCircularReference'
|
|
108
|
-
namespace 'com.my-namespace'
|
|
109
|
-
key_config field: :a_string
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
context 'nested true' do
|
|
115
|
-
it 'should generate the correct classes' do
|
|
116
|
-
Deimos.with_config('schema.nest_child_schemas' => true) do
|
|
117
|
-
described_class.start
|
|
118
|
-
expect(files).to match_snapshot('consumers_circular', snapshot_serializer: MultiFileSerializer)
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
context 'nested false' do
|
|
124
|
-
it 'should generate the correct classes' do
|
|
125
|
-
Deimos.with_config('schema.nest_child_schemas' => false) do
|
|
126
|
-
described_class.start
|
|
127
|
-
expect(files).to match_snapshot('consumers_circular-no-nest', snapshot_serializer: MultiFileSerializer)
|
|
128
|
-
end
|
|
129
|
-
end
|
|
130
|
-
end
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
context 'with a Producers Schema and a Key' do
|
|
134
|
-
before(:each) do
|
|
135
|
-
Deimos.configure do
|
|
136
|
-
producer do
|
|
137
|
-
class_name 'ConsumerTest::MyConsumer'
|
|
138
|
-
topic 'MyTopic'
|
|
139
|
-
schema 'MySchema'
|
|
140
|
-
namespace 'com.my-namespace'
|
|
141
|
-
key_config schema: 'MySchema_key'
|
|
142
|
-
end
|
|
143
|
-
end
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
context 'nested true' do
|
|
147
|
-
it 'should generate the correct classes' do
|
|
148
|
-
Deimos.with_config('schema.nest_child_schemas' => true) do
|
|
149
|
-
described_class.start
|
|
150
|
-
expect(files).to match_snapshot('producers_with_key', snapshot_serializer: MultiFileSerializer)
|
|
151
|
-
end
|
|
152
|
-
end
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
context 'nested false' do
|
|
156
|
-
it 'should generate the correct classes' do
|
|
157
|
-
Deimos.with_config('schema.nest_child_schemas' => false) do
|
|
158
|
-
described_class.start
|
|
159
|
-
expect(files).to match_snapshot('producers_with_key-no-nest', snapshot_serializer: MultiFileSerializer)
|
|
160
|
-
end
|
|
161
|
-
end
|
|
162
|
-
end
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
context 'with a Consumers Nested Schema' do
|
|
166
|
-
before(:each) do
|
|
167
|
-
Deimos.configure do
|
|
168
|
-
consumer do
|
|
169
|
-
class_name 'ConsumerTest::MyConsumer'
|
|
170
|
-
topic 'MyTopic'
|
|
171
|
-
schema 'MyNestedSchema'
|
|
172
|
-
namespace 'com.my-namespace'
|
|
173
|
-
key_config field: :test_id
|
|
174
|
-
end
|
|
175
|
-
end
|
|
176
|
-
end
|
|
177
|
-
|
|
178
|
-
context 'nested true' do
|
|
179
|
-
it 'should generate the correct classes' do
|
|
180
|
-
Deimos.with_config('schema.nest_child_schemas' => true) do
|
|
181
|
-
described_class.start
|
|
182
|
-
expect(files).to match_snapshot('consumers_nested', snapshot_serializer: MultiFileSerializer)
|
|
183
|
-
end
|
|
184
|
-
end
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
context 'nested false' do
|
|
188
|
-
it 'should generate the correct classes' do
|
|
189
|
-
Deimos.with_config('schema.nest_child_schemas' => false) do
|
|
190
|
-
described_class.start
|
|
191
|
-
expect(files).to match_snapshot('consumers_nested-no-nest', snapshot_serializer: MultiFileSerializer)
|
|
192
|
-
end
|
|
193
|
-
end
|
|
194
|
-
end
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
context 'with a mix of Consumer and Producer Schemas' do
|
|
198
|
-
before(:each) do
|
|
199
|
-
Deimos.configure do
|
|
200
|
-
consumer do
|
|
201
|
-
class_name 'ConsumerTest::MyConsumer'
|
|
202
|
-
topic 'MyTopic'
|
|
203
|
-
schema 'Generated'
|
|
204
|
-
namespace 'com.my-namespace'
|
|
205
|
-
key_config field: :a_string
|
|
206
|
-
end
|
|
207
|
-
|
|
208
|
-
producer do
|
|
209
|
-
class_name 'ConsumerTest::MyConsumer'
|
|
210
|
-
topic 'MyTopic'
|
|
211
|
-
schema 'MySchema'
|
|
212
|
-
namespace 'com.my-namespace'
|
|
213
|
-
key_config schema: 'MySchema_key'
|
|
214
|
-
end
|
|
215
|
-
|
|
216
|
-
producer do
|
|
217
|
-
class_name 'ConsumerTest::MyConsumer'
|
|
218
|
-
topic 'MyTopic'
|
|
219
|
-
schema 'MyNestedSchema'
|
|
220
|
-
namespace 'com.my-namespace'
|
|
221
|
-
key_config field: :test_id
|
|
222
|
-
end
|
|
223
|
-
end
|
|
224
|
-
end
|
|
225
|
-
|
|
226
|
-
context 'with namespace folders' do
|
|
227
|
-
it 'should generate the correct classes' do
|
|
228
|
-
Deimos.with_config('schema.use_full_namespace' => true) do
|
|
229
|
-
described_class.start
|
|
230
|
-
expect(files).to match_snapshot('namespace_folders', snapshot_serializer: MultiFileSerializer)
|
|
231
|
-
end
|
|
232
|
-
end
|
|
233
|
-
end
|
|
234
|
-
|
|
235
|
-
context 'with namespace map' do
|
|
236
|
-
it 'should generate the correct classes' do
|
|
237
|
-
Deimos.with_config(
|
|
238
|
-
{
|
|
239
|
-
'schema.use_full_namespace' => true,
|
|
240
|
-
'schema.schema_namespace_map' => {
|
|
241
|
-
'com' => 'Schemas',
|
|
242
|
-
'com.my-namespace.my-suborg' => %w(Schemas MyNamespace)
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
) do
|
|
246
|
-
described_class.start
|
|
247
|
-
expect(files).to match_snapshot('namespace_map', snapshot_serializer: MultiFileSerializer)
|
|
248
|
-
end
|
|
249
|
-
end
|
|
250
|
-
end
|
|
251
|
-
|
|
252
|
-
context 'nested true' do
|
|
253
|
-
it 'should generate the correct classes' do
|
|
254
|
-
Deimos.with_config('schema.nest_child_schemas' => true) do
|
|
255
|
-
described_class.start
|
|
256
|
-
expect(files).to match_snapshot('consumers_and_producers', snapshot_serializer: MultiFileSerializer)
|
|
257
|
-
end
|
|
258
|
-
end
|
|
259
|
-
end
|
|
260
|
-
|
|
261
|
-
context 'nested false' do
|
|
262
|
-
it 'should generate the correct classes' do
|
|
263
|
-
Deimos.with_config('schema.nest_child_schemas' => false) do
|
|
264
|
-
described_class.start
|
|
265
|
-
expect(files).to match_snapshot('consumers_and_producers-no-nest', snapshot_serializer: MultiFileSerializer)
|
|
266
|
-
end
|
|
267
|
-
end
|
|
268
|
-
end
|
|
269
|
-
end
|
|
270
|
-
|
|
271
|
-
context 'with non-avro schema backends' do
|
|
272
|
-
before(:each) do
|
|
273
|
-
Deimos.config.schema.backend :mock
|
|
274
|
-
end
|
|
275
|
-
|
|
276
|
-
it 'should fail to start schema class generation' do
|
|
277
|
-
expect {
|
|
278
|
-
described_class.start
|
|
279
|
-
}.to raise_error(message='Schema Class Generation requires an Avro-based Schema Backend')
|
|
280
|
-
end
|
|
281
|
-
end
|
|
282
|
-
|
|
283
|
-
end
|