fluent-plugin-droonga 0.8.0 → 0.9.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 (107) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Gemfile +7 -0
  4. data/benchmark/watch/benchmark-notify.rb +6 -6
  5. data/benchmark/watch/benchmark-notify.sh +3 -2
  6. data/bin/grn2jsons +0 -3
  7. data/doc/text/news.md +13 -0
  8. data/fluent-plugin-droonga.gemspec +1 -1
  9. data/lib/droonga/catalog/base.rb +8 -3
  10. data/lib/droonga/catalog.rb +1 -16
  11. data/lib/droonga/catalog_observer.rb +57 -0
  12. data/lib/droonga/collector.rb +1 -1
  13. data/lib/droonga/dispatcher.rb +3 -1
  14. data/lib/droonga/distributor_plugin.rb +47 -19
  15. data/lib/droonga/handler_messenger.rb +26 -2
  16. data/lib/droonga/message_processing_error.rb +6 -8
  17. data/lib/droonga/output_message.rb +17 -1
  18. data/lib/droonga/plugin/collector/basic.rb +44 -81
  19. data/lib/droonga/plugin/collector/groonga.rb +83 -0
  20. data/lib/droonga/plugin/collector/search.rb +104 -0
  21. data/lib/droonga/plugin/distributor/crud.rb +41 -0
  22. data/lib/droonga/plugin/distributor/distributed_search_planner.rb +4 -4
  23. data/lib/droonga/plugin/distributor/groonga.rb +38 -0
  24. data/lib/droonga/plugin/handler/add.rb +4 -1
  25. data/lib/droonga/plugin/handler/groonga/column_create.rb +7 -0
  26. data/lib/droonga/plugin/handler/groonga/table_remove.rb +42 -0
  27. data/lib/droonga/plugin/handler/groonga.rb +17 -2
  28. data/lib/droonga/plugin/handler/watch.rb +4 -4
  29. data/lib/droonga/plugin/input_adapter/crud.rb +27 -0
  30. data/lib/droonga/plugin/input_adapter/groonga.rb +16 -1
  31. data/lib/droonga/plugin/output_adapter/crud.rb +51 -0
  32. data/lib/droonga/plugin/output_adapter/groonga.rb +8 -1
  33. data/lib/droonga/plugin.rb +1 -1
  34. data/lib/droonga/replier.rb +7 -1
  35. data/lib/droonga/searcher.rb +168 -74
  36. data/lib/droonga/session.rb +1 -1
  37. data/lib/groonga_command_converter.rb +7 -1
  38. data/test/command/config/default/catalog.json +1 -1
  39. data/test/command/suite/add/error/invalid-integer.expected +31 -1
  40. data/test/command/suite/add/error/invalid-time.expected +31 -1
  41. data/test/command/suite/add/error/missing-key.expected +17 -1
  42. data/test/command/suite/add/error/missing-table.expected +17 -1
  43. data/test/command/suite/add/error/unknown-column.expected +31 -1
  44. data/test/command/suite/add/error/unknown-table.expected +17 -1
  45. data/test/command/suite/add/minimum.expected +1 -1
  46. data/test/command/suite/add/with-values.expected +1 -1
  47. data/test/command/suite/add/without-key.expected +1 -1
  48. data/test/command/suite/groonga/column_create/scalar.expected +2 -2
  49. data/test/command/suite/groonga/column_create/unknown-table.expected +18 -0
  50. data/test/command/suite/groonga/column_create/unknown-table.test +7 -0
  51. data/test/command/suite/groonga/column_create/vector.expected +2 -2
  52. data/test/command/suite/groonga/select/minimum.expected +1 -1
  53. data/test/command/suite/groonga/table_create/array.expected +1 -1
  54. data/test/command/suite/groonga/table_create/hash.expected +1 -1
  55. data/test/command/suite/groonga/table_remove/success.expected +17 -0
  56. data/test/command/suite/groonga/table_remove/success.test +8 -0
  57. data/test/command/suite/groonga/table_remove/unknown-table.expected +18 -0
  58. data/test/command/suite/groonga/table_remove/unknown-table.test +7 -0
  59. data/test/command/suite/message/error/missing-dataset.expected +1 -1
  60. data/test/command/suite/message/error/unknown-command.expected +1 -1
  61. data/test/command/suite/message/error/unknown-dataset.expected +1 -1
  62. data/test/command/suite/search/attributes/array.expected +1 -1
  63. data/test/command/suite/search/attributes/hash.expected +1 -1
  64. data/test/command/suite/search/complex.expected +1 -1
  65. data/test/command/suite/search/condition/nested.expected +1 -1
  66. data/test/command/suite/search/condition/query.expected +1 -1
  67. data/test/command/suite/search/condition/script.expected +1 -1
  68. data/test/command/suite/search/error/cyclic-source.expected +1 -1
  69. data/test/command/suite/search/error/deeply-cyclic-source.expected +1 -1
  70. data/test/command/suite/search/error/missing-source-parameter.expected +1 -1
  71. data/test/command/suite/search/error/unknown-source.expected +1 -1
  72. data/test/command/suite/search/group/count.expected +1 -1
  73. data/test/command/suite/search/group/limit.expected +1 -1
  74. data/test/command/suite/search/group/string.expected +1 -1
  75. data/test/command/suite/search/multiple/chained.expected +1 -1
  76. data/test/command/suite/search/multiple/parallel.expected +1 -1
  77. data/test/command/suite/search/range/only-output.expected +1 -1
  78. data/test/command/suite/search/range/only-sort.expected +1 -1
  79. data/test/command/suite/search/range/sort-and-output.expected +1 -1
  80. data/test/command/suite/search/range/too-large-output-offset.expected +1 -1
  81. data/test/command/suite/search/range/too-large-sort-offset.expected +1 -1
  82. data/test/command/suite/search/response/records/value/time.expected +1 -1
  83. data/test/command/suite/search/simple.expected +1 -1
  84. data/test/command/suite/search/sort/default-offset-limit.expected +1 -1
  85. data/test/command/suite/search/sort/invisible-column.expected +1 -1
  86. data/test/command/suite/watch/subscribe.expected +1 -1
  87. data/test/command/suite/watch/unsubscribe.expected +1 -1
  88. data/test/performance/run-test.rb +56 -0
  89. data/{benchmark → test/performance}/watch/catalog.json +0 -0
  90. data/test/performance/watch/feed.json +9 -0
  91. data/{benchmark → test/performance}/watch/fluentd.conf +0 -0
  92. data/test/performance/watch/subscribe.json +3 -0
  93. data/test/unit/catalog/test_version1.rb +34 -0
  94. data/test/unit/plugin/collector/test_basic.rb +300 -479
  95. data/test/unit/plugin/collector/test_search.rb +814 -0
  96. data/test/unit/plugin/distributor/test_search.rb +4 -4
  97. data/test/unit/plugin/distributor/test_search_planner.rb +260 -260
  98. data/test/unit/plugin/handler/groonga/test_column_create.rb +15 -1
  99. data/test/unit/plugin/handler/groonga/test_table_create.rb +6 -2
  100. data/test/unit/plugin/handler/groonga/test_table_remove.rb +58 -0
  101. data/test/unit/plugin/handler/test_add.rb +3 -1
  102. data/test/unit/plugin/handler/test_groonga.rb +24 -0
  103. data/test/unit/plugin/handler/test_search.rb +294 -0
  104. data/test/unit/plugin/handler/test_watch.rb +1 -1
  105. data/test/unit/plugin/{adapter → input_adapter}/groonga/test_select.rb +5 -37
  106. data/test/unit/plugin/output_adapter/groonga/test_select.rb +55 -0
  107. metadata +38 -6
@@ -16,15 +16,15 @@
16
16
  require "droonga/plugin/distributor/distributed_search_planner"
17
17
 
18
18
  class DistributedSearchPlannerTest < Test::Unit::TestCase
19
- def assert_planned(expected, search_request_envelope)
20
- plan = Droonga::DistributedSearchPlanner.new(search_request_envelope)
19
+ def assert_planned(expected, search_request)
20
+ plan = Droonga::DistributedSearchPlanner.new(search_request)
21
21
  actual = plan.messages
22
22
  assert_equal(expected, actual)
23
23
  end
24
24
 
25
25
  class MultipleQueriesTest < self
26
26
  def test_distribute
27
- envelope = {
27
+ request = {
28
28
  "type" => "search",
29
29
  "dataset" => "Droonga",
30
30
  "body" => {
@@ -63,10 +63,10 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase
63
63
  },
64
64
  }
65
65
 
66
- message = []
66
+ expected_plan = []
67
67
 
68
- message << {
69
- "type" => "reduce",
68
+ expected_plan << {
69
+ "type" => "search_reduce",
70
70
  "body" => {
71
71
  "query1" => {
72
72
  "query1_reduced" => {
@@ -84,8 +84,8 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase
84
84
  "inputs" => ["query1"],
85
85
  "outputs" => ["query1_reduced"],
86
86
  }
87
- message << {
88
- "type" => "reduce",
87
+ expected_plan << {
88
+ "type" => "search_reduce",
89
89
  "body" => {
90
90
  "query2" => {
91
91
  "query2_reduced" => {
@@ -103,8 +103,8 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase
103
103
  "inputs" => ["query2"],
104
104
  "outputs" => ["query2_reduced"],
105
105
  }
106
- message << {
107
- "type" => "reduce",
106
+ expected_plan << {
107
+ "type" => "search_reduce",
108
108
  "body" => {
109
109
  "query3" => {
110
110
  "query3_reduced" => {
@@ -124,7 +124,7 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase
124
124
  }
125
125
 
126
126
  gatherer = {
127
- "type" => "gather",
127
+ "type" => "search_gather",
128
128
  "body" => {
129
129
  "query1_reduced" => {
130
130
  "output" => "query1",
@@ -170,7 +170,7 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase
170
170
  ],
171
171
  "post" => true,
172
172
  }
173
- message << gatherer
173
+ expected_plan << gatherer
174
174
 
175
175
  searcher = {
176
176
  "type" => "broadcast",
@@ -217,15 +217,15 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase
217
217
  ],
218
218
  "replica" => "random",
219
219
  }
220
- message << searcher
220
+ expected_plan << searcher
221
221
 
222
- assert_planned(message, envelope)
222
+ assert_planned(expected_plan, request)
223
223
  end
224
224
  end
225
225
 
226
226
  class SingleQueryTest < self
227
227
  def test_no_output
228
- envelope = {
228
+ request = {
229
229
  "type" => "search",
230
230
  "dataset" => "Droonga",
231
231
  "body" => {
@@ -242,14 +242,14 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase
242
242
  },
243
243
  }
244
244
 
245
- message = []
246
- message << gatherer(envelope, :no_output => true)
247
- message << searcher(envelope, :no_output => true)
248
- assert_planned(message, envelope)
245
+ expected_plan = []
246
+ expected_plan << gatherer(request, :no_output => true)
247
+ expected_plan << searcher(request, :no_output => true)
248
+ assert_planned(expected_plan, request)
249
249
  end
250
250
 
251
251
  def test_no_records_element
252
- envelope = {
252
+ request = {
253
253
  "type" => "search",
254
254
  "dataset" => "Droonga",
255
255
  "body" => {
@@ -269,20 +269,20 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase
269
269
  },
270
270
  }
271
271
 
272
- message = []
273
- message << reducer(envelope, {
272
+ expected_plan = []
273
+ expected_plan << reducer(request, {
274
274
  "count" => {
275
275
  "type" => "sum",
276
276
  },
277
277
  })
278
- message << gatherer(envelope)
279
- message << searcher(envelope, :sort_limit => 1,
280
- :output_limit => 0)
281
- assert_planned(message, envelope)
278
+ expected_plan << gatherer(request)
279
+ expected_plan << searcher(request, :sort_limit => 1,
280
+ :output_limit => 0)
281
+ assert_planned(expected_plan, request)
282
282
  end
283
283
 
284
284
  def test_no_output_limit
285
- envelope = {
285
+ request = {
286
286
  "type" => "search",
287
287
  "dataset" => "Droonga",
288
288
  "body" => {
@@ -298,20 +298,20 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase
298
298
  },
299
299
  }
300
300
 
301
- message = []
302
- message << reducer(envelope, {
301
+ expected_plan = []
302
+ expected_plan << reducer(request, {
303
303
  "count" => {
304
304
  "type" => "sum",
305
305
  },
306
306
  })
307
- message << gatherer(envelope)
308
- message << searcher(envelope, :output_offset => 0,
309
- :output_limit => 0)
310
- assert_planned(message, envelope)
307
+ expected_plan << gatherer(request)
308
+ expected_plan << searcher(request, :output_offset => 0,
309
+ :output_limit => 0)
310
+ assert_planned(expected_plan, request)
311
311
  end
312
312
 
313
313
  def test_have_records
314
- envelope = {
314
+ request = {
315
315
  "type" => "search",
316
316
  "dataset" => "Droonga",
317
317
  "body" => {
@@ -330,29 +330,29 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase
330
330
  },
331
331
  }
332
332
 
333
- message = []
334
- message << reducer(envelope, {
333
+ expected_plan = []
334
+ expected_plan << reducer(request, {
335
335
  "records" => {
336
336
  "type" => "sort",
337
337
  "operators" => [],
338
338
  "limit" => 1,
339
339
  },
340
340
  })
341
- message << gatherer(envelope, :elements => {
342
- "records" => records_mapper(
343
- :offset => 0,
344
- :limit => 1,
345
- :format => "complex",
346
- :attributes => ["_key", "name", "age"],
347
- ),
348
- })
349
- message << searcher(envelope, :output_offset => 0,
350
- :output_limit => 1)
351
- assert_planned(message, envelope)
341
+ expected_plan << gatherer(request, :elements => {
342
+ "records" => records_mapper(
343
+ :offset => 0,
344
+ :limit => 1,
345
+ :format => "complex",
346
+ :attributes => ["_key", "name", "age"],
347
+ ),
348
+ })
349
+ expected_plan << searcher(request, :output_offset => 0,
350
+ :output_limit => 1)
351
+ assert_planned(expected_plan, request)
352
352
  end
353
353
 
354
354
  def test_have_output_offset
355
- envelope = {
355
+ request = {
356
356
  "type" => "search",
357
357
  "dataset" => "Droonga",
358
358
  "body" => {
@@ -371,29 +371,29 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase
371
371
  },
372
372
  }
373
373
 
374
- message = []
375
- message << reducer(envelope, {
374
+ expected_plan = []
375
+ expected_plan << reducer(request, {
376
376
  "records" => {
377
377
  "type" => "sort",
378
378
  "operators" => [],
379
379
  "limit" => 2,
380
380
  },
381
381
  })
382
- message << gatherer(envelope, :elements => {
383
- "records" => records_mapper(
384
- :offset => 1,
385
- :limit => 1,
386
- :format => "complex",
387
- :attributes => ["_key", "name", "age"],
388
- ),
389
- })
390
- message << searcher(envelope, :output_offset => 0,
391
- :output_limit => 2)
392
- assert_planned(message, envelope)
382
+ expected_plan << gatherer(request, :elements => {
383
+ "records" => records_mapper(
384
+ :offset => 1,
385
+ :limit => 1,
386
+ :format => "complex",
387
+ :attributes => ["_key", "name", "age"],
388
+ ),
389
+ })
390
+ expected_plan << searcher(request, :output_offset => 0,
391
+ :output_limit => 2)
392
+ assert_planned(expected_plan, request)
393
393
  end
394
394
 
395
395
  def test_have_simple_sortBy
396
- envelope = {
396
+ request = {
397
397
  "type" => "search",
398
398
  "dataset" => "Droonga",
399
399
  "body" => {
@@ -413,8 +413,8 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase
413
413
  },
414
414
  }
415
415
 
416
- message = []
417
- message << reducer(envelope, {
416
+ expected_plan = []
417
+ expected_plan << reducer(request, {
418
418
  "records" => {
419
419
  "type" => "sort",
420
420
  "operators" => [
@@ -423,21 +423,21 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase
423
423
  "limit" => 1,
424
424
  },
425
425
  })
426
- message << gatherer(envelope, :elements => {
427
- "records" => records_mapper(
428
- :offset => 0,
429
- :limit => 1,
430
- :format => "complex",
431
- :attributes => ["_key", "name", "age"],
432
- ),
433
- })
434
- message << searcher(envelope, :output_offset => 0,
435
- :output_limit => 1)
436
- assert_planned(message, envelope)
426
+ expected_plan << gatherer(request, :elements => {
427
+ "records" => records_mapper(
428
+ :offset => 0,
429
+ :limit => 1,
430
+ :format => "complex",
431
+ :attributes => ["_key", "name", "age"],
432
+ ),
433
+ })
434
+ expected_plan << searcher(request, :output_offset => 0,
435
+ :output_limit => 1)
436
+ assert_planned(expected_plan, request)
437
437
  end
438
438
 
439
439
  def test_have_sortBy
440
- envelope = {
440
+ request = {
441
441
  "type" => "search",
442
442
  "dataset" => "Droonga",
443
443
  "body" => {
@@ -459,8 +459,8 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase
459
459
  },
460
460
  }
461
461
 
462
- message = []
463
- message << reducer(envelope, {
462
+ expected_plan = []
463
+ expected_plan << reducer(request, {
464
464
  "records" => {
465
465
  "type" => "sort",
466
466
  "operators" => [
@@ -469,23 +469,23 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase
469
469
  "limit" => 1,
470
470
  },
471
471
  })
472
- message << gatherer(envelope, :elements => {
473
- "records" => records_mapper(
474
- :offset => 0,
475
- :limit => 1,
476
- :format => "complex",
477
- :attributes => ["_key", "name", "age"],
478
- ),
479
- })
480
- message << searcher(envelope, :sort_offset => 0,
481
- :sort_limit => 1,
482
- :output_offset => 0,
483
- :output_limit => 1)
484
- assert_planned(message, envelope)
472
+ expected_plan << gatherer(request, :elements => {
473
+ "records" => records_mapper(
474
+ :offset => 0,
475
+ :limit => 1,
476
+ :format => "complex",
477
+ :attributes => ["_key", "name", "age"],
478
+ ),
479
+ })
480
+ expected_plan << searcher(request, :sort_offset => 0,
481
+ :sort_limit => 1,
482
+ :output_offset => 0,
483
+ :output_limit => 1)
484
+ assert_planned(expected_plan, request)
485
485
  end
486
486
 
487
487
  def test_have_sortBy_offset_limit
488
- envelope = {
488
+ request = {
489
489
  "type" => "search",
490
490
  "dataset" => "Droonga",
491
491
  "body" => {
@@ -511,8 +511,8 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase
511
511
 
512
512
  sort_limit = 1 + 4 + [2, 8].max
513
513
  output_limit = 1 + 4 + [2, 8].min
514
- message = []
515
- message << reducer(envelope, {
514
+ expected_plan = []
515
+ expected_plan << reducer(request, {
516
516
  "records" => {
517
517
  "type" => "sort",
518
518
  "operators" => [
@@ -521,23 +521,23 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase
521
521
  "limit" => output_limit,
522
522
  },
523
523
  })
524
- message << gatherer(envelope, :elements => {
525
- "records" => records_mapper(
526
- :offset => 5,
527
- :limit => 2,
528
- :format => "complex",
529
- :attributes => ["_key", "name", "age"],
530
- ),
531
- })
532
- message << searcher(envelope, :sort_offset => 0,
533
- :sort_limit => sort_limit,
534
- :output_offset => 0,
535
- :output_limit => output_limit)
536
- assert_planned(message, envelope)
524
+ expected_plan << gatherer(request, :elements => {
525
+ "records" => records_mapper(
526
+ :offset => 5,
527
+ :limit => 2,
528
+ :format => "complex",
529
+ :attributes => ["_key", "name", "age"],
530
+ ),
531
+ })
532
+ expected_plan << searcher(request, :sort_offset => 0,
533
+ :sort_limit => sort_limit,
534
+ :output_offset => 0,
535
+ :output_limit => output_limit)
536
+ assert_planned(expected_plan, request)
537
537
  end
538
538
 
539
539
  def test_have_sortBy_with_infinity_output_limit
540
- envelope = {
540
+ request = {
541
541
  "type" => "search",
542
542
  "dataset" => "Droonga",
543
543
  "body" => {
@@ -562,8 +562,8 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase
562
562
  }
563
563
 
564
564
  limit = 1 + 4 + 2
565
- message = []
566
- message << reducer(envelope, {
565
+ expected_plan = []
566
+ expected_plan << reducer(request, {
567
567
  "records" => {
568
568
  "type" => "sort",
569
569
  "operators" => [
@@ -572,23 +572,23 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase
572
572
  "limit" => limit,
573
573
  },
574
574
  })
575
- message << gatherer(envelope, :elements => {
576
- "records" => records_mapper(
577
- :offset => 5,
578
- :limit => 2,
579
- :format => "complex",
580
- :attributes => ["_key", "name", "age"],
581
- ),
582
- })
583
- message << searcher(envelope, :sort_offset => 0,
584
- :sort_limit => limit,
585
- :output_offset => 0,
586
- :output_limit => limit)
587
- assert_planned(message, envelope)
575
+ expected_plan << gatherer(request, :elements => {
576
+ "records" => records_mapper(
577
+ :offset => 5,
578
+ :limit => 2,
579
+ :format => "complex",
580
+ :attributes => ["_key", "name", "age"],
581
+ ),
582
+ })
583
+ expected_plan << searcher(request, :sort_offset => 0,
584
+ :sort_limit => limit,
585
+ :output_offset => 0,
586
+ :output_limit => limit)
587
+ assert_planned(expected_plan, request)
588
588
  end
589
589
 
590
590
  def test_have_sortBy_with_infinity_sort_limit
591
- envelope = {
591
+ request = {
592
592
  "type" => "search",
593
593
  "dataset" => "Droonga",
594
594
  "body" => {
@@ -613,8 +613,8 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase
613
613
  }
614
614
 
615
615
  limit = 1 + 4 + 8
616
- message = []
617
- message << reducer(envelope, {
616
+ expected_plan = []
617
+ expected_plan << reducer(request, {
618
618
  "records" => {
619
619
  "type" => "sort",
620
620
  "operators" => [
@@ -623,23 +623,23 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase
623
623
  "limit" => limit,
624
624
  },
625
625
  })
626
- message << gatherer(envelope, :elements => {
627
- "records" => records_mapper(
628
- :offset => 5,
629
- :limit => 8,
630
- :format => "complex",
631
- :attributes => ["_key", "name", "age"],
632
- ),
633
- })
634
- message << searcher(envelope, :sort_offset => 0,
635
- :sort_limit => limit,
636
- :output_offset => 0,
637
- :output_limit => limit)
638
- assert_planned(message, envelope)
626
+ expected_plan << gatherer(request, :elements => {
627
+ "records" => records_mapper(
628
+ :offset => 5,
629
+ :limit => 8,
630
+ :format => "complex",
631
+ :attributes => ["_key", "name", "age"],
632
+ ),
633
+ })
634
+ expected_plan << searcher(request, :sort_offset => 0,
635
+ :sort_limit => limit,
636
+ :output_offset => 0,
637
+ :output_limit => limit)
638
+ assert_planned(expected_plan, request)
639
639
  end
640
640
 
641
641
  def test_have_sortBy_with_infinity_limit
642
- envelope = {
642
+ request = {
643
643
  "type" => "search",
644
644
  "dataset" => "Droonga",
645
645
  "body" => {
@@ -663,8 +663,8 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase
663
663
  },
664
664
  }
665
665
 
666
- message = []
667
- message << reducer(envelope, {
666
+ expected_plan = []
667
+ expected_plan << reducer(request, {
668
668
  "records" => {
669
669
  "type" => "sort",
670
670
  "operators" => [
@@ -673,23 +673,23 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase
673
673
  "limit" => -1,
674
674
  },
675
675
  })
676
- message << gatherer(envelope, :elements => {
677
- "records" => records_mapper(
678
- :offset => 5,
679
- :limit => -1,
680
- :format => "complex",
681
- :attributes => ["_key", "name", "age"],
682
- ),
683
- })
684
- message << searcher(envelope, :sort_offset => 0,
685
- :sort_limit => -1,
686
- :output_offset => 0,
687
- :output_limit => -1)
688
- assert_planned(message, envelope)
676
+ expected_plan << gatherer(request, :elements => {
677
+ "records" => records_mapper(
678
+ :offset => 5,
679
+ :limit => -1,
680
+ :format => "complex",
681
+ :attributes => ["_key", "name", "age"],
682
+ ),
683
+ })
684
+ expected_plan << searcher(request, :sort_offset => 0,
685
+ :sort_limit => -1,
686
+ :output_offset => 0,
687
+ :output_limit => -1)
688
+ assert_planned(expected_plan, request)
689
689
  end
690
690
 
691
691
  def test_have_sortBy_with_multiple_sort_keys
692
- envelope = {
692
+ request = {
693
693
  "type" => "search",
694
694
  "dataset" => "Droonga",
695
695
  "body" => {
@@ -711,8 +711,8 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase
711
711
  },
712
712
  }
713
713
 
714
- message = []
715
- message << reducer(envelope, {
714
+ expected_plan = []
715
+ expected_plan << reducer(request, {
716
716
  "records" => {
717
717
  "type" => "sort",
718
718
  "operators" => [
@@ -722,23 +722,23 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase
722
722
  "limit" => -1,
723
723
  },
724
724
  })
725
- message << gatherer(envelope, :elements => {
726
- "records" => records_mapper(
727
- :offset => 0,
728
- :limit => -1,
729
- :format => "complex",
730
- :attributes => ["_key", "name", "age"],
731
- ),
732
- })
733
- message << searcher(envelope, :sort_offset => 0,
734
- :sort_limit => -1,
735
- :output_offset => 0,
736
- :output_limit => -1)
737
- assert_planned(message, envelope)
725
+ expected_plan << gatherer(request, :elements => {
726
+ "records" => records_mapper(
727
+ :offset => 0,
728
+ :limit => -1,
729
+ :format => "complex",
730
+ :attributes => ["_key", "name", "age"],
731
+ ),
732
+ })
733
+ expected_plan << searcher(request, :sort_offset => 0,
734
+ :sort_limit => -1,
735
+ :output_offset => 0,
736
+ :output_limit => -1)
737
+ assert_planned(expected_plan, request)
738
738
  end
739
739
 
740
740
  def test_have_sortBy_with_missing_sort_attributes
741
- envelope = {
741
+ request = {
742
742
  "type" => "search",
743
743
  "dataset" => "Droonga",
744
744
  "body" => {
@@ -760,8 +760,8 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase
760
760
  },
761
761
  }
762
762
 
763
- message = []
764
- message << reducer(envelope, {
763
+ expected_plan = []
764
+ expected_plan << reducer(request, {
765
765
  "records" => {
766
766
  "type" => "sort",
767
767
  "operators" => [
@@ -771,24 +771,24 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase
771
771
  "limit" => -1,
772
772
  },
773
773
  })
774
- message << gatherer(envelope, :elements => {
775
- "records" => records_mapper(
776
- :offset => 0,
777
- :limit => -1,
778
- :format => "complex",
779
- :attributes => ["_key", "name", "age"],
780
- ),
781
- })
782
- message << searcher(envelope, :sort_offset => 0,
783
- :sort_limit => -1,
784
- :output_offset => 0,
785
- :output_limit => -1,
786
- :extra_attributes => ["public_age", "public_name"])
787
- assert_planned(message, envelope)
774
+ expected_plan << gatherer(request, :elements => {
775
+ "records" => records_mapper(
776
+ :offset => 0,
777
+ :limit => -1,
778
+ :format => "complex",
779
+ :attributes => ["_key", "name", "age"],
780
+ ),
781
+ })
782
+ expected_plan << searcher(request, :sort_offset => 0,
783
+ :sort_limit => -1,
784
+ :output_offset => 0,
785
+ :output_limit => -1,
786
+ :extra_attributes => ["public_age", "public_name"])
787
+ assert_planned(expected_plan, request)
788
788
  end
789
789
 
790
790
  def test_hash_attributes
791
- envelope = {
791
+ request = {
792
792
  "type" => "search",
793
793
  "dataset" => "Droonga",
794
794
  "body" => {
@@ -814,8 +814,8 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase
814
814
  },
815
815
  }
816
816
 
817
- message = []
818
- message << reducer(envelope, {
817
+ expected_plan = []
818
+ expected_plan << reducer(request, {
819
819
  "records" => {
820
820
  "type" => "sort",
821
821
  "operators" => [
@@ -825,24 +825,24 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase
825
825
  "limit" => -1,
826
826
  },
827
827
  })
828
- message << gatherer(envelope, :elements => {
829
- "records" => records_mapper(
830
- :offset => 0,
831
- :limit => -1,
832
- :format => "complex",
833
- :attributes => ["id", "name", "age"],
834
- ),
835
- })
836
- message << searcher(envelope, :sort_offset => 0,
837
- :sort_limit => -1,
838
- :output_offset => 0,
839
- :output_limit => -1,
840
- :extra_attributes => ["public_age", "public_name"])
841
- assert_planned(message, envelope)
828
+ expected_plan << gatherer(request, :elements => {
829
+ "records" => records_mapper(
830
+ :offset => 0,
831
+ :limit => -1,
832
+ :format => "complex",
833
+ :attributes => ["id", "name", "age"],
834
+ ),
835
+ })
836
+ expected_plan << searcher(request, :sort_offset => 0,
837
+ :sort_limit => -1,
838
+ :output_offset => 0,
839
+ :output_limit => -1,
840
+ :extra_attributes => ["public_age", "public_name"])
841
+ assert_planned(expected_plan, request)
842
842
  end
843
843
 
844
844
  def test_groupBy
845
- envelope = {
845
+ request = {
846
846
  "type" => "search",
847
847
  "dataset" => "Droonga",
848
848
  "body" => {
@@ -861,8 +861,8 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase
861
861
  },
862
862
  }
863
863
 
864
- message = []
865
- message << reducer(envelope, {
864
+ expected_plan = []
865
+ expected_plan << reducer(request, {
866
866
  "records" => {
867
867
  "type" => "sort",
868
868
  "operators" => [],
@@ -870,22 +870,22 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase
870
870
  "limit" => -1,
871
871
  },
872
872
  })
873
- message << gatherer(envelope, :elements => {
874
- "records" => records_mapper(
875
- :offset => 0,
876
- :limit => -1,
877
- :format => "complex",
878
- :attributes => ["_key", "_nsubrecs"],
879
- ),
880
- })
881
- message << searcher(envelope, :output_offset => 0,
882
- :output_limit => -1,
883
- :unifiable => true)
884
- assert_planned(message, envelope)
873
+ expected_plan << gatherer(request, :elements => {
874
+ "records" => records_mapper(
875
+ :offset => 0,
876
+ :limit => -1,
877
+ :format => "complex",
878
+ :attributes => ["_key", "_nsubrecs"],
879
+ ),
880
+ })
881
+ expected_plan << searcher(request, :output_offset => 0,
882
+ :output_limit => -1,
883
+ :unifiable => true)
884
+ assert_planned(expected_plan, request)
885
885
  end
886
886
 
887
887
  def test_groupBy_count
888
- envelope = {
888
+ request = {
889
889
  "type" => "search",
890
890
  "dataset" => "Droonga",
891
891
  "body" => {
@@ -901,8 +901,8 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase
901
901
  },
902
902
  }
903
903
 
904
- message = []
905
- message << reducer(envelope, {
904
+ expected_plan = []
905
+ expected_plan << reducer(request, {
906
906
  "count" => {
907
907
  "type" => "sum",
908
908
  },
@@ -913,23 +913,23 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase
913
913
  "limit" => -1,
914
914
  },
915
915
  })
916
- message << gatherer(envelope, :elements => {
917
- "count" => count_mapper,
918
- "records" => records_mapper(
919
- :limit => -1,
920
- :attributes => ["_key"],
921
- :no_output => true,
922
- ),
923
- })
924
- message << searcher(envelope, :output_limit => -1,
925
- :extra_attributes => ["_key"],
926
- :extra_elements => ["records"],
927
- :unifiable => true)
928
- assert_planned(message, envelope)
916
+ expected_plan << gatherer(request, :elements => {
917
+ "count" => count_mapper,
918
+ "records" => records_mapper(
919
+ :limit => -1,
920
+ :attributes => ["_key"],
921
+ :no_output => true,
922
+ ),
923
+ })
924
+ expected_plan << searcher(request, :output_limit => -1,
925
+ :extra_attributes => ["_key"],
926
+ :extra_elements => ["records"],
927
+ :unifiable => true)
928
+ assert_planned(expected_plan, request)
929
929
  end
930
930
 
931
931
  def test_groupBy_hash
932
- envelope = {
932
+ request = {
933
933
  "type" => "search",
934
934
  "dataset" => "Droonga",
935
935
  "body" => {
@@ -957,8 +957,8 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase
957
957
  },
958
958
  }
959
959
 
960
- message = []
961
- message << reducer(envelope, {
960
+ expected_plan = []
961
+ expected_plan << reducer(request, {
962
962
  "records" => {
963
963
  "type" => "sort",
964
964
  "operators" => [],
@@ -966,28 +966,28 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase
966
966
  "limit" => -1,
967
967
  },
968
968
  })
969
- message << gatherer(envelope, :elements => {
970
- "records" => records_mapper(
971
- :offset => 0,
972
- :limit => -1,
973
- :format => "complex",
974
- :attributes => ["family_name", "count", "users"],
975
- ),
976
- })
977
- message << searcher(envelope, :output_offset => 0,
978
- :output_limit => -1,
979
- :extra_attributes => ["_key"],
980
- :unifiable => true)
981
- assert_planned(message, envelope)
969
+ expected_plan << gatherer(request, :elements => {
970
+ "records" => records_mapper(
971
+ :offset => 0,
972
+ :limit => -1,
973
+ :format => "complex",
974
+ :attributes => ["family_name", "count", "users"],
975
+ ),
976
+ })
977
+ expected_plan << searcher(request, :output_offset => 0,
978
+ :output_limit => -1,
979
+ :extra_attributes => ["_key"],
980
+ :unifiable => true)
981
+ assert_planned(expected_plan, request)
982
982
  end
983
983
 
984
984
  private
985
- def reducer(search_request_envelope, reducer_body)
986
- queries = search_request_envelope["body"]["queries"]
985
+ def reducer(search_request, reducer_body)
986
+ queries = search_request["body"]["queries"]
987
987
  query_name = queries.keys.first
988
988
 
989
989
  reducer = {
990
- "type" => "reduce",
990
+ "type" => "search_reduce",
991
991
  "body" => {
992
992
  query_name => {
993
993
  "#{query_name}_reduced" => reducer_body,
@@ -1022,12 +1022,12 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase
1022
1022
  mapper
1023
1023
  end
1024
1024
 
1025
- def gatherer(search_request_envelope, options={})
1026
- queries = search_request_envelope["body"]["queries"]
1025
+ def gatherer(search_request, options={})
1026
+ queries = search_request["body"]["queries"]
1027
1027
  query_name = queries.keys.first
1028
1028
 
1029
1029
  gatherer = {
1030
- "type" => "gather",
1030
+ "type" => "search_gather",
1031
1031
  "body" => {
1032
1032
  },
1033
1033
  "inputs" => [
@@ -1047,9 +1047,9 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase
1047
1047
  gatherer
1048
1048
  end
1049
1049
 
1050
- def searcher(search_request_envelope, options={})
1050
+ def searcher(search_request, options={})
1051
1051
  # dup and clone don't copy it deeply...
1052
- searcher = Marshal.load(Marshal.dump(search_request_envelope))
1052
+ searcher = Marshal.load(Marshal.dump(search_request))
1053
1053
 
1054
1054
  queries = searcher["body"]["queries"]
1055
1055
  query_name = queries.keys.first