fluent-plugin-droonga 0.0.2 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -0
  3. data/.yardopts +7 -0
  4. data/Gemfile +14 -2
  5. data/LICENSE.txt +1 -1
  6. data/README.md +1 -1
  7. data/Rakefile +27 -5
  8. data/benchmark/benchmark.rb +1 -1
  9. data/benchmark/utils.rb +9 -6
  10. data/benchmark/watch/benchmark-notify.rb +2 -2
  11. data/benchmark/watch/benchmark-publish.rb +1 -1
  12. data/benchmark/watch/benchmark-scan.rb +1 -1
  13. data/benchmark/watch/catalog.json +1 -1
  14. data/bin/grn2jsons +1 -1
  15. data/fluent-plugin-droonga.gemspec +5 -3
  16. data/lib/droonga/adapter.rb +13 -130
  17. data/lib/droonga/adapter_plugin.rb +51 -0
  18. data/lib/droonga/catalog.rb +2 -2
  19. data/lib/droonga/collector.rb +107 -0
  20. data/lib/droonga/collector_plugin.rb +82 -0
  21. data/lib/droonga/command_mapper.rb +1 -1
  22. data/lib/droonga/{proxy.rb → dispatcher.rb} +116 -151
  23. data/lib/droonga/distributor.rb +51 -0
  24. data/lib/droonga/distributor_plugin.rb +59 -0
  25. data/lib/droonga/engine.rb +9 -50
  26. data/lib/droonga/farm.rb +47 -0
  27. data/lib/droonga/forwarder.rb +125 -0
  28. data/lib/droonga/handler.rb +69 -60
  29. data/lib/droonga/handler_plugin.rb +22 -11
  30. data/lib/droonga/input_message.rb +51 -0
  31. data/lib/droonga/job_queue.rb +5 -1
  32. data/lib/droonga/job_queue_schema.rb +1 -1
  33. data/lib/droonga/logger.rb +1 -1
  34. data/lib/droonga/partition.rb +76 -0
  35. data/lib/droonga/pluggable.rb +62 -0
  36. data/lib/droonga/plugin.rb +18 -16
  37. data/lib/droonga/plugin/{adapter_groonga.rb → adapter/groonga.rb} +10 -10
  38. data/lib/droonga/plugin/adapter/groonga/select.rb +13 -4
  39. data/lib/droonga/plugin/collector/basic.rb +142 -0
  40. data/lib/droonga/plugin/distributor/crud.rb +43 -0
  41. data/lib/droonga/plugin/distributor/groonga.rb +37 -0
  42. data/lib/droonga/plugin/distributor/search.rb +273 -0
  43. data/lib/droonga/plugin/distributor/watch.rb +39 -0
  44. data/lib/droonga/plugin/{handler_add.rb → handler/add.rb} +6 -6
  45. data/lib/droonga/plugin/{handler_forward.rb → handler/forward.rb} +9 -4
  46. data/lib/droonga/plugin/{handler_groonga.rb → handler/groonga.rb} +36 -4
  47. data/lib/droonga/plugin/handler/groonga/column_create.rb +5 -9
  48. data/lib/droonga/plugin/handler/groonga/table_create.rb +9 -18
  49. data/lib/droonga/plugin/{handler_search.rb → handler/search.rb} +4 -4
  50. data/lib/droonga/plugin/{handler_watch.rb → handler/watch.rb} +4 -4
  51. data/lib/droonga/plugin_loader.rb +45 -0
  52. data/lib/droonga/plugin_registerable.rb +51 -0
  53. data/lib/droonga/plugin_repository.rb +56 -0
  54. data/lib/droonga/processor.rb +64 -0
  55. data/lib/droonga/searcher.rb +16 -7
  56. data/lib/droonga/server.rb +5 -9
  57. data/lib/droonga/sweeper.rb +1 -1
  58. data/lib/droonga/watch_schema.rb +1 -1
  59. data/lib/droonga/watcher.rb +1 -1
  60. data/lib/droonga/worker.rb +21 -9
  61. data/lib/fluent/plugin/out_droonga.rb +33 -15
  62. data/lib/groonga_command_converter.rb +1 -1
  63. data/sample/cluster/fluentd.conf +0 -1
  64. data/test/command/config/default/catalog.json +43 -0
  65. data/test/command/config/default/fluentd.conf +11 -0
  66. data/test/command/fixture/documents.jsons +208 -0
  67. data/test/command/fixture/user-table-array.jsons +38 -0
  68. data/test/command/fixture/user-table.jsons +38 -0
  69. data/test/command/run-test.rb +35 -0
  70. data/test/command/suite/add/minimum.expected +12 -0
  71. data/test/command/suite/add/minimum.test +11 -0
  72. data/test/command/suite/add/with-values.expected +12 -0
  73. data/test/command/suite/add/with-values.test +17 -0
  74. data/test/command/suite/add/without-key.expected +12 -0
  75. data/test/command/suite/add/without-key.test +16 -0
  76. data/test/command/suite/groonga/column_create/scalar.expected +34 -0
  77. data/test/command/suite/groonga/column_create/scalar.test +17 -0
  78. data/test/command/suite/groonga/column_create/vector.expected +34 -0
  79. data/test/command/suite/groonga/column_create/vector.test +18 -0
  80. data/test/command/suite/groonga/select/minimum.expected +26 -0
  81. data/test/command/suite/groonga/select/minimum.test +8 -0
  82. data/test/command/suite/groonga/table_create/array.expected +17 -0
  83. data/test/command/suite/groonga/table_create/array.test +8 -0
  84. data/test/command/suite/groonga/table_create/hash.expected +17 -0
  85. data/test/command/suite/groonga/table_create/hash.test +8 -0
  86. data/test/command/suite/search/array-attribute-label.expected +25 -0
  87. data/test/command/suite/search/array-attribute-label.test +30 -0
  88. data/test/command/suite/search/chained-queries.expected +45 -0
  89. data/test/command/suite/search/chained-queries.test +43 -0
  90. data/test/command/suite/search/complex.expected +52 -0
  91. data/test/command/suite/search/complex.test +25 -0
  92. data/test/command/suite/search/condition-nested.expected +19 -0
  93. data/test/command/suite/search/condition-nested.test +29 -0
  94. data/test/command/suite/search/condition-query.expected +28 -0
  95. data/test/command/suite/search/condition-query.test +25 -0
  96. data/test/command/suite/search/condition-script.expected +28 -0
  97. data/test/command/suite/search/condition-script.test +28 -0
  98. data/test/command/suite/search/hash-attribute-label.expected +34 -0
  99. data/test/command/suite/search/hash-attribute-label.test +38 -0
  100. data/test/command/suite/search/minimum.expected +13 -0
  101. data/test/command/suite/search/minimum.test +16 -0
  102. data/test/command/suite/search/multiple-queries.expected +39 -0
  103. data/test/command/suite/search/multiple-queries.test +39 -0
  104. data/test/command/suite/search/output-range.expected +28 -0
  105. data/test/command/suite/search/output-range.test +25 -0
  106. data/test/command/suite/search/simple.expected +52 -0
  107. data/test/command/suite/search/simple.test +24 -0
  108. data/test/command/suite/search/sort-and-output-range.expected +25 -0
  109. data/test/command/suite/search/sort-and-output-range.test +29 -0
  110. data/test/command/suite/search/sort-range.expected +28 -0
  111. data/test/command/suite/search/sort-range.test +28 -0
  112. data/test/command/suite/search/sort-with-invisible-column.expected +28 -0
  113. data/test/command/suite/search/sort-with-invisible-column.test +28 -0
  114. data/test/unit/fixtures/array.grn +18 -0
  115. data/test/{fixtures → unit/fixtures}/catalog.json +0 -0
  116. data/test/{fixtures → unit/fixtures}/document.grn +20 -9
  117. data/test/unit/fixtures/reference/array.grn +11 -0
  118. data/test/unit/fixtures/reference/hash.grn +7 -0
  119. data/test/{helper.rb → unit/helper.rb} +2 -1
  120. data/test/{helper → unit/helper}/fixture.rb +1 -1
  121. data/test/unit/helper/plugin_helper.rb +38 -0
  122. data/test/{helper → unit/helper}/sandbox.rb +19 -6
  123. data/test/{helper → unit/helper}/stub_worker.rb +1 -1
  124. data/test/{helper → unit/helper}/watch_helper.rb +1 -13
  125. data/test/{plugin → unit/plugin}/adapter/groonga/test_select.rb +108 -4
  126. data/test/unit/plugin/collector/test_basic.rb +558 -0
  127. data/test/unit/plugin/distributor/test_search.rb +914 -0
  128. data/test/{plugin → unit/plugin}/handler/groonga/test_column_create.rb +18 -14
  129. data/test/{plugin → unit/plugin}/handler/groonga/test_table_create.rb +13 -11
  130. data/test/{plugin/handler/test_handler_add.rb → unit/plugin/handler/test_add.rb} +2 -14
  131. data/test/{plugin/handler/test_handler_groonga.rb → unit/plugin/handler/test_groonga.rb} +6 -26
  132. data/test/unit/plugin/handler/test_search.rb +601 -0
  133. data/test/{plugin/handler/test_handler_watch.rb → unit/plugin/handler/test_watch.rb} +2 -2
  134. data/test/{run-test.rb → unit/run-test.rb} +3 -3
  135. data/test/{test_adapter.rb → unit/test_adapter.rb} +17 -14
  136. data/test/{test_catalog.rb → unit/test_catalog.rb} +4 -4
  137. data/test/{test_command_mapper.rb → unit/test_command_mapper.rb} +1 -1
  138. data/test/{test_groonga_command_converter.rb → unit/test_groonga_command_converter.rb} +3 -3
  139. data/test/{test_job_queue_schema.rb → unit/test_job_queue_schema.rb} +1 -1
  140. data/test/{test_output.rb → unit/test_output.rb} +9 -9
  141. data/test/{test_handler.rb → unit/test_plugin.rb} +19 -22
  142. data/test/unit/test_plugin_repository.rb +89 -0
  143. data/test/{test_sweeper.rb → unit/test_sweeper.rb} +1 -1
  144. data/test/{test_watch_schema.rb → unit/test_watch_schema.rb} +1 -1
  145. data/test/{test_watcher.rb → unit/test_watcher.rb} +1 -1
  146. metadata +226 -66
  147. data/lib/droonga/executor.rb +0 -289
  148. data/lib/droonga/plugin/handler_proxy.rb +0 -82
  149. data/test/plugin/handler/test_handler_search.rb +0 -512
  150. data/test/test_worker.rb +0 -144
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013 droonga project
1
+ # Copyright (C) 2013 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
@@ -0,0 +1,38 @@
1
+ # Copyright (C) 2013 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
+ module PluginHelper
17
+ def setup_plugin(plugin_class)
18
+ @worker = StubWorker.new
19
+ @plugin = plugin_class.new(@worker)
20
+
21
+ @messages = []
22
+ stub(@plugin).emit do |*message|
23
+ @messages << message
24
+ end
25
+
26
+ @posted = []
27
+ stub(@plugin).post do |*message|
28
+ @posted << message
29
+ end
30
+ end
31
+
32
+ def teardown_plugin
33
+ @plugin = nil
34
+ @worker = nil
35
+ @messages = nil
36
+ @posted = nil
37
+ end
38
+ end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013 droonga project
1
+ # Copyright (C) 2013 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
@@ -51,12 +51,25 @@ module Sandbox
51
51
  Groonga::Context.default_options = nil
52
52
  end
53
53
 
54
+ def setup_database
55
+ @database = Groonga::Database.create(:path => @database_path.to_s)
56
+ end
57
+
58
+ def teardown_database
59
+ @database.close
60
+ @database = nil
61
+ end
62
+
54
63
  def restore(dumped_command)
55
- context = Groonga::Context.new
56
- database = context.create_database(@database_path.to_s)
57
- context.restore(dumped_command)
58
- database.close
59
- context.close
64
+ if @database
65
+ Groonga::Context.default.restore(dumped_command)
66
+ else
67
+ context = Groonga::Context.new
68
+ database = context.create_database(@database_path.to_s)
69
+ context.restore(dumped_command)
70
+ database.close
71
+ context.close
72
+ end
60
73
  end
61
74
 
62
75
  def teardown_sandbox
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013 droonga project
1
+ # Copyright (C) 2013 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
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013 droonga project
1
+ # Copyright (C) 2013 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,20 +16,8 @@
16
16
  require "droonga/watch_schema"
17
17
 
18
18
  module WatchHelper
19
- def setup_database
20
- FileUtils.rm_rf(@database_path.dirname.to_s)
21
- FileUtils.mkdir_p(@database_path.dirname.to_s)
22
- @database = Groonga::Database.create(:path => @database_path.to_s)
23
- end
24
-
25
19
  def setup_schema
26
20
  schema = Droonga::WatchSchema.new(Groonga::Context.default)
27
21
  schema.ensure_created
28
22
  end
29
-
30
- def teardown_database
31
- @database.close
32
- @database = nil
33
- FileUtils.rm_rf(@database_path.dirname.to_s)
34
- end
35
23
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013 droonga project
1
+ # Copyright (C) 2013 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
@@ -29,7 +29,7 @@ class AdapterGroongaSelectTest < Test::Unit::TestCase
29
29
 
30
30
  expected_search_request = {
31
31
  "queries" => {
32
- "EmptyTable" => {
32
+ "EmptyTable_result" => {
33
33
  "source" => "EmptyTable",
34
34
  "output" => {
35
35
  "elements" => [
@@ -40,6 +40,8 @@ class AdapterGroongaSelectTest < Test::Unit::TestCase
40
40
  "records",
41
41
  ],
42
42
  "attributes" => ["_id"],
43
+ "offset" => 0,
44
+ "limit" => 10,
43
45
  },
44
46
  },
45
47
  },
@@ -62,7 +64,7 @@ class AdapterGroongaSelectTest < Test::Unit::TestCase
62
64
 
63
65
  expected_search_request = {
64
66
  "queries" => {
65
- "EmptyTable" => {
67
+ "EmptyTable_result" => {
66
68
  "source" => "EmptyTable",
67
69
  "output" => {
68
70
  "elements" => [
@@ -73,6 +75,8 @@ class AdapterGroongaSelectTest < Test::Unit::TestCase
73
75
  "records",
74
76
  ],
75
77
  "attributes" => expected_attributes,
78
+ "offset" => 0,
79
+ "limit" => 10,
76
80
  },
77
81
  },
78
82
  },
@@ -106,7 +110,7 @@ class AdapterGroongaSelectTest < Test::Unit::TestCase
106
110
 
107
111
  expected_search_request = {
108
112
  "queries" => {
109
- "EmptyTable" => {
113
+ "EmptyTable_result" => {
110
114
  "source" => "EmptyTable",
111
115
  "condition"=> {
112
116
  "query" => "QueryTest",
@@ -124,6 +128,8 @@ class AdapterGroongaSelectTest < Test::Unit::TestCase
124
128
  "records",
125
129
  ],
126
130
  "attributes" => ["_id"],
131
+ "offset" => 0,
132
+ "limit" => 10,
127
133
  },
128
134
  },
129
135
  },
@@ -139,6 +145,104 @@ class AdapterGroongaSelectTest < Test::Unit::TestCase
139
145
  assert_matchTo(["_key", "content"], "_key || content")
140
146
  end
141
147
  end
148
+
149
+ class OffsetTest < self
150
+ def assert_offset(expected_offset, offset)
151
+ select_request = {
152
+ "table" => "EmptyTable",
153
+ "output_columns" => "_id",
154
+ }
155
+ select_request["offset"] = offset unless offset.nil?
156
+
157
+ expected_search_request = {
158
+ "queries" => {
159
+ "EmptyTable_result" => {
160
+ "source" => "EmptyTable",
161
+ "output" => {
162
+ "elements" => [
163
+ "startTime",
164
+ "elapsedTime",
165
+ "count",
166
+ "attributes",
167
+ "records",
168
+ ],
169
+ "attributes" => ["_id"],
170
+ "offset" => expected_offset,
171
+ "limit" => 10,
172
+ },
173
+ },
174
+ },
175
+ }
176
+ assert_equal(expected_search_request, convert(select_request))
177
+ end
178
+
179
+ def test_zero
180
+ assert_offset(0, "0")
181
+ end
182
+
183
+ def test_large
184
+ assert_offset(100, "100")
185
+ end
186
+
187
+ def test_integer
188
+ assert_offset(100, 100)
189
+ end
190
+
191
+ def test_default
192
+ assert_offset(0, nil)
193
+ end
194
+ end
195
+
196
+ class LimitTest < self
197
+ def assert_limit(expected_limit, limit)
198
+ select_request = {
199
+ "table" => "EmptyTable",
200
+ "output_columns" => "_id",
201
+ }
202
+ select_request["limit"] = limit unless limit.nil?
203
+
204
+ expected_search_request = {
205
+ "queries" => {
206
+ "EmptyTable_result" => {
207
+ "source" => "EmptyTable",
208
+ "output" => {
209
+ "elements" => [
210
+ "startTime",
211
+ "elapsedTime",
212
+ "count",
213
+ "attributes",
214
+ "records",
215
+ ],
216
+ "attributes" => ["_id"],
217
+ "offset" => 0,
218
+ "limit" => expected_limit,
219
+ },
220
+ },
221
+ },
222
+ }
223
+ assert_equal(expected_search_request, convert(select_request))
224
+ end
225
+
226
+ def test_zero
227
+ assert_limit(0, "0")
228
+ end
229
+
230
+ def test_large
231
+ assert_limit(100, "100")
232
+ end
233
+
234
+ def test_negative
235
+ assert_limit(-1, "-1")
236
+ end
237
+
238
+ def test_integer
239
+ assert_limit(100, 100)
240
+ end
241
+
242
+ def test_default
243
+ assert_limit(10, nil)
244
+ end
245
+ end
142
246
  end
143
247
 
144
248
  class ResponseTest < self
@@ -0,0 +1,558 @@
1
+ # Copyright (C) 2013 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/plugin/collector/basic"
17
+
18
+ class BasicCollectorTest < Test::Unit::TestCase
19
+ include PluginHelper
20
+
21
+ def setup
22
+ setup_database
23
+ setup_plugin(Droonga::BasicCollector)
24
+ end
25
+
26
+ def teardown
27
+ teardown_plugin
28
+ teardown_database
29
+ end
30
+
31
+ private
32
+ def create_record(*columns)
33
+ columns
34
+ end
35
+
36
+ class << self
37
+ def create_record(*columns)
38
+ columns
39
+ end
40
+ end
41
+
42
+ class GatherTest < self
43
+ data(
44
+ :simple_mapping => {
45
+ :expected => "result",
46
+ :source => "result",
47
+ :mapping => "string_name",
48
+ },
49
+ :complex_mapping => {
50
+ :expected => {
51
+ "count" => 3,
52
+ "records" => [
53
+ create_record(0),
54
+ create_record(1),
55
+ create_record(2),
56
+ ],
57
+ },
58
+ :source => {
59
+ "count" => 3,
60
+ "records" => [
61
+ create_record(0),
62
+ create_record(1),
63
+ create_record(2),
64
+ ],
65
+ },
66
+ :mapping => {
67
+ "output" => "search_result",
68
+ },
69
+ },
70
+ :offset_and_limit => {
71
+ :expected => {
72
+ "count" => 3,
73
+ "records" => [
74
+ create_record(1),
75
+ ],
76
+ },
77
+ :source => {
78
+ "count" => 3,
79
+ "records" => [
80
+ create_record(0),
81
+ create_record(1),
82
+ create_record(2),
83
+ ],
84
+ },
85
+ :mapping => {
86
+ "output" => "search_result",
87
+ "element" => "records",
88
+ "offset" => 1,
89
+ "limit" => 1,
90
+ },
91
+ },
92
+ :offset_and_unlimited_limit => {
93
+ :expected => {
94
+ "count" => 3,
95
+ "records" => [
96
+ create_record(1),
97
+ create_record(2),
98
+ ],
99
+ },
100
+ :source => {
101
+ "count" => 3,
102
+ "records" => [
103
+ create_record(0),
104
+ create_record(1),
105
+ create_record(2),
106
+ ],
107
+ },
108
+ :mapping => {
109
+ "output" => "search_result",
110
+ "element" => "records",
111
+ "offset" => 1,
112
+ "limit" => -1,
113
+ },
114
+ },
115
+ :attributes => {
116
+ :expected => {
117
+ "count" => 2,
118
+ "records" => [
119
+ create_record(1, 1.1, 1.2, 1.3, 1.4),
120
+ create_record(2, 2.1, 2.2, 2.3, 2.4),
121
+ ],
122
+ },
123
+ :source => {
124
+ "count" => 2,
125
+ "records" => [
126
+ create_record(1, 1.1, 1.2, 1.3, 1.4),
127
+ create_record(2, 2.1, 2.2, 2.3, 2.4),
128
+ ],
129
+ },
130
+ :mapping => {
131
+ "output" => "search_result",
132
+ "element" => "records",
133
+ "attributes" => ["_key", "chapter", "section", "subsection", "paragraph"],
134
+ "limit" => -1,
135
+ },
136
+ },
137
+ :attributes_with_sort_attributes => {
138
+ :expected => {
139
+ "count" => 2,
140
+ "records" => [
141
+ create_record(1, 1.1, 1.2),
142
+ create_record(2, 2.1, 2.2),
143
+ ],
144
+ },
145
+ :source => {
146
+ "count" => 2,
147
+ "records" => [
148
+ create_record(1, 1.1, 1.2, 1.3, 1.4),
149
+ create_record(2, 2.1, 2.2, 2.3, 2.4),
150
+ ],
151
+ },
152
+ :mapping => {
153
+ "output" => "search_result",
154
+ "element" => "records",
155
+ "attributes" => ["_key", "chapter", "section"],
156
+ "limit" => -1,
157
+ },
158
+ },
159
+ :format_simple => {
160
+ :expected => {
161
+ "count" => 2,
162
+ "records" => [
163
+ create_record(1, 1.1, 1.2),
164
+ create_record(2, 2.1, 2.2),
165
+ ],
166
+ },
167
+ :source => {
168
+ "count" => 2,
169
+ "records" => [
170
+ create_record(1, 1.1, 1.2),
171
+ create_record(2, 2.1, 2.2),
172
+ ],
173
+ },
174
+ :mapping => {
175
+ "output" => "search_result",
176
+ "element" => "records",
177
+ "format" => "simple",
178
+ "attributes" => ["_key", "chapter", "section"],
179
+ "limit" => -1,
180
+ },
181
+ },
182
+ :format_complex => {
183
+ :expected => {
184
+ "count" => 2,
185
+ "records" => [
186
+ { "_key" => 1, "chapter" => 1.1, "section" => 1.2 },
187
+ { "_key" => 2, "chapter" => 2.1, "section" => 2.2 },
188
+ ],
189
+ },
190
+ :source => {
191
+ "count" => 2,
192
+ "records" => [
193
+ create_record(1, 1.1, 1.2),
194
+ create_record(2, 2.1, 2.2),
195
+ ],
196
+ },
197
+ :mapping => {
198
+ "output" => "search_result",
199
+ "element" => "records",
200
+ "format" => "complex",
201
+ "attributes" => ["_key", "chapter", "section"],
202
+ "limit" => -1,
203
+ },
204
+ },
205
+ )
206
+ def test_gather(data)
207
+ request = {
208
+ "task" => {
209
+ "values" => nil,
210
+ "component" => {
211
+ "body" => nil,
212
+ "outputs" => nil,
213
+ },
214
+ },
215
+ "id" => nil,
216
+ "value" => data[:source],
217
+ "name" => data[:mapping],
218
+ "descendants" => nil,
219
+ }
220
+ @plugin.process("collector_gather", request)
221
+ output_name = data[:mapping]
222
+ output_name = output_name["output"] if output_name.is_a?(Hash)
223
+ assert_equal([data[:expected], output_name], @messages.last)
224
+ end
225
+ end
226
+
227
+ class ReduceTest < self
228
+ def test_sum
229
+ input_name = "input_#{Time.now.to_i}"
230
+ output_name = "output_#{Time.now.to_i}"
231
+ request = {
232
+ "task" => {
233
+ "values" => {
234
+ output_name => {
235
+ "numeric_value" => 1,
236
+ "numeric_key_records" => [
237
+ create_record(1),
238
+ create_record(2),
239
+ create_record(3),
240
+ ],
241
+ "string_key_records" => [
242
+ create_record("a"),
243
+ create_record("b"),
244
+ create_record("c"),
245
+ ],
246
+ },
247
+ },
248
+ "component" => {
249
+ "body" => {
250
+ input_name => {
251
+ output_name => {
252
+ "numeric_value" => {
253
+ "type" => "sum",
254
+ "limit" => -1,
255
+ },
256
+ "numeric_key_records" => {
257
+ "type" => "sum",
258
+ "limit" => -1,
259
+ },
260
+ "string_key_records" => {
261
+ "type" => "sum",
262
+ "limit" => -1,
263
+ },
264
+ },
265
+ },
266
+ },
267
+ "outputs" => nil,
268
+ },
269
+ },
270
+ "id" => nil,
271
+ "value" => {
272
+ "numeric_value" => 2,
273
+ "numeric_key_records" => [
274
+ create_record(4),
275
+ create_record(5),
276
+ create_record(6),
277
+ ],
278
+ "string_key_records" => [
279
+ create_record("d"),
280
+ create_record("e"),
281
+ create_record("f"),
282
+ ],
283
+ },
284
+ "name" => input_name,
285
+ "descendants" => nil,
286
+ }
287
+ @plugin.process("collector_reduce", request)
288
+ assert_equal([
289
+ {
290
+ "numeric_value" => 3,
291
+ "numeric_key_records" => [
292
+ create_record(1),
293
+ create_record(2),
294
+ create_record(3),
295
+ create_record(4),
296
+ create_record(5),
297
+ create_record(6),
298
+ ],
299
+ "string_key_records" => [
300
+ create_record("a"),
301
+ create_record("b"),
302
+ create_record("c"),
303
+ create_record("d"),
304
+ create_record("e"),
305
+ create_record("f"),
306
+ ],
307
+ },
308
+ output_name
309
+ ],
310
+ @messages.last)
311
+ end
312
+
313
+ def test_sum_with_limit
314
+ input_name = "input_#{Time.now.to_i}"
315
+ output_name = "output_#{Time.now.to_i}"
316
+ request = {
317
+ "task" => {
318
+ "values" => {
319
+ output_name => {
320
+ "numeric_value" => 1,
321
+ "numeric_key_records" => [
322
+ create_record(1),
323
+ create_record(2),
324
+ create_record(3),
325
+ ],
326
+ "string_key_records" => [
327
+ create_record("a"),
328
+ create_record("b"),
329
+ create_record("c"),
330
+ ],
331
+ },
332
+ },
333
+ "component" => {
334
+ "body" => {
335
+ input_name => {
336
+ output_name => {
337
+ "numeric_value" => {
338
+ "type" => "sum",
339
+ "limit" => 2,
340
+ },
341
+ "numeric_key_records" => {
342
+ "type" => "sum",
343
+ "limit" => 2,
344
+ },
345
+ "string_key_records" => {
346
+ "type" => "sum",
347
+ "limit" => -1,
348
+ },
349
+ },
350
+ },
351
+ },
352
+ "outputs" => nil,
353
+ },
354
+ },
355
+ "id" => nil,
356
+ "value" => {
357
+ "numeric_value" => 2,
358
+ "numeric_key_records" => [
359
+ create_record(4),
360
+ create_record(5),
361
+ create_record(6),
362
+ ],
363
+ "string_key_records" => [
364
+ create_record("d"),
365
+ create_record("e"),
366
+ create_record("f"),
367
+ ],
368
+ },
369
+ "name" => input_name,
370
+ "descendants" => nil,
371
+ }
372
+ @plugin.process("collector_reduce", request)
373
+ assert_equal([
374
+ {
375
+ "numeric_value" => 3,
376
+ "numeric_key_records" => [
377
+ create_record(1),
378
+ create_record(2),
379
+ ],
380
+ "string_key_records" => [
381
+ create_record("a"),
382
+ create_record("b"),
383
+ create_record("c"),
384
+ create_record("d"),
385
+ create_record("e"),
386
+ create_record("f"),
387
+ ],
388
+ },
389
+ output_name
390
+ ],
391
+ @messages.last)
392
+ end
393
+
394
+ def test_sort
395
+ input_name = "input_#{Time.now.to_i}"
396
+ output_name = "output_#{Time.now.to_i}"
397
+ request = {
398
+ "task" => {
399
+ "values" => {
400
+ output_name => {
401
+ "numeric_key_records" => [
402
+ create_record(1),
403
+ create_record(3),
404
+ create_record(5),
405
+ ],
406
+ "string_key_records" => [
407
+ create_record("a"),
408
+ create_record("c"),
409
+ create_record("e"),
410
+ ],
411
+ },
412
+ },
413
+ "component" => {
414
+ "body" => {
415
+ input_name => {
416
+ output_name => {
417
+ "numeric_key_records" => {
418
+ "type" => "sort",
419
+ "operators" => [
420
+ { "column" => 0, "operator" => "<" },
421
+ ],
422
+ "limit" => -1,
423
+ },
424
+ "string_key_records" => {
425
+ "type" => "sort",
426
+ "operators" => [
427
+ { "column" => 0, "operator" => "<" },
428
+ ],
429
+ "limit" => -1,
430
+ },
431
+ },
432
+ },
433
+ },
434
+ "outputs" => nil,
435
+ },
436
+ },
437
+ "id" => nil,
438
+ "value" => {
439
+ "numeric_key_records" => [
440
+ create_record(2),
441
+ create_record(4),
442
+ create_record(6),
443
+ ],
444
+ "string_key_records" => [
445
+ create_record("b"),
446
+ create_record("d"),
447
+ create_record("f"),
448
+ ],
449
+ },
450
+ "name" => input_name,
451
+ "descendants" => nil,
452
+ }
453
+ @plugin.process("collector_reduce", request)
454
+ assert_equal([
455
+ {
456
+ "numeric_key_records" => [
457
+ create_record(1),
458
+ create_record(2),
459
+ create_record(3),
460
+ create_record(4),
461
+ create_record(5),
462
+ create_record(6),
463
+ ],
464
+ "string_key_records" => [
465
+ create_record("a"),
466
+ create_record("b"),
467
+ create_record("c"),
468
+ create_record("d"),
469
+ create_record("e"),
470
+ create_record("f"),
471
+ ],
472
+ },
473
+ output_name
474
+ ],
475
+ @messages.last)
476
+ end
477
+
478
+ def test_sort_with_limit
479
+ input_name = "input_#{Time.now.to_i}"
480
+ output_name = "output_#{Time.now.to_i}"
481
+ request = {
482
+ "task" => {
483
+ "values" => {
484
+ output_name => {
485
+ "numeric_key_records" => [
486
+ create_record(1),
487
+ create_record(3),
488
+ create_record(5),
489
+ ],
490
+ "string_key_records" => [
491
+ create_record("a"),
492
+ create_record("c"),
493
+ create_record("e"),
494
+ ],
495
+ },
496
+ },
497
+ "component" => {
498
+ "body" => {
499
+ input_name => {
500
+ output_name => {
501
+ "numeric_key_records" => {
502
+ "type" => "sort",
503
+ "operators" => [
504
+ { "column" => 0, "operator" => "<" },
505
+ ],
506
+ "limit" => 2,
507
+ },
508
+ "string_key_records" => {
509
+ "type" => "sort",
510
+ "operators" => [
511
+ { "column" => 0, "operator" => "<" },
512
+ ],
513
+ "limit" => -1,
514
+ },
515
+ },
516
+ },
517
+ },
518
+ "outputs" => nil,
519
+ },
520
+ },
521
+ "id" => nil,
522
+ "value" => {
523
+ "numeric_key_records" => [
524
+ create_record(2),
525
+ create_record(4),
526
+ create_record(6),
527
+ ],
528
+ "string_key_records" => [
529
+ create_record("b"),
530
+ create_record("d"),
531
+ create_record("f"),
532
+ ],
533
+ },
534
+ "name" => input_name,
535
+ "descendants" => nil,
536
+ }
537
+ @plugin.process("collector_reduce", request)
538
+ assert_equal([
539
+ {
540
+ "numeric_key_records" => [
541
+ create_record(1),
542
+ create_record(2),
543
+ ],
544
+ "string_key_records" => [
545
+ create_record("a"),
546
+ create_record("b"),
547
+ create_record("c"),
548
+ create_record("d"),
549
+ create_record("e"),
550
+ create_record("f"),
551
+ ],
552
+ },
553
+ output_name
554
+ ],
555
+ @messages.last)
556
+ end
557
+ end
558
+ end