rroonga 2.0.4 → 2.0.5
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.
- data/Rakefile +21 -2
- data/bin/grndump +3 -2
- data/ext/groonga/extconf.rb +1 -6
- data/ext/groonga/rb-grn-array.c +58 -31
- data/ext/groonga/rb-grn-column.c +220 -148
- data/ext/groonga/rb-grn-context.c +46 -32
- data/ext/groonga/rb-grn-database.c +102 -90
- data/ext/groonga/rb-grn-double-array-trie.c +205 -163
- data/ext/groonga/rb-grn-encoding-support.c +2 -3
- data/ext/groonga/rb-grn-encoding.c +13 -8
- data/ext/groonga/rb-grn-exception.c +1 -1
- data/ext/groonga/rb-grn-expression.c +110 -133
- data/ext/groonga/rb-grn-fix-size-column.c +5 -4
- data/ext/groonga/rb-grn-geo-point.c +55 -0
- data/ext/groonga/rb-grn-hash.c +120 -82
- data/ext/groonga/rb-grn-index-column.c +66 -70
- data/ext/groonga/rb-grn-index-cursor.c +3 -0
- data/ext/groonga/rb-grn-logger.c +33 -51
- data/ext/groonga/rb-grn-object.c +2 -0
- data/ext/groonga/rb-grn-operator.c +1 -1
- data/ext/groonga/rb-grn-patricia-trie.c +287 -232
- data/ext/groonga/rb-grn-plugin.c +11 -14
- data/ext/groonga/rb-grn-snippet.c +37 -54
- data/ext/groonga/rb-grn-table-cursor-key-support.c +3 -3
- data/ext/groonga/rb-grn-table-cursor.c +8 -6
- data/ext/groonga/rb-grn-table-key-support.c +22 -29
- data/ext/groonga/rb-grn-table.c +355 -279
- data/ext/groonga/rb-grn-type.c +18 -25
- data/ext/groonga/rb-grn-utils.c +77 -7
- data/ext/groonga/rb-grn-variable-size-column.c +12 -20
- data/ext/groonga/rb-grn-view.c +56 -51
- data/ext/groonga/rb-grn.h +28 -1
- data/ext/groonga/rb-groonga.c +1 -0
- data/lib/groonga.rb +2 -0
- data/lib/groonga/command.rb +3 -1
- data/lib/groonga/database.rb +27 -0
- data/lib/groonga/dumper.rb +96 -17
- data/lib/groonga/geo-point.rb +216 -0
- data/lib/groonga/schema.rb +29 -46
- data/rroonga-build.rb +1 -1
- data/rroonga.gemspec +90 -0
- data/test/groonga-test-utils.rb +168 -0
- data/test/run-test.rb +60 -0
- data/test/test-accessor.rb +36 -0
- data/test/test-array.rb +146 -0
- data/test/test-column.rb +350 -0
- data/test/test-command-select.rb +181 -0
- data/test/test-context.rb +130 -0
- data/test/test-database-dumper.rb +259 -0
- data/test/test-database.rb +173 -0
- data/test/test-double-array-trie.rb +189 -0
- data/test/test-encoding.rb +33 -0
- data/test/test-exception.rb +230 -0
- data/test/test-expression-builder.rb +602 -0
- data/test/test-expression.rb +134 -0
- data/test/test-fix-size-column.rb +77 -0
- data/test/test-geo-point.rb +190 -0
- data/test/test-gqtp.rb +70 -0
- data/test/test-hash.rb +367 -0
- data/test/test-index-column.rb +180 -0
- data/test/test-index-cursor.rb +123 -0
- data/test/test-logger.rb +37 -0
- data/test/test-pagination.rb +249 -0
- data/test/test-patricia-trie.rb +440 -0
- data/test/test-plugin.rb +35 -0
- data/test/test-procedure.rb +37 -0
- data/test/test-query-log.rb +258 -0
- data/test/test-record.rb +577 -0
- data/test/test-remote.rb +63 -0
- data/test/test-schema-create-table.rb +267 -0
- data/test/test-schema-dumper.rb +235 -0
- data/test/test-schema-type.rb +208 -0
- data/test/test-schema-view.rb +90 -0
- data/test/test-schema.rb +886 -0
- data/test/test-snippet.rb +130 -0
- data/test/test-table-dumper.rb +353 -0
- data/test/test-table-offset-and-limit.rb +100 -0
- data/test/test-table-select-mecab.rb +80 -0
- data/test/test-table-select-normalize.rb +57 -0
- data/test/test-table-select-weight.rb +123 -0
- data/test/test-table-select.rb +191 -0
- data/test/test-table-traverse.rb +304 -0
- data/test/test-table.rb +711 -0
- data/test/test-type.rb +79 -0
- data/test/test-variable-size-column.rb +147 -0
- data/test/test-variable.rb +28 -0
- data/test/test-vector-column.rb +76 -0
- data/test/test-version.rb +61 -0
- data/test/test-view.rb +72 -0
- metadata +330 -202
@@ -0,0 +1,173 @@
|
|
1
|
+
# Copyright (C) 2009-2011 Kouhei Sutou <kou@clear-code.com>
|
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 DatabaseTest < Test::Unit::TestCase
|
17
|
+
include GroongaTestUtils
|
18
|
+
|
19
|
+
def test_create
|
20
|
+
assert_nil(Groonga::Context.default.database)
|
21
|
+
|
22
|
+
db_path = @tmp_dir + "db"
|
23
|
+
assert_not_predicate(db_path, :exist?)
|
24
|
+
database = Groonga::Database.create(:path => db_path.to_s)
|
25
|
+
assert_predicate(db_path, :exist?)
|
26
|
+
assert_not_predicate(database, :closed?)
|
27
|
+
|
28
|
+
assert_equal(database, Groonga::Context.default.database)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_temporary
|
32
|
+
before_files = @tmp_dir.children
|
33
|
+
database = Groonga::Database.create
|
34
|
+
assert_nil(database.name)
|
35
|
+
assert_equal(before_files, @tmp_dir.children)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_open
|
39
|
+
db_path = @tmp_dir + "db"
|
40
|
+
database = Groonga::Database.create(:path => db_path.to_s)
|
41
|
+
database.close
|
42
|
+
|
43
|
+
assert_predicate(database, :closed?)
|
44
|
+
called = false
|
45
|
+
Groonga::Database.open(db_path.to_s) do |_database|
|
46
|
+
database = _database
|
47
|
+
assert_not_predicate(database, :closed?)
|
48
|
+
called = true
|
49
|
+
end
|
50
|
+
assert_true(called)
|
51
|
+
assert_predicate(database, :closed?)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_close
|
55
|
+
db_path = @tmp_dir + "db"
|
56
|
+
database = Groonga::Database.create(:path => db_path.to_s)
|
57
|
+
database.close
|
58
|
+
|
59
|
+
database = Groonga::Database.open(db_path.to_s)
|
60
|
+
assert_not_predicate(database, :closed?)
|
61
|
+
database.close
|
62
|
+
assert_predicate(database, :closed?)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_new
|
66
|
+
db_path = @tmp_dir + "db"
|
67
|
+
assert_raise(Groonga::NoSuchFileOrDirectory) do
|
68
|
+
Groonga::Database.new(db_path.to_s)
|
69
|
+
end
|
70
|
+
|
71
|
+
Groonga::Database.create(:path => db_path.to_s)
|
72
|
+
assert_not_predicate(Groonga::Database.new(db_path.to_s), :closed?)
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_each
|
76
|
+
db_path = @tmp_dir + "db"
|
77
|
+
database = Groonga::Database.create(:path => db_path.to_s)
|
78
|
+
default_object_names = database.collect {|object| object.name}.sort
|
79
|
+
assert_send([default_object_names, :include?, "Bool"])
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_each_without_block
|
83
|
+
setup_database
|
84
|
+
default_object_names = @database.each.collect {|object| object.name}.sort
|
85
|
+
assert_send([default_object_names, :include?, "Bool"])
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_encoding
|
89
|
+
assert_equal(Groonga::Encoding.default,
|
90
|
+
Groonga::Database.create.encoding)
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_lock
|
94
|
+
database = Groonga::Database.create
|
95
|
+
|
96
|
+
assert_not_predicate(database, :locked?)
|
97
|
+
database.lock
|
98
|
+
assert_predicate(database, :locked?)
|
99
|
+
database.unlock
|
100
|
+
assert_not_predicate(database, :locked?)
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_lock_failed
|
104
|
+
database = Groonga::Database.create
|
105
|
+
|
106
|
+
database.lock
|
107
|
+
assert_raise(Groonga::ResourceDeadlockAvoided) do
|
108
|
+
database.lock
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_lock_block
|
113
|
+
database = Groonga::Database.create
|
114
|
+
|
115
|
+
assert_not_predicate(database, :locked?)
|
116
|
+
database.lock do
|
117
|
+
assert_predicate(database, :locked?)
|
118
|
+
end
|
119
|
+
assert_not_predicate(database, :locked?)
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_clear_lock
|
123
|
+
database = Groonga::Database.create
|
124
|
+
|
125
|
+
assert_not_predicate(database, :locked?)
|
126
|
+
database.lock
|
127
|
+
assert_predicate(database, :locked?)
|
128
|
+
database.clear_lock
|
129
|
+
assert_not_predicate(database, :locked?)
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_touch
|
133
|
+
database = Groonga::Database.create
|
134
|
+
assert_nothing_raised do
|
135
|
+
database.touch
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_defrag
|
140
|
+
setup_database
|
141
|
+
Groonga::Schema.define do |schema|
|
142
|
+
schema.create_table("Users") do |table|
|
143
|
+
table.short_text("name")
|
144
|
+
table.short_text("address")
|
145
|
+
end
|
146
|
+
end
|
147
|
+
users = context["Users"]
|
148
|
+
1000.times do |i|
|
149
|
+
users.add(:name => "user #{i}" * 1000,
|
150
|
+
:address => "address #{i}" * 1000)
|
151
|
+
end
|
152
|
+
assert_equal(7, @database.defrag)
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_tables
|
156
|
+
setup_database
|
157
|
+
Groonga::Schema.define do |schema|
|
158
|
+
schema.create_table("HashTable") do |table|
|
159
|
+
end
|
160
|
+
|
161
|
+
schema.create_table("PatriciaTrie",
|
162
|
+
:type => :patricia_trie) do |table|
|
163
|
+
end
|
164
|
+
|
165
|
+
schema.create_table("DoubleArrayTrie",
|
166
|
+
:type => :double_array_trie) do |table|
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
assert_equal(["HashTable", "PatriciaTrie", "DoubleArrayTrie"].sort,
|
171
|
+
@database.tables.collect(&:name).sort)
|
172
|
+
end
|
173
|
+
end
|
@@ -0,0 +1,189 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2011-2012 Kouhei Sutou <kou@clear-code.com>
|
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
|
+
class DoubleArrayTrieTest < Test::Unit::TestCase
|
19
|
+
include GroongaTestUtils
|
20
|
+
include ERB::Util
|
21
|
+
|
22
|
+
setup :setup_database
|
23
|
+
|
24
|
+
def test_support_key?
|
25
|
+
assert_predicate(Groonga::DoubleArrayTrie.create(:name => "Users",
|
26
|
+
:key_type => "ShortText"),
|
27
|
+
:support_key?)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_encoding
|
31
|
+
assert_equal(Groonga::Encoding.default,
|
32
|
+
Groonga::DoubleArrayTrie.create.encoding)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_tokenizer
|
36
|
+
trie = Groonga::DoubleArrayTrie.create
|
37
|
+
assert_nil(trie.default_tokenizer)
|
38
|
+
trie.default_tokenizer = "TokenTrigram"
|
39
|
+
assert_equal(Groonga::Context.default["TokenTrigram"],
|
40
|
+
trie.default_tokenizer)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_search
|
44
|
+
users = Groonga::Array.create(:name => "Users")
|
45
|
+
users.define_column("name", "ShortText")
|
46
|
+
|
47
|
+
bookmarks = Groonga::DoubleArrayTrie.create(:name => "Bookmarks",
|
48
|
+
:key_type => "ShortText")
|
49
|
+
bookmarks.define_column("user_id", users)
|
50
|
+
|
51
|
+
daijiro = users.add
|
52
|
+
daijiro["name"] = "daijiro"
|
53
|
+
gunyarakun = users.add
|
54
|
+
gunyarakun["name"] = "gunyarakun"
|
55
|
+
|
56
|
+
groonga = bookmarks.add("http://groonga.org/")
|
57
|
+
groonga["user_id"] = daijiro
|
58
|
+
|
59
|
+
records = bookmarks.search("http://groonga.org/")
|
60
|
+
assert_equal(["daijiro"],
|
61
|
+
records.records.collect {|record| record[".user_id.name"]})
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_add
|
65
|
+
users = Groonga::DoubleArrayTrie.create(:name => "Users")
|
66
|
+
users.define_column("address", "Text")
|
67
|
+
me = users.add("me", :address => "me@example.com")
|
68
|
+
assert_equal("me@example.com", me[:address])
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_default_tokenizer_on_create
|
72
|
+
terms = Groonga::DoubleArrayTrie.create(:name => "Terms",
|
73
|
+
:default_tokenizer => "TokenUnigram")
|
74
|
+
assert_equal(context[Groonga::Type::UNIGRAM],
|
75
|
+
terms.default_tokenizer)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_duplicated_name
|
79
|
+
Groonga::DoubleArrayTrie.create(:name => "Users")
|
80
|
+
assert_raise(Groonga::InvalidArgument) do
|
81
|
+
Groonga::DoubleArrayTrie.create(:name => "Users")
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_has_key?
|
86
|
+
users = Groonga::DoubleArrayTrie.create(:name => "Users")
|
87
|
+
assert_false(users.has_key?("morita"))
|
88
|
+
users.add("morita")
|
89
|
+
assert_true(users.has_key?("morita"))
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_prefix_cursor
|
93
|
+
paths = Groonga::DoubleArrayTrie.create(:name => "Paths",
|
94
|
+
:key_type => 'ShortText')
|
95
|
+
paths.add('/')
|
96
|
+
paths.add('/tmp')
|
97
|
+
paths.add('/usr/bin')
|
98
|
+
paths.add('/usr/local/bin')
|
99
|
+
|
100
|
+
assert_prefix_cursor(["/usr/local/bin", "/usr/bin", "/tmp", "/"],
|
101
|
+
paths, "/", {:order => :desc})
|
102
|
+
assert_prefix_cursor(["/", "/tmp", "/usr/bin", "/usr/local/bin"],
|
103
|
+
paths, "/")
|
104
|
+
assert_prefix_cursor(["/usr/local/bin", "/usr/bin"],
|
105
|
+
paths, "/usr/local",
|
106
|
+
{:key_bytes => "/usr".size, :order => :desc})
|
107
|
+
assert_prefix_cursor(["/tmp", "/usr/bin"],
|
108
|
+
paths, "/",
|
109
|
+
{:offset => 1, :limit => 2})
|
110
|
+
end
|
111
|
+
|
112
|
+
def assert_prefix_cursor(expected, tables, prefix, options={})
|
113
|
+
actual = []
|
114
|
+
tables.open_prefix_cursor(prefix, options) do |cursor|
|
115
|
+
cursor.each do |record|
|
116
|
+
actual << record.key
|
117
|
+
end
|
118
|
+
end
|
119
|
+
assert_equal(expected, actual)
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_add_uint_key
|
123
|
+
numbers = Groonga::DoubleArrayTrie.create(:name => "Numbers",
|
124
|
+
:key_type => "UInt32")
|
125
|
+
numbers.add(1)
|
126
|
+
numbers.add(2)
|
127
|
+
numbers.add(5)
|
128
|
+
numbers.add(7)
|
129
|
+
assert_equal([1, 2, 5, 7], numbers.collect {|number| number.key})
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_added?
|
133
|
+
users = Groonga::DoubleArrayTrie.create(:name => "Users",
|
134
|
+
:key_type => "ShortText")
|
135
|
+
bob = users.add("bob")
|
136
|
+
assert_predicate(bob, :added?)
|
137
|
+
bob_again = users.add("bob")
|
138
|
+
assert_not_predicate(bob_again, :added?)
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_defrag
|
142
|
+
users = Groonga::DoubleArrayTrie.create(:name => "Users",
|
143
|
+
:key_type => "ShortText")
|
144
|
+
users.define_column("name", "ShortText")
|
145
|
+
users.define_column("address", "ShortText")
|
146
|
+
1000.times do |i|
|
147
|
+
users.add("user #{i}",
|
148
|
+
:name => "user #{i}" * 1000,
|
149
|
+
:address => "address #{i}" * 1000)
|
150
|
+
end
|
151
|
+
assert_equal(7, users.defrag)
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_rename
|
155
|
+
users = Groonga::DoubleArrayTrie.create(:name => "Users",
|
156
|
+
:key_type => "ShortText")
|
157
|
+
name = users.define_column("name", "ShortText")
|
158
|
+
address = users.define_column("address", "ShortText")
|
159
|
+
|
160
|
+
users.rename("People")
|
161
|
+
assert_equal(["People", "People.name", "People.address"],
|
162
|
+
[users.name, name.name, address.name])
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_each
|
166
|
+
users = Groonga::DoubleArrayTrie.create(:name => "Users",
|
167
|
+
:key_type => "ShortText")
|
168
|
+
users.add("Alice")
|
169
|
+
users.add("Bob")
|
170
|
+
users.add("Carl")
|
171
|
+
|
172
|
+
user_names = []
|
173
|
+
users.each do |user|
|
174
|
+
user_names << user.key
|
175
|
+
end
|
176
|
+
assert_equal(["Alice", "Bob", "Carl"], user_names)
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_each_without_block
|
180
|
+
users = Groonga::DoubleArrayTrie.create(:name => "Users",
|
181
|
+
:key_type => "ShortText")
|
182
|
+
users.add("Alice")
|
183
|
+
users.add("Bob")
|
184
|
+
users.add("Carl")
|
185
|
+
|
186
|
+
user_names = users.each.collect(&:key)
|
187
|
+
assert_equal(["Alice", "Bob", "Carl"], user_names)
|
188
|
+
end
|
189
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
|
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 EncodingTest < Test::Unit::TestCase
|
17
|
+
include GroongaTestUtils
|
18
|
+
|
19
|
+
def test_constants
|
20
|
+
assert_equal(:default, Groonga::Encoding::DEFAULT)
|
21
|
+
assert_equal(:none, Groonga::Encoding::NONE)
|
22
|
+
assert_equal(:euc_jp, Groonga::Encoding::EUC_JP)
|
23
|
+
assert_equal(:sjis, Groonga::Encoding::SJIS)
|
24
|
+
assert_equal(:utf8, Groonga::Encoding::UTF8)
|
25
|
+
assert_equal(:latin1, Groonga::Encoding::LATIN1)
|
26
|
+
assert_equal(:koi8r, Groonga::Encoding::KOI8R)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_default
|
30
|
+
Groonga::Encoding.default = :utf8
|
31
|
+
assert_equal(:utf8, Groonga::Encoding.default)
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,230 @@
|
|
1
|
+
# Copyright (C) 2009-2010 Kouhei Sutou <kou@clear-code.com>
|
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 ExceptionTest < Test::Unit::TestCase
|
17
|
+
include GroongaTestUtils
|
18
|
+
|
19
|
+
def test_defined
|
20
|
+
assert_not_const_defined(Groonga, :Success)
|
21
|
+
|
22
|
+
assert_const_defined(Groonga, :Error)
|
23
|
+
assert_const_defined(Groonga, :ObjectClosed)
|
24
|
+
|
25
|
+
assert_const_defined(Groonga, :EndOfData)
|
26
|
+
assert_const_defined(Groonga, :UnknownError)
|
27
|
+
assert_const_defined(Groonga, :OperationNotPermitted)
|
28
|
+
assert_const_defined(Groonga, :NoSuchFileOrDirectory)
|
29
|
+
assert_const_defined(Groonga, :NoSuchProcess)
|
30
|
+
assert_const_defined(Groonga, :InterruptedFunctionCall)
|
31
|
+
assert_const_defined(Groonga, :InputOutputError)
|
32
|
+
assert_const_defined(Groonga, :NoSuchDeviceOrAddress)
|
33
|
+
assert_const_defined(Groonga, :ArgumentListTooLong)
|
34
|
+
assert_const_defined(Groonga, :ExecFormatError)
|
35
|
+
assert_const_defined(Groonga, :BadFileDescriptor)
|
36
|
+
assert_const_defined(Groonga, :NoChildProcesses)
|
37
|
+
assert_const_defined(Groonga, :ResourceTemporarilyUnavailable)
|
38
|
+
assert_const_defined(Groonga, :NotEnoughSpace)
|
39
|
+
assert_const_defined(Groonga, :PermissionDenied)
|
40
|
+
assert_const_defined(Groonga, :BadAddress)
|
41
|
+
assert_const_defined(Groonga, :ResourceBusy)
|
42
|
+
assert_const_defined(Groonga, :FileExists)
|
43
|
+
assert_const_defined(Groonga, :ImproperLink)
|
44
|
+
assert_const_defined(Groonga, :NoSuchDevice)
|
45
|
+
assert_const_defined(Groonga, :NotADirectory)
|
46
|
+
assert_const_defined(Groonga, :IsADirectory)
|
47
|
+
assert_const_defined(Groonga, :InvalidArgument)
|
48
|
+
assert_const_defined(Groonga, :TooManyOpenFilesInSystem)
|
49
|
+
assert_const_defined(Groonga, :TooManyOpenFiles)
|
50
|
+
assert_const_defined(Groonga, :InappropriateIOControlOperation)
|
51
|
+
assert_const_defined(Groonga, :FileTooLarge)
|
52
|
+
assert_const_defined(Groonga, :NoSpaceLeftOnDevice)
|
53
|
+
assert_const_defined(Groonga, :InvalidSeek)
|
54
|
+
assert_const_defined(Groonga, :ReadOnlyFileSystem)
|
55
|
+
assert_const_defined(Groonga, :TooManyLinks)
|
56
|
+
assert_const_defined(Groonga, :BrokenPipe)
|
57
|
+
assert_const_defined(Groonga, :DomainError)
|
58
|
+
assert_const_defined(Groonga, :ResultTooLarge)
|
59
|
+
assert_const_defined(Groonga, :ResourceDeadlockAvoided)
|
60
|
+
assert_const_defined(Groonga, :NoMemoryAvailable)
|
61
|
+
assert_const_defined(Groonga, :FilenameTooLong)
|
62
|
+
assert_const_defined(Groonga, :NoLocksAvailable)
|
63
|
+
assert_const_defined(Groonga, :FunctionNotImplemented)
|
64
|
+
assert_const_defined(Groonga, :DirectoryNotEmpty)
|
65
|
+
assert_const_defined(Groonga, :IllegalByteSequence)
|
66
|
+
assert_const_defined(Groonga, :SocketNotInitialized)
|
67
|
+
assert_const_defined(Groonga, :OperationWouldBlock)
|
68
|
+
assert_const_defined(Groonga, :AddressIsNotAvailable)
|
69
|
+
assert_const_defined(Groonga, :NetworkIsDown)
|
70
|
+
assert_const_defined(Groonga, :NoBuffer)
|
71
|
+
assert_const_defined(Groonga, :SocketIsAlreadyConnected)
|
72
|
+
assert_const_defined(Groonga, :SocketIsNotConnected)
|
73
|
+
assert_const_defined(Groonga, :SocketIsAlreadyShutdowned)
|
74
|
+
assert_const_defined(Groonga, :OperationTimeout)
|
75
|
+
assert_const_defined(Groonga, :ConnectionRefused)
|
76
|
+
assert_const_defined(Groonga, :RangeError)
|
77
|
+
assert_const_defined(Groonga, :TokenizerError)
|
78
|
+
assert_const_defined(Groonga, :FileCorrupt)
|
79
|
+
assert_const_defined(Groonga, :InvalidFormat)
|
80
|
+
assert_const_defined(Groonga, :ObjectCorrupt)
|
81
|
+
assert_const_defined(Groonga, :TooManySymbolicLinks)
|
82
|
+
assert_const_defined(Groonga, :NotSocket)
|
83
|
+
assert_const_defined(Groonga, :OperationNotSupported)
|
84
|
+
assert_const_defined(Groonga, :AddressIsInUse)
|
85
|
+
assert_const_defined(Groonga, :ZLibError)
|
86
|
+
assert_const_defined(Groonga, :LZOError)
|
87
|
+
assert_const_defined(Groonga, :StackOverFlow)
|
88
|
+
assert_const_defined(Groonga, :SyntaxError)
|
89
|
+
assert_const_defined(Groonga, :RetryMax)
|
90
|
+
assert_const_defined(Groonga, :IncompatibleFileFormat)
|
91
|
+
assert_const_defined(Groonga, :UpdateNotAllowed)
|
92
|
+
assert_const_defined(Groonga, :TooSmallOffset)
|
93
|
+
assert_const_defined(Groonga, :TooLargeOffset)
|
94
|
+
assert_const_defined(Groonga, :TooSmallLimit)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
class TooManyOpenFilesTest < Test::Unit::TestCase
|
99
|
+
include GroongaTestUtils
|
100
|
+
|
101
|
+
def setup
|
102
|
+
setup_database
|
103
|
+
@context = create_sub_context
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_database_each
|
107
|
+
setup_users
|
108
|
+
|
109
|
+
assert_error do
|
110
|
+
over_limit do
|
111
|
+
@context.database.each do
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_context_array_reference
|
118
|
+
setup_users
|
119
|
+
|
120
|
+
assert_error do
|
121
|
+
over_limit do
|
122
|
+
@context["Users"]
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_table_columns
|
128
|
+
setup_schema do |schema|
|
129
|
+
schema.create_table("Users") do |table|
|
130
|
+
table.short_text("name")
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
table = @context["Users"]
|
135
|
+
assert_error do
|
136
|
+
over_limit do
|
137
|
+
table.columns
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_column_sources
|
143
|
+
setup_schema do |schema|
|
144
|
+
schema.create_table("Users") do |table|
|
145
|
+
table.short_text("name")
|
146
|
+
end
|
147
|
+
schema.create_table("Bookmarks") do |table|
|
148
|
+
table.reference("user", "Users")
|
149
|
+
end
|
150
|
+
schema.create_table("Users") do |table|
|
151
|
+
table.index("Bookmarks.user")
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
column = @context["Users"].column("Bookmarks_user")
|
156
|
+
assert_error do
|
157
|
+
over_limit do
|
158
|
+
column.sources
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_string_key_type
|
164
|
+
setup_users
|
165
|
+
|
166
|
+
assert_error do
|
167
|
+
over_limit do
|
168
|
+
create_reference_table("Users")
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_id_key_type
|
174
|
+
setup_users
|
175
|
+
users_id = Groonga["Users"].id
|
176
|
+
|
177
|
+
assert_error do
|
178
|
+
over_limit do
|
179
|
+
create_reference_table(users_id)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
private
|
185
|
+
def setup_schema
|
186
|
+
Groonga::Schema.define do |schema|
|
187
|
+
yield(schema)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
def setup_users
|
192
|
+
setup_schema do |schema|
|
193
|
+
schema.create_table("Users")
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
def create_sub_context
|
198
|
+
context = Groonga::Context.new
|
199
|
+
context.open_database(Groonga::Context.default.database.path)
|
200
|
+
context
|
201
|
+
end
|
202
|
+
|
203
|
+
def over_limit
|
204
|
+
unavailable = 0
|
205
|
+
original, max = Process.getrlimit(open_files)
|
206
|
+
|
207
|
+
Process.setrlimit(open_files, unavailable, max)
|
208
|
+
begin
|
209
|
+
yield
|
210
|
+
ensure
|
211
|
+
Process.setrlimit(open_files, original, max)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
def open_files
|
216
|
+
Process::RLIMIT_NOFILE
|
217
|
+
end
|
218
|
+
|
219
|
+
def assert_error
|
220
|
+
assert_raise(Groonga::TooManyOpenFiles) do
|
221
|
+
yield
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
def create_reference_table(key)
|
226
|
+
Groonga::Hash.create(:context => @context,
|
227
|
+
:name => "Bookmarks",
|
228
|
+
:key_type => key)
|
229
|
+
end
|
230
|
+
end
|