fluent-plugin-droonga 0.9.0 → 0.9.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -0
  3. data/Gemfile +8 -1
  4. data/fluent-plugin-droonga.gemspec +2 -2
  5. data/lib/droonga/adapter.rb +39 -0
  6. data/lib/droonga/adapter_runner.rb +99 -0
  7. data/lib/droonga/catalog/base.rb +11 -11
  8. data/lib/droonga/catalog/dataset.rb +54 -0
  9. data/lib/droonga/catalog/version1.rb +1 -1
  10. data/lib/droonga/collector.rb +5 -7
  11. data/lib/droonga/collector_plugin.rb +7 -7
  12. data/lib/droonga/command.rb +36 -0
  13. data/lib/droonga/{plugin/input_adapter/crud.rb → command_repository.rb} +14 -8
  14. data/lib/droonga/dispatcher.rb +86 -54
  15. data/lib/droonga/distributed_command_planner.rb +183 -0
  16. data/lib/droonga/distributor.rb +43 -17
  17. data/lib/droonga/handler.rb +13 -72
  18. data/lib/droonga/handler_message.rb +5 -5
  19. data/lib/droonga/handler_messenger.rb +4 -1
  20. data/lib/droonga/handler_plugin.rb +2 -2
  21. data/lib/droonga/handler_runner.rb +104 -0
  22. data/lib/droonga/input_message.rb +4 -4
  23. data/lib/droonga/legacy_pluggable.rb +66 -0
  24. data/lib/droonga/{input_adapter.rb → legacy_plugin.rb} +27 -22
  25. data/lib/droonga/{plugin_repository.rb → legacy_plugin_repository.rb} +2 -4
  26. data/lib/droonga/message_matcher.rb +101 -0
  27. data/lib/droonga/{input_adapter_plugin.rb → planner.rb} +14 -10
  28. data/lib/droonga/planner_plugin.rb +54 -0
  29. data/lib/droonga/pluggable.rb +9 -45
  30. data/lib/droonga/plugin.rb +9 -33
  31. data/lib/droonga/plugin/collector/basic.rb +2 -0
  32. data/lib/droonga/plugin/collector/search.rb +31 -37
  33. data/lib/droonga/plugin/{handler/groonga/table_remove.rb → metadata/adapter_message.rb} +23 -18
  34. data/lib/droonga/plugin/{handler/search.rb → metadata/handler_action.rb} +19 -15
  35. data/lib/droonga/plugin/metadata/input_message.rb +39 -0
  36. data/lib/droonga/plugin/planner/crud.rb +49 -0
  37. data/lib/droonga/plugin/{distributor → planner}/distributed_search_planner.rb +62 -70
  38. data/lib/droonga/plugin/{distributor → planner}/groonga.rb +11 -32
  39. data/lib/droonga/plugin/{distributor → planner}/search.rb +5 -5
  40. data/lib/droonga/plugin/{distributor → planner}/watch.rb +15 -6
  41. data/lib/droonga/plugin_loader.rb +10 -0
  42. data/lib/droonga/plugin_registerable.rb +34 -10
  43. data/lib/droonga/plugin_registry.rb +58 -0
  44. data/lib/droonga/plugins/crud.rb +124 -0
  45. data/lib/droonga/plugins/error.rb +50 -0
  46. data/lib/droonga/{output_adapter_plugin.rb → plugins/groonga.rb} +9 -13
  47. data/lib/droonga/plugins/groonga/column_create.rb +123 -0
  48. data/lib/droonga/plugins/groonga/generic_command.rb +65 -0
  49. data/lib/droonga/{plugin/output_adapter/groonga.rb → plugins/groonga/generic_response.rb} +16 -15
  50. data/lib/droonga/plugins/groonga/select.rb +124 -0
  51. data/lib/droonga/plugins/groonga/table_create.rb +106 -0
  52. data/lib/droonga/plugins/groonga/table_remove.rb +57 -0
  53. data/lib/droonga/plugins/search.rb +40 -0
  54. data/lib/droonga/plugins/watch.rb +156 -0
  55. data/lib/droonga/processor.rb +8 -10
  56. data/lib/droonga/searcher.rb +14 -4
  57. data/lib/droonga/searcher/mecab_filter.rb +67 -0
  58. data/lib/droonga/session.rb +5 -5
  59. data/lib/droonga/test.rb +1 -1
  60. data/lib/droonga/test/stub_handler_message.rb +1 -1
  61. data/lib/droonga/test/{stub_distributor.rb → stub_planner.rb} +1 -1
  62. data/lib/droonga/worker.rb +7 -8
  63. data/lib/fluent/plugin/out_droonga.rb +0 -1
  64. data/sample/cluster/catalog.json +2 -4
  65. data/sample/mecab_filter/data.grn +7 -0
  66. data/sample/mecab_filter/ddl.grn +7 -0
  67. data/sample/mecab_filter/search_with_mecab_filter.json +21 -0
  68. data/sample/mecab_filter/search_without_mecab_filter.json +21 -0
  69. data/test/command/config/default/catalog.json +2 -5
  70. data/test/command/suite/search/error/no-query.expected +13 -0
  71. data/test/command/suite/search/error/no-query.test +7 -0
  72. data/test/command/suite/search/error/unknown-source.expected +26 -0
  73. data/test/command/suite/watch/subscribe.expected +3 -3
  74. data/test/command/suite/watch/unsubscribe.expected +3 -3
  75. data/test/unit/catalog/test_dataset.rb +385 -0
  76. data/test/unit/catalog/test_version1.rb +111 -45
  77. data/test/unit/fixtures/catalog/version1.json +0 -3
  78. data/test/unit/helper.rb +2 -1
  79. data/test/unit/helper/distributed_search_planner_helper.rb +83 -0
  80. data/test/unit/plugin/collector/test_basic.rb +233 -376
  81. data/test/unit/plugin/collector/test_search.rb +8 -17
  82. data/test/unit/plugin/planner/search_planner/test_basic.rb +120 -0
  83. data/test/unit/plugin/planner/search_planner/test_group_by.rb +573 -0
  84. data/test/unit/plugin/planner/search_planner/test_output.rb +388 -0
  85. data/test/unit/plugin/planner/search_planner/test_sort_by.rb +938 -0
  86. data/test/unit/plugin/{distributor → planner}/test_search.rb +20 -75
  87. data/test/unit/{plugin/handler → plugins/crud}/test_add.rb +11 -11
  88. data/test/unit/plugins/groonga/select/test_adapter_input.rb +213 -0
  89. data/test/unit/{plugin/output_adapter/groonga/test_select.rb → plugins/groonga/select/test_adapter_output.rb} +12 -13
  90. data/test/unit/{plugin/handler → plugins}/groonga/test_column_create.rb +20 -5
  91. data/test/unit/{plugin/handler → plugins}/groonga/test_table_create.rb +5 -0
  92. data/test/unit/{plugin/handler → plugins}/groonga/test_table_remove.rb +8 -1
  93. data/test/unit/{plugin/handler → plugins}/test_groonga.rb +5 -5
  94. data/test/unit/{plugin/handler → plugins}/test_search.rb +21 -5
  95. data/test/unit/{plugin/handler → plugins}/test_watch.rb +29 -10
  96. data/{lib/droonga/command_mapper.rb → test/unit/test_command_repository.rb} +16 -22
  97. data/test/unit/{test_plugin.rb → test_legacy_plugin.rb} +3 -3
  98. data/test/unit/{test_plugin_repository.rb → test_legacy_plugin_repository.rb} +3 -3
  99. data/test/unit/test_message_matcher.rb +137 -0
  100. metadata +86 -66
  101. data/bin/grn2jsons +0 -82
  102. data/lib/droonga/distribution_planner.rb +0 -76
  103. data/lib/droonga/distributor_plugin.rb +0 -95
  104. data/lib/droonga/output_adapter.rb +0 -53
  105. data/lib/droonga/plugin/collector/groonga.rb +0 -83
  106. data/lib/droonga/plugin/distributor/crud.rb +0 -84
  107. data/lib/droonga/plugin/handler/add.rb +0 -109
  108. data/lib/droonga/plugin/handler/forward.rb +0 -75
  109. data/lib/droonga/plugin/handler/groonga.rb +0 -99
  110. data/lib/droonga/plugin/handler/groonga/column_create.rb +0 -106
  111. data/lib/droonga/plugin/handler/groonga/table_create.rb +0 -91
  112. data/lib/droonga/plugin/handler/watch.rb +0 -108
  113. data/lib/droonga/plugin/input_adapter/groonga.rb +0 -49
  114. data/lib/droonga/plugin/input_adapter/groonga/select.rb +0 -63
  115. data/lib/droonga/plugin/output_adapter/crud.rb +0 -51
  116. data/lib/droonga/plugin/output_adapter/groonga/select.rb +0 -54
  117. data/lib/groonga_command_converter.rb +0 -143
  118. data/sample/fluentd.conf +0 -8
  119. data/test/unit/plugin/distributor/test_search_planner.rb +0 -1102
  120. data/test/unit/plugin/input_adapter/groonga/test_select.rb +0 -248
  121. data/test/unit/test_command_mapper.rb +0 -44
  122. data/test/unit/test_groonga_command_converter.rb +0 -242
@@ -5,8 +5,8 @@
5
5
  "inReplyTo": "request-id",
6
6
  "statusCode": 200,
7
7
  "type": "watch.subscribe.result",
8
- "body": [
9
- true
10
- ]
8
+ "body": {
9
+ "success": true
10
+ }
11
11
  }
12
12
  ]
@@ -5,8 +5,8 @@
5
5
  "inReplyTo": "request-id",
6
6
  "statusCode": 200,
7
7
  "type": "watch.unsubscribe.result",
8
- "body": [
9
- true
10
- ]
8
+ "body": {
9
+ "success": true
10
+ }
11
11
  }
12
12
  ]
@@ -0,0 +1,385 @@
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/dataset"
17
+
18
+ class CatalogDatasetTest < Test::Unit::TestCase
19
+ private
20
+ def create_dataset(data)
21
+ Droonga::Catalog::Dataset.new(data)
22
+ end
23
+
24
+ class ContinuumTest < self
25
+ def setup
26
+ @ring = {
27
+ "localhost:23041" => {
28
+ "weight" => 50,
29
+ "partitions" => {
30
+ "2014-02-09" => [
31
+ "localhost:20341/droonga.000",
32
+ "localhost:20341/droonga.001",
33
+ ],
34
+ },
35
+ },
36
+ "localhost:23042" => {
37
+ "weight" => 50,
38
+ "partitions" => {
39
+ "2014-02-09" => [
40
+ "localhost:20342/droonga.002",
41
+ "localhost:20342/droonga.003",
42
+ ],
43
+ },
44
+ },
45
+ }
46
+ end
47
+
48
+ def continuum(data)
49
+ create_dataset(data).continuum
50
+ end
51
+
52
+ def test_no_partition
53
+ assert_equal([],
54
+ continuum("number_of_partitions" => 1,
55
+ "ring" => @ring))
56
+ end
57
+
58
+ def test_multiple_partitions
59
+ assert_equal([
60
+ [9603047, "localhost:23041"],
61
+ [27629778, "localhost:23042"],
62
+ [41438004, "localhost:23042"],
63
+ [46078372, "localhost:23042"],
64
+ [49960577, "localhost:23041"],
65
+ [50458434, "localhost:23042"],
66
+ [62539901, "localhost:23041"],
67
+ [102160356, "localhost:23042"],
68
+ [118777121, "localhost:23041"],
69
+ [135178227, "localhost:23041"],
70
+ [137745106, "localhost:23042"],
71
+ [145409221, "localhost:23041"],
72
+ [151846190, "localhost:23042"],
73
+ [159720530, "localhost:23041"],
74
+ [174946501, "localhost:23042"],
75
+ [180602930, "localhost:23042"],
76
+ [202106994, "localhost:23042"],
77
+ [205862983, "localhost:23042"],
78
+ [214712657, "localhost:23041"],
79
+ [247420023, "localhost:23041"],
80
+ [259057847, "localhost:23041"],
81
+ [272576744, "localhost:23042"],
82
+ [273722093, "localhost:23041"],
83
+ [281067628, "localhost:23042"],
84
+ [293157057, "localhost:23041"],
85
+ [316454767, "localhost:23041"],
86
+ [329395260, "localhost:23041"],
87
+ [336035525, "localhost:23042"],
88
+ [337183821, "localhost:23042"],
89
+ [345936445, "localhost:23042"],
90
+ [352998716, "localhost:23042"],
91
+ [356549233, "localhost:23042"],
92
+ [365790167, "localhost:23042"],
93
+ [366761715, "localhost:23042"],
94
+ [374718742, "localhost:23042"],
95
+ [423944977, "localhost:23041"],
96
+ [441573727, "localhost:23041"],
97
+ [442348808, "localhost:23042"],
98
+ [456608714, "localhost:23042"],
99
+ [486506717, "localhost:23042"],
100
+ [503359185, "localhost:23041"],
101
+ [507968811, "localhost:23041"],
102
+ [522389108, "localhost:23041"],
103
+ [538007376, "localhost:23042"],
104
+ [552940093, "localhost:23041"],
105
+ [565987242, "localhost:23041"],
106
+ [582806095, "localhost:23041"],
107
+ [611312183, "localhost:23041"],
108
+ [621389814, "localhost:23041"],
109
+ [644400226, "localhost:23041"],
110
+ [654418860, "localhost:23041"],
111
+ [669337050, "localhost:23042"],
112
+ [672929644, "localhost:23042"],
113
+ [677668675, "localhost:23041"],
114
+ [703432973, "localhost:23041"],
115
+ [716459360, "localhost:23041"],
116
+ [746047339, "localhost:23042"],
117
+ [789450083, "localhost:23041"],
118
+ [796244908, "localhost:23042"],
119
+ [801162758, "localhost:23041"],
120
+ [806867059, "localhost:23041"],
121
+ [818911813, "localhost:23042"],
122
+ [819949679, "localhost:23042"],
123
+ [833118130, "localhost:23042"],
124
+ [833679755, "localhost:23041"],
125
+ [873615689, "localhost:23042"],
126
+ [880898222, "localhost:23041"],
127
+ [894480469, "localhost:23042"],
128
+ [910910091, "localhost:23041"],
129
+ [919595198, "localhost:23041"],
130
+ [932350249, "localhost:23042"],
131
+ [939377609, "localhost:23041"],
132
+ [958562472, "localhost:23042"],
133
+ [981240873, "localhost:23041"],
134
+ [986623018, "localhost:23042"],
135
+ [999488955, "localhost:23042"],
136
+ [1017009664, "localhost:23041"],
137
+ [1018813132, "localhost:23042"],
138
+ [1027591410, "localhost:23041"],
139
+ [1048831053, "localhost:23041"],
140
+ [1065756786, "localhost:23042"],
141
+ [1068022889, "localhost:23042"],
142
+ [1074085731, "localhost:23042"],
143
+ [1084163769, "localhost:23041"],
144
+ [1098037927, "localhost:23042"],
145
+ [1121835916, "localhost:23042"],
146
+ [1129345220, "localhost:23042"],
147
+ [1148803987, "localhost:23041"],
148
+ [1151870780, "localhost:23042"],
149
+ [1151876336, "localhost:23042"],
150
+ [1172639414, "localhost:23042"],
151
+ [1174498870, "localhost:23041"],
152
+ [1185602679, "localhost:23042"],
153
+ [1197984299, "localhost:23042"],
154
+ [1207475922, "localhost:23042"],
155
+ [1235417559, "localhost:23041"],
156
+ [1238004412, "localhost:23042"],
157
+ [1243706366, "localhost:23042"],
158
+ [1245715925, "localhost:23042"],
159
+ [1250583493, "localhost:23041"],
160
+ [1288824895, "localhost:23041"],
161
+ [1308702666, "localhost:23042"],
162
+ [1327123066, "localhost:23042"],
163
+ [1327995980, "localhost:23041"],
164
+ [1330953926, "localhost:23042"],
165
+ [1339581304, "localhost:23042"],
166
+ [1347736889, "localhost:23042"],
167
+ [1360110626, "localhost:23042"],
168
+ [1384082650, "localhost:23042"],
169
+ [1401035340, "localhost:23041"],
170
+ [1411013100, "localhost:23041"],
171
+ [1426568376, "localhost:23042"],
172
+ [1431710724, "localhost:23041"],
173
+ [1444398493, "localhost:23041"],
174
+ [1479189521, "localhost:23041"],
175
+ [1513093825, "localhost:23041"],
176
+ [1514666132, "localhost:23041"],
177
+ [1519362198, "localhost:23042"],
178
+ [1531494698, "localhost:23042"],
179
+ [1535282727, "localhost:23041"],
180
+ [1535626422, "localhost:23042"],
181
+ [1553592951, "localhost:23042"],
182
+ [1559468978, "localhost:23041"],
183
+ [1581367000, "localhost:23042"],
184
+ [1589920429, "localhost:23041"],
185
+ [1605687052, "localhost:23042"],
186
+ [1624945150, "localhost:23042"],
187
+ [1628150772, "localhost:23041"],
188
+ [1670394510, "localhost:23041"],
189
+ [1683839421, "localhost:23041"],
190
+ [1689437303, "localhost:23042"],
191
+ [1696925840, "localhost:23042"],
192
+ [1696962849, "localhost:23041"],
193
+ [1711148491, "localhost:23041"],
194
+ [1715075293, "localhost:23042"],
195
+ [1727144721, "localhost:23041"],
196
+ [1741689697, "localhost:23041"],
197
+ [1747842507, "localhost:23042"],
198
+ [1756538966, "localhost:23042"],
199
+ [1756579826, "localhost:23041"],
200
+ [1759918231, "localhost:23041"],
201
+ [1763420733, "localhost:23042"],
202
+ [1773027279, "localhost:23041"],
203
+ [1783071332, "localhost:23042"],
204
+ [1783904572, "localhost:23041"],
205
+ [1798455991, "localhost:23041"],
206
+ [1873514423, "localhost:23042"],
207
+ [1891118101, "localhost:23041"],
208
+ [1893238867, "localhost:23042"],
209
+ [1903033611, "localhost:23041"],
210
+ [1925915300, "localhost:23041"],
211
+ [1938049314, "localhost:23041"],
212
+ [1944148871, "localhost:23041"],
213
+ [1948017755, "localhost:23042"],
214
+ [1968402121, "localhost:23041"],
215
+ [1991372406, "localhost:23042"],
216
+ [1994291866, "localhost:23041"],
217
+ [2008535226, "localhost:23042"],
218
+ [2018311062, "localhost:23041"],
219
+ [2034595495, "localhost:23041"],
220
+ [2035213452, "localhost:23041"],
221
+ [2037794404, "localhost:23041"],
222
+ [2045835634, "localhost:23041"],
223
+ [2047702072, "localhost:23041"],
224
+ [2047817697, "localhost:23041"],
225
+ [2055369974, "localhost:23042"],
226
+ [2080668066, "localhost:23042"],
227
+ [2103770068, "localhost:23041"],
228
+ [2123603348, "localhost:23042"],
229
+ [2139800272, "localhost:23041"],
230
+ [2179129230, "localhost:23041"],
231
+ [2196771767, "localhost:23042"],
232
+ [2201832130, "localhost:23041"],
233
+ [2202361965, "localhost:23041"],
234
+ [2205203213, "localhost:23041"],
235
+ [2224638783, "localhost:23041"],
236
+ [2231966397, "localhost:23042"],
237
+ [2246002957, "localhost:23041"],
238
+ [2268183028, "localhost:23041"],
239
+ [2278962012, "localhost:23041"],
240
+ [2281079708, "localhost:23041"],
241
+ [2319189432, "localhost:23041"],
242
+ [2333806182, "localhost:23042"],
243
+ [2382832820, "localhost:23042"],
244
+ [2395820598, "localhost:23042"],
245
+ [2400631930, "localhost:23042"],
246
+ [2423755877, "localhost:23042"],
247
+ [2463262611, "localhost:23042"],
248
+ [2472430585, "localhost:23042"],
249
+ [2485153021, "localhost:23041"],
250
+ [2496668371, "localhost:23041"],
251
+ [2514014586, "localhost:23041"],
252
+ [2558870426, "localhost:23042"],
253
+ [2564276753, "localhost:23042"],
254
+ [2574277968, "localhost:23041"],
255
+ [2592472493, "localhost:23042"],
256
+ [2607258621, "localhost:23041"],
257
+ [2614254907, "localhost:23041"],
258
+ [2620760890, "localhost:23042"],
259
+ [2651983985, "localhost:23042"],
260
+ [2655195461, "localhost:23041"],
261
+ [2659913742, "localhost:23042"],
262
+ [2661202449, "localhost:23042"],
263
+ [2685822324, "localhost:23041"],
264
+ [2697042260, "localhost:23042"],
265
+ [2703527078, "localhost:23042"],
266
+ [2705978309, "localhost:23042"],
267
+ [2721148403, "localhost:23042"],
268
+ [2733447702, "localhost:23041"],
269
+ [2736188580, "localhost:23041"],
270
+ [2758967840, "localhost:23041"],
271
+ [2784848842, "localhost:23042"],
272
+ [2833516863, "localhost:23042"],
273
+ [2840102575, "localhost:23041"],
274
+ [2865654417, "localhost:23041"],
275
+ [2879431763, "localhost:23041"],
276
+ [2885879450, "localhost:23042"],
277
+ [2886116302, "localhost:23042"],
278
+ [2893306625, "localhost:23042"],
279
+ [2894128113, "localhost:23042"],
280
+ [2897556237, "localhost:23041"],
281
+ [2908592163, "localhost:23041"],
282
+ [2921288405, "localhost:23041"],
283
+ [2946669890, "localhost:23042"],
284
+ [2963904259, "localhost:23042"],
285
+ [2975325206, "localhost:23041"],
286
+ [2996645729, "localhost:23041"],
287
+ [3000094069, "localhost:23042"],
288
+ [3004191432, "localhost:23042"],
289
+ [3008276260, "localhost:23042"],
290
+ [3009066823, "localhost:23042"],
291
+ [3010043272, "localhost:23041"],
292
+ [3021930201, "localhost:23041"],
293
+ [3022561244, "localhost:23041"],
294
+ [3035183544, "localhost:23041"],
295
+ [3061834112, "localhost:23041"],
296
+ [3081895333, "localhost:23042"],
297
+ [3100253179, "localhost:23041"],
298
+ [3105348121, "localhost:23042"],
299
+ [3128093110, "localhost:23041"],
300
+ [3139279598, "localhost:23041"],
301
+ [3161507274, "localhost:23042"],
302
+ [3176232817, "localhost:23042"],
303
+ [3179328318, "localhost:23041"],
304
+ [3193971258, "localhost:23042"],
305
+ [3197623137, "localhost:23042"],
306
+ [3243553025, "localhost:23041"],
307
+ [3256140856, "localhost:23041"],
308
+ [3276287733, "localhost:23042"],
309
+ [3276659656, "localhost:23041"],
310
+ [3336803621, "localhost:23041"],
311
+ [3340771432, "localhost:23041"],
312
+ [3342756131, "localhost:23041"],
313
+ [3349847214, "localhost:23041"],
314
+ [3362320951, "localhost:23042"],
315
+ [3367216947, "localhost:23042"],
316
+ [3373220713, "localhost:23042"],
317
+ [3390486913, "localhost:23042"],
318
+ [3394808552, "localhost:23041"],
319
+ [3427153669, "localhost:23041"],
320
+ [3455884916, "localhost:23042"],
321
+ [3477557293, "localhost:23041"],
322
+ [3490640959, "localhost:23042"],
323
+ [3492869366, "localhost:23042"],
324
+ [3498663241, "localhost:23041"],
325
+ [3511308806, "localhost:23042"],
326
+ [3518217839, "localhost:23041"],
327
+ [3550643661, "localhost:23042"],
328
+ [3560340265, "localhost:23042"],
329
+ [3581763062, "localhost:23042"],
330
+ [3586388888, "localhost:23041"],
331
+ [3613146094, "localhost:23042"],
332
+ [3638310074, "localhost:23041"],
333
+ [3675913657, "localhost:23042"],
334
+ [3707869452, "localhost:23042"],
335
+ [3809749253, "localhost:23042"],
336
+ [3866669476, "localhost:23042"],
337
+ [3868747768, "localhost:23042"],
338
+ [3893516035, "localhost:23042"],
339
+ [3925429782, "localhost:23042"],
340
+ [3930474602, "localhost:23042"],
341
+ [3975500031, "localhost:23041"],
342
+ [3976115920, "localhost:23042"],
343
+ [3977644234, "localhost:23041"],
344
+ [3979776870, "localhost:23041"],
345
+ [3980299749, "localhost:23041"],
346
+ [3980347759, "localhost:23042"],
347
+ [4003152522, "localhost:23041"],
348
+ [4008016337, "localhost:23041"],
349
+ [4009078721, "localhost:23041"],
350
+ [4023291693, "localhost:23041"],
351
+ [4044935778, "localhost:23042"],
352
+ [4069030469, "localhost:23041"],
353
+ [4089201952, "localhost:23041"],
354
+ [4102445160, "localhost:23042"],
355
+ [4110744646, "localhost:23041"],
356
+ [4111449069, "localhost:23042"],
357
+ [4115421801, "localhost:23041"],
358
+ [4146806390, "localhost:23041"],
359
+ [4155072858, "localhost:23041"],
360
+ [4158437676, "localhost:23041"],
361
+ [4169311721, "localhost:23042"],
362
+ [4175251809, "localhost:23041"],
363
+ [4175808068, "localhost:23042"],
364
+ [4197302191, "localhost:23042"],
365
+ [4230703474, "localhost:23041"],
366
+ [4230786979, "localhost:23042"],
367
+ [4233561014, "localhost:23041"],
368
+ [4234760241, "localhost:23042"],
369
+ [4240706113, "localhost:23042"],
370
+ [4242248154, "localhost:23041"],
371
+ [4244962758, "localhost:23042"],
372
+ [4249972704, "localhost:23042"],
373
+ [4255505170, "localhost:23042"],
374
+ [4261033451, "localhost:23041"],
375
+ [4280396822, "localhost:23041"],
376
+ [4281027412, "localhost:23042"],
377
+ [4292367368, "localhost:23042"],
378
+ [4294093319, "localhost:23042"],
379
+ [4294346407, "localhost:23041"],
380
+ ],
381
+ continuum("number_of_partitions" => 2,
382
+ "ring" => @ring))
383
+ end
384
+ end
385
+ end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013 Droonga Project
1
+ # Copyright (C) 2013-2014 Droonga Project
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -16,61 +16,128 @@
16
16
  require "droonga/catalog/version1"
17
17
 
18
18
  class CatalogTest < Test::Unit::TestCase
19
- def setup
20
- data = JSON.parse(File.read(catalog_path))
21
- @catalog = Droonga::Catalog::Version1.new(data, base_path)
19
+ private
20
+ def minimum_data
21
+ {
22
+ "datasets" => [],
23
+ }
22
24
  end
23
25
 
24
- def test_option
25
- assert_equal(["for_global"], @catalog.option("plugins"))
26
+ def create_catalog(data, base_path)
27
+ Droonga::Catalog::Version1.new(data, base_path)
26
28
  end
27
29
 
28
- def test_get_partitions
29
- partitions = @catalog.get_partitions("localhost:23003/test")
30
- assert_equal({
31
- "localhost:23003/test.000" => {
32
- :database => "#{base_path}/000/db",
33
- :handlers => ["for_dataset"],
34
- :n_workers => 0
35
- },
36
- "localhost:23003/test.001" => {
37
- :database => "#{base_path}/001/db",
38
- :handlers => ["for_dataset"],
39
- :n_workers => 0
40
- },
41
- "localhost:23003/test.002" => {
42
- :database => "#{base_path}/002/db",
43
- :handlers => ["for_dataset"],
44
- :n_workers => 0
45
- },
46
- "localhost:23003/test.003" => {
47
- :database => "#{base_path}/003/db",
48
- :handlers => ["for_dataset"],
49
- :n_workers => 0
50
- },
51
- },
52
- partitions)
53
- end
30
+ class OptionTest < self
31
+ def create_catalog(options)
32
+ super(minimum_data.merge("options" => options), "base-path")
33
+ end
54
34
 
55
- private
56
- def fixture_path(base_path)
57
- File.expand_path("../../fixtures/#{base_path}", __FILE__)
58
- end
35
+ def test_nonexistent
36
+ catalog = create_catalog({})
37
+ assert_nil(catalog.option("nonexistent"))
38
+ end
59
39
 
60
- def catalog_path
61
- @catalog_path ||= fixture_path("catalog/version1.json")
40
+ def test_existent
41
+ catalog = create_catalog("plugins" => ["crud", "groonga"])
42
+ assert_equal(["crud", "groonga"],
43
+ catalog.option("plugins"))
44
+ end
62
45
  end
63
46
 
64
- def base_path
65
- File.dirname(catalog_path)
47
+ class PartitionTest < self
48
+ def setup
49
+ data = JSON.parse(File.read(catalog_path))
50
+ @catalog = create_catalog(data, base_path)
51
+ end
52
+
53
+ def test_get_partitions
54
+ partitions = @catalog.get_partitions("localhost:23003/test")
55
+ assert_equal({
56
+ "localhost:23003/test.000" => {
57
+ :database => "#{base_path}/000/db",
58
+ :plugins => ["for_dataset"],
59
+ :n_workers => 0
60
+ },
61
+ "localhost:23003/test.001" => {
62
+ :database => "#{base_path}/001/db",
63
+ :plugins => ["for_dataset"],
64
+ :n_workers => 0
65
+ },
66
+ "localhost:23003/test.002" => {
67
+ :database => "#{base_path}/002/db",
68
+ :plugins => ["for_dataset"],
69
+ :n_workers => 0
70
+ },
71
+ "localhost:23003/test.003" => {
72
+ :database => "#{base_path}/003/db",
73
+ :plugins => ["for_dataset"],
74
+ :n_workers => 0
75
+ },
76
+ },
77
+ partitions)
78
+ end
79
+
80
+ def fixture_path(base_path)
81
+ File.expand_path("../../fixtures/#{base_path}", __FILE__)
82
+ end
83
+
84
+ def catalog_path
85
+ @catalog_path ||= fixture_path("catalog/version1.json")
86
+ end
87
+
88
+ def base_path
89
+ File.dirname(catalog_path)
90
+ end
91
+
92
+ class PluginsTest < self
93
+ def setup
94
+ @data = {
95
+ "farms" => {
96
+ farm_name => {
97
+ "device" => ".",
98
+ },
99
+ },
100
+ "datasets" => {
101
+ "Droonga" => {
102
+ "number_of_partitions" => 1,
103
+ "ring" => {
104
+ "localhost:23041" => {
105
+ "weight" => 50,
106
+ "partitions" => {
107
+ "2014-02-09" => [
108
+ "#{farm_name}.000",
109
+ ],
110
+ },
111
+ },
112
+ },
113
+ },
114
+ },
115
+ }
116
+ end
117
+
118
+ def farm_name
119
+ "localhost:23041/droonga"
120
+ end
121
+
122
+ def plugins(data)
123
+ catalog = create_catalog(data, base_path)
124
+ catalog.get_partitions(farm_name).collect do |partition, options|
125
+ options[:plugins]
126
+ end
127
+ end
128
+
129
+ def test_plugins
130
+ @data["datasets"]["Droonga"]["plugins"] = ["search", "groonga", "add"]
131
+ assert_equal([["search", "groonga", "add"]],
132
+ plugins(@data))
133
+
134
+ end
135
+ end
66
136
  end
67
137
 
68
138
  class DataSetTest < self
69
139
  class RingTest < self
70
140
  class TotalWeightTest < self
71
- def setup
72
- end
73
-
74
141
  def test_three_zones
75
142
  dataset = {
76
143
  "ring" => {
@@ -91,8 +158,7 @@ class CatalogTest < Test::Unit::TestCase
91
158
 
92
159
  private
93
160
  def total_weight(dataset)
94
- catalog = Droonga::Catalog::Version1.new({"datasets" => []},
95
- "base-path")
161
+ catalog = create_catalog({"datasets" => []}, "base-path")
96
162
  catalog.send(:compute_total_weight, dataset)
97
163
  end
98
164
  end