fluent-plugin-droonga 0.9.9 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.dir-locals.el +3 -0
- data/.travis.yml +6 -2
- data/README.md +6 -7
- data/Rakefile +23 -6
- data/fluent-plugin-droonga.gemspec +2 -2
- data/lib/droonga/adapter.rb +12 -3
- data/lib/droonga/adapter_runner.rb +28 -23
- data/lib/droonga/catalog/base.rb +7 -111
- data/lib/droonga/catalog/dataset.rb +13 -25
- data/lib/droonga/catalog/errors.rb +94 -0
- data/lib/droonga/catalog/schema.rb +277 -0
- data/lib/droonga/catalog/version1.rb +404 -0
- data/lib/droonga/catalog/version2.rb +160 -0
- data/lib/droonga/catalog_loader.rb +27 -4
- data/lib/droonga/catalog_observer.rb +44 -6
- data/lib/droonga/collector.rb +12 -10
- data/lib/droonga/{handler_plugin.rb → collector_message.rb} +47 -20
- data/lib/droonga/collector_runner.rb +64 -0
- data/lib/droonga/collectors.rb +18 -0
- data/lib/droonga/{catalog.rb → collectors/add.rb} +9 -7
- data/lib/droonga/{command_repository.rb → collectors/and.rb} +7 -14
- data/lib/droonga/collectors/sum.rb +26 -0
- data/lib/droonga/dispatcher.rb +74 -41
- data/lib/droonga/distributed_command_planner.rb +2 -2
- data/lib/droonga/engine.rb +13 -5
- data/lib/droonga/{message_processing_error.rb → error.rb} +33 -12
- data/lib/droonga/{plugin/planner/search.rb → error_messages.rb} +12 -10
- data/lib/droonga/farm.rb +15 -14
- data/lib/droonga/fluent_message_sender.rb +15 -11
- data/lib/droonga/forwarder.rb +22 -18
- data/lib/droonga/handler.rb +8 -2
- data/lib/droonga/handler_runner.rb +47 -26
- data/lib/droonga/input_message.rb +6 -6
- data/lib/droonga/{command.rb → loggable.rb} +7 -14
- data/lib/droonga/logger.rb +56 -15
- data/lib/droonga/message_matcher.rb +12 -7
- data/lib/droonga/message_pusher.rb +8 -4
- data/lib/droonga/message_receiver.rb +11 -9
- data/lib/droonga/output_message.rb +2 -0
- data/lib/droonga/planner.rb +21 -10
- data/lib/droonga/plugin.rb +15 -0
- data/lib/droonga/plugin/metadata/{adapter_message.rb → adapter_input_message.rb} +6 -14
- data/lib/droonga/plugin/metadata/adapter_output_message.rb +39 -0
- data/lib/droonga/plugin/metadata/collector_message.rb +39 -0
- data/lib/droonga/plugin/metadata/input_message.rb +15 -0
- data/lib/droonga/plugin_loader.rb +33 -25
- data/lib/droonga/plugin_registry.rb +9 -1
- data/lib/droonga/plugins/basic.rb +54 -0
- data/lib/droonga/plugins/crud.rb +36 -15
- data/lib/droonga/plugins/error.rb +5 -4
- data/lib/droonga/plugins/groonga.rb +9 -6
- data/lib/droonga/plugins/groonga/column_create.rb +10 -5
- data/lib/droonga/plugins/groonga/generic_command.rb +2 -8
- data/lib/droonga/plugins/groonga/generic_response.rb +2 -2
- data/lib/droonga/plugins/groonga/select.rb +2 -2
- data/lib/droonga/plugins/groonga/table_create.rb +9 -4
- data/lib/droonga/plugins/groonga/table_remove.rb +10 -5
- data/lib/droonga/plugins/search.rb +106 -5
- data/lib/droonga/plugins/search/distributed_search_planner.rb +398 -0
- data/lib/droonga/plugins/watch.rb +41 -20
- data/lib/droonga/processor.rb +12 -9
- data/lib/droonga/{plugin/collector/basic.rb → reducer.rb} +36 -50
- data/lib/droonga/replier.rb +7 -4
- data/lib/droonga/searcher.rb +40 -37
- data/lib/droonga/server.rb +8 -6
- data/lib/droonga/session.rb +17 -7
- data/lib/droonga/single_step.rb +53 -0
- data/lib/droonga/{plugin/planner/watch.rb → single_step_definition.rb} +27 -26
- data/lib/droonga/{partition.rb → slice.rb} +23 -12
- data/lib/droonga/status_code.rb +25 -0
- data/lib/droonga/step_runner.rb +63 -0
- data/lib/droonga/watch_schema.rb +7 -3
- data/lib/droonga/watcher.rb +4 -4
- data/lib/droonga/worker.rb +6 -6
- data/lib/fluent/plugin/out_droonga.rb +27 -2
- data/sample/cluster/catalog.json +33 -32
- data/test/command/config/default/catalog.json +72 -45
- data/test/command/config/version1/catalog.json +68 -0
- data/test/command/config/version1/fluentd.conf +11 -0
- data/test/command/suite/message/error/missing-dataset.expected +1 -1
- data/test/command/suite/message/error/unknown-dataset.expected +1 -1
- data/test/command/suite/message/error/unknown-type.expected +13 -0
- data/test/command/suite/message/error/{unknown-command.test → unknown-type.test} +1 -1
- data/test/command/suite/search/error/missing-source-parameter.expected +1 -1
- data/test/command/suite/search/error/unknown-source.expected +15 -3
- data/test/command/suite/watch/subscribe.expected +1 -3
- data/test/command/suite/watch/unsubscribe.expected +1 -3
- data/test/performance/watch/catalog.json +1 -0
- data/test/unit/catalog/test_dataset.rb +16 -358
- data/test/unit/catalog/test_schema.rb +285 -0
- data/test/unit/catalog/test_version1.rb +222 -28
- data/test/unit/catalog/test_version2.rb +155 -0
- data/test/unit/fixtures/catalog/version2.json +62 -0
- data/test/unit/helper/distributed_search_planner_helper.rb +2 -2
- data/test/unit/plugins/crud/test_add.rb +13 -13
- data/test/unit/plugins/groonga/test_column_create.rb +14 -11
- data/test/unit/plugins/groonga/test_table_create.rb +4 -9
- data/test/unit/plugins/groonga/test_table_remove.rb +4 -9
- data/test/unit/{plugin/planner/search_planner → plugins/search/planner}/test_basic.rb +0 -0
- data/test/unit/{plugin/planner/search_planner → plugins/search/planner}/test_group_by.rb +0 -0
- data/test/unit/{plugin/planner/search_planner → plugins/search/planner}/test_output.rb +0 -0
- data/test/unit/{plugin/planner/search_planner → plugins/search/planner}/test_sort_by.rb +0 -0
- data/test/unit/{plugin/collector/test_search.rb → plugins/search/test_collector.rb} +40 -39
- data/test/unit/plugins/{test_search.rb → search/test_handler.rb} +6 -5
- data/test/unit/{plugin/planner/test_search.rb → plugins/search/test_planner.rb} +3 -3
- data/test/unit/{plugin/collector → plugins}/test_basic.rb +68 -50
- data/test/unit/plugins/test_groonga.rb +2 -15
- data/test/unit/plugins/test_watch.rb +25 -22
- data/test/unit/test_message_matcher.rb +29 -6
- data/test/unit/test_output.rb +4 -0
- metadata +58 -50
- data/lib/droonga/collector_plugin.rb +0 -50
- data/lib/droonga/legacy_pluggable.rb +0 -66
- data/lib/droonga/legacy_plugin.rb +0 -57
- data/lib/droonga/legacy_plugin_repository.rb +0 -54
- data/lib/droonga/planner_plugin.rb +0 -54
- data/lib/droonga/plugin/collector/search.rb +0 -98
- data/lib/droonga/plugin/planner/crud.rb +0 -49
- data/lib/droonga/plugin/planner/distributed_search_planner.rb +0 -393
- data/lib/droonga/plugin/planner/groonga.rb +0 -54
- data/lib/droonga/plugin_registerable.rb +0 -75
- data/test/command/suite/message/error/unknown-command.expected +0 -13
- data/test/unit/test_command_repository.rb +0 -39
- data/test/unit/test_legacy_plugin.rb +0 -50
- data/test/unit/test_legacy_plugin_repository.rb +0 -89
@@ -0,0 +1,155 @@
|
|
1
|
+
# Copyright (C) 2013-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/catalog/version2"
|
17
|
+
|
18
|
+
class CatalogTestVersion2 < Test::Unit::TestCase
|
19
|
+
class << self
|
20
|
+
def minimum_data
|
21
|
+
{
|
22
|
+
"effectiveDate" => "2014-02-28T00:00:00Z",
|
23
|
+
"datasets" => {
|
24
|
+
},
|
25
|
+
}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def minimum_data
|
31
|
+
self.class.minimum_data
|
32
|
+
end
|
33
|
+
|
34
|
+
def create_catalog(data, path)
|
35
|
+
Droonga::Catalog::Version2.new(data, path)
|
36
|
+
end
|
37
|
+
|
38
|
+
class SliceTest < self
|
39
|
+
def setup
|
40
|
+
data = JSON.parse(File.read(catalog_path))
|
41
|
+
@catalog = create_catalog(data, catalog_path)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_slices
|
45
|
+
slices = @catalog.slices("localhost:23003/test")
|
46
|
+
assert_equal({
|
47
|
+
"localhost:23003/test.000" => {
|
48
|
+
:database => "#{base_path}/000/db",
|
49
|
+
:dataset => "Test",
|
50
|
+
:plugins => ["plugin1", "plugin2", "plugin3"],
|
51
|
+
:n_workers => 4,
|
52
|
+
},
|
53
|
+
"localhost:23003/test.001" => {
|
54
|
+
:database => "#{base_path}/001/db",
|
55
|
+
:dataset => "Test",
|
56
|
+
:plugins => ["plugin1", "plugin2", "plugin3"],
|
57
|
+
:n_workers => 4,
|
58
|
+
},
|
59
|
+
"localhost:23003/test.002" => {
|
60
|
+
:database => "#{base_path}/002/db",
|
61
|
+
:dataset => "Test",
|
62
|
+
:plugins => ["plugin1", "plugin2", "plugin3"],
|
63
|
+
:n_workers => 4,
|
64
|
+
},
|
65
|
+
},
|
66
|
+
slices)
|
67
|
+
end
|
68
|
+
|
69
|
+
def fixture_path(base_path)
|
70
|
+
File.expand_path("../../fixtures/#{base_path}", __FILE__)
|
71
|
+
end
|
72
|
+
|
73
|
+
def catalog_path
|
74
|
+
@catalog_path ||= fixture_path("catalog/version2.json")
|
75
|
+
end
|
76
|
+
|
77
|
+
def base_path
|
78
|
+
File.dirname(catalog_path)
|
79
|
+
end
|
80
|
+
|
81
|
+
class PluginsTest < self
|
82
|
+
def setup
|
83
|
+
custom_data = {
|
84
|
+
"datasets" => {
|
85
|
+
"Droonga" => {
|
86
|
+
"nWorkers" => 1,
|
87
|
+
"replicas" => [
|
88
|
+
{
|
89
|
+
"slices" => [
|
90
|
+
{
|
91
|
+
"volume" => {
|
92
|
+
"address" => "#{farm_name}.000",
|
93
|
+
},
|
94
|
+
},
|
95
|
+
],
|
96
|
+
},
|
97
|
+
],
|
98
|
+
},
|
99
|
+
},
|
100
|
+
|
101
|
+
}
|
102
|
+
@data = minimum_data.merge(custom_data)
|
103
|
+
end
|
104
|
+
|
105
|
+
def farm_name
|
106
|
+
"localhost:23041/droonga"
|
107
|
+
end
|
108
|
+
|
109
|
+
def plugins(data)
|
110
|
+
catalog = create_catalog(data, catalog_path)
|
111
|
+
catalog.slices(farm_name).collect do |volum_address, options|
|
112
|
+
options[:plugins]
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_plugins
|
117
|
+
@data["datasets"]["Droonga"]["plugins"] = ["search", "groonga", "add"]
|
118
|
+
assert_equal([["search", "groonga", "add"]],
|
119
|
+
plugins(@data))
|
120
|
+
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
class DataSetTest < self
|
126
|
+
class ReplicaTest < self
|
127
|
+
class TotalWeightTest < self
|
128
|
+
def test_three_slices
|
129
|
+
replica = {
|
130
|
+
"slices" => [
|
131
|
+
{
|
132
|
+
"weight" => 10,
|
133
|
+
},
|
134
|
+
{
|
135
|
+
"weight" => 20,
|
136
|
+
},
|
137
|
+
{
|
138
|
+
"weight" => 30,
|
139
|
+
},
|
140
|
+
],
|
141
|
+
}
|
142
|
+
assert_equal(10 + 20 + 30,
|
143
|
+
total_weight(replica))
|
144
|
+
end
|
145
|
+
|
146
|
+
private
|
147
|
+
def total_weight(replica)
|
148
|
+
catalog = create_catalog(minimum_data,
|
149
|
+
"base-path")
|
150
|
+
catalog.send(:compute_total_weight, replica)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
{
|
2
|
+
"version": 2,
|
3
|
+
"effectiveDate": "2014-02-28T00:00:00Z",
|
4
|
+
"datasets": {
|
5
|
+
"Test": {
|
6
|
+
"nWorkers": 4,
|
7
|
+
"plugins": [
|
8
|
+
"plugin1",
|
9
|
+
"plugin2",
|
10
|
+
"plugin3"
|
11
|
+
],
|
12
|
+
"replicas": [
|
13
|
+
{
|
14
|
+
"dimension": "_key",
|
15
|
+
"slicer": "hash",
|
16
|
+
"slices": [
|
17
|
+
{
|
18
|
+
"label": "slice00",
|
19
|
+
"volume": {
|
20
|
+
"address": "localhost:23003/test.000"
|
21
|
+
}
|
22
|
+
},
|
23
|
+
{
|
24
|
+
"label": "slice01",
|
25
|
+
"volume": {
|
26
|
+
"address": "localhost:23003/test.001"
|
27
|
+
}
|
28
|
+
},
|
29
|
+
{
|
30
|
+
"label": "slice02",
|
31
|
+
"volume": {
|
32
|
+
"address": "localhost:23003/test.002"
|
33
|
+
}
|
34
|
+
}
|
35
|
+
]
|
36
|
+
},
|
37
|
+
{
|
38
|
+
"slices": [
|
39
|
+
{
|
40
|
+
"label": "slice10",
|
41
|
+
"volume": {
|
42
|
+
"address": "localhost:23004/test.010"
|
43
|
+
}
|
44
|
+
},
|
45
|
+
{
|
46
|
+
"label": "slice11",
|
47
|
+
"volume": {
|
48
|
+
"address": "localhost:23004/test.011"
|
49
|
+
}
|
50
|
+
},
|
51
|
+
{
|
52
|
+
"label": "slice12",
|
53
|
+
"volume": {
|
54
|
+
"address": "localhost:23004/test.012"
|
55
|
+
}
|
56
|
+
}
|
57
|
+
]
|
58
|
+
}
|
59
|
+
]
|
60
|
+
}
|
61
|
+
}
|
62
|
+
}
|
@@ -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/
|
16
|
+
require "droonga/plugins/search/distributed_search_planner"
|
17
17
|
|
18
18
|
module DistributedSearchPlannerHelper
|
19
19
|
def plan(search_request)
|
20
|
-
planner = Droonga::DistributedSearchPlanner.new(search_request)
|
20
|
+
planner = Droonga::Plugins::Search::DistributedSearchPlanner.new(search_request)
|
21
21
|
planner.plan
|
22
22
|
end
|
23
23
|
|
@@ -16,9 +16,7 @@
|
|
16
16
|
require "droonga/plugins/crud"
|
17
17
|
|
18
18
|
class CRUDAddHandlerTest < Test::Unit::TestCase
|
19
|
-
SUCCESS_RESPONSE_BODY =
|
20
|
-
"success" => true,
|
21
|
-
}
|
19
|
+
SUCCESS_RESPONSE_BODY = true
|
22
20
|
|
23
21
|
def setup
|
24
22
|
setup_database
|
@@ -37,8 +35,10 @@ class CRUDAddHandlerTest < Test::Unit::TestCase
|
|
37
35
|
|
38
36
|
def setup_handler
|
39
37
|
@worker = StubWorker.new
|
40
|
-
@handler = Droonga::Plugins::CRUD::Handler.new("name", @worker.context)
|
41
38
|
@messenger = Droonga::Test::StubHandlerMessenger.new
|
39
|
+
@handler = Droonga::Plugins::CRUD::Handler.new("name",
|
40
|
+
@worker.context,
|
41
|
+
@messenger)
|
42
42
|
end
|
43
43
|
|
44
44
|
def teardown_handler
|
@@ -47,7 +47,7 @@ class CRUDAddHandlerTest < Test::Unit::TestCase
|
|
47
47
|
|
48
48
|
def process(request)
|
49
49
|
message = Droonga::Test::StubHandlerMessage.new(request)
|
50
|
-
@handler.handle(message
|
50
|
+
@handler.handle(message)
|
51
51
|
end
|
52
52
|
|
53
53
|
public
|
@@ -70,8 +70,8 @@ class CRUDAddHandlerTest < Test::Unit::TestCase
|
|
70
70
|
"key" => "mori",
|
71
71
|
"values" => {},
|
72
72
|
}
|
73
|
-
process(request)
|
74
|
-
assert_equal(
|
73
|
+
response = process(request)
|
74
|
+
assert_equal(SUCCESS_RESPONSE_BODY, response)
|
75
75
|
table = @worker.context["Users"]
|
76
76
|
assert_equal(["mori"], table.collect(&:key))
|
77
77
|
end
|
@@ -82,8 +82,8 @@ class CRUDAddHandlerTest < Test::Unit::TestCase
|
|
82
82
|
"key" => "mori",
|
83
83
|
"values" => {"country" => "japan"},
|
84
84
|
}
|
85
|
-
process(request)
|
86
|
-
assert_equal(
|
85
|
+
response = process(request)
|
86
|
+
assert_equal(SUCCESS_RESPONSE_BODY, response)
|
87
87
|
table = @worker.context["Users"]
|
88
88
|
assert_equal(["japan"], table.collect(&:country))
|
89
89
|
end
|
@@ -147,8 +147,8 @@ class CRUDAddHandlerTest < Test::Unit::TestCase
|
|
147
147
|
"table" => "Books",
|
148
148
|
"values" => {},
|
149
149
|
}
|
150
|
-
process(request)
|
151
|
-
assert_equal(
|
150
|
+
response = process(request)
|
151
|
+
assert_equal(SUCCESS_RESPONSE_BODY, response)
|
152
152
|
table = @worker.context["Books"]
|
153
153
|
assert_equal([nil], table.collect(&:title))
|
154
154
|
end
|
@@ -158,8 +158,8 @@ class CRUDAddHandlerTest < Test::Unit::TestCase
|
|
158
158
|
"table" => "Books",
|
159
159
|
"values" => {"title" => "CSS"},
|
160
160
|
}
|
161
|
-
process(request)
|
162
|
-
assert_equal(
|
161
|
+
response = process(request)
|
162
|
+
assert_equal(SUCCESS_RESPONSE_BODY, response)
|
163
163
|
table = @worker.context["Books"]
|
164
164
|
assert_equal(["CSS"], table.collect(&:title))
|
165
165
|
end
|
@@ -16,18 +16,20 @@
|
|
16
16
|
class ColumnCreateTest < GroongaHandlerTest
|
17
17
|
def create_handler
|
18
18
|
Droonga::Plugins::Groonga::ColumnCreate::Handler.new("droonga",
|
19
|
-
@handler.context
|
19
|
+
@handler.context,
|
20
|
+
@messages)
|
20
21
|
end
|
21
22
|
|
22
23
|
def test_success
|
23
24
|
Groonga::Schema.define(:context => @context) do |schema|
|
24
25
|
schema.create_table("Books", :type => :hash)
|
25
26
|
end
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
message = {
|
28
|
+
"table" => "Books",
|
29
|
+
"name" => "title",
|
30
|
+
"type" => "ShortText",
|
31
|
+
}
|
32
|
+
response = process(:column_create, message)
|
31
33
|
assert_equal(
|
32
34
|
[NORMALIZED_HEADER_SUCCESS, true],
|
33
35
|
[normalize_header(response.first), response.last]
|
@@ -35,11 +37,12 @@ class ColumnCreateTest < GroongaHandlerTest
|
|
35
37
|
end
|
36
38
|
|
37
39
|
def test_unknown_table
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
message = {
|
41
|
+
"table" => "Unknown",
|
42
|
+
"name" => "title",
|
43
|
+
"type" => "ShortText",
|
44
|
+
}
|
45
|
+
response = process(:column_create, message)
|
43
46
|
assert_equal(
|
44
47
|
[NORMALIZED_HEADER_INVALID_ARGUMENT, false],
|
45
48
|
[normalize_header(response.first), response.last]
|
@@ -16,14 +16,12 @@
|
|
16
16
|
class TableCreateTest < GroongaHandlerTest
|
17
17
|
def create_handler
|
18
18
|
Droonga::Plugins::Groonga::TableCreate::Handler.new("droonga",
|
19
|
-
@handler.context
|
19
|
+
@handler.context,
|
20
|
+
@messenger)
|
20
21
|
end
|
21
22
|
|
22
23
|
def test_success
|
23
|
-
process(:table_create, {"name" => "Books"})
|
24
|
-
response = @messenger.values.last
|
25
|
-
assert_valid_output(response)
|
26
|
-
response = response["result"]
|
24
|
+
response = process(:table_create, {"name" => "Books"})
|
27
25
|
assert_equal(
|
28
26
|
[NORMALIZED_HEADER_SUCCESS, true],
|
29
27
|
[normalize_header(response.first), response.last]
|
@@ -31,10 +29,7 @@ class TableCreateTest < GroongaHandlerTest
|
|
31
29
|
end
|
32
30
|
|
33
31
|
def test_failure
|
34
|
-
process(:table_create, {})
|
35
|
-
response = @messenger.values.last
|
36
|
-
assert_valid_output(response)
|
37
|
-
response = response["result"]
|
32
|
+
response = process(:table_create, {})
|
38
33
|
assert_equal(
|
39
34
|
[NORMALIZED_HEADER_INVALID_ARGUMENT, false],
|
40
35
|
[normalize_header(response.first), response.last]
|
@@ -16,7 +16,8 @@
|
|
16
16
|
class TableRemoveTest < GroongaHandlerTest
|
17
17
|
def create_handler
|
18
18
|
Droonga::Plugins::Groonga::TableRemove::Handler.new("droonga",
|
19
|
-
@handler.context
|
19
|
+
@handler.context,
|
20
|
+
@messenger)
|
20
21
|
end
|
21
22
|
|
22
23
|
def setup
|
@@ -27,10 +28,7 @@ class TableRemoveTest < GroongaHandlerTest
|
|
27
28
|
end
|
28
29
|
|
29
30
|
def test_success
|
30
|
-
process(:table_remove, {"name" => "Books"})
|
31
|
-
response = @messenger.values.last
|
32
|
-
assert_valid_output(response)
|
33
|
-
response = response["result"]
|
31
|
+
response = process(:table_remove, {"name" => "Books"})
|
34
32
|
assert_equal(
|
35
33
|
[NORMALIZED_HEADER_SUCCESS, true],
|
36
34
|
[normalize_header(response.first), response.last]
|
@@ -40,10 +38,7 @@ class TableRemoveTest < GroongaHandlerTest
|
|
40
38
|
end
|
41
39
|
|
42
40
|
def test_failure
|
43
|
-
process(:table_remove, {})
|
44
|
-
response = @messenger.values.last
|
45
|
-
assert_valid_output(response)
|
46
|
-
response = response["result"]
|
41
|
+
response = process(:table_remove, {})
|
47
42
|
assert_equal(
|
48
43
|
[NORMALIZED_HEADER_INVALID_ARGUMENT, false],
|
49
44
|
[normalize_header(response.first), response.last]
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -13,16 +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/
|
16
|
+
require "droonga/plugins/search"
|
17
17
|
|
18
18
|
class SearchCollectorTest < Test::Unit::TestCase
|
19
19
|
def setup
|
20
20
|
setup_database
|
21
|
-
@plugin = Droonga::SearchCollector.new
|
22
|
-
@outputs = []
|
23
|
-
stub(@plugin).emit do |name, value|
|
24
|
-
@outputs << [name, value]
|
25
|
-
end
|
26
21
|
end
|
27
22
|
|
28
23
|
def teardown
|
@@ -34,6 +29,22 @@ class SearchCollectorTest < Test::Unit::TestCase
|
|
34
29
|
columns
|
35
30
|
end
|
36
31
|
|
32
|
+
def run_collector(collector, message)
|
33
|
+
collector_message = Droonga::CollectorMessage.new(message)
|
34
|
+
collector.collect(collector_message)
|
35
|
+
collector_message.values
|
36
|
+
end
|
37
|
+
|
38
|
+
def gather(message)
|
39
|
+
collector = Droonga::Plugins::Search::GatherCollector.new
|
40
|
+
run_collector(collector, message)
|
41
|
+
end
|
42
|
+
|
43
|
+
def reduce(message)
|
44
|
+
collector = Droonga::Plugins::Search::ReduceCollector.new
|
45
|
+
run_collector(collector, message)
|
46
|
+
end
|
47
|
+
|
37
48
|
class << self
|
38
49
|
def create_record(*columns)
|
39
50
|
columns
|
@@ -307,7 +318,7 @@ class SearchCollectorTest < Test::Unit::TestCase
|
|
307
318
|
def test_gather(data)
|
308
319
|
request = {
|
309
320
|
"task" => {
|
310
|
-
"values" =>
|
321
|
+
"values" => {},
|
311
322
|
"step" => {
|
312
323
|
"body" => nil,
|
313
324
|
"outputs" => nil,
|
@@ -318,10 +329,10 @@ class SearchCollectorTest < Test::Unit::TestCase
|
|
318
329
|
"name" => data[:mapping],
|
319
330
|
"descendants" => nil,
|
320
331
|
}
|
321
|
-
@plugin.process("collector_search_gather", request)
|
322
332
|
output_name = data[:mapping]
|
323
333
|
output_name = output_name["output"] if output_name.is_a?(Hash)
|
324
|
-
assert_equal(
|
334
|
+
assert_equal({ output_name => data[:expected] },
|
335
|
+
gather(request))
|
325
336
|
end
|
326
337
|
end
|
327
338
|
|
@@ -385,10 +396,8 @@ class SearchCollectorTest < Test::Unit::TestCase
|
|
385
396
|
"name" => input_name,
|
386
397
|
"descendants" => nil,
|
387
398
|
}
|
388
|
-
|
389
|
-
|
390
|
-
output_name,
|
391
|
-
{
|
399
|
+
assert_equal({
|
400
|
+
output_name => {
|
392
401
|
"numeric_value" => 3,
|
393
402
|
"numeric_key_records" => [
|
394
403
|
create_record(1),
|
@@ -407,8 +416,8 @@ class SearchCollectorTest < Test::Unit::TestCase
|
|
407
416
|
create_record("f"),
|
408
417
|
],
|
409
418
|
},
|
410
|
-
|
411
|
-
|
419
|
+
},
|
420
|
+
reduce(request))
|
412
421
|
end
|
413
422
|
|
414
423
|
def test_sum_with_limit
|
@@ -470,10 +479,8 @@ class SearchCollectorTest < Test::Unit::TestCase
|
|
470
479
|
"name" => input_name,
|
471
480
|
"descendants" => nil,
|
472
481
|
}
|
473
|
-
|
474
|
-
|
475
|
-
output_name,
|
476
|
-
{
|
482
|
+
assert_equal({
|
483
|
+
output_name => {
|
477
484
|
"numeric_value" => 3,
|
478
485
|
"numeric_key_records" => [
|
479
486
|
create_record(1),
|
@@ -488,8 +495,8 @@ class SearchCollectorTest < Test::Unit::TestCase
|
|
488
495
|
create_record("f"),
|
489
496
|
],
|
490
497
|
},
|
491
|
-
|
492
|
-
|
498
|
+
},
|
499
|
+
reduce(request))
|
493
500
|
end
|
494
501
|
|
495
502
|
def test_sort
|
@@ -551,10 +558,8 @@ class SearchCollectorTest < Test::Unit::TestCase
|
|
551
558
|
"name" => input_name,
|
552
559
|
"descendants" => nil,
|
553
560
|
}
|
554
|
-
|
555
|
-
|
556
|
-
output_name,
|
557
|
-
{
|
561
|
+
assert_equal({
|
562
|
+
output_name => {
|
558
563
|
"numeric_key_records" => [
|
559
564
|
create_record(1),
|
560
565
|
create_record(2),
|
@@ -572,8 +577,8 @@ class SearchCollectorTest < Test::Unit::TestCase
|
|
572
577
|
create_record("f"),
|
573
578
|
],
|
574
579
|
},
|
575
|
-
|
576
|
-
|
580
|
+
},
|
581
|
+
reduce(request))
|
577
582
|
end
|
578
583
|
|
579
584
|
def test_sort_with_limit
|
@@ -635,10 +640,8 @@ class SearchCollectorTest < Test::Unit::TestCase
|
|
635
640
|
"name" => input_name,
|
636
641
|
"descendants" => nil,
|
637
642
|
}
|
638
|
-
|
639
|
-
|
640
|
-
output_name,
|
641
|
-
{
|
643
|
+
assert_equal({
|
644
|
+
output_name => {
|
642
645
|
"numeric_key_records" => [
|
643
646
|
create_record(1),
|
644
647
|
create_record(2),
|
@@ -652,8 +655,8 @@ class SearchCollectorTest < Test::Unit::TestCase
|
|
652
655
|
create_record("f"),
|
653
656
|
],
|
654
657
|
},
|
655
|
-
|
656
|
-
|
658
|
+
},
|
659
|
+
reduce(request))
|
657
660
|
end
|
658
661
|
end
|
659
662
|
|
@@ -749,10 +752,8 @@ class SearchCollectorTest < Test::Unit::TestCase
|
|
749
752
|
"name" => input_name,
|
750
753
|
"descendants" => nil,
|
751
754
|
}
|
752
|
-
|
753
|
-
|
754
|
-
output_name,
|
755
|
-
{
|
755
|
+
assert_equal({
|
756
|
+
output_name => {
|
756
757
|
"records" => [
|
757
758
|
[
|
758
759
|
"group3",
|
@@ -798,8 +799,8 @@ class SearchCollectorTest < Test::Unit::TestCase
|
|
798
799
|
],
|
799
800
|
],
|
800
801
|
},
|
801
|
-
|
802
|
-
|
802
|
+
},
|
803
|
+
reduce(request))
|
803
804
|
end
|
804
805
|
end
|
805
806
|
end
|