fluent-plugin-droonga 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/.travis.yml +7 -0
  4. data/Gemfile +40 -0
  5. data/LICENSE.txt +14 -0
  6. data/README.md +18 -0
  7. data/Rakefile +25 -0
  8. data/benchmark/benchmark.rb +123 -0
  9. data/benchmark/utils.rb +243 -0
  10. data/benchmark/watch/benchmark-notify.rb +143 -0
  11. data/benchmark/watch/benchmark-notify.sh +19 -0
  12. data/benchmark/watch/benchmark-publish.rb +120 -0
  13. data/benchmark/watch/benchmark-scan.rb +210 -0
  14. data/benchmark/watch/catalog.json +32 -0
  15. data/benchmark/watch/fluentd.conf +12 -0
  16. data/bin/grn2jsons +85 -0
  17. data/fluent-plugin-droonga.gemspec +41 -0
  18. data/lib/droonga/adapter.rb +156 -0
  19. data/lib/droonga/catalog.rb +153 -0
  20. data/lib/droonga/command_mapper.rb +45 -0
  21. data/lib/droonga/engine.rb +83 -0
  22. data/lib/droonga/executor.rb +289 -0
  23. data/lib/droonga/handler.rb +140 -0
  24. data/lib/droonga/handler_plugin.rb +35 -0
  25. data/lib/droonga/job_queue.rb +83 -0
  26. data/lib/droonga/job_queue_schema.rb +65 -0
  27. data/lib/droonga/logger.rb +34 -0
  28. data/lib/droonga/plugin.rb +41 -0
  29. data/lib/droonga/plugin/adapter/groonga/select.rb +88 -0
  30. data/lib/droonga/plugin/adapter_groonga.rb +40 -0
  31. data/lib/droonga/plugin/handler/groonga/column_create.rb +103 -0
  32. data/lib/droonga/plugin/handler/groonga/table_create.rb +100 -0
  33. data/lib/droonga/plugin/handler_add.rb +44 -0
  34. data/lib/droonga/plugin/handler_forward.rb +70 -0
  35. data/lib/droonga/plugin/handler_groonga.rb +52 -0
  36. data/lib/droonga/plugin/handler_proxy.rb +82 -0
  37. data/lib/droonga/plugin/handler_search.rb +33 -0
  38. data/lib/droonga/plugin/handler_watch.rb +102 -0
  39. data/lib/droonga/proxy.rb +371 -0
  40. data/lib/droonga/searcher.rb +415 -0
  41. data/lib/droonga/server.rb +112 -0
  42. data/lib/droonga/sweeper.rb +42 -0
  43. data/lib/droonga/watch_schema.rb +88 -0
  44. data/lib/droonga/watcher.rb +256 -0
  45. data/lib/droonga/worker.rb +51 -0
  46. data/lib/fluent/plugin/out_droonga.rb +56 -0
  47. data/lib/groonga_command_converter.rb +137 -0
  48. data/sample/cluster/catalog.json +43 -0
  49. data/sample/cluster/fluentd.conf +12 -0
  50. data/sample/fluentd.conf +8 -0
  51. data/test/fixtures/catalog.json +43 -0
  52. data/test/fixtures/document.grn +23 -0
  53. data/test/helper.rb +24 -0
  54. data/test/helper/fixture.rb +28 -0
  55. data/test/helper/sandbox.rb +73 -0
  56. data/test/helper/stub_worker.rb +27 -0
  57. data/test/helper/watch_helper.rb +35 -0
  58. data/test/plugin/adapter/groonga/test_select.rb +176 -0
  59. data/test/plugin/handler/groonga/test_column_create.rb +127 -0
  60. data/test/plugin/handler/groonga/test_table_create.rb +140 -0
  61. data/test/plugin/handler/test_handler_add.rb +135 -0
  62. data/test/plugin/handler/test_handler_groonga.rb +64 -0
  63. data/test/plugin/handler/test_handler_search.rb +512 -0
  64. data/test/plugin/handler/test_handler_watch.rb +168 -0
  65. data/test/run-test.rb +55 -0
  66. data/test/test_adapter.rb +48 -0
  67. data/test/test_catalog.rb +59 -0
  68. data/test/test_command_mapper.rb +44 -0
  69. data/test/test_groonga_command_converter.rb +242 -0
  70. data/test/test_handler.rb +53 -0
  71. data/test/test_job_queue_schema.rb +45 -0
  72. data/test/test_output.rb +99 -0
  73. data/test/test_sweeper.rb +95 -0
  74. data/test/test_watch_schema.rb +57 -0
  75. data/test/test_watcher.rb +336 -0
  76. data/test/test_worker.rb +144 -0
  77. metadata +299 -0
@@ -0,0 +1,27 @@
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
+ class StubWorker
17
+ attr_reader :context, :body, :envelope
18
+
19
+ def initialize()
20
+ @context = Groonga::Context.default
21
+ @envelope = {}
22
+ end
23
+
24
+ def post(body, destination=nil)
25
+ @body = body
26
+ end
27
+ end
@@ -0,0 +1,35 @@
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/watch_schema"
17
+
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
+ def setup_schema
26
+ schema = Droonga::WatchSchema.new(Groonga::Context.default)
27
+ schema.ensure_created
28
+ end
29
+
30
+ def teardown_database
31
+ @database.close
32
+ @database = nil
33
+ FileUtils.rm_rf(@database_path.dirname.to_s)
34
+ end
35
+ end
@@ -0,0 +1,176 @@
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/adapter/groonga/select"
17
+
18
+ class AdapterGroongaSelectTest < Test::Unit::TestCase
19
+ def setup
20
+ @select = Droonga::GroongaAdapter::Select.new
21
+ end
22
+
23
+ class RequestTest < self
24
+ def test_empty
25
+ select_request = {
26
+ "table" => "EmptyTable",
27
+ "output_columns" => "_id",
28
+ }
29
+
30
+ expected_search_request = {
31
+ "queries" => {
32
+ "EmptyTable" => {
33
+ "source" => "EmptyTable",
34
+ "output" => {
35
+ "elements" => [
36
+ "startTime",
37
+ "elapsedTime",
38
+ "count",
39
+ "attributes",
40
+ "records",
41
+ ],
42
+ "attributes" => ["_id"],
43
+ },
44
+ },
45
+ },
46
+ }
47
+
48
+ assert_equal(expected_search_request, convert(select_request))
49
+ end
50
+
51
+ private
52
+ def convert(select_request)
53
+ @select.convert_request(select_request)
54
+ end
55
+
56
+ class OutputColumnsTest < self
57
+ def assert_attributes(expected_attributes, output_columns)
58
+ select_request = {
59
+ "table" => "EmptyTable",
60
+ "output_columns" => output_columns,
61
+ }
62
+
63
+ expected_search_request = {
64
+ "queries" => {
65
+ "EmptyTable" => {
66
+ "source" => "EmptyTable",
67
+ "output" => {
68
+ "elements" => [
69
+ "startTime",
70
+ "elapsedTime",
71
+ "count",
72
+ "attributes",
73
+ "records",
74
+ ],
75
+ "attributes" => expected_attributes,
76
+ },
77
+ },
78
+ },
79
+ }
80
+ assert_equal(expected_search_request, convert(select_request))
81
+ end
82
+
83
+ def test_multiple_columns
84
+ assert_attributes(["_id", "_key"], "_id,_key")
85
+ end
86
+
87
+ class FunctionTest < self
88
+ def test_single_argument
89
+ assert_attributes(["snippet_html(content)"], "snippet_html(content)")
90
+ end
91
+
92
+ def test_with_columns
93
+ assert_attributes(["_id","_key","snippet_html(content)"], "_id,_key,snippet_html(content)")
94
+ end
95
+ end
96
+ end
97
+
98
+ class MatchColumnsTest < self
99
+ def assert_matchTo(expected_matchTo, match_columns)
100
+ select_request = {
101
+ "table" => "EmptyTable",
102
+ "match_columns" => match_columns,
103
+ "query" => "QueryTest",
104
+ "output_columns" => "_id",
105
+ }
106
+
107
+ expected_search_request = {
108
+ "queries" => {
109
+ "EmptyTable" => {
110
+ "source" => "EmptyTable",
111
+ "condition"=> {
112
+ "query" => "QueryTest",
113
+ "matchTo"=> expected_matchTo,
114
+ "defaultOperator"=> "&&",
115
+ "allowPragma"=> false,
116
+ "allowColumn"=> true,
117
+ },
118
+ "output" => {
119
+ "elements" => [
120
+ "startTime",
121
+ "elapsedTime",
122
+ "count",
123
+ "attributes",
124
+ "records",
125
+ ],
126
+ "attributes" => ["_id"],
127
+ },
128
+ },
129
+ },
130
+ }
131
+ assert_equal(expected_search_request, convert(select_request))
132
+ end
133
+
134
+ def test_single_column
135
+ assert_matchTo(["_key"], "_key")
136
+ end
137
+
138
+ def test_multiple_columns
139
+ assert_matchTo(["_key", "content"], "_key || content")
140
+ end
141
+ end
142
+ end
143
+
144
+ class ResponseTest < self
145
+ def test_empty
146
+ start_time = "2001-08-02T10:45:23.5+09:00"
147
+ elapsed_time = 0
148
+ count = 0
149
+
150
+ search_response = {
151
+ "EmptyTable" => {
152
+ "startTime" => start_time,
153
+ "elapsedTime" => elapsed_time,
154
+ "count" => count,
155
+ "attributes" => [
156
+ {"name" => "_id", "type" => "UInt32", "vector" => false},
157
+ ],
158
+ "records" => [],
159
+ },
160
+ }
161
+
162
+ status_code = 0
163
+ start_time_in_unix_time = Time.parse(start_time).to_f
164
+ headers = [["_id","UInt32"]]
165
+ expected_select_response = [[status_code, start_time_in_unix_time, elapsed_time],
166
+ [[[count], headers]]]
167
+
168
+ assert_equal(expected_select_response, convert(search_response))
169
+ end
170
+
171
+ private
172
+ def convert(search_response)
173
+ @select.convert_response(search_response)
174
+ end
175
+ end
176
+ end
@@ -0,0 +1,127 @@
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
+ class ColumnCreateTest < GroongaHandlerTest
17
+ def test_success
18
+ @handler.table_create({"name" => "Books"})
19
+ @handler.column_create({"table" => "Books", "name" => "title", "type" => "ShortText"})
20
+ assert_equal([true], @worker.body)
21
+ end
22
+
23
+ def test_name
24
+ @handler.table_create({"name" => "Books"})
25
+ @handler.column_create({"table" => "Books", "name" => "title", "type" => "ShortText"})
26
+ assert_equal(<<-SCHEMA, dump)
27
+ table_create Books TABLE_HASH_KEY --key_type ShortText
28
+ column_create Books title COLUMN_SCALAR ShortText
29
+ SCHEMA
30
+ end
31
+
32
+ def test_type
33
+ @handler.table_create({"name" => "Books"})
34
+ @handler.column_create({"table" => "Books", "name" => "main_text", "type" => "LongText"})
35
+ assert_equal(<<-SCHEMA, dump)
36
+ table_create Books TABLE_HASH_KEY --key_type ShortText
37
+ column_create Books main_text COLUMN_SCALAR LongText
38
+ SCHEMA
39
+ end
40
+
41
+ class FlagsTest < self
42
+ class DataStoreTest < self
43
+ data({
44
+ "COLUMN_SCALAR" => {
45
+ :flags => "COLUMN_SCALAR",
46
+ },
47
+ "COLUMN_VECTOR" => {
48
+ :flags => "COLUMN_VECTOR",
49
+ },
50
+ })
51
+ def test_data_store_column_type(data)
52
+ request = {
53
+ "table" => "Books",
54
+ "name" => "title",
55
+ "type" => "ShortText",
56
+ "flags" => data[:flags],
57
+ }
58
+ @handler.table_create({"name" => "Books"})
59
+ @handler.column_create(request)
60
+ assert_equal(<<-EXPECTED, dump)
61
+ table_create Books TABLE_HASH_KEY --key_type ShortText
62
+ column_create Books title #{data[:flags]} ShortText
63
+ EXPECTED
64
+ end
65
+ end
66
+
67
+ class IndexTest < self
68
+ def setup
69
+ super
70
+ @handler.table_create({"name" => "Books"})
71
+ @handler.column_create({"table" => "Books", "name" => "title", "type" => "ShortText"})
72
+ end
73
+
74
+ def test_index_column_type
75
+ data = {
76
+ :flags => "COLUMN_INDEX",
77
+ }
78
+ request = {
79
+ "table" => "Books",
80
+ "name" => "entry_title",
81
+ "type" => "Books",
82
+ "source" => "title",
83
+ "flags" => data[:flags],
84
+ }
85
+ @handler.column_create(request)
86
+ assert_equal(<<-EXPECTED, dump)
87
+ table_create Books TABLE_HASH_KEY --key_type ShortText
88
+ column_create Books title COLUMN_SCALAR ShortText
89
+
90
+ column_create Books entry_title #{data[:flags]} Books title
91
+ EXPECTED
92
+ end
93
+
94
+ data({
95
+ "WITH_SECTION" => {
96
+ :flags => "WITH_SECTION",
97
+ },
98
+ "WITH_WEIGHT" => {
99
+ :flags => "WITH_WEIGHT",
100
+ },
101
+ "WITH_POSITION" => {
102
+ :flags => "WITH_POSITION",
103
+ },
104
+ "COLUMN_INDEX with all" => {
105
+ :flags => "WITH_SECTION|WITH_WEIGHT|WITH_POSITION",
106
+ },
107
+ })
108
+ def test_index_flags(data)
109
+ flags = "COLUMN_INDEX|#{data[:flags]}"
110
+ request = {
111
+ "table" => "Books",
112
+ "name" => "entry_title",
113
+ "type" => "Books",
114
+ "source" => "title",
115
+ "flags" => flags,
116
+ }
117
+ @handler.column_create(request)
118
+ assert_equal(<<-EXPECTED, dump)
119
+ table_create Books TABLE_HASH_KEY --key_type ShortText
120
+ column_create Books title COLUMN_SCALAR ShortText
121
+
122
+ column_create Books entry_title #{flags} Books title
123
+ EXPECTED
124
+ end
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,140 @@
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
+ class TableCreateTest < GroongaHandlerTest
17
+ def test_success
18
+ @handler.table_create({"name" => "Books"})
19
+ assert_equal(
20
+ [[Droonga::GroongaHandler::Status::SUCCESS, NORMALIZED_START_TIME, NORMALIZED_ELAPSED_TIME], true],
21
+ [normalize_header(@worker.body.first), @worker.body.last]
22
+ )
23
+ end
24
+
25
+ def test_failure
26
+ @handler.table_create({})
27
+ assert_equal(
28
+ [[Droonga::GroongaHandler::Status::INVALID_ARGUMENT, NORMALIZED_START_TIME, NORMALIZED_ELAPSED_TIME], false],
29
+ [normalize_header(@worker.body.first), @worker.body.last]
30
+ )
31
+ end
32
+
33
+ def test_name
34
+ @handler.table_create({"name" => "Books"})
35
+ assert_equal(<<-SCHEMA, dump)
36
+ table_create Books TABLE_HASH_KEY --key_type ShortText
37
+ SCHEMA
38
+ end
39
+
40
+ class FlagsTest < self
41
+ data({
42
+ "TABLE_NO_KEY" => {
43
+ :flags => "TABLE_NO_KEY",
44
+ :schema => <<-SCHEMA,
45
+ table_create Books TABLE_NO_KEY
46
+ SCHEMA
47
+ },
48
+ "TABLE_HASH_KEY" => {
49
+ :flags => "TABLE_HASH_KEY",
50
+ :schema => <<-SCHEMA,
51
+ table_create Books TABLE_HASH_KEY --key_type ShortText
52
+ SCHEMA
53
+ },
54
+ "TABLE_PAT_KEY" => {
55
+ :flags => "TABLE_PAT_KEY",
56
+ :schema => <<-SCHEMA,
57
+ table_create Books TABLE_PAT_KEY --key_type ShortText
58
+ SCHEMA
59
+ },
60
+ "TABLE_DAT_KEY" => {
61
+ :flags => "TABLE_DAT_KEY",
62
+ :schema => <<-SCHEMA,
63
+ table_create Books TABLE_DAT_KEY --key_type ShortText
64
+ SCHEMA
65
+ },
66
+ "KEY_WITH_SIS with TABLE_PAT_KEY" => {
67
+ :flags => "KEY_WITH_SIS|TABLE_PAT_KEY",
68
+ :schema => <<-SCHEMA,
69
+ table_create Books TABLE_PAT_KEY|KEY_WITH_SIS --key_type ShortText
70
+ SCHEMA
71
+ },
72
+ "KEY_WITH_SIS without TABLE_PAT_KEY" => {
73
+ :flags => "TABLE_NO_KEY|KEY_WITH_SIS",
74
+ :schema => <<-SCHEMA,
75
+ table_create Books TABLE_NO_KEY
76
+ SCHEMA
77
+ },
78
+ })
79
+ def test_flags(data)
80
+ request = {
81
+ "name" => "Books",
82
+ "flags" => data[:flags],
83
+ }
84
+ @handler.table_create(request)
85
+ assert_equal(data[:schema], dump)
86
+ end
87
+ end
88
+
89
+ class KeyTypeTest < self
90
+ def test_key_type
91
+ request = {
92
+ "name" => "Books",
93
+ "key_type" => "Int32",
94
+ }
95
+ @handler.table_create(request)
96
+ assert_equal(<<-SCHEMA, dump)
97
+ table_create Books TABLE_HASH_KEY --key_type Int32
98
+ SCHEMA
99
+ end
100
+ end
101
+
102
+ class ValueTypeTest < self
103
+ def test_value_type
104
+ request = {
105
+ "name" => "Books",
106
+ "value_type" => "Int32",
107
+ }
108
+ @handler.table_create(request)
109
+ assert_equal(<<-SCHEMA, dump)
110
+ table_create Books TABLE_HASH_KEY --key_type ShortText --value_type Int32
111
+ SCHEMA
112
+ end
113
+ end
114
+
115
+ class DefaultTokenizerTest < self
116
+ def test_default_tokenizer
117
+ request = {
118
+ "name" => "Books",
119
+ "default_tokenizer" => "TokenBigram",
120
+ }
121
+ @handler.table_create(request)
122
+ assert_equal(<<-SCHEMA, dump)
123
+ table_create Books TABLE_HASH_KEY --key_type ShortText --default_tokenizer TokenBigram
124
+ SCHEMA
125
+ end
126
+ end
127
+
128
+ class NormalizerTest < self
129
+ def test_normalizer
130
+ request = {
131
+ "name" => "Books",
132
+ "normalizer" => "NormalizerAuto",
133
+ }
134
+ @handler.table_create(request)
135
+ assert_equal(<<-SCHEMA, dump)
136
+ table_create Books TABLE_HASH_KEY|KEY_NORMALIZE --key_type ShortText
137
+ SCHEMA
138
+ end
139
+ end
140
+ end