fluent-plugin-droonga 0.9.0 → 0.9.9

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 (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
@@ -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
@@ -13,14 +13,16 @@
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/plugin/output_adapter/groonga/select"
16
+ require "droonga/plugins/groonga/select"
17
17
 
18
- class OutputAdapterGroongaSelectTest < Test::Unit::TestCase
19
- def setup
20
- @select = Droonga::GroongaOutputAdapter::Select.new
18
+ class GroongaSelectAdapterOutputTest < Test::Unit::TestCase
19
+ private
20
+ def convert(search_response)
21
+ converter = Droonga::Plugins::Groonga::Select::ResponseConverter.new
22
+ converter.convert(search_response)
21
23
  end
22
24
 
23
- class ResponseTest < self
25
+ class RecordsTest < self
24
26
  def test_empty
25
27
  start_time = "2001-08-02T10:45:23.5+09:00"
26
28
  elapsed_time = 0
@@ -41,15 +43,12 @@ class OutputAdapterGroongaSelectTest < Test::Unit::TestCase
41
43
  status_code = 0
42
44
  start_time_in_unix_time = Time.parse(start_time).to_f
43
45
  headers = [["_id","UInt32"]]
44
- expected_select_response = [[status_code, start_time_in_unix_time, elapsed_time],
45
- [[[count], headers]]]
46
+ expected_select_response = [
47
+ [status_code, start_time_in_unix_time, elapsed_time],
48
+ [[[count], headers]],
49
+ ]
46
50
 
47
51
  assert_equal(expected_select_response, convert(search_response))
48
52
  end
49
-
50
- private
51
- def convert(search_response)
52
- @select.convert(search_response)
53
- end
54
53
  end
55
54
  end
@@ -14,8 +14,15 @@
14
14
  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
15
 
16
16
  class ColumnCreateTest < GroongaHandlerTest
17
+ def create_handler
18
+ Droonga::Plugins::Groonga::ColumnCreate::Handler.new("droonga",
19
+ @handler.context)
20
+ end
21
+
17
22
  def test_success
18
- process(:table_create, {"name" => "Books"})
23
+ Groonga::Schema.define(:context => @context) do |schema|
24
+ schema.create_table("Books", :type => :hash)
25
+ end
19
26
  process(:column_create,
20
27
  {"table" => "Books", "name" => "title", "type" => "ShortText"})
21
28
  response = @messenger.values.last
@@ -40,7 +47,9 @@ class ColumnCreateTest < GroongaHandlerTest
40
47
  end
41
48
 
42
49
  def test_name
43
- process(:table_create, {"name" => "Books"})
50
+ Groonga::Schema.define(:context => @context) do |schema|
51
+ schema.create_table("Books", :type => :hash)
52
+ end
44
53
  process(:column_create,
45
54
  {"table" => "Books", "name" => "title", "type" => "ShortText"})
46
55
  assert_equal(<<-SCHEMA, dump)
@@ -50,7 +59,9 @@ column_create Books title COLUMN_SCALAR ShortText
50
59
  end
51
60
 
52
61
  def test_type
53
- process(:table_create, {"name" => "Books"})
62
+ Groonga::Schema.define(:context => @context) do |schema|
63
+ schema.create_table("Books", :type => :hash)
64
+ end
54
65
  process(:column_create,
55
66
  {"table" => "Books", "name" => "main_text", "type" => "LongText"})
56
67
  assert_equal(<<-SCHEMA, dump)
@@ -76,7 +87,9 @@ column_create Books main_text COLUMN_SCALAR LongText
76
87
  "type" => "ShortText",
77
88
  "flags" => data[:flags],
78
89
  }
79
- process(:table_create, {"name" => "Books"})
90
+ Groonga::Schema.define(:context => @context) do |schema|
91
+ schema.create_table("Books", :type => :hash)
92
+ end
80
93
  process(:column_create, request)
81
94
  assert_equal(<<-EXPECTED, dump)
82
95
  table_create Books TABLE_HASH_KEY --key_type ShortText
@@ -88,7 +101,9 @@ column_create Books title #{data[:flags]} ShortText
88
101
  class IndexTest < self
89
102
  def setup
90
103
  super
91
- process(:table_create, {"name" => "Books"})
104
+ Groonga::Schema.define(:context => @context) do |schema|
105
+ schema.create_table("Books", :type => :hash)
106
+ end
92
107
  process(:column_create,
93
108
  {"table" => "Books", "name" => "title", "type" => "ShortText"})
94
109
  end
@@ -14,6 +14,11 @@
14
14
  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
15
 
16
16
  class TableCreateTest < GroongaHandlerTest
17
+ def create_handler
18
+ Droonga::Plugins::Groonga::TableCreate::Handler.new("droonga",
19
+ @handler.context)
20
+ end
21
+
17
22
  def test_success
18
23
  process(:table_create, {"name" => "Books"})
19
24
  response = @messenger.values.last
@@ -14,9 +14,16 @@
14
14
  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
15
 
16
16
  class TableRemoveTest < GroongaHandlerTest
17
+ def create_handler
18
+ Droonga::Plugins::Groonga::TableRemove::Handler.new("droonga",
19
+ @handler.context)
20
+ end
21
+
17
22
  def setup
18
23
  super
19
- process(:table_create, {"name" => "Books"})
24
+ Groonga::Schema.define(:context => @context) do |schema|
25
+ schema.create_table("Books", :type => :hash)
26
+ end
20
27
  end
21
28
 
22
29
  def test_success
@@ -13,7 +13,7 @@
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/plugin/handler/groonga"
16
+ require "droonga/plugins/groonga"
17
17
 
18
18
  class GroongaHandlerTest < Test::Unit::TestCase
19
19
  include PluginHelper
@@ -31,7 +31,6 @@ class GroongaHandlerTest < Test::Unit::TestCase
31
31
  private
32
32
  def setup_plugin
33
33
  @handler = Droonga::Test::StubHandler.new
34
- @plugin = Droonga::GroongaHandler.new(@handler)
35
34
  @messenger = Droonga::Test::StubHandlerMessenger.new
36
35
  end
37
36
 
@@ -45,7 +44,8 @@ class GroongaHandlerTest < Test::Unit::TestCase
45
44
 
46
45
  def process(command, request)
47
46
  message = Droonga::Test::StubHandlerMessage.new(request)
48
- @plugin.send(command, message, @messenger)
47
+ handler = create_handler
48
+ handler.handle(message, @messenger)
49
49
  end
50
50
 
51
51
  NORMALIZED_START_TIME = Time.parse("2013-07-11T16:04:28+0900").to_i
@@ -57,12 +57,12 @@ class GroongaHandlerTest < Test::Unit::TestCase
57
57
  end
58
58
 
59
59
  NORMALIZED_HEADER_SUCCESS = [
60
- Droonga::GroongaHandler::Status::SUCCESS,
60
+ Droonga::Plugins::Groonga::Status::SUCCESS,
61
61
  NORMALIZED_START_TIME,
62
62
  NORMALIZED_ELAPSED_TIME,
63
63
  ]
64
64
  NORMALIZED_HEADER_INVALID_ARGUMENT = [
65
- Droonga::GroongaHandler::Status::INVALID_ARGUMENT,
65
+ Droonga::Plugins::Groonga::Status::INVALID_ARGUMENT,
66
66
  NORMALIZED_START_TIME,
67
67
  NORMALIZED_ELAPSED_TIME,
68
68
  ]
@@ -13,7 +13,7 @@
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/plugin/handler/search"
16
+ require "droonga/plugins/search"
17
17
 
18
18
  class SearchHandlerTest < Test::Unit::TestCase
19
19
  def setup
@@ -29,7 +29,7 @@ class SearchHandlerTest < Test::Unit::TestCase
29
29
 
30
30
  def setup_plugin
31
31
  @handler = Droonga::Test::StubHandler.new
32
- @plugin = Droonga::SearchHandler.new(@handler)
32
+ @plugin = Droonga::Plugins::Search::Handler.new("droonga", @handler.context)
33
33
  @messenger = Droonga::Test::StubHandlerMessenger.new
34
34
  end
35
35
 
@@ -41,7 +41,7 @@ class SearchHandlerTest < Test::Unit::TestCase
41
41
  private
42
42
  def search(request, headers={})
43
43
  message = Droonga::Test::StubHandlerMessage.new(request, headers)
44
- @plugin.search(message, @messenger)
44
+ @plugin.handle(message, @messenger)
45
45
  results_to_result_set(@messenger.values.first)
46
46
  end
47
47
 
@@ -78,13 +78,29 @@ class SearchHandlerTest < Test::Unit::TestCase
78
78
 
79
79
  class NoParameterTest < self
80
80
  def test_empty
81
- assert_search({}, {})
81
+ assert_raise(Droonga::Searcher::NoQuery) do
82
+ search({})
83
+ end
84
+ end
85
+
86
+ def test_nil
87
+ assert_raise(Droonga::Searcher::NoQuery) do
88
+ search(nil)
89
+ end
82
90
  end
83
91
  end
84
92
 
85
93
  class QueriesTest < self
86
94
  def test_empty
87
- assert_search({}, {"queries" => {}})
95
+ assert_raise(Droonga::Searcher::NoQuery) do
96
+ search({"queries" => {}})
97
+ end
98
+ end
99
+
100
+ def test_nil
101
+ assert_raise(Droonga::Searcher::NoQuery) do
102
+ search({"queries" => nil})
103
+ end
88
104
  end
89
105
  end
90
106
 
@@ -15,11 +15,13 @@
15
15
  # License along with this library; if not, write to the Free Software
16
16
  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
17
 
18
- require "droonga/plugin/handler/watch"
18
+ require "droonga/plugins/watch"
19
19
 
20
20
  class WatchHandlerTest < Test::Unit::TestCase
21
21
  include WatchHelper
22
22
 
23
+ SUCCESS_RESULT = { "success" => true }
24
+
23
25
  def setup
24
26
  setup_database
25
27
  setup_schema
@@ -34,7 +36,6 @@ class WatchHandlerTest < Test::Unit::TestCase
34
36
  private
35
37
  def setup_plugin
36
38
  @handler = Droonga::Test::StubHandler.new
37
- @plugin = Droonga::WatchHandler.new(@handler)
38
39
  @messenger = Droonga::Test::StubHandlerMessenger.new
39
40
  end
40
41
 
@@ -44,11 +45,15 @@ class WatchHandlerTest < Test::Unit::TestCase
44
45
 
45
46
  def process(command, request, headers={})
46
47
  message = Droonga::Test::StubHandlerMessage.new(request, headers)
47
- @plugin.send(command, message, @messenger)
48
+ create_plugin.handle(message, @messenger)
48
49
  end
49
50
 
50
51
  public
51
52
  class SubscribeTest < self
53
+ def create_plugin
54
+ Droonga::Plugins::Watch::SubscribeHandler.new("droonga", @handler.context)
55
+ end
56
+
52
57
  def test_subscribe
53
58
  request = {
54
59
  "route" => "localhost:23003/output",
@@ -56,7 +61,7 @@ class WatchHandlerTest < Test::Unit::TestCase
56
61
  "subscriber" => "localhost"
57
62
  }
58
63
  process(:subscribe, request)
59
- assert_equal([[true]], @messenger.values)
64
+ assert_equal([SUCCESS_RESULT], @messenger.values)
60
65
 
61
66
  assert_equal(
62
67
  ["localhost:23003/output"],
@@ -70,7 +75,7 @@ class WatchHandlerTest < Test::Unit::TestCase
70
75
  "subscriber" => "localhost"
71
76
  }
72
77
  process(:subscribe, request, "from" => "localhost:23004/output")
73
- assert_equal([[true]], @messenger.values)
78
+ assert_equal([SUCCESS_RESULT], @messenger.values)
74
79
 
75
80
  assert_equal(
76
81
  ["localhost:23004/output"],
@@ -85,7 +90,7 @@ class WatchHandlerTest < Test::Unit::TestCase
85
90
  "route" => "localhost:23003/output"
86
91
  }
87
92
  process(:subscribe, request, "from" => "localhost:23004/output")
88
- assert_equal([[true]], @messenger.values)
93
+ assert_equal([SUCCESS_RESULT], @messenger.values)
89
94
 
90
95
  assert_equal(
91
96
  ["localhost:23003/output"],
@@ -109,6 +114,11 @@ class WatchHandlerTest < Test::Unit::TestCase
109
114
  setup_subscription
110
115
  end
111
116
 
117
+ def create_plugin
118
+ Droonga::Plugins::Watch::UnsubscribeHandler.new("droonga",
119
+ @handler.context)
120
+ end
121
+
112
122
  def test_unsubscribe
113
123
  request = {
114
124
  "route" => "localhost:23003/output",
@@ -116,7 +126,7 @@ class WatchHandlerTest < Test::Unit::TestCase
116
126
  "subscriber" => "localhost"
117
127
  }
118
128
  process(:unsubscribe, request)
119
- assert_equal([[true]], @messenger.values)
129
+ assert_equal([SUCCESS_RESULT], @messenger.values)
120
130
  end
121
131
 
122
132
  private
@@ -127,7 +137,7 @@ class WatchHandlerTest < Test::Unit::TestCase
127
137
  "subscriber" => "localhost"
128
138
  }
129
139
  process(:subscribe, request)
130
- assert_equal([[true]], @messenger.values)
140
+ assert_equal([SUCCESS_RESULT], @messenger.values)
131
141
  @messenger.values.clear
132
142
  end
133
143
  end
@@ -138,6 +148,11 @@ class WatchHandlerTest < Test::Unit::TestCase
138
148
  setup_subscription
139
149
  end
140
150
 
151
+ def create_plugin
152
+ Droonga::Plugins::Watch::FeedHandler.new("droonga",
153
+ @handler.context)
154
+ end
155
+
141
156
  def test_feed_match
142
157
  request = {
143
158
  "targets" => {
@@ -177,8 +192,12 @@ class WatchHandlerTest < Test::Unit::TestCase
177
192
  "condition" => "たいやき",
178
193
  "subscriber" => "localhost"
179
194
  }
180
- process(:subscribe, request)
181
- assert_equal([[true]], @messenger.values)
195
+ message = Droonga::Test::StubHandlerMessage.new(request, {})
196
+ subscribe_handler =
197
+ Droonga::Plugins::Watch::SubscribeHandler.new("droonga",
198
+ @handler.context)
199
+ subscribe_handler.handle(message, @messenger)
200
+ assert_equal([SUCCESS_RESULT], @messenger.values)
182
201
  end
183
202
  end
184
203
  end
@@ -1,5 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
1
  # Copyright (C) 2013 Droonga Project
4
2
  #
5
3
  # This library is free software; you can redistribute it and/or
@@ -15,31 +13,27 @@
15
13
  # License along with this library; if not, write to the Free Software
16
14
  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
15
 
18
- module Droonga
19
- class CommandMapper
20
- def initialize
21
- @commands = {}
22
- end
16
+ require "droonga/command_repository"
17
+
18
+ class CommandRepositoryTest < Test::Unit::TestCase
19
+ def setup
20
+ @repository = Droonga::CommandRepository.new
21
+ end
23
22
 
24
- def register(name_or_map)
25
- if name_or_map.is_a?(Hash)
26
- command_map = name_or_map
27
- command_map.each do |command_name, method_name|
28
- @commands[command_name.to_s] = method_name
29
- end
30
- else
31
- name = name_or_map
32
- method_name = name
33
- @commands[name.to_s] = method_name
34
- end
23
+ class FindTest < self
24
+ def setup
25
+ super
26
+ @command = Droonga::Command.new(:select,
27
+ :pattern => ["type", :equal, "select"])
28
+ @repository.register(@command)
35
29
  end
36
30
 
37
- def [](command)
38
- @commands[command.to_s]
31
+ def test_match
32
+ assert_equal(@command, @repository.find({ "type" => "select" }))
39
33
  end
40
34
 
41
- def commands
42
- @commands.keys
35
+ def test_not_match
36
+ assert_nil(@repository.find({ "type" => "search" }))
43
37
  end
44
38
  end
45
39
  end
@@ -13,11 +13,11 @@
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/plugin"
16
+ require "droonga/legacy_plugin"
17
17
 
18
- class PluginTest < Test::Unit::TestCase
18
+ class LegacyPluginTest < Test::Unit::TestCase
19
19
  class PluggableTest < self
20
- class DummyTypePlugin < Droonga::Plugin
20
+ class DummyTypePlugin < Droonga::LegacyPlugin
21
21
  extend Droonga::PluginRegisterable
22
22
  end
23
23
 
@@ -13,11 +13,11 @@
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/plugin_repository"
16
+ require "droonga/legacy_plugin_repository"
17
17
 
18
- class PluginRepositoryTest < Test::Unit::TestCase
18
+ class LegacyPluginRepositoryTest < Test::Unit::TestCase
19
19
  def setup
20
- @repository = Droonga::PluginRepository.new
20
+ @repository = Droonga::LegacyPluginRepository.new
21
21
  end
22
22
 
23
23
  class StubPlugin
@@ -0,0 +1,137 @@
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/message_matcher"
17
+
18
+ class MessageMatcherTest < Test::Unit::TestCase
19
+ def matcher(pattern)
20
+ Droonga::MessageMatcher.new(pattern)
21
+ end
22
+
23
+ class ResolvePathTest < self
24
+ def resolve_path(path, message)
25
+ matcher(nil).send(:resolve_path, path, message)
26
+ end
27
+
28
+ def test_nonexistent
29
+ assert_equal(Droonga::MessageMatcher::NONEXISTENT_PATH,
30
+ resolve_path("nonexistent.path", {}))
31
+ end
32
+
33
+ def test_top_level
34
+ assert_equal("select",
35
+ resolve_path("type",
36
+ {
37
+ "type" => "select"
38
+ }))
39
+ end
40
+
41
+ def test_nested
42
+ assert_equal(10,
43
+ resolve_path("body.output.limit",
44
+ {
45
+ "body" => {
46
+ "output" => {
47
+ "limit" => 10,
48
+ },
49
+ },
50
+ }))
51
+ end
52
+ end
53
+
54
+ class MatchTest < self
55
+ def match?(pattern, message)
56
+ matcher(pattern).match?(message)
57
+ end
58
+
59
+ class EqualTest < self
60
+ def test_same_value
61
+ assert_true(match?(["type", :equal, "select"],
62
+ {
63
+ "type" => "select"
64
+ }))
65
+ end
66
+
67
+ def test_different_value
68
+ assert_false(match?(["type", :equal, "select"],
69
+ {
70
+ "type" => "search",
71
+ }))
72
+ end
73
+ end
74
+
75
+ class InTest < self
76
+ def test_exist
77
+ assert_true(match?(["type", :in, ["table_create", "table_remove"]],
78
+ {
79
+ "type" => "table_remove"
80
+ }))
81
+ end
82
+
83
+ def test_not_exist
84
+ assert_false(match?(["type", :in, ["table_create", "table_remove"]],
85
+ {
86
+ "type" => "column_create",
87
+ }))
88
+ end
89
+ end
90
+
91
+ class IncludeTest < self
92
+ def test_exist
93
+ assert_true(match?(["originalTypes", :include?, "select"],
94
+ {
95
+ "originalTypes" => ["search", "select"],
96
+ }))
97
+ end
98
+
99
+ def test_not_exist
100
+ assert_false(match?(["originalTypes", :include?, "select"],
101
+ {
102
+ "originalTypes" => ["load"],
103
+ }))
104
+ end
105
+
106
+ def test_no_key
107
+ assert_false(match?(["originalTypes", :include?, "select"],
108
+ {}))
109
+ end
110
+
111
+ def test_not_enumerable
112
+ assert_false(match?(["originalTypes", :include?, "select"],
113
+ {
114
+ "originalTypes" => 29,
115
+ }))
116
+ end
117
+ end
118
+
119
+ class ExistTest < self
120
+ def test_exist
121
+ assert_true(match?(["body.result", :exist?],
122
+ {
123
+ "body" => {
124
+ "result" => nil,
125
+ },
126
+ }))
127
+ end
128
+
129
+ def test_not_exist
130
+ assert_false(match?(["body.result", :exist?],
131
+ {
132
+ "body" => nil,
133
+ }))
134
+ end
135
+ end
136
+ end
137
+ end