fluent-plugin-droonga 0.9.9 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.dir-locals.el +3 -0
- data/.travis.yml +6 -2
- data/README.md +6 -7
- data/Rakefile +23 -6
- data/fluent-plugin-droonga.gemspec +2 -2
- data/lib/droonga/adapter.rb +12 -3
- data/lib/droonga/adapter_runner.rb +28 -23
- data/lib/droonga/catalog/base.rb +7 -111
- data/lib/droonga/catalog/dataset.rb +13 -25
- data/lib/droonga/catalog/errors.rb +94 -0
- data/lib/droonga/catalog/schema.rb +277 -0
- data/lib/droonga/catalog/version1.rb +404 -0
- data/lib/droonga/catalog/version2.rb +160 -0
- data/lib/droonga/catalog_loader.rb +27 -4
- data/lib/droonga/catalog_observer.rb +44 -6
- data/lib/droonga/collector.rb +12 -10
- data/lib/droonga/{handler_plugin.rb → collector_message.rb} +47 -20
- data/lib/droonga/collector_runner.rb +64 -0
- data/lib/droonga/collectors.rb +18 -0
- data/lib/droonga/{catalog.rb → collectors/add.rb} +9 -7
- data/lib/droonga/{command_repository.rb → collectors/and.rb} +7 -14
- data/lib/droonga/collectors/sum.rb +26 -0
- data/lib/droonga/dispatcher.rb +74 -41
- data/lib/droonga/distributed_command_planner.rb +2 -2
- data/lib/droonga/engine.rb +13 -5
- data/lib/droonga/{message_processing_error.rb → error.rb} +33 -12
- data/lib/droonga/{plugin/planner/search.rb → error_messages.rb} +12 -10
- data/lib/droonga/farm.rb +15 -14
- data/lib/droonga/fluent_message_sender.rb +15 -11
- data/lib/droonga/forwarder.rb +22 -18
- data/lib/droonga/handler.rb +8 -2
- data/lib/droonga/handler_runner.rb +47 -26
- data/lib/droonga/input_message.rb +6 -6
- data/lib/droonga/{command.rb → loggable.rb} +7 -14
- data/lib/droonga/logger.rb +56 -15
- data/lib/droonga/message_matcher.rb +12 -7
- data/lib/droonga/message_pusher.rb +8 -4
- data/lib/droonga/message_receiver.rb +11 -9
- data/lib/droonga/output_message.rb +2 -0
- data/lib/droonga/planner.rb +21 -10
- data/lib/droonga/plugin.rb +15 -0
- data/lib/droonga/plugin/metadata/{adapter_message.rb → adapter_input_message.rb} +6 -14
- data/lib/droonga/plugin/metadata/adapter_output_message.rb +39 -0
- data/lib/droonga/plugin/metadata/collector_message.rb +39 -0
- data/lib/droonga/plugin/metadata/input_message.rb +15 -0
- data/lib/droonga/plugin_loader.rb +33 -25
- data/lib/droonga/plugin_registry.rb +9 -1
- data/lib/droonga/plugins/basic.rb +54 -0
- data/lib/droonga/plugins/crud.rb +36 -15
- data/lib/droonga/plugins/error.rb +5 -4
- data/lib/droonga/plugins/groonga.rb +9 -6
- data/lib/droonga/plugins/groonga/column_create.rb +10 -5
- data/lib/droonga/plugins/groonga/generic_command.rb +2 -8
- data/lib/droonga/plugins/groonga/generic_response.rb +2 -2
- data/lib/droonga/plugins/groonga/select.rb +2 -2
- data/lib/droonga/plugins/groonga/table_create.rb +9 -4
- data/lib/droonga/plugins/groonga/table_remove.rb +10 -5
- data/lib/droonga/plugins/search.rb +106 -5
- data/lib/droonga/plugins/search/distributed_search_planner.rb +398 -0
- data/lib/droonga/plugins/watch.rb +41 -20
- data/lib/droonga/processor.rb +12 -9
- data/lib/droonga/{plugin/collector/basic.rb → reducer.rb} +36 -50
- data/lib/droonga/replier.rb +7 -4
- data/lib/droonga/searcher.rb +40 -37
- data/lib/droonga/server.rb +8 -6
- data/lib/droonga/session.rb +17 -7
- data/lib/droonga/single_step.rb +53 -0
- data/lib/droonga/{plugin/planner/watch.rb → single_step_definition.rb} +27 -26
- data/lib/droonga/{partition.rb → slice.rb} +23 -12
- data/lib/droonga/status_code.rb +25 -0
- data/lib/droonga/step_runner.rb +63 -0
- data/lib/droonga/watch_schema.rb +7 -3
- data/lib/droonga/watcher.rb +4 -4
- data/lib/droonga/worker.rb +6 -6
- data/lib/fluent/plugin/out_droonga.rb +27 -2
- data/sample/cluster/catalog.json +33 -32
- data/test/command/config/default/catalog.json +72 -45
- data/test/command/config/version1/catalog.json +68 -0
- data/test/command/config/version1/fluentd.conf +11 -0
- data/test/command/suite/message/error/missing-dataset.expected +1 -1
- data/test/command/suite/message/error/unknown-dataset.expected +1 -1
- data/test/command/suite/message/error/unknown-type.expected +13 -0
- data/test/command/suite/message/error/{unknown-command.test → unknown-type.test} +1 -1
- data/test/command/suite/search/error/missing-source-parameter.expected +1 -1
- data/test/command/suite/search/error/unknown-source.expected +15 -3
- data/test/command/suite/watch/subscribe.expected +1 -3
- data/test/command/suite/watch/unsubscribe.expected +1 -3
- data/test/performance/watch/catalog.json +1 -0
- data/test/unit/catalog/test_dataset.rb +16 -358
- data/test/unit/catalog/test_schema.rb +285 -0
- data/test/unit/catalog/test_version1.rb +222 -28
- data/test/unit/catalog/test_version2.rb +155 -0
- data/test/unit/fixtures/catalog/version2.json +62 -0
- data/test/unit/helper/distributed_search_planner_helper.rb +2 -2
- data/test/unit/plugins/crud/test_add.rb +13 -13
- data/test/unit/plugins/groonga/test_column_create.rb +14 -11
- data/test/unit/plugins/groonga/test_table_create.rb +4 -9
- data/test/unit/plugins/groonga/test_table_remove.rb +4 -9
- data/test/unit/{plugin/planner/search_planner → plugins/search/planner}/test_basic.rb +0 -0
- data/test/unit/{plugin/planner/search_planner → plugins/search/planner}/test_group_by.rb +0 -0
- data/test/unit/{plugin/planner/search_planner → plugins/search/planner}/test_output.rb +0 -0
- data/test/unit/{plugin/planner/search_planner → plugins/search/planner}/test_sort_by.rb +0 -0
- data/test/unit/{plugin/collector/test_search.rb → plugins/search/test_collector.rb} +40 -39
- data/test/unit/plugins/{test_search.rb → search/test_handler.rb} +6 -5
- data/test/unit/{plugin/planner/test_search.rb → plugins/search/test_planner.rb} +3 -3
- data/test/unit/{plugin/collector → plugins}/test_basic.rb +68 -50
- data/test/unit/plugins/test_groonga.rb +2 -15
- data/test/unit/plugins/test_watch.rb +25 -22
- data/test/unit/test_message_matcher.rb +29 -6
- data/test/unit/test_output.rb +4 -0
- metadata +58 -50
- data/lib/droonga/collector_plugin.rb +0 -50
- data/lib/droonga/legacy_pluggable.rb +0 -66
- data/lib/droonga/legacy_plugin.rb +0 -57
- data/lib/droonga/legacy_plugin_repository.rb +0 -54
- data/lib/droonga/planner_plugin.rb +0 -54
- data/lib/droonga/plugin/collector/search.rb +0 -98
- data/lib/droonga/plugin/planner/crud.rb +0 -49
- data/lib/droonga/plugin/planner/distributed_search_planner.rb +0 -393
- data/lib/droonga/plugin/planner/groonga.rb +0 -54
- data/lib/droonga/plugin_registerable.rb +0 -75
- data/test/command/suite/message/error/unknown-command.expected +0 -13
- data/test/unit/test_command_repository.rb +0 -39
- data/test/unit/test_legacy_plugin.rb +0 -50
- data/test/unit/test_legacy_plugin_repository.rb +0 -89
@@ -0,0 +1,285 @@
|
|
1
|
+
# Copyright (C) 2014 Droonga Project
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License version 2.1 as published by the Free Software Foundation.
|
6
|
+
#
|
7
|
+
# This library is distributed in the hope that it will be useful,
|
8
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
9
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
10
|
+
# Lesser General Public License for more details.
|
11
|
+
#
|
12
|
+
# You should have received a copy of the GNU Lesser General Public
|
13
|
+
# License along with this library; if not, write to the Free Software
|
14
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
15
|
+
|
16
|
+
require "droonga/catalog/schema"
|
17
|
+
|
18
|
+
class CatalogSchemaTest < Test::Unit::TestCase
|
19
|
+
private
|
20
|
+
def create_schema(dataset_name, data)
|
21
|
+
Droonga::Catalog::Schema.new(dataset_name, data)
|
22
|
+
end
|
23
|
+
|
24
|
+
class SchemaTest < self
|
25
|
+
def test_schema_not_specified
|
26
|
+
assert_equal([],
|
27
|
+
create_schema("dataset_name", nil).to_messages)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_no_table
|
31
|
+
assert_equal([],
|
32
|
+
create_schema("dataset_name", {}).to_messages)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_key_index
|
36
|
+
assert_equal([
|
37
|
+
{
|
38
|
+
"type" => "table_create",
|
39
|
+
"dataset" => "dataset_name",
|
40
|
+
"body" => {
|
41
|
+
"name" => "Term",
|
42
|
+
"key_type" => "ShortText",
|
43
|
+
"flags" => "TABLE_PAT_KEY",
|
44
|
+
"normalizer" => "NormalizerAuto",
|
45
|
+
}
|
46
|
+
},
|
47
|
+
{
|
48
|
+
"type" => "table_create",
|
49
|
+
"dataset" => "dataset_name",
|
50
|
+
"body" => {
|
51
|
+
"name" => "Store",
|
52
|
+
"key_type" => "ShortText",
|
53
|
+
"flags" => "TABLE_HASH_KEY",
|
54
|
+
}
|
55
|
+
},
|
56
|
+
{
|
57
|
+
"type" => "column_create",
|
58
|
+
"dataset" => "dataset_name",
|
59
|
+
"body" => {
|
60
|
+
"name" => "stores__key",
|
61
|
+
"table" => "Term",
|
62
|
+
"type" => "Store",
|
63
|
+
"flags" => "COLUMN_INDEX",
|
64
|
+
"source" => "_key"
|
65
|
+
}
|
66
|
+
}
|
67
|
+
],
|
68
|
+
create_schema(
|
69
|
+
"dataset_name",
|
70
|
+
"Term" => {
|
71
|
+
"type" => "PatriciaTrie",
|
72
|
+
"keyType" => "ShortText",
|
73
|
+
"normalizer" => "NormalizerAuto",
|
74
|
+
"columns" => {
|
75
|
+
"stores__key" => {
|
76
|
+
"type" => "Index",
|
77
|
+
"valueType" => "Store",
|
78
|
+
"indexOptions" => {
|
79
|
+
"sources" => [
|
80
|
+
"_key"
|
81
|
+
]
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}
|
85
|
+
},
|
86
|
+
"Store" => {
|
87
|
+
"keyType" => "ShortText"
|
88
|
+
}
|
89
|
+
).to_messages)
|
90
|
+
end
|
91
|
+
|
92
|
+
class TableTest < self
|
93
|
+
def create_table(name, data)
|
94
|
+
Droonga::Catalog::Schema::Table.new(name, data)
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_name
|
98
|
+
assert_equal("table_name",
|
99
|
+
create_table("table_name",
|
100
|
+
{}).name)
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_type_default
|
104
|
+
assert_equal("Hash",
|
105
|
+
create_table("table_name",
|
106
|
+
{}).type)
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_type
|
110
|
+
assert_equal("Hash",
|
111
|
+
create_table("table_name",
|
112
|
+
{
|
113
|
+
"type" => "Hash"
|
114
|
+
}).type)
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_flags
|
118
|
+
assert_equal(["TABLE_HASH_KEY"],
|
119
|
+
create_table("table_name",
|
120
|
+
{
|
121
|
+
"type" => "Hash"
|
122
|
+
}).flags)
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_key_type
|
126
|
+
assert_equal("ShortText",
|
127
|
+
create_table("table_name",
|
128
|
+
{
|
129
|
+
"keyType" => "ShortText"
|
130
|
+
}).key_type)
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_key_type_groonga
|
134
|
+
assert_equal("Int64",
|
135
|
+
create_table("table_name",
|
136
|
+
{
|
137
|
+
"keyType" => "Integer"
|
138
|
+
}).key_type_groonga)
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_tokenizer
|
142
|
+
assert_equal("TokenBigram",
|
143
|
+
create_table("table_name",
|
144
|
+
{
|
145
|
+
"tokenizer" => "TokenBigram"
|
146
|
+
}).tokenizer)
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_normalizer
|
150
|
+
assert_equal("NormalizerAuto",
|
151
|
+
create_table("table_name",
|
152
|
+
{
|
153
|
+
"normalizer" => "NormalizerAuto"
|
154
|
+
}).normalizer)
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_to_table_create_body
|
158
|
+
assert_equal({
|
159
|
+
"name" => "table_name",
|
160
|
+
"key_type" => "ShortText",
|
161
|
+
"flags" => "TABLE_PAT_KEY",
|
162
|
+
"normalizer" => "NormalizerAuto",
|
163
|
+
"default_tokenizer" => "TokenBigram"
|
164
|
+
},
|
165
|
+
create_table("table_name",
|
166
|
+
{
|
167
|
+
"type" => "PatriciaTrie",
|
168
|
+
"keyType" => "ShortText",
|
169
|
+
"normalizer" => "NormalizerAuto",
|
170
|
+
"tokenizer" => "TokenBigram"
|
171
|
+
}).to_table_create_body)
|
172
|
+
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
class ColumnTest < self
|
177
|
+
def create_column(name, data)
|
178
|
+
Droonga::Catalog::Schema::Column.new("table_name", name, data)
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_name
|
182
|
+
assert_equal("column_name",
|
183
|
+
create_column("column_name",
|
184
|
+
{}).name)
|
185
|
+
end
|
186
|
+
|
187
|
+
def test_type
|
188
|
+
assert_equal("Scalar",
|
189
|
+
create_column("column_name",
|
190
|
+
{
|
191
|
+
"type" => "Scalar"
|
192
|
+
}).type)
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_type_default
|
196
|
+
assert_equal("Scalar",
|
197
|
+
create_column("column_name",
|
198
|
+
{}).type)
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_flags
|
202
|
+
assert_equal(["COLUMN_SCALAR"],
|
203
|
+
create_column("column_name",
|
204
|
+
{
|
205
|
+
"type" => "Scalar"
|
206
|
+
}).flags)
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_value_type
|
210
|
+
assert_equal("ShortText",
|
211
|
+
create_column("column_name",
|
212
|
+
{
|
213
|
+
"valueType" => "ShortText"
|
214
|
+
}).value_type)
|
215
|
+
end
|
216
|
+
|
217
|
+
def test_value_type_groonga
|
218
|
+
assert_equal("Int64",
|
219
|
+
create_column("column_name",
|
220
|
+
{
|
221
|
+
"valueType" => "Integer"
|
222
|
+
}).value_type_groonga)
|
223
|
+
end
|
224
|
+
|
225
|
+
def test_flags_with_column_index_options
|
226
|
+
assert_equal(["COLUMN_SCALAR", "WITH_SECTION"],
|
227
|
+
create_column("column_name",
|
228
|
+
{
|
229
|
+
"type" => "Scalar",
|
230
|
+
"indexOptions" => {
|
231
|
+
"section" => true
|
232
|
+
}
|
233
|
+
}).flags)
|
234
|
+
end
|
235
|
+
|
236
|
+
def test_to_column_create_body
|
237
|
+
assert_equal({
|
238
|
+
"name" => "column_name",
|
239
|
+
"flags" => "COLUMN_SCALAR",
|
240
|
+
"table" => "table_name",
|
241
|
+
"type" => "ShortText"
|
242
|
+
},
|
243
|
+
create_column("column_name",
|
244
|
+
{
|
245
|
+
"type" => "Scalar",
|
246
|
+
"valueType" => "ShortText"
|
247
|
+
}).to_column_create_body)
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
class ColumnIndexOptionsTest < self
|
252
|
+
def create_options(data)
|
253
|
+
Droonga::Catalog::Schema::ColumnIndexOptions.new(data)
|
254
|
+
end
|
255
|
+
|
256
|
+
def test_section
|
257
|
+
assert_equal(true,
|
258
|
+
create_options({
|
259
|
+
"section" => true
|
260
|
+
}).section)
|
261
|
+
end
|
262
|
+
|
263
|
+
def test_weight
|
264
|
+
assert_equal(true,
|
265
|
+
create_options({
|
266
|
+
"weight" => true
|
267
|
+
}).weight)
|
268
|
+
end
|
269
|
+
|
270
|
+
def test_position
|
271
|
+
assert_equal(true,
|
272
|
+
create_options({
|
273
|
+
"position" => true
|
274
|
+
}).position)
|
275
|
+
end
|
276
|
+
|
277
|
+
def test_flags
|
278
|
+
assert_equal(["WITH_SECTION"],
|
279
|
+
create_options({
|
280
|
+
"section" => true
|
281
|
+
}).flags)
|
282
|
+
end
|
283
|
+
end
|
284
|
+
end
|
285
|
+
end
|
@@ -15,39 +15,31 @@
|
|
15
15
|
|
16
16
|
require "droonga/catalog/version1"
|
17
17
|
|
18
|
-
class
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
class CatalogTestVersion1 < Test::Unit::TestCase
|
19
|
+
class << self
|
20
|
+
def minimum_data
|
21
|
+
{
|
22
|
+
"effective_date" => "2013-09-01T00:00:00Z",
|
23
|
+
"zones" => [],
|
24
|
+
"farms" => {},
|
25
|
+
"datasets" => {},
|
26
|
+
}
|
27
|
+
end
|
24
28
|
end
|
25
29
|
|
26
|
-
|
27
|
-
|
30
|
+
private
|
31
|
+
def minimum_data
|
32
|
+
self.class.minimum_data
|
28
33
|
end
|
29
34
|
|
30
|
-
|
31
|
-
|
32
|
-
super(minimum_data.merge("options" => options), "base-path")
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_nonexistent
|
36
|
-
catalog = create_catalog({})
|
37
|
-
assert_nil(catalog.option("nonexistent"))
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_existent
|
41
|
-
catalog = create_catalog("plugins" => ["crud", "groonga"])
|
42
|
-
assert_equal(["crud", "groonga"],
|
43
|
-
catalog.option("plugins"))
|
44
|
-
end
|
35
|
+
def create_catalog(data, path)
|
36
|
+
Droonga::Catalog::Version1.new(data, path)
|
45
37
|
end
|
46
38
|
|
47
39
|
class PartitionTest < self
|
48
40
|
def setup
|
49
41
|
data = JSON.parse(File.read(catalog_path))
|
50
|
-
@catalog = create_catalog(data,
|
42
|
+
@catalog = create_catalog(data, catalog_path)
|
51
43
|
end
|
52
44
|
|
53
45
|
def test_get_partitions
|
@@ -55,21 +47,25 @@ class CatalogTest < Test::Unit::TestCase
|
|
55
47
|
assert_equal({
|
56
48
|
"localhost:23003/test.000" => {
|
57
49
|
:database => "#{base_path}/000/db",
|
50
|
+
:dataset => "Test",
|
58
51
|
:plugins => ["for_dataset"],
|
59
52
|
:n_workers => 0
|
60
53
|
},
|
61
54
|
"localhost:23003/test.001" => {
|
62
55
|
:database => "#{base_path}/001/db",
|
56
|
+
:dataset => "Test",
|
63
57
|
:plugins => ["for_dataset"],
|
64
58
|
:n_workers => 0
|
65
59
|
},
|
66
60
|
"localhost:23003/test.002" => {
|
67
61
|
:database => "#{base_path}/002/db",
|
62
|
+
:dataset => "Test",
|
68
63
|
:plugins => ["for_dataset"],
|
69
64
|
:n_workers => 0
|
70
65
|
},
|
71
66
|
"localhost:23003/test.003" => {
|
72
67
|
:database => "#{base_path}/003/db",
|
68
|
+
:dataset => "Test",
|
73
69
|
:plugins => ["for_dataset"],
|
74
70
|
:n_workers => 0
|
75
71
|
},
|
@@ -91,7 +87,8 @@ class CatalogTest < Test::Unit::TestCase
|
|
91
87
|
|
92
88
|
class PluginsTest < self
|
93
89
|
def setup
|
94
|
-
@data = {
|
90
|
+
@data = minimum_data.merge({
|
91
|
+
"zones" => [farm_name],
|
95
92
|
"farms" => {
|
96
93
|
farm_name => {
|
97
94
|
"device" => ".",
|
@@ -99,7 +96,12 @@ class CatalogTest < Test::Unit::TestCase
|
|
99
96
|
},
|
100
97
|
"datasets" => {
|
101
98
|
"Droonga" => {
|
99
|
+
"workers" => 1,
|
102
100
|
"number_of_partitions" => 1,
|
101
|
+
"number_of_replicas" => 1,
|
102
|
+
"date_range" => "infinity",
|
103
|
+
"partition_key" => "_key",
|
104
|
+
"plugins" => [],
|
103
105
|
"ring" => {
|
104
106
|
"localhost:23041" => {
|
105
107
|
"weight" => 50,
|
@@ -112,7 +114,7 @@ class CatalogTest < Test::Unit::TestCase
|
|
112
114
|
},
|
113
115
|
},
|
114
116
|
},
|
115
|
-
}
|
117
|
+
})
|
116
118
|
end
|
117
119
|
|
118
120
|
def farm_name
|
@@ -120,7 +122,7 @@ class CatalogTest < Test::Unit::TestCase
|
|
120
122
|
end
|
121
123
|
|
122
124
|
def plugins(data)
|
123
|
-
catalog = create_catalog(data,
|
125
|
+
catalog = create_catalog(data, catalog_path)
|
124
126
|
catalog.get_partitions(farm_name).collect do |partition, options|
|
125
127
|
options[:plugins]
|
126
128
|
end
|
@@ -158,10 +160,202 @@ class CatalogTest < Test::Unit::TestCase
|
|
158
160
|
|
159
161
|
private
|
160
162
|
def total_weight(dataset)
|
161
|
-
catalog = create_catalog(
|
163
|
+
catalog = create_catalog(minimum_data,
|
164
|
+
"base-path")
|
162
165
|
catalog.send(:compute_total_weight, dataset)
|
163
166
|
end
|
164
167
|
end
|
165
168
|
end
|
166
169
|
end
|
170
|
+
|
171
|
+
class ValidationTest < self
|
172
|
+
class << self
|
173
|
+
def farm_name
|
174
|
+
"localhost:23041/droonga"
|
175
|
+
end
|
176
|
+
|
177
|
+
def ring_name
|
178
|
+
"localhost:23041"
|
179
|
+
end
|
180
|
+
|
181
|
+
def range_name
|
182
|
+
"2013-09-01"
|
183
|
+
end
|
184
|
+
|
185
|
+
def path
|
186
|
+
"path/to/catalog"
|
187
|
+
end
|
188
|
+
|
189
|
+
def valid_farms
|
190
|
+
{
|
191
|
+
farm_name => {
|
192
|
+
"device" => ".",
|
193
|
+
},
|
194
|
+
}
|
195
|
+
end
|
196
|
+
|
197
|
+
def valid_zones
|
198
|
+
valid_farms.keys
|
199
|
+
end
|
200
|
+
|
201
|
+
def valid_dataset_base
|
202
|
+
{
|
203
|
+
"workers" => 0,
|
204
|
+
"number_of_replicas" => 1,
|
205
|
+
"number_of_partitions" => 1,
|
206
|
+
"partition_key" => "_key",
|
207
|
+
"date_range" => "infinity",
|
208
|
+
"ring" => {},
|
209
|
+
}
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
data(
|
214
|
+
:missing_root_elements => {
|
215
|
+
:catalog => {},
|
216
|
+
:errors => [
|
217
|
+
Droonga::Catalog::MissingRequiredParameter.new(
|
218
|
+
"effective_date", path),
|
219
|
+
Droonga::Catalog::MissingRequiredParameter.new(
|
220
|
+
"zones", path),
|
221
|
+
Droonga::Catalog::MissingRequiredParameter.new(
|
222
|
+
"farms", path),
|
223
|
+
Droonga::Catalog::MissingRequiredParameter.new(
|
224
|
+
"datasets", path),
|
225
|
+
],
|
226
|
+
},
|
227
|
+
:invalid_farms => {
|
228
|
+
:catalog => minimum_data.merge(
|
229
|
+
"farms" => {
|
230
|
+
farm_name => {
|
231
|
+
},
|
232
|
+
},
|
233
|
+
"zones" => [farm_name],
|
234
|
+
),
|
235
|
+
:errors => [
|
236
|
+
Droonga::Catalog::MissingRequiredParameter.new(
|
237
|
+
"farms.#{farm_name}.device", path),
|
238
|
+
],
|
239
|
+
},
|
240
|
+
:missing_dataset_parameters => {
|
241
|
+
:catalog => minimum_data.merge(
|
242
|
+
"farms" => valid_farms,
|
243
|
+
"zones" => valid_zones,
|
244
|
+
"datasets" => {
|
245
|
+
"Droonga" => {
|
246
|
+
},
|
247
|
+
},
|
248
|
+
),
|
249
|
+
:errors => [
|
250
|
+
Droonga::Catalog::MissingRequiredParameter.new(
|
251
|
+
"datasets.Droonga.workers", path),
|
252
|
+
Droonga::Catalog::MissingRequiredParameter.new(
|
253
|
+
"datasets.Droonga.number_of_replicas", path),
|
254
|
+
Droonga::Catalog::MissingRequiredParameter.new(
|
255
|
+
"datasets.Droonga.number_of_partitions", path),
|
256
|
+
Droonga::Catalog::MissingRequiredParameter.new(
|
257
|
+
"datasets.Droonga.partition_key", path),
|
258
|
+
Droonga::Catalog::MissingRequiredParameter.new(
|
259
|
+
"datasets.Droonga.date_range", path),
|
260
|
+
Droonga::Catalog::MissingRequiredParameter.new(
|
261
|
+
"datasets.Droonga.ring", path),
|
262
|
+
],
|
263
|
+
},
|
264
|
+
:invalid_date_parameters => {
|
265
|
+
:catalog => minimum_data.merge(
|
266
|
+
"effective_date" => "invalid",
|
267
|
+
),
|
268
|
+
:errors => [
|
269
|
+
Droonga::Catalog::InvalidDate.new(
|
270
|
+
"effective_date", "invalid", path),
|
271
|
+
],
|
272
|
+
},
|
273
|
+
:non_integer_numeric_parameters => {
|
274
|
+
:catalog => minimum_data.merge(
|
275
|
+
"farms" => valid_farms,
|
276
|
+
"zones" => valid_zones,
|
277
|
+
"datasets" => {
|
278
|
+
"Droonga" => valid_dataset_base.merge(
|
279
|
+
"workers" => 0.1,
|
280
|
+
"number_of_replicas" => 0.1,
|
281
|
+
"number_of_partitions" => 0.1,
|
282
|
+
"ring" => {
|
283
|
+
ring_name => {
|
284
|
+
"weight" => 0.1,
|
285
|
+
"partitions" => {},
|
286
|
+
},
|
287
|
+
},
|
288
|
+
),
|
289
|
+
},
|
290
|
+
),
|
291
|
+
:errors => [
|
292
|
+
Droonga::Catalog::MismatchedParameterType.new(
|
293
|
+
"datasets.Droonga.workers", Integer, Float, path),
|
294
|
+
Droonga::Catalog::MismatchedParameterType.new(
|
295
|
+
"datasets.Droonga.number_of_replicas", Integer, Float, path),
|
296
|
+
Droonga::Catalog::MismatchedParameterType.new(
|
297
|
+
"datasets.Droonga.number_of_partitions", Integer, Float, path),
|
298
|
+
],
|
299
|
+
},
|
300
|
+
:negative_numeric_parameters => {
|
301
|
+
:catalog => minimum_data.merge(
|
302
|
+
"farms" => valid_farms,
|
303
|
+
"zones" => valid_zones,
|
304
|
+
"datasets" => {
|
305
|
+
"Droonga" => valid_dataset_base.merge(
|
306
|
+
"workers" => -1,
|
307
|
+
"number_of_replicas" => -1,
|
308
|
+
"number_of_partitions" => -1,
|
309
|
+
"ring" => {
|
310
|
+
ring_name => {
|
311
|
+
"weight" => -1,
|
312
|
+
"partitions" => {},
|
313
|
+
},
|
314
|
+
},
|
315
|
+
),
|
316
|
+
},
|
317
|
+
),
|
318
|
+
:errors => [
|
319
|
+
Droonga::Catalog::NegativeNumber.new(
|
320
|
+
"datasets.Droonga.workers", -1, path),
|
321
|
+
Droonga::Catalog::SmallerThanOne.new(
|
322
|
+
"datasets.Droonga.number_of_replicas", -1, path),
|
323
|
+
Droonga::Catalog::SmallerThanOne.new(
|
324
|
+
"datasets.Droonga.number_of_partitions", -1, path),
|
325
|
+
Droonga::Catalog::NegativeNumber.new(
|
326
|
+
"datasets.Droonga.ring.#{ring_name}.weight", -1, path),
|
327
|
+
],
|
328
|
+
},
|
329
|
+
:broken_relations_unknown_farm => {
|
330
|
+
:catalog => minimum_data.merge(
|
331
|
+
"farms" => valid_farms,
|
332
|
+
"zones" => valid_zones,
|
333
|
+
"datasets" => {
|
334
|
+
"Droonga" => valid_dataset_base.merge(
|
335
|
+
"ring" => {
|
336
|
+
ring_name => {
|
337
|
+
"weight" => 1,
|
338
|
+
"partitions" => {
|
339
|
+
range_name => [
|
340
|
+
"unknown:0/unknown.000",
|
341
|
+
],
|
342
|
+
},
|
343
|
+
},
|
344
|
+
},
|
345
|
+
),
|
346
|
+
},
|
347
|
+
),
|
348
|
+
:errors => [
|
349
|
+
Droonga::Catalog::UnknownFarmForPartition.new(
|
350
|
+
"datasets.Droonga.ring.#{ring_name}.partitions.#{range_name}[0]",
|
351
|
+
"unknown:0/unknown.000", path),
|
352
|
+
],
|
353
|
+
},
|
354
|
+
)
|
355
|
+
def test_validation(data)
|
356
|
+
assert_raise(Droonga::MultiplexError.new(data[:errors])) do
|
357
|
+
create_catalog(data[:catalog], "path/to/catalog")
|
358
|
+
end
|
359
|
+
end
|
360
|
+
end
|
167
361
|
end
|