fluent-plugin-droonga 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.travis.yml +7 -0
- data/Gemfile +40 -0
- data/LICENSE.txt +14 -0
- data/README.md +18 -0
- data/Rakefile +25 -0
- data/benchmark/benchmark.rb +123 -0
- data/benchmark/utils.rb +243 -0
- data/benchmark/watch/benchmark-notify.rb +143 -0
- data/benchmark/watch/benchmark-notify.sh +19 -0
- data/benchmark/watch/benchmark-publish.rb +120 -0
- data/benchmark/watch/benchmark-scan.rb +210 -0
- data/benchmark/watch/catalog.json +32 -0
- data/benchmark/watch/fluentd.conf +12 -0
- data/bin/grn2jsons +85 -0
- data/fluent-plugin-droonga.gemspec +41 -0
- data/lib/droonga/adapter.rb +156 -0
- data/lib/droonga/catalog.rb +153 -0
- data/lib/droonga/command_mapper.rb +45 -0
- data/lib/droonga/engine.rb +83 -0
- data/lib/droonga/executor.rb +289 -0
- data/lib/droonga/handler.rb +140 -0
- data/lib/droonga/handler_plugin.rb +35 -0
- data/lib/droonga/job_queue.rb +83 -0
- data/lib/droonga/job_queue_schema.rb +65 -0
- data/lib/droonga/logger.rb +34 -0
- data/lib/droonga/plugin.rb +41 -0
- data/lib/droonga/plugin/adapter/groonga/select.rb +88 -0
- data/lib/droonga/plugin/adapter_groonga.rb +40 -0
- data/lib/droonga/plugin/handler/groonga/column_create.rb +103 -0
- data/lib/droonga/plugin/handler/groonga/table_create.rb +100 -0
- data/lib/droonga/plugin/handler_add.rb +44 -0
- data/lib/droonga/plugin/handler_forward.rb +70 -0
- data/lib/droonga/plugin/handler_groonga.rb +52 -0
- data/lib/droonga/plugin/handler_proxy.rb +82 -0
- data/lib/droonga/plugin/handler_search.rb +33 -0
- data/lib/droonga/plugin/handler_watch.rb +102 -0
- data/lib/droonga/proxy.rb +371 -0
- data/lib/droonga/searcher.rb +415 -0
- data/lib/droonga/server.rb +112 -0
- data/lib/droonga/sweeper.rb +42 -0
- data/lib/droonga/watch_schema.rb +88 -0
- data/lib/droonga/watcher.rb +256 -0
- data/lib/droonga/worker.rb +51 -0
- data/lib/fluent/plugin/out_droonga.rb +56 -0
- data/lib/groonga_command_converter.rb +137 -0
- data/sample/cluster/catalog.json +43 -0
- data/sample/cluster/fluentd.conf +12 -0
- data/sample/fluentd.conf +8 -0
- data/test/fixtures/catalog.json +43 -0
- data/test/fixtures/document.grn +23 -0
- data/test/helper.rb +24 -0
- data/test/helper/fixture.rb +28 -0
- data/test/helper/sandbox.rb +73 -0
- data/test/helper/stub_worker.rb +27 -0
- data/test/helper/watch_helper.rb +35 -0
- data/test/plugin/adapter/groonga/test_select.rb +176 -0
- data/test/plugin/handler/groonga/test_column_create.rb +127 -0
- data/test/plugin/handler/groonga/test_table_create.rb +140 -0
- data/test/plugin/handler/test_handler_add.rb +135 -0
- data/test/plugin/handler/test_handler_groonga.rb +64 -0
- data/test/plugin/handler/test_handler_search.rb +512 -0
- data/test/plugin/handler/test_handler_watch.rb +168 -0
- data/test/run-test.rb +55 -0
- data/test/test_adapter.rb +48 -0
- data/test/test_catalog.rb +59 -0
- data/test/test_command_mapper.rb +44 -0
- data/test/test_groonga_command_converter.rb +242 -0
- data/test/test_handler.rb +53 -0
- data/test/test_job_queue_schema.rb +45 -0
- data/test/test_output.rb +99 -0
- data/test/test_sweeper.rb +95 -0
- data/test/test_watch_schema.rb +57 -0
- data/test/test_watcher.rb +336 -0
- data/test/test_worker.rb +144 -0
- metadata +299 -0
@@ -0,0 +1,168 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2013 droonga project
|
4
|
+
#
|
5
|
+
# This library is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License version 2.1 as published by the Free Software Foundation.
|
8
|
+
#
|
9
|
+
# This library is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
+
# Lesser General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU Lesser General Public
|
15
|
+
# License along with this library; if not, write to the Free Software
|
16
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
17
|
+
|
18
|
+
require "droonga/plugin/handler_watch"
|
19
|
+
|
20
|
+
class WatchHandlerTest < Test::Unit::TestCase
|
21
|
+
include WatchHelper
|
22
|
+
|
23
|
+
def setup
|
24
|
+
setup_database
|
25
|
+
setup_schema
|
26
|
+
setup_handler
|
27
|
+
end
|
28
|
+
|
29
|
+
def teardown
|
30
|
+
teardown_handler
|
31
|
+
teardown_database
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def setup_handler
|
36
|
+
@worker = StubWorker.new
|
37
|
+
@handler = Droonga::WatchHandler.new(@worker)
|
38
|
+
end
|
39
|
+
|
40
|
+
def teardown_handler
|
41
|
+
@handler = nil
|
42
|
+
end
|
43
|
+
|
44
|
+
public
|
45
|
+
class SubscribeTest < self
|
46
|
+
def test_subscribe
|
47
|
+
request = {
|
48
|
+
"route" => "localhost:23003/output",
|
49
|
+
"condition" => "たいやき",
|
50
|
+
"subscriber" => "localhost"
|
51
|
+
}
|
52
|
+
mock(@handler).emit([true])
|
53
|
+
@handler.subscribe(request)
|
54
|
+
|
55
|
+
assert_equal(
|
56
|
+
["localhost:23003/output"],
|
57
|
+
actual_routes_for_query("たいやき")
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_subscribe_route_omitted_from_specified
|
62
|
+
request = {
|
63
|
+
"condition" => "たいやき",
|
64
|
+
"subscriber" => "localhost"
|
65
|
+
}
|
66
|
+
@worker.envelope["from"] = "localhost:23004/output"
|
67
|
+
mock(@handler).emit([true])
|
68
|
+
@handler.subscribe(request)
|
69
|
+
|
70
|
+
assert_equal(
|
71
|
+
["localhost:23004/output"],
|
72
|
+
actual_routes_for_query("たいやき")
|
73
|
+
)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_subscribe_both_route_and_from_specified
|
77
|
+
request = {
|
78
|
+
"condition" => "たいやき",
|
79
|
+
"subscriber" => "localhost",
|
80
|
+
"route" => "localhost:23003/output"
|
81
|
+
}
|
82
|
+
@worker.envelope["from"] = "localhost:23004/output"
|
83
|
+
mock(@handler).emit([true])
|
84
|
+
@handler.subscribe(request)
|
85
|
+
|
86
|
+
assert_equal(
|
87
|
+
["localhost:23003/output"],
|
88
|
+
actual_routes_for_query("たいやき")
|
89
|
+
)
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
def actual_routes_for_query(query)
|
94
|
+
@worker.context["Subscriber"].select {|record|
|
95
|
+
record[:subscriptions] =~ query.to_json
|
96
|
+
}.map {|subscriber|
|
97
|
+
subscriber.route.key
|
98
|
+
}
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
class UnsubscribeTest < self
|
103
|
+
def setup
|
104
|
+
super
|
105
|
+
setup_subscription
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_unsubscribe
|
109
|
+
request = {
|
110
|
+
"route" => "localhost:23003/output",
|
111
|
+
"condition" => "たいやき",
|
112
|
+
"subscriber" => "localhost"
|
113
|
+
}
|
114
|
+
mock(@handler).emit([true])
|
115
|
+
@handler.unsubscribe(request)
|
116
|
+
end
|
117
|
+
|
118
|
+
private
|
119
|
+
def setup_subscription
|
120
|
+
request = {
|
121
|
+
"route" => "localhost:23003/output",
|
122
|
+
"condition" => "たいやき",
|
123
|
+
"subscriber" => "localhost"
|
124
|
+
}
|
125
|
+
stub(@handler).emit([true])
|
126
|
+
@handler.subscribe(request)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
class FeedTest < self
|
131
|
+
def setup
|
132
|
+
super
|
133
|
+
setup_subscription
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_feed_match
|
137
|
+
request = {
|
138
|
+
"targets" => {
|
139
|
+
"text" => "たいやきおいしいです"
|
140
|
+
}
|
141
|
+
}
|
142
|
+
@handler.feed(request)
|
143
|
+
assert_equal(request, @worker.body)
|
144
|
+
assert_equal({"to" => ["localhost"]}, @worker.envelope)
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_feed_not_match
|
148
|
+
request = {
|
149
|
+
"targets" => {
|
150
|
+
"text" => "たこやきおいしいです"
|
151
|
+
}
|
152
|
+
}
|
153
|
+
@handler.feed(request)
|
154
|
+
assert_nil(@worker.body)
|
155
|
+
end
|
156
|
+
|
157
|
+
private
|
158
|
+
def setup_subscription
|
159
|
+
request = {
|
160
|
+
"route" => "localhost:23003/output",
|
161
|
+
"condition" => "たいやき",
|
162
|
+
"subscriber" => "localhost"
|
163
|
+
}
|
164
|
+
stub(@handler).emit([true])
|
165
|
+
@handler.subscribe(request)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
data/test/run-test.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
#
|
4
|
+
# Copyright (C) 2013 droonga project
|
5
|
+
#
|
6
|
+
# This library is free software; you can redistribute it and/or
|
7
|
+
# modify it under the terms of the GNU Lesser General Public
|
8
|
+
# License version 2.1 as published by the Free Software Foundation.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
18
|
+
|
19
|
+
require "pathname"
|
20
|
+
|
21
|
+
require "rubygems"
|
22
|
+
require "bundler"
|
23
|
+
begin
|
24
|
+
Bundler.setup(:default, :development)
|
25
|
+
rescue Bundler::BundlerError => e
|
26
|
+
$stderr.puts e.message
|
27
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
28
|
+
exit e.status_code
|
29
|
+
end
|
30
|
+
|
31
|
+
require "test-unit"
|
32
|
+
require "test/unit/notify"
|
33
|
+
require "test/unit/rr"
|
34
|
+
|
35
|
+
require "fluent/test"
|
36
|
+
unless ENV.has_key?("VERBOSE")
|
37
|
+
null_logger = Object.new
|
38
|
+
null_logger.instance_eval do |obj|
|
39
|
+
def method_missing(method, *args)
|
40
|
+
# pass
|
41
|
+
end
|
42
|
+
end
|
43
|
+
$log = null_logger
|
44
|
+
end
|
45
|
+
|
46
|
+
base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
47
|
+
lib_dir = File.join(base_dir, "lib")
|
48
|
+
test_dir = File.join(base_dir, "test")
|
49
|
+
|
50
|
+
$LOAD_PATH.unshift(lib_dir)
|
51
|
+
$LOAD_PATH.unshift(test_dir)
|
52
|
+
|
53
|
+
require "helper"
|
54
|
+
|
55
|
+
exit Test::Unit::AutoRunner.run(true, test_dir)
|
@@ -0,0 +1,48 @@
|
|
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/adapter"
|
17
|
+
|
18
|
+
class AdapterTest < Test::Unit::TestCase
|
19
|
+
class AdaptTest < self
|
20
|
+
class GroongaAdapter < Droonga::Adapter
|
21
|
+
command :select
|
22
|
+
def select(request)
|
23
|
+
post(:search) do |response|
|
24
|
+
# do nothing
|
25
|
+
end
|
26
|
+
:selected
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def setup
|
31
|
+
@proxy = Object.new
|
32
|
+
@groonga_adapter = GroongaAdapter.new(@proxy)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_called
|
36
|
+
request = nil
|
37
|
+
stub(@proxy).post
|
38
|
+
assert_equal(:selected, @groonga_adapter.adapt(:select, request))
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_post
|
42
|
+
request = nil
|
43
|
+
response = nil
|
44
|
+
mock(@proxy).post(:search).yields(response)
|
45
|
+
@groonga_adapter.adapt(:select, request)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,59 @@
|
|
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/catalog"
|
17
|
+
|
18
|
+
class CatalogTest < Test::Unit::TestCase
|
19
|
+
def setup
|
20
|
+
@catalog = Droonga::Catalog.new(catalog_path)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_option
|
24
|
+
assert_equal(["for_global"], @catalog.option("plugins"))
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_get_engines
|
28
|
+
engines = @catalog.get_engines("localhost:23003/test")
|
29
|
+
base_path = File.expand_path("../fixtures", __FILE__)
|
30
|
+
assert_equal({
|
31
|
+
"localhost:23003/test.000" => {
|
32
|
+
:database => "#{base_path}/000/db",
|
33
|
+
:handlers => ["for_dataset"],
|
34
|
+
:n_workers => 0
|
35
|
+
},
|
36
|
+
"localhost:23003/test.001" => {
|
37
|
+
:database => "#{base_path}/001/db",
|
38
|
+
:handlers => ["for_dataset"],
|
39
|
+
:n_workers => 0
|
40
|
+
},
|
41
|
+
"localhost:23003/test.002" => {
|
42
|
+
:database => "#{base_path}/002/db",
|
43
|
+
:handlers => ["for_dataset"],
|
44
|
+
:n_workers => 0
|
45
|
+
},
|
46
|
+
"localhost:23003/test.003" => {
|
47
|
+
:database => "#{base_path}/003/db",
|
48
|
+
:handlers => ["for_dataset"],
|
49
|
+
:n_workers => 0
|
50
|
+
},
|
51
|
+
},
|
52
|
+
engines)
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
def catalog_path
|
57
|
+
@catalog_path ||= File.expand_path("../fixtures/catalog.json", __FILE__)
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,44 @@
|
|
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/command_mapper"
|
17
|
+
|
18
|
+
class CommandMapperTest < Test::Unit::TestCase
|
19
|
+
class RegisterTest < self
|
20
|
+
def setup
|
21
|
+
@command_mapper = Droonga::CommandMapper.new
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_name
|
25
|
+
@command_mapper.register(:select)
|
26
|
+
assert_equal(:select, @command_mapper[:select])
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_different_method_name
|
30
|
+
@command_mapper.register(:command_name => :method_name)
|
31
|
+
assert_equal(:method_name, @command_mapper[:command_name])
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_multiple_pairs
|
35
|
+
map = {
|
36
|
+
:command_name_1 => :command_name_1,
|
37
|
+
:command_name_2 => :command_name_2,
|
38
|
+
}
|
39
|
+
@command_mapper.register(map)
|
40
|
+
assert_equal(["command_name_1", "command_name_2"],
|
41
|
+
@command_mapper.commands)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,242 @@
|
|
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 "groonga_command_converter"
|
17
|
+
|
18
|
+
class GroongaCommandConverterTest < Test::Unit::TestCase
|
19
|
+
def setup
|
20
|
+
options = {
|
21
|
+
:id => "test",
|
22
|
+
:date => date,
|
23
|
+
:reply_to => reply_to,
|
24
|
+
:status_code => status_code,
|
25
|
+
:dataset => dataset,
|
26
|
+
}
|
27
|
+
@converter = Droonga::GroongaCommandConverter.new(options)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_table_create
|
31
|
+
droonga_commands = []
|
32
|
+
command = <<-COMMAND.chomp
|
33
|
+
table_create Terms TABLE_PAT_KEY ShortText \
|
34
|
+
--default_tokenizer TokenBigram --normalizer NormalizerAuto
|
35
|
+
COMMAND
|
36
|
+
@converter.convert(command) do |droonga_command|
|
37
|
+
droonga_commands << droonga_command
|
38
|
+
end
|
39
|
+
assert_equal([
|
40
|
+
{
|
41
|
+
:id => "test:0",
|
42
|
+
:date => formatted_date,
|
43
|
+
:replyTo => reply_to,
|
44
|
+
:statusCode => status_code,
|
45
|
+
:dataset => dataset,
|
46
|
+
:type => "table_create",
|
47
|
+
:body => {
|
48
|
+
:name => "Terms",
|
49
|
+
:flags => "TABLE_PAT_KEY",
|
50
|
+
:key_type => "ShortText",
|
51
|
+
:default_tokenizer => "TokenBigram",
|
52
|
+
:normalizer => "NormalizerAuto",
|
53
|
+
},
|
54
|
+
},
|
55
|
+
],
|
56
|
+
droonga_commands)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_column_create
|
60
|
+
droonga_commands = []
|
61
|
+
command = <<-COMMAND.chomp
|
62
|
+
column_create Terms Users_name COLUMN_INDEX|WITH_POSITION Users name
|
63
|
+
COMMAND
|
64
|
+
@converter.convert(command) do |droonga_command|
|
65
|
+
droonga_commands << droonga_command
|
66
|
+
end
|
67
|
+
assert_equal([
|
68
|
+
{
|
69
|
+
:id => "test:0",
|
70
|
+
:date => formatted_date,
|
71
|
+
:replyTo => reply_to,
|
72
|
+
:statusCode => status_code,
|
73
|
+
:dataset => dataset,
|
74
|
+
:type => "column_create",
|
75
|
+
:body => {
|
76
|
+
:table => "Terms",
|
77
|
+
:name => "Users_name",
|
78
|
+
:flags => "COLUMN_INDEX|WITH_POSITION",
|
79
|
+
:type => "Users",
|
80
|
+
:source => "name",
|
81
|
+
},
|
82
|
+
},
|
83
|
+
],
|
84
|
+
droonga_commands)
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_load
|
88
|
+
droonga_commands = []
|
89
|
+
command = <<-COMMAND.chomp
|
90
|
+
load --table Users
|
91
|
+
[
|
92
|
+
["_key","name"],
|
93
|
+
["user0","Abe Shinzo"],
|
94
|
+
["user1","Noda Yoshihiko"],
|
95
|
+
["user2","Kan Naoto"]
|
96
|
+
]
|
97
|
+
COMMAND
|
98
|
+
@converter.convert(command) do |droonga_command|
|
99
|
+
droonga_commands << droonga_command
|
100
|
+
end
|
101
|
+
assert_equal([
|
102
|
+
{
|
103
|
+
:id => "test:0",
|
104
|
+
:date => formatted_date,
|
105
|
+
:replyTo => reply_to,
|
106
|
+
:statusCode => status_code,
|
107
|
+
:dataset => dataset,
|
108
|
+
:type => "add",
|
109
|
+
:body => {
|
110
|
+
:table => "Users",
|
111
|
+
:key => "user0",
|
112
|
+
:values => {
|
113
|
+
:name => "Abe Shinzo",
|
114
|
+
},
|
115
|
+
},
|
116
|
+
},
|
117
|
+
{
|
118
|
+
:id => "test:1",
|
119
|
+
:date => formatted_date,
|
120
|
+
:replyTo => reply_to,
|
121
|
+
:statusCode => status_code,
|
122
|
+
:dataset => dataset,
|
123
|
+
:type => "add",
|
124
|
+
:body => {
|
125
|
+
:table => "Users",
|
126
|
+
:key => "user1",
|
127
|
+
:values => {
|
128
|
+
:name => "Noda Yoshihiko",
|
129
|
+
},
|
130
|
+
},
|
131
|
+
},
|
132
|
+
{
|
133
|
+
:id => "test:2",
|
134
|
+
:date => formatted_date,
|
135
|
+
:replyTo => reply_to,
|
136
|
+
:statusCode => status_code,
|
137
|
+
:dataset => dataset,
|
138
|
+
:type => "add",
|
139
|
+
:body => {
|
140
|
+
:table => "Users",
|
141
|
+
:key => "user2",
|
142
|
+
:values => {
|
143
|
+
:name => "Kan Naoto",
|
144
|
+
},
|
145
|
+
},
|
146
|
+
},
|
147
|
+
],
|
148
|
+
droonga_commands)
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_select
|
152
|
+
droonga_commands = []
|
153
|
+
command = <<-COMMAND.chomp
|
154
|
+
select --filter "age<=30" --output_type "json" --table "Users"
|
155
|
+
COMMAND
|
156
|
+
@converter.convert(command) do |droonga_command|
|
157
|
+
droonga_commands << droonga_command
|
158
|
+
end
|
159
|
+
assert_equal([
|
160
|
+
{
|
161
|
+
:id => "test:0",
|
162
|
+
:date => formatted_date,
|
163
|
+
:replyTo => reply_to,
|
164
|
+
:statusCode => status_code,
|
165
|
+
:dataset => dataset,
|
166
|
+
:type => "select",
|
167
|
+
:body => {
|
168
|
+
:table => "Users",
|
169
|
+
:filter => "age<=30",
|
170
|
+
:output_type => "json",
|
171
|
+
},
|
172
|
+
},
|
173
|
+
],
|
174
|
+
droonga_commands)
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_multiple_commands
|
178
|
+
droonga_commands = []
|
179
|
+
commands = <<-COMMANDS.chomp
|
180
|
+
table_create Terms TABLE_PAT_KEY ShortText \
|
181
|
+
--default_tokenizer TokenBigram --normalizer NormalizerAuto
|
182
|
+
column_create Terms Users_name COLUMN_INDEX|WITH_POSITION Users name
|
183
|
+
COMMANDS
|
184
|
+
@converter.convert(commands) do |droonga_command|
|
185
|
+
droonga_commands << droonga_command
|
186
|
+
end
|
187
|
+
assert_equal([
|
188
|
+
{
|
189
|
+
:id => "test:0",
|
190
|
+
:date => formatted_date,
|
191
|
+
:replyTo => reply_to,
|
192
|
+
:statusCode => status_code,
|
193
|
+
:dataset => dataset,
|
194
|
+
:type => "table_create",
|
195
|
+
:body => {
|
196
|
+
:name => "Terms",
|
197
|
+
:flags => "TABLE_PAT_KEY",
|
198
|
+
:key_type => "ShortText",
|
199
|
+
:default_tokenizer => "TokenBigram",
|
200
|
+
:normalizer => "NormalizerAuto",
|
201
|
+
},
|
202
|
+
},
|
203
|
+
{
|
204
|
+
:id => "test:1",
|
205
|
+
:date => formatted_date,
|
206
|
+
:replyTo => reply_to,
|
207
|
+
:statusCode => status_code,
|
208
|
+
:dataset => dataset,
|
209
|
+
:type => "column_create",
|
210
|
+
:body => {
|
211
|
+
:table => "Terms",
|
212
|
+
:name => "Users_name",
|
213
|
+
:flags => "COLUMN_INDEX|WITH_POSITION",
|
214
|
+
:type => "Users",
|
215
|
+
:source => "name",
|
216
|
+
},
|
217
|
+
},
|
218
|
+
],
|
219
|
+
droonga_commands)
|
220
|
+
end
|
221
|
+
|
222
|
+
private
|
223
|
+
def date
|
224
|
+
Time.new(2013, 11, 29, 0, 0, 0)
|
225
|
+
end
|
226
|
+
|
227
|
+
def formatted_date
|
228
|
+
"2013-11-29T00:00:00+09:00"
|
229
|
+
end
|
230
|
+
|
231
|
+
def reply_to
|
232
|
+
"localhost:20033"
|
233
|
+
end
|
234
|
+
|
235
|
+
def status_code
|
236
|
+
200
|
237
|
+
end
|
238
|
+
|
239
|
+
def dataset
|
240
|
+
"test-dataset"
|
241
|
+
end
|
242
|
+
end
|