fluent-plugin-droonga 0.7.0 → 0.8.0

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.
Files changed (163) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -4
  3. data/benchmark/watch/benchmark-notify.rb +2 -2
  4. data/benchmark/watch/benchmark-scan.rb +3 -0
  5. data/benchmark/watch/fluentd.conf +0 -1
  6. data/fluent-plugin-droonga.gemspec +2 -3
  7. data/lib/droonga/catalog.rb +10 -124
  8. data/lib/droonga/catalog/base.rb +140 -0
  9. data/lib/droonga/catalog/version1.rb +23 -0
  10. data/lib/droonga/catalog_loader.rb +33 -0
  11. data/lib/droonga/collector.rb +2 -71
  12. data/lib/droonga/collector_plugin.rb +2 -34
  13. data/lib/droonga/dispatcher.rb +141 -196
  14. data/lib/droonga/distribution_planner.rb +76 -0
  15. data/lib/droonga/distributor.rb +5 -7
  16. data/lib/droonga/distributor_plugin.rb +23 -15
  17. data/lib/droonga/engine.rb +2 -2
  18. data/lib/droonga/event_loop.rb +46 -0
  19. data/lib/droonga/farm.rb +9 -5
  20. data/lib/droonga/fluent_message_sender.rb +84 -0
  21. data/lib/droonga/forwarder.rb +43 -53
  22. data/lib/droonga/handler.rb +20 -68
  23. data/lib/droonga/handler_message.rb +61 -0
  24. data/lib/droonga/handler_messenger.rb +92 -0
  25. data/lib/droonga/handler_plugin.rb +10 -12
  26. data/lib/droonga/input_adapter.rb +52 -0
  27. data/lib/droonga/{adapter.rb → input_adapter_plugin.rb} +7 -13
  28. data/lib/droonga/input_message.rb +11 -11
  29. data/lib/droonga/logger.rb +4 -3
  30. data/lib/droonga/message_pack_packer.rb +62 -0
  31. data/lib/droonga/message_processing_error.rb +54 -0
  32. data/lib/droonga/message_pusher.rb +60 -0
  33. data/lib/droonga/message_receiver.rb +61 -0
  34. data/lib/droonga/output_adapter.rb +53 -0
  35. data/lib/droonga/{adapter_plugin.rb → output_adapter_plugin.rb} +3 -21
  36. data/lib/droonga/output_message.rb +37 -0
  37. data/lib/droonga/partition.rb +27 -5
  38. data/lib/droonga/pluggable.rb +9 -4
  39. data/lib/droonga/plugin.rb +12 -3
  40. data/lib/droonga/plugin/collector/basic.rb +91 -18
  41. data/lib/droonga/plugin/distributor/crud.rb +9 -9
  42. data/lib/droonga/plugin/distributor/distributed_search_planner.rb +401 -0
  43. data/lib/droonga/plugin/distributor/groonga.rb +5 -5
  44. data/lib/droonga/plugin/distributor/search.rb +4 -246
  45. data/lib/droonga/plugin/distributor/watch.rb +11 -6
  46. data/lib/droonga/plugin/handler/add.rb +69 -7
  47. data/lib/droonga/plugin/handler/groonga.rb +6 -6
  48. data/lib/droonga/plugin/handler/search.rb +5 -3
  49. data/lib/droonga/plugin/handler/watch.rb +19 -13
  50. data/lib/droonga/plugin/{adapter → input_adapter}/groonga.rb +5 -11
  51. data/lib/droonga/plugin/{adapter → input_adapter}/groonga/select.rb +2 -36
  52. data/lib/droonga/plugin/output_adapter/groonga.rb +30 -0
  53. data/lib/droonga/plugin/output_adapter/groonga/select.rb +54 -0
  54. data/lib/droonga/plugin_loader.rb +2 -2
  55. data/lib/droonga/processor.rb +21 -23
  56. data/lib/droonga/replier.rb +40 -0
  57. data/lib/droonga/searcher.rb +298 -174
  58. data/lib/droonga/server.rb +0 -67
  59. data/lib/droonga/session.rb +85 -0
  60. data/lib/droonga/test.rb +21 -0
  61. data/lib/droonga/test/stub_distributor.rb +31 -0
  62. data/lib/droonga/test/stub_handler.rb +37 -0
  63. data/lib/droonga/test/stub_handler_message.rb +35 -0
  64. data/lib/droonga/test/stub_handler_messenger.rb +34 -0
  65. data/lib/droonga/time_formatter.rb +37 -0
  66. data/lib/droonga/watcher.rb +1 -0
  67. data/lib/droonga/worker.rb +16 -19
  68. data/lib/fluent/plugin/out_droonga.rb +9 -9
  69. data/lib/groonga_command_converter.rb +5 -5
  70. data/sample/cluster/catalog.json +1 -1
  71. data/test/command/config/default/catalog.json +19 -1
  72. data/test/command/fixture/event.jsons +41 -0
  73. data/test/command/fixture/user-table.jsons +9 -0
  74. data/test/command/run-test.rb +2 -2
  75. data/test/command/suite/add/error/invalid-integer.expected +20 -0
  76. data/test/command/suite/add/error/invalid-integer.test +12 -0
  77. data/test/command/suite/add/error/invalid-time.expected +20 -0
  78. data/test/command/suite/add/error/invalid-time.test +12 -0
  79. data/test/command/suite/add/error/missing-key.expected +13 -0
  80. data/test/command/suite/add/error/missing-key.test +16 -0
  81. data/test/command/suite/add/error/missing-table.expected +13 -0
  82. data/test/command/suite/add/error/missing-table.test +16 -0
  83. data/test/command/suite/add/error/unknown-column.expected +20 -0
  84. data/test/command/suite/add/error/unknown-column.test +12 -0
  85. data/test/command/suite/add/error/unknown-table.expected +13 -0
  86. data/test/command/suite/add/error/unknown-table.test +17 -0
  87. data/test/command/suite/add/minimum.expected +1 -3
  88. data/test/command/suite/add/with-values.expected +1 -3
  89. data/test/command/suite/add/without-key.expected +1 -3
  90. data/test/command/suite/message/error/missing-dataset.expected +13 -0
  91. data/test/command/suite/message/error/missing-dataset.test +5 -0
  92. data/test/command/suite/message/error/unknown-command.expected +13 -0
  93. data/test/command/suite/message/error/unknown-command.test +6 -0
  94. data/test/command/suite/message/error/unknown-dataset.expected +13 -0
  95. data/test/command/suite/message/error/unknown-dataset.test +6 -0
  96. data/test/command/suite/search/{array-attribute-label.expected → attributes/array.expected} +0 -0
  97. data/test/command/suite/search/{array-attribute-label.test → attributes/array.test} +0 -0
  98. data/test/command/suite/search/{hash-attribute-label.expected → attributes/hash.expected} +0 -0
  99. data/test/command/suite/search/{hash-attribute-label.test → attributes/hash.test} +0 -0
  100. data/test/command/suite/search/{condition-nested.expected → condition/nested.expected} +0 -0
  101. data/test/command/suite/search/{condition-nested.test → condition/nested.test} +0 -0
  102. data/test/command/suite/search/{condition-query.expected → condition/query.expected} +0 -0
  103. data/test/command/suite/search/{condition-query.test → condition/query.test} +0 -0
  104. data/test/command/suite/search/{condition-script.expected → condition/script.expected} +0 -0
  105. data/test/command/suite/search/{condition-script.test → condition/script.test} +0 -0
  106. data/test/command/suite/search/error/cyclic-source.expected +18 -0
  107. data/test/command/suite/search/error/cyclic-source.test +12 -0
  108. data/test/command/suite/search/error/deeply-cyclic-source.expected +21 -0
  109. data/test/command/suite/search/error/deeply-cyclic-source.test +15 -0
  110. data/test/command/suite/search/error/missing-source-parameter.expected +17 -0
  111. data/test/command/suite/search/error/missing-source-parameter.test +11 -0
  112. data/test/command/suite/search/error/unknown-source.expected +18 -0
  113. data/test/command/suite/search/error/unknown-source.test +12 -0
  114. data/test/command/suite/search/{minimum.expected → group/count.expected} +2 -1
  115. data/test/command/suite/search/{minimum.test → group/count.test} +5 -3
  116. data/test/command/suite/search/group/limit.expected +19 -0
  117. data/test/command/suite/search/group/limit.test +20 -0
  118. data/test/command/suite/search/group/string.expected +36 -0
  119. data/test/command/suite/search/group/string.test +44 -0
  120. data/test/command/suite/search/{chained-queries.expected → multiple/chained.expected} +0 -0
  121. data/test/command/suite/search/{chained-queries.test → multiple/chained.test} +0 -0
  122. data/test/command/suite/search/{multiple-queries.expected → multiple/parallel.expected} +0 -0
  123. data/test/command/suite/search/{multiple-queries.test → multiple/parallel.test} +0 -0
  124. data/test/command/suite/search/{output-range.expected → range/only-output.expected} +0 -0
  125. data/test/command/suite/search/{output-range.test → range/only-output.test} +0 -0
  126. data/test/command/suite/search/{sort-range.expected → range/only-sort.expected} +0 -0
  127. data/test/command/suite/search/{sort-range.test → range/only-sort.test} +0 -0
  128. data/test/command/suite/search/{sort-and-output-range.expected → range/sort-and-output.expected} +0 -0
  129. data/test/command/suite/search/{sort-and-output-range.test → range/sort-and-output.test} +0 -0
  130. data/test/command/suite/search/range/too-large-output-offset.expected +16 -0
  131. data/test/command/suite/search/range/too-large-output-offset.test +25 -0
  132. data/test/command/suite/search/range/too-large-sort-offset.expected +16 -0
  133. data/test/command/suite/search/range/too-large-sort-offset.test +28 -0
  134. data/test/command/suite/search/response/records/value/time.expected +24 -0
  135. data/test/command/suite/search/response/records/value/time.test +24 -0
  136. data/test/command/suite/search/sort/default-offset-limit.expected +43 -0
  137. data/test/command/suite/search/sort/default-offset-limit.test +26 -0
  138. data/test/command/suite/search/{sort-with-invisible-column.expected → sort/invisible-column.expected} +0 -0
  139. data/test/command/suite/search/{sort-with-invisible-column.test → sort/invisible-column.test} +0 -0
  140. data/test/command/suite/watch/subscribe.expected +12 -0
  141. data/test/command/suite/watch/subscribe.test +9 -0
  142. data/test/command/suite/watch/unsubscribe.expected +12 -0
  143. data/test/command/suite/watch/unsubscribe.test +9 -0
  144. data/test/unit/{test_catalog.rb → catalog/test_version1.rb} +12 -4
  145. data/test/unit/fixtures/{catalog.json → catalog/version1.json} +0 -0
  146. data/test/unit/helper.rb +2 -0
  147. data/test/unit/plugin/collector/test_basic.rb +289 -33
  148. data/test/unit/plugin/distributor/test_search.rb +176 -861
  149. data/test/unit/plugin/distributor/test_search_planner.rb +1102 -0
  150. data/test/unit/plugin/handler/groonga/test_column_create.rb +17 -13
  151. data/test/unit/plugin/handler/groonga/test_table_create.rb +10 -10
  152. data/test/unit/plugin/handler/test_add.rb +74 -11
  153. data/test/unit/plugin/handler/test_groonga.rb +15 -1
  154. data/test/unit/plugin/handler/test_search.rb +33 -17
  155. data/test/unit/plugin/handler/test_watch.rb +43 -27
  156. data/test/unit/run-test.rb +2 -0
  157. data/test/unit/test_message_pack_packer.rb +51 -0
  158. data/test/unit/test_time_formatter.rb +29 -0
  159. metadata +208 -110
  160. data/lib/droonga/job_queue.rb +0 -87
  161. data/lib/droonga/job_queue_schema.rb +0 -65
  162. data/test/unit/test_adapter.rb +0 -51
  163. data/test/unit/test_job_queue_schema.rb +0 -45
@@ -0,0 +1,24 @@
1
+ [
2
+ "droonga.message",
3
+ 0,
4
+ {
5
+ "inReplyTo": null,
6
+ "statusCode": 200,
7
+ "type": "search.result",
8
+ "body": {
9
+ "result": {
10
+ "count": 2,
11
+ "records": [
12
+ [
13
+ "Groonga Night 3",
14
+ "2012-11-29T10:00:00.000000Z"
15
+ ],
16
+ [
17
+ "Groonga Night 4",
18
+ "2013-11-29T08:00:00.000000Z"
19
+ ]
20
+ ]
21
+ }
22
+ }
23
+ }
24
+ ]
@@ -0,0 +1,24 @@
1
+ #@include fixture/event.jsons
2
+ {
3
+ "type": "search",
4
+ "dataset": "Droonga",
5
+ "body": {
6
+ "queries": {
7
+ "result": {
8
+ "source": "Event",
9
+ "sortBy": ["_key"],
10
+ "output": {
11
+ "elements": [
12
+ "startTime",
13
+ "elapsedTime",
14
+ "count",
15
+ "attributes",
16
+ "records"
17
+ ],
18
+ "limit": -1,
19
+ "attributes": ["_key", "start"]
20
+ }
21
+ }
22
+ }
23
+ }
24
+ }
@@ -0,0 +1,43 @@
1
+ [
2
+ "droonga.message",
3
+ 0,
4
+ {
5
+ "inReplyTo": null,
6
+ "statusCode": 200,
7
+ "type": "search.result",
8
+ "body": {
9
+ "result": {
10
+ "count": 9,
11
+ "records": [
12
+ [
13
+ "1.9"
14
+ ],
15
+ [
16
+ "1.8"
17
+ ],
18
+ [
19
+ "1.7"
20
+ ],
21
+ [
22
+ "1.6"
23
+ ],
24
+ [
25
+ "1.5"
26
+ ],
27
+ [
28
+ "1.4"
29
+ ],
30
+ [
31
+ "1.3"
32
+ ],
33
+ [
34
+ "1.2"
35
+ ],
36
+ [
37
+ "1.1"
38
+ ]
39
+ ]
40
+ }
41
+ }
42
+ }
43
+ ]
@@ -0,0 +1,26 @@
1
+ #@include fixture/documents.jsons
2
+ {
3
+ "type": "search",
4
+ "dataset": "Droonga",
5
+ "body": {
6
+ "queries": {
7
+ "result": {
8
+ "source": "Sections",
9
+ "sortBy": {
10
+ "keys": ["-_key"]
11
+ },
12
+ "output": {
13
+ "elements": [
14
+ "startTime",
15
+ "elapsedTime",
16
+ "count",
17
+ "attributes",
18
+ "records"
19
+ ],
20
+ "limit": -1,
21
+ "attributes": ["_key"]
22
+ }
23
+ }
24
+ }
25
+ }
26
+ }
@@ -0,0 +1,12 @@
1
+ [
2
+ "droonga.message",
3
+ 0,
4
+ {
5
+ "inReplyTo": null,
6
+ "statusCode": 200,
7
+ "type": "watch.subscribe.result",
8
+ "body": [
9
+ true
10
+ ]
11
+ }
12
+ ]
@@ -0,0 +1,9 @@
1
+ {
2
+ "type": "watch.subscribe",
3
+ "dataset": "Watch",
4
+ "body": {
5
+ "condition": "condition",
6
+ "subscriber": "subscriber",
7
+ "route": "localhost:23003/output"
8
+ }
9
+ }
@@ -0,0 +1,12 @@
1
+ [
2
+ "droonga.message",
3
+ 0,
4
+ {
5
+ "inReplyTo": null,
6
+ "statusCode": 200,
7
+ "type": "watch.unsubscribe.result",
8
+ "body": [
9
+ true
10
+ ]
11
+ }
12
+ ]
@@ -0,0 +1,9 @@
1
+ {
2
+ "type": "watch.unsubscribe",
3
+ "dataset": "Watch",
4
+ "body": {
5
+ "condition": "condition",
6
+ "subscriber": "subscriber",
7
+ "route": "localhost:23003/output"
8
+ }
9
+ }
@@ -13,11 +13,12 @@
13
13
  # License along with this library; if not, write to the Free Software
14
14
  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
15
 
16
- require "droonga/catalog"
16
+ require "droonga/catalog/version1"
17
17
 
18
18
  class CatalogTest < Test::Unit::TestCase
19
19
  def setup
20
- @catalog = Droonga::Catalog.new(catalog_path)
20
+ data = JSON.parse(File.read(catalog_path))
21
+ @catalog = Droonga::Catalog::Version1.new(data, base_path)
21
22
  end
22
23
 
23
24
  def test_option
@@ -26,7 +27,6 @@ class CatalogTest < Test::Unit::TestCase
26
27
 
27
28
  def test_get_partitions
28
29
  partitions = @catalog.get_partitions("localhost:23003/test")
29
- base_path = File.expand_path("../fixtures", __FILE__)
30
30
  assert_equal({
31
31
  "localhost:23003/test.000" => {
32
32
  :database => "#{base_path}/000/db",
@@ -53,7 +53,15 @@ class CatalogTest < Test::Unit::TestCase
53
53
  end
54
54
 
55
55
  private
56
+ def fixture_path(base_path)
57
+ File.expand_path("../../fixtures/#{base_path}", __FILE__)
58
+ end
59
+
56
60
  def catalog_path
57
- @catalog_path ||= File.expand_path("../fixtures/catalog.json", __FILE__)
61
+ @catalog_path ||= fixture_path("catalog/version1.json")
62
+ end
63
+
64
+ def base_path
65
+ File.dirname(catalog_path)
58
66
  end
59
67
  end
data/test/unit/helper.rb CHANGED
@@ -13,6 +13,8 @@
13
13
  # License along with this library; if not, write to the Free Software
14
14
  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
15
 
16
+ require "droonga/test"
17
+
16
18
  require_relative "helper/sandbox"
17
19
  require_relative "helper/fixture"
18
20
  require_relative "helper/stub_worker"
@@ -16,15 +16,16 @@
16
16
  require "droonga/plugin/collector/basic"
17
17
 
18
18
  class BasicCollectorTest < Test::Unit::TestCase
19
- include PluginHelper
20
-
21
19
  def setup
22
20
  setup_database
23
- setup_plugin(Droonga::BasicCollector)
21
+ @plugin = Droonga::BasicCollector.new
22
+ @outputs = []
23
+ stub(@plugin).emit do |name, value|
24
+ @outputs << [name, value]
25
+ end
24
26
  end
25
27
 
26
28
  def teardown
27
- teardown_plugin
28
29
  teardown_database
29
30
  end
30
31
 
@@ -84,9 +85,13 @@ class BasicCollectorTest < Test::Unit::TestCase
84
85
  },
85
86
  :mapping => {
86
87
  "output" => "search_result",
87
- "element" => "records",
88
- "offset" => 1,
89
- "limit" => 1,
88
+ "elements" => {
89
+ "records" => {
90
+ "type" => "sort",
91
+ "offset" => 1,
92
+ "limit" => 1,
93
+ },
94
+ },
90
95
  },
91
96
  },
92
97
  :offset_and_unlimited_limit => {
@@ -107,9 +112,39 @@ class BasicCollectorTest < Test::Unit::TestCase
107
112
  },
108
113
  :mapping => {
109
114
  "output" => "search_result",
110
- "element" => "records",
111
- "offset" => 1,
112
- "limit" => -1,
115
+ "elements" => {
116
+ "records" => {
117
+ "type" => "sort",
118
+ "offset" => 1,
119
+ "limit" => -1,
120
+ },
121
+ },
122
+ },
123
+ },
124
+ :too_large_offset => {
125
+ :expected => {
126
+ "count" => 2,
127
+ "records" => [
128
+ ],
129
+ },
130
+ :source => {
131
+ "count" => 2,
132
+ "records" => [
133
+ create_record(1, 1.1, 1.2),
134
+ create_record(2, 2.1, 2.2),
135
+ ],
136
+ },
137
+ :mapping => {
138
+ "output" => "search_result",
139
+ "elements" => {
140
+ "records" => {
141
+ "type" => "sort",
142
+ "format" => "simple",
143
+ "attributes" => [],
144
+ "offset" => 10000,
145
+ "limit" => -1,
146
+ },
147
+ },
113
148
  },
114
149
  },
115
150
  :attributes => {
@@ -129,9 +164,13 @@ class BasicCollectorTest < Test::Unit::TestCase
129
164
  },
130
165
  :mapping => {
131
166
  "output" => "search_result",
132
- "element" => "records",
133
- "attributes" => ["_key", "chapter", "section", "subsection", "paragraph"],
134
- "limit" => -1,
167
+ "elements" => {
168
+ "records" => {
169
+ "type" => "sort",
170
+ "attributes" => ["_key", "chapter", "section", "subsection", "paragraph"],
171
+ "limit" => -1,
172
+ },
173
+ },
135
174
  },
136
175
  },
137
176
  :attributes_with_sort_attributes => {
@@ -151,9 +190,13 @@ class BasicCollectorTest < Test::Unit::TestCase
151
190
  },
152
191
  :mapping => {
153
192
  "output" => "search_result",
154
- "element" => "records",
155
- "attributes" => ["_key", "chapter", "section"],
156
- "limit" => -1,
193
+ "elements" => {
194
+ "records" => {
195
+ "type" => "sort",
196
+ "attributes" => ["_key", "chapter", "section"],
197
+ "limit" => -1,
198
+ },
199
+ },
157
200
  },
158
201
  },
159
202
  :format_simple => {
@@ -173,10 +216,14 @@ class BasicCollectorTest < Test::Unit::TestCase
173
216
  },
174
217
  :mapping => {
175
218
  "output" => "search_result",
176
- "element" => "records",
177
- "format" => "simple",
178
- "attributes" => ["_key", "chapter", "section"],
179
- "limit" => -1,
219
+ "elements" => {
220
+ "records" => {
221
+ "type" => "sort",
222
+ "format" => "simple",
223
+ "attributes" => ["_key", "chapter", "section"],
224
+ "limit" => -1,
225
+ },
226
+ },
180
227
  },
181
228
  },
182
229
  :format_complex => {
@@ -196,10 +243,73 @@ class BasicCollectorTest < Test::Unit::TestCase
196
243
  },
197
244
  :mapping => {
198
245
  "output" => "search_result",
199
- "element" => "records",
200
- "format" => "complex",
201
- "attributes" => ["_key", "chapter", "section"],
202
- "limit" => -1,
246
+ "elements" => {
247
+ "records" => {
248
+ "type" => "sort",
249
+ "format" => "complex",
250
+ "attributes" => ["_key", "chapter", "section"],
251
+ "limit" => -1,
252
+ },
253
+ },
254
+ },
255
+ },
256
+ :count_with_records => {
257
+ :expected => {
258
+ "count" => 2,
259
+ "records" => [
260
+ [],
261
+ [],
262
+ ],
263
+ },
264
+ :source => {
265
+ "count" => 5,
266
+ "records" => [
267
+ [],
268
+ [],
269
+ ],
270
+ },
271
+ :mapping => {
272
+ "output" => "search_result",
273
+ "elements" => {
274
+ "count" => {
275
+ "type" => "count",
276
+ "target" => "records",
277
+ },
278
+ "records" => {
279
+ "type" => "sort",
280
+ "format" => "simple",
281
+ "attributes" => [],
282
+ "limit" => -1,
283
+ },
284
+ },
285
+ },
286
+ },
287
+ :count_only => {
288
+ :expected => {
289
+ "count" => 2,
290
+ },
291
+ :source => {
292
+ "count" => 5,
293
+ "records" => [
294
+ [],
295
+ [],
296
+ ],
297
+ },
298
+ :mapping => {
299
+ "output" => "search_result",
300
+ "elements" => {
301
+ "count" => {
302
+ "type" => "count",
303
+ "target" => "records",
304
+ },
305
+ "records" => {
306
+ "type" => "sort",
307
+ "format" => "simple",
308
+ "attributes" => [],
309
+ "limit" => -1,
310
+ "no_output" => true,
311
+ },
312
+ },
203
313
  },
204
314
  },
205
315
  )
@@ -220,7 +330,7 @@ class BasicCollectorTest < Test::Unit::TestCase
220
330
  @plugin.process("collector_gather", request)
221
331
  output_name = data[:mapping]
222
332
  output_name = output_name["output"] if output_name.is_a?(Hash)
223
- assert_equal([data[:expected], output_name], @messages.last)
333
+ assert_equal([output_name, data[:expected]], @outputs.last)
224
334
  end
225
335
  end
226
336
 
@@ -286,6 +396,7 @@ class BasicCollectorTest < Test::Unit::TestCase
286
396
  }
287
397
  @plugin.process("collector_reduce", request)
288
398
  assert_equal([
399
+ output_name,
289
400
  {
290
401
  "numeric_value" => 3,
291
402
  "numeric_key_records" => [
@@ -305,9 +416,8 @@ class BasicCollectorTest < Test::Unit::TestCase
305
416
  create_record("f"),
306
417
  ],
307
418
  },
308
- output_name
309
419
  ],
310
- @messages.last)
420
+ @outputs.last)
311
421
  end
312
422
 
313
423
  def test_sum_with_limit
@@ -371,6 +481,7 @@ class BasicCollectorTest < Test::Unit::TestCase
371
481
  }
372
482
  @plugin.process("collector_reduce", request)
373
483
  assert_equal([
484
+ output_name,
374
485
  {
375
486
  "numeric_value" => 3,
376
487
  "numeric_key_records" => [
@@ -386,9 +497,8 @@ class BasicCollectorTest < Test::Unit::TestCase
386
497
  create_record("f"),
387
498
  ],
388
499
  },
389
- output_name
390
500
  ],
391
- @messages.last)
501
+ @outputs.last)
392
502
  end
393
503
 
394
504
  def test_sort
@@ -452,6 +562,7 @@ class BasicCollectorTest < Test::Unit::TestCase
452
562
  }
453
563
  @plugin.process("collector_reduce", request)
454
564
  assert_equal([
565
+ output_name,
455
566
  {
456
567
  "numeric_key_records" => [
457
568
  create_record(1),
@@ -470,9 +581,8 @@ class BasicCollectorTest < Test::Unit::TestCase
470
581
  create_record("f"),
471
582
  ],
472
583
  },
473
- output_name
474
584
  ],
475
- @messages.last)
585
+ @outputs.last)
476
586
  end
477
587
 
478
588
  def test_sort_with_limit
@@ -536,6 +646,7 @@ class BasicCollectorTest < Test::Unit::TestCase
536
646
  }
537
647
  @plugin.process("collector_reduce", request)
538
648
  assert_equal([
649
+ output_name,
539
650
  {
540
651
  "numeric_key_records" => [
541
652
  create_record(1),
@@ -550,9 +661,154 @@ class BasicCollectorTest < Test::Unit::TestCase
550
661
  create_record("f"),
551
662
  ],
552
663
  },
553
- output_name
554
664
  ],
555
- @messages.last)
665
+ @outputs.last)
666
+ end
667
+ end
668
+
669
+ class MergeTest < self
670
+ def test_grouped
671
+ input_name = "input_#{Time.now.to_i}"
672
+ output_name = "output_#{Time.now.to_i}"
673
+ request = {
674
+ "task" => {
675
+ "values" => {
676
+ output_name => {
677
+ "records" => [
678
+ [
679
+ "group1",
680
+ 10,
681
+ [
682
+ create_record(1),
683
+ create_record(3),
684
+ create_record(5),
685
+ ],
686
+ ],
687
+ [
688
+ "group2",
689
+ 20,
690
+ [
691
+ create_record("a"),
692
+ create_record("c"),
693
+ create_record("e"),
694
+ ],
695
+ ],
696
+ [
697
+ "group3",
698
+ 30,
699
+ [
700
+ create_record("A"),
701
+ create_record("B"),
702
+ create_record("C"),
703
+ ],
704
+ ],
705
+ ],
706
+ },
707
+ },
708
+ "component" => {
709
+ "body" => {
710
+ input_name => {
711
+ output_name => {
712
+ "records" => {
713
+ "type" => "sort",
714
+ "operators" => [
715
+ { "column" => 1, "operator" => "<" },
716
+ ],
717
+ "key_column" => 0,
718
+ "limit" => -1,
719
+ },
720
+ },
721
+ },
722
+ },
723
+ "outputs" => nil,
724
+ },
725
+ },
726
+ "id" => nil,
727
+ "value" => {
728
+ "records" => [
729
+ [
730
+ "group1",
731
+ 30,
732
+ [
733
+ create_record(2),
734
+ create_record(4),
735
+ create_record(6),
736
+ ],
737
+ ],
738
+ [
739
+ "group2",
740
+ 40,
741
+ [
742
+ create_record("b"),
743
+ create_record("d"),
744
+ create_record("f"),
745
+ ],
746
+ ],
747
+ [
748
+ "group4",
749
+ 50,
750
+ [
751
+ create_record("D"),
752
+ create_record("E"),
753
+ create_record("F"),
754
+ ],
755
+ ],
756
+ ],
757
+ },
758
+ "name" => input_name,
759
+ "descendants" => nil,
760
+ }
761
+ @plugin.process("collector_reduce", request)
762
+ assert_equal([
763
+ output_name,
764
+ {
765
+ "records" => [
766
+ [
767
+ "group3",
768
+ 30,
769
+ [
770
+ create_record("A"),
771
+ create_record("B"),
772
+ create_record("C"),
773
+ ],
774
+ ],
775
+ [
776
+ "group1",
777
+ 40,
778
+ [
779
+ create_record(2),
780
+ create_record(4),
781
+ create_record(6),
782
+ create_record(1),
783
+ create_record(3),
784
+ create_record(5),
785
+ ],
786
+ ],
787
+ [
788
+ "group4",
789
+ 50,
790
+ [
791
+ create_record("D"),
792
+ create_record("E"),
793
+ create_record("F"),
794
+ ],
795
+ ],
796
+ [
797
+ "group2",
798
+ 60,
799
+ [
800
+ create_record("b"),
801
+ create_record("d"),
802
+ create_record("f"),
803
+ create_record("a"),
804
+ create_record("c"),
805
+ create_record("e"),
806
+ ],
807
+ ],
808
+ ],
809
+ },
810
+ ],
811
+ @outputs.last)
556
812
  end
557
813
  end
558
814
  end