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,51 @@
|
|
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/executor"
|
19
|
+
|
20
|
+
module Droonga
|
21
|
+
module Worker
|
22
|
+
attr_reader :context, :envelope, :name
|
23
|
+
|
24
|
+
def initialize
|
25
|
+
@executor = Executor.new(config.merge(:proxy => false))
|
26
|
+
end
|
27
|
+
|
28
|
+
def run
|
29
|
+
$log.trace("#{log_tag}: run: start")
|
30
|
+
@running = true
|
31
|
+
while @running
|
32
|
+
$log.trace("#{log_tag}: run: pull_message: start")
|
33
|
+
@executor.execute_one
|
34
|
+
$log.trace("#{log_tag}: run: pull_message: done")
|
35
|
+
end
|
36
|
+
@executor.shutdown
|
37
|
+
$log.trace("#{log_tag}: run: done")
|
38
|
+
end
|
39
|
+
|
40
|
+
def stop
|
41
|
+
$log.trace("#{log_tag}: stop: start")
|
42
|
+
@running = false
|
43
|
+
$log.trace("#{log_tag}: stop: done")
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
def log_tag
|
48
|
+
"[#{Process.ppid}][#{Process.pid}] worker"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,56 @@
|
|
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/engine"
|
19
|
+
|
20
|
+
module Fluent
|
21
|
+
class DroongaOutput < Output
|
22
|
+
Plugin.register_output("droonga", self)
|
23
|
+
|
24
|
+
config_param :name, :string, :default => ""
|
25
|
+
config_param :proxy, :bool, :default => false
|
26
|
+
config_param :n_workers, :integer, :default => 0
|
27
|
+
config_param :database, :string, :default => ""
|
28
|
+
config_param :queue_name, :string, :default => "DroongaQueue"
|
29
|
+
config_param :handlers, :default => [] do |value|
|
30
|
+
value.split(/\s*,\s*/)
|
31
|
+
end
|
32
|
+
|
33
|
+
def start
|
34
|
+
super
|
35
|
+
@engine = Droonga::Engine.new(:database => @database,
|
36
|
+
:queue_name => @queue_name,
|
37
|
+
:n_workers => @n_workers,
|
38
|
+
:handlers => @handlers,
|
39
|
+
:name => @name,
|
40
|
+
:proxy => @proxy)
|
41
|
+
@engine.start
|
42
|
+
end
|
43
|
+
|
44
|
+
def shutdown
|
45
|
+
@engine.shutdown
|
46
|
+
super
|
47
|
+
end
|
48
|
+
|
49
|
+
def emit(tag, es, chain)
|
50
|
+
es.each do |time, record|
|
51
|
+
@engine.emit(tag, time, record)
|
52
|
+
end
|
53
|
+
chain.next
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,137 @@
|
|
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 "groonga/command/parser"
|
19
|
+
require "digest/sha1"
|
20
|
+
require "time"
|
21
|
+
|
22
|
+
module Droonga
|
23
|
+
class GroongaCommandConverter
|
24
|
+
STATUS_OK = 200.freeze
|
25
|
+
|
26
|
+
def initialize(options={})
|
27
|
+
@options = options
|
28
|
+
@count = 0
|
29
|
+
|
30
|
+
@command_parser = Groonga::Command::Parser.new
|
31
|
+
end
|
32
|
+
|
33
|
+
def convert(input, &block)
|
34
|
+
@command_parser.on_command do |command|
|
35
|
+
case command.name
|
36
|
+
when "table_create"
|
37
|
+
yield create_table_create_command(command)
|
38
|
+
when "column_create"
|
39
|
+
yield create_column_create_command(command)
|
40
|
+
when "select"
|
41
|
+
yield create_select_command(command)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
parsed_values = nil
|
46
|
+
parsed_columns = nil
|
47
|
+
@command_parser.on_load_start do |command|
|
48
|
+
parsed_values = []
|
49
|
+
parsed_columns = nil
|
50
|
+
end
|
51
|
+
@command_parser.on_load_columns do |command, columns|
|
52
|
+
parsed_columns = columns
|
53
|
+
end
|
54
|
+
@command_parser.on_load_value do |command, value|
|
55
|
+
parsed_values << value
|
56
|
+
end
|
57
|
+
@command_parser.on_load_complete do |command|
|
58
|
+
command[:columns] = parsed_columns.join(",")
|
59
|
+
command[:values] = parsed_values.to_json
|
60
|
+
split_load_command_to_add_commands(command, &block)
|
61
|
+
end
|
62
|
+
|
63
|
+
input.each_line do |line|
|
64
|
+
@command_parser << line
|
65
|
+
end
|
66
|
+
@command_parser.finish
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
def create_envelope(type, body)
|
71
|
+
id = @options[:id]
|
72
|
+
if id.nil?
|
73
|
+
id = new_unique_id
|
74
|
+
else
|
75
|
+
id = "#{id}:#{@count}"
|
76
|
+
@count += 1
|
77
|
+
end
|
78
|
+
|
79
|
+
{
|
80
|
+
:id => id,
|
81
|
+
:date => format_date(@options[:date] || Time.now),
|
82
|
+
:replyTo => @options[:reply_to],
|
83
|
+
:statusCode => @options[:status_code] || STATUS_OK,
|
84
|
+
:dataset => @options[:dataset],
|
85
|
+
:type => type,
|
86
|
+
:body => body,
|
87
|
+
}
|
88
|
+
end
|
89
|
+
|
90
|
+
def new_unique_id
|
91
|
+
now = Time.now
|
92
|
+
now_msec = now.to_i * 1000 + now.usec
|
93
|
+
random_string = rand(36 ** 16).to_s(36) # Base36
|
94
|
+
Digest::SHA1.hexdigest("#{now_msec}:#{random_string}")
|
95
|
+
end
|
96
|
+
|
97
|
+
def format_date(time)
|
98
|
+
time.iso8601
|
99
|
+
end
|
100
|
+
|
101
|
+
def create_table_create_command(command)
|
102
|
+
create_envelope("table_create", command.arguments)
|
103
|
+
end
|
104
|
+
|
105
|
+
def create_column_create_command(command)
|
106
|
+
create_envelope("column_create", command.arguments)
|
107
|
+
end
|
108
|
+
|
109
|
+
def split_load_command_to_add_commands(command, &block)
|
110
|
+
columns = command[:columns].split(",")
|
111
|
+
values = command[:values]
|
112
|
+
values = JSON.parse(values)
|
113
|
+
values.each do |record|
|
114
|
+
body = {
|
115
|
+
:table => command[:table],
|
116
|
+
}
|
117
|
+
|
118
|
+
record_values = {}
|
119
|
+
record.each_with_index do |value, column_index|
|
120
|
+
column = columns[column_index]
|
121
|
+
if column == "_key"
|
122
|
+
body[:key] = value
|
123
|
+
else
|
124
|
+
record_values[column.to_sym] = value
|
125
|
+
end
|
126
|
+
end
|
127
|
+
body[:values] = record_values unless record_values.empty?
|
128
|
+
|
129
|
+
yield create_envelope("add", body)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def create_select_command(command)
|
134
|
+
create_envelope("select", command.arguments)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
{
|
2
|
+
"effective_date": "2013-09-01T00:00:00Z",
|
3
|
+
"zones": ["localhost:23003/droonga"],
|
4
|
+
"farms": {
|
5
|
+
"localhost:23003/droonga": {
|
6
|
+
"device": ".",
|
7
|
+
"capacity": 10
|
8
|
+
}
|
9
|
+
},
|
10
|
+
"datasets": {
|
11
|
+
"Droonga": {
|
12
|
+
"workers": 2,
|
13
|
+
"plugins": ["search", "groonga", "add"],
|
14
|
+
"number_of_replicas": 2,
|
15
|
+
"number_of_partitions": 2,
|
16
|
+
"partition_key": "_key",
|
17
|
+
"date_range": "infinity",
|
18
|
+
"ring": {
|
19
|
+
"localhost:23041": {
|
20
|
+
"weight": 50,
|
21
|
+
"partitions": {
|
22
|
+
"2013-09-01": [
|
23
|
+
"localhost:23003/droonga.000",
|
24
|
+
"localhost:23003/droonga.001"
|
25
|
+
]
|
26
|
+
}
|
27
|
+
},
|
28
|
+
"localhost:23042": {
|
29
|
+
"weight": 50,
|
30
|
+
"partitions": {
|
31
|
+
"2013-09-01": [
|
32
|
+
"localhost:23003/droonga.002",
|
33
|
+
"localhost:23003/droonga.003"
|
34
|
+
]
|
35
|
+
}
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}
|
39
|
+
},
|
40
|
+
"options": {
|
41
|
+
"plugins": ["select"]
|
42
|
+
}
|
43
|
+
}
|
data/sample/fluentd.conf
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
{
|
2
|
+
"effective_date": "2013-09-01T00:00:00Z",
|
3
|
+
"zones": ["localhost:23003/test"],
|
4
|
+
"farms": {
|
5
|
+
"localhost:23003/test": {
|
6
|
+
"device": ".",
|
7
|
+
"capacity": 10
|
8
|
+
}
|
9
|
+
},
|
10
|
+
"datasets": {
|
11
|
+
"Test": {
|
12
|
+
"workers": 0,
|
13
|
+
"plugins": ["for_dataset"],
|
14
|
+
"number_of_replicas": 2,
|
15
|
+
"number_of_partitions": 2,
|
16
|
+
"partition_key": "_key",
|
17
|
+
"date_range": "infinity",
|
18
|
+
"ring": {
|
19
|
+
"localhost:23041": {
|
20
|
+
"weight": 50,
|
21
|
+
"partitions": {
|
22
|
+
"2013-09-01": [
|
23
|
+
"localhost:23003/test.000",
|
24
|
+
"localhost:23003/test.001"
|
25
|
+
]
|
26
|
+
}
|
27
|
+
},
|
28
|
+
"localhost:23042": {
|
29
|
+
"weight": 50,
|
30
|
+
"partitions": {
|
31
|
+
"2013-09-01": [
|
32
|
+
"localhost:23003/test.002",
|
33
|
+
"localhost:23003/test.003"
|
34
|
+
]
|
35
|
+
}
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}
|
39
|
+
},
|
40
|
+
"options": {
|
41
|
+
"plugins": ["for_global"]
|
42
|
+
}
|
43
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
table_create Bigram TABLE_PAT_KEY ShortText \
|
2
|
+
--default_tokenizer TokenBigram \
|
3
|
+
--normalizer NormalizerAuto
|
4
|
+
|
5
|
+
|
6
|
+
table_create Sections TABLE_HASH_KEY ShortText
|
7
|
+
column_create Sections title COLUMN_SCALAR ShortText
|
8
|
+
column_create Sections content COLUMN_SCALAR Text
|
9
|
+
column_create Bigram Sections_title COLUMN_INDEX|WITH_POSITION Sections title
|
10
|
+
column_create Bigram Sections_content COLUMN_INDEX|WITH_POSITION Sections content
|
11
|
+
|
12
|
+
load --table Sections
|
13
|
+
[
|
14
|
+
{"_key": "1.1", "title": "Groonga overview", "content": "Groonga is a fast and accurate full text search engine based on inverted index. One of the characteristics of groonga is that a newly registered document instantly appears in search results. Also, groonga allows updates without read locks. These characteristics result in superior performance on real-time applications."},
|
15
|
+
{"_key": "1.2", "title": "Full text search and Instant update", "content": "In widely used DBMSs, updates are immediately processed, for example, a newly registered record appears in the result of the next query. In contrast, some full text search engines do not support instant updates, because it is difficult to dynamically update inverted indexes, the underlying data structure."},
|
16
|
+
{"_key": "1.3", "title": "Column store and aggregate query", "content": "People can collect more than enough data in the Internet era. However, it is difficult to extract informative knowledge from a large database, and such a task requires a many-sided analysis through trial and error. For example, search refinement by date, time and location may reveal hidden patterns. Aggregate queries are useful to perform this kind of tasks."},
|
17
|
+
{"_key": "1.4", "title": "Inverted index and tokenizer", "content": "An inverted index is a traditional data structure used for large-scale full text search. A search engine based on inverted index extracts index terms from a document when it is added. Then in retrieval, a query is divided into index terms to find documents containing those index terms. In this way, index terms play an important role in full text search and thus the way of extracting index terms is a key to a better search engine."},
|
18
|
+
{"_key": "1.5", "title": "Sharable storage and read lock-free", "content": "Multi-core processors are mainstream today and the number of cores per processor is increasing. In order to exploit multiple cores, executing multiple queries in parallel or dividing a query into sub-queries for parallel processing is becoming more important."},
|
19
|
+
{"_key": "1.6", "title": "Geo-location (latitude and longitude) search", "content": "Location services are getting more convenient because of mobile devices with GPS. For example, if you are going to have lunch or dinner at a nearby restaurant, a local search service for restaurants may be very useful, and for such services, fast geo-location search is becoming more important."},
|
20
|
+
{"_key": "1.7", "title": "Groonga library", "content": "The basic functions of groonga are provided in a C library and any application can use groonga as a full text search engine or a column-oriented database. Also, libraries for languages other than C/C++, such as Ruby, are provided in related projects. See related projects for details."},
|
21
|
+
{"_key": "1.8", "title": "Groonga server", "content": "Groonga provides a built-in server command which supports HTTP, the memcached binary protocol and the groonga query transfer protocol (gqtp). Also, a groonga server supports query caching, which significantly reduces response time for repeated read queries. Using this command, groonga is available even on a server that does not allow you to install new libraries."},
|
22
|
+
{"_key": "1.9", "title": "Groonga storage engine", "content": "Groonga works not only as an independent column-oriented DBMS but also as storage engines of well-known DBMSs. For example, mroonga is a MySQL pluggable storage engine using groonga. By using mroonga, you can use groonga for column-oriented storage and full text search. A combination of a built-in storage engine, MyISAM or InnoDB, and a groonga-based full text search engine is also available. All the combinations have good and bad points and the best one depends on the application. See related projects for details."}
|
23
|
+
]
|
data/test/helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
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_relative "helper/sandbox"
|
17
|
+
require_relative "helper/fixture"
|
18
|
+
require_relative "helper/stub_worker"
|
19
|
+
require_relative "helper/watch_helper"
|
20
|
+
|
21
|
+
class Test::Unit::TestCase
|
22
|
+
include Sandbox
|
23
|
+
include Fixture
|
24
|
+
end
|
@@ -0,0 +1,28 @@
|
|
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
|
+
module Fixture
|
17
|
+
def fixture_directory
|
18
|
+
File.join(File.dirname(__FILE__), "..", "fixtures")
|
19
|
+
end
|
20
|
+
|
21
|
+
def fixture_path(*path_components)
|
22
|
+
File.join(fixture_directory, *path_components)
|
23
|
+
end
|
24
|
+
|
25
|
+
def fixture_data(*path_components)
|
26
|
+
File.read(fixture_path(*path_components))
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,73 @@
|
|
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
|
+
module Sandbox
|
17
|
+
class << self
|
18
|
+
def included(base)
|
19
|
+
base.setup :setup_sandbox, :before => :prepend
|
20
|
+
base.teardown :teardown_sandbox, :after => :append
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def setup_sandbox
|
25
|
+
setup_temporary_directory
|
26
|
+
|
27
|
+
setup_context
|
28
|
+
|
29
|
+
@database_path = @temporary_directory + "database"
|
30
|
+
@database = nil
|
31
|
+
end
|
32
|
+
|
33
|
+
def setup_temporary_directory
|
34
|
+
@base_temporary_directory = Pathname(File.dirname(__FILE__)) + "tmp"
|
35
|
+
memory_file_system = "/run/shm"
|
36
|
+
if File.exist?(memory_file_system)
|
37
|
+
FileUtils.mkdir_p(@base_temporary_directory.parent.to_s)
|
38
|
+
FileUtils.rm_f(@base_temporary_directory.to_s)
|
39
|
+
FileUtils.ln_s(memory_file_system, @base_temporary_directory.to_s)
|
40
|
+
else
|
41
|
+
FileUtils.mkdir_p(@base_temporary_directory.to_s)
|
42
|
+
end
|
43
|
+
|
44
|
+
@temporary_directory = @base_temporary_directory + "fluent-plugin-droonga"
|
45
|
+
FileUtils.rm_rf(@temporary_directory.to_s)
|
46
|
+
FileUtils.mkdir_p(@temporary_directory.to_s)
|
47
|
+
end
|
48
|
+
|
49
|
+
def setup_context
|
50
|
+
Groonga::Context.default = nil
|
51
|
+
Groonga::Context.default_options = nil
|
52
|
+
end
|
53
|
+
|
54
|
+
def restore(dumped_command)
|
55
|
+
context = Groonga::Context.new
|
56
|
+
database = context.create_database(@database_path.to_s)
|
57
|
+
context.restore(dumped_command)
|
58
|
+
database.close
|
59
|
+
context.close
|
60
|
+
end
|
61
|
+
|
62
|
+
def teardown_sandbox
|
63
|
+
Groonga::Context.default.close
|
64
|
+
Groonga::Context.default = nil
|
65
|
+
GC.start
|
66
|
+
teardown_temporary_directory
|
67
|
+
end
|
68
|
+
|
69
|
+
def teardown_temporary_directory
|
70
|
+
FileUtils.rm_rf(@temporary_directory.to_s)
|
71
|
+
FileUtils.rm_rf(@base_temporary_directory.to_s)
|
72
|
+
end
|
73
|
+
end
|