rroonga 2.0.2 → 2.0.3

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.
Files changed (62) hide show
  1. data/AUTHORS +5 -0
  2. data/Gemfile +1 -12
  3. data/Rakefile +4 -57
  4. data/bin/grndump +11 -1
  5. data/ext/groonga/extconf.rb +125 -54
  6. data/ext/groonga/rb-grn-context.c +25 -7
  7. data/ext/groonga/rb-grn-database.c +25 -0
  8. data/ext/groonga/rb-grn-object.c +19 -7
  9. data/ext/groonga/rb-grn-table.c +8 -10
  10. data/ext/groonga/rb-grn.h +9 -2
  11. data/lib/groonga/dumper.rb +2 -2
  12. data/lib/groonga/expression-builder.rb +33 -18
  13. data/rroonga-build.rb +1 -1
  14. metadata +97 -180
  15. data/TODO +0 -0
  16. data/test/groonga-test-utils.rb +0 -139
  17. data/test/run-test.rb +0 -60
  18. data/test/test-accessor.rb +0 -36
  19. data/test/test-array.rb +0 -123
  20. data/test/test-column.rb +0 -350
  21. data/test/test-command-select.rb +0 -147
  22. data/test/test-context.rb +0 -130
  23. data/test/test-database-dumper.rb +0 -259
  24. data/test/test-database.rb +0 -148
  25. data/test/test-double-array-trie.rb +0 -164
  26. data/test/test-encoding.rb +0 -33
  27. data/test/test-exception.rb +0 -96
  28. data/test/test-expression-builder.rb +0 -269
  29. data/test/test-expression.rb +0 -134
  30. data/test/test-fix-size-column.rb +0 -77
  31. data/test/test-gqtp.rb +0 -70
  32. data/test/test-hash.rb +0 -344
  33. data/test/test-index-column.rb +0 -180
  34. data/test/test-index-cursor.rb +0 -93
  35. data/test/test-logger.rb +0 -37
  36. data/test/test-pagination.rb +0 -249
  37. data/test/test-patricia-trie.rb +0 -415
  38. data/test/test-plugin.rb +0 -35
  39. data/test/test-procedure.rb +0 -37
  40. data/test/test-query-log.rb +0 -258
  41. data/test/test-record.rb +0 -569
  42. data/test/test-remote.rb +0 -63
  43. data/test/test-schema-create-table.rb +0 -267
  44. data/test/test-schema-dumper.rb +0 -235
  45. data/test/test-schema-type.rb +0 -208
  46. data/test/test-schema-view.rb +0 -90
  47. data/test/test-schema.rb +0 -886
  48. data/test/test-snippet.rb +0 -130
  49. data/test/test-table-cursor.rb +0 -187
  50. data/test/test-table-dumper.rb +0 -83
  51. data/test/test-table-offset-and-limit.rb +0 -100
  52. data/test/test-table-select-mecab.rb +0 -80
  53. data/test/test-table-select-normalize.rb +0 -57
  54. data/test/test-table-select-weight.rb +0 -123
  55. data/test/test-table-select.rb +0 -191
  56. data/test/test-table.rb +0 -675
  57. data/test/test-type.rb +0 -79
  58. data/test/test-variable-size-column.rb +0 -147
  59. data/test/test-variable.rb +0 -28
  60. data/test/test-vector-column.rb +0 -76
  61. data/test/test-version.rb +0 -61
  62. data/test/test-view.rb +0 -72
@@ -1,37 +0,0 @@
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 ProcedureTest < Test::Unit::TestCase
17
- include GroongaTestUtils
18
-
19
- setup :setup_database
20
-
21
- def test_builtins
22
- assert_equal_procedure("TokenDelimit", Groonga::Procedure::DELIMIT)
23
- assert_equal_procedure("TokenUnigram", Groonga::Procedure::UNIGRAM)
24
- assert_equal_procedure("TokenBigram", Groonga::Procedure::BIGRAM)
25
- assert_equal_procedure("TokenTrigram", Groonga::Procedure::TRIGRAM)
26
- assert_equal_procedure("TokenMecab", Groonga::Procedure::MECAB,
27
- :accept_nil => true)
28
- end
29
-
30
- private
31
- def assert_equal_procedure(expected_name, id, options={})
32
- procedure = Groonga::Context.default[id]
33
- expected_name = nil if procedure.nil? and options[:accept_nil]
34
- assert_equal(expected_name,
35
- procedure ? procedure.name : procedure)
36
- end
37
- end
@@ -1,258 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- # Copyright (C) 2011 Kouhei Sutou <kou@clear-code.com>
3
- #
4
- # This library is free software; you can redistribute it and/or
5
- # modify it under the terms of the GNU Lesser General Public
6
- # License version 2.1 as published by the Free Software Foundation.
7
- #
8
- # This library is distributed in the hope that it will be useful,
9
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
- # Lesser General Public License for more details.
12
- #
13
- # You should have received a copy of the GNU Lesser General Public
14
- # License along with this library; if not, write to the Free Software
15
- # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
-
17
- require "cgi"
18
-
19
- module QueryLogTest
20
- module CommandParseTestUtils
21
- private
22
- def command(name, parameters)
23
- Groonga::QueryLog::Command.new(name, parameters)
24
- end
25
-
26
- def parse_http_path(command, parameters)
27
- path = "/d/#{command}.json"
28
- unless parameters.empty?
29
- uri_parameters = parameters.collect do |key, value|
30
- [CGI.escape(key.to_s), CGI.escape(value.to_s)].join("=")
31
- end
32
- path << "?"
33
- path << uri_parameters.join("&")
34
- end
35
- Groonga::QueryLog::Command.parse(path)
36
- end
37
-
38
- def parse_command_line(command, parameters)
39
- command_line = "#{command} --output_type json"
40
- parameters.each do |key, value|
41
- if /"| / =~ value
42
- escaped_value = '"' + value.gsub(/"/, '\"') + '"'
43
- else
44
- escaped_value = value
45
- end
46
- command_line << " --#{key} #{escaped_value}"
47
- end
48
- Groonga::QueryLog::Command.parse(command_line)
49
- end
50
- end
51
-
52
- module HTTPCommandParseTestUtils
53
- private
54
- def parse(command, parameters={})
55
- parse_http_path(command, parameters)
56
- end
57
- end
58
-
59
- module CommandLineCommandParseTestUtils
60
- private
61
- def parse(command, parameters={})
62
- parse_command_line(command, parameters)
63
- end
64
- end
65
-
66
- module SelectCommandParseTests
67
- include CommandParseTestUtils
68
-
69
- def test_parameters
70
- select = parse("select",
71
- :table => "Users",
72
- :filter => "age<=30")
73
- assert_equal(command("select",
74
- "table" => "Users",
75
- "filter" => "age<=30",
76
- "output_type" => "json"),
77
- select)
78
- end
79
-
80
- def test_scorer
81
- select = parse("select",
82
- :table => "Users",
83
- :filter => "age<=30",
84
- :scorer => "_score = random()")
85
- assert_equal("_score = random()", select.scorer)
86
- end
87
-
88
- def test_to_uri_format
89
- select = parse("select",
90
- :table => "Users",
91
- :filter => "age<=30")
92
- assert_equal("/d/select.json?filter=age%3C%3D30&table=Users",
93
- select.to_uri_format)
94
- end
95
-
96
- def test_to_command_format
97
- select = parse("select",
98
- :table => "Users",
99
- :filter => "age<=30")
100
- assert_equal("select --filter \"age<=30\" " +
101
- "--output_type \"json\" --table \"Users\"",
102
- select.to_command_format)
103
- end
104
- end
105
-
106
- module SelectCommandParseFilterTests
107
- include CommandParseTestUtils
108
-
109
- def test_parenthesis
110
- filter = 'geo_in_rectangle(location,' +
111
- '"35.73360x139.7394","62614x139.7714") && ' +
112
- '((type == "たいやき" || type == "和菓子")) && ' +
113
- 'keyword @ "たいやき" &! keyword @ "白" &! keyword @ "養殖"'
114
- select = parse("select",
115
- :table => "Users",
116
- :filter => filter)
117
- assert_equal(['geo_in_rectangle(location,' +
118
- '"35.73360x139.7394","62614x139.7714")',
119
- 'type == "たいやき"',
120
- 'type == "和菓子"',
121
- 'keyword @ "たいやき"',
122
- 'keyword @ "白"',
123
- 'keyword @ "養殖"'],
124
- select.conditions)
125
- end
126
-
127
- def test_to_uri_format
128
- filter = 'geo_in_rectangle(location,' +
129
- '"35.73360x139.7394","62614x139.7714") && ' +
130
- '((type == "たいやき" || type == "和菓子")) && ' +
131
- 'keyword @ "たいやき" &! keyword @ "白" &! keyword @ "養殖"'
132
- select = parse("select",
133
- :table => "Users",
134
- :filter => filter)
135
- assert_equal("/d/select.json?filter=geo_in_rectangle%28location%2C" +
136
- "%2235.73360x139.7394%22%2C%2262614x139.7714%22%29+" +
137
- "%26%26+%28%28type+" +
138
- "%3D%3D+%22%E3%81%9F%E3%81%84%E3%82%84%E3%81%8D%22+" +
139
- "%7C%7C+type+%3D%3D+" +
140
- "%22%E5%92%8C%E8%8F%93%E5%AD%90%22%29%29+" +
141
- "%26%26+keyword+%40+" +
142
- "%22%E3%81%9F%E3%81%84%E3%82%84%E3%81%8D%22+%26%21+" +
143
- "keyword+%40+%22%E7%99%BD%22+%26%21+" +
144
- "keyword+%40+%22%E9%A4%8A%E6%AE%96%22&table=Users",
145
- select.to_uri_format)
146
- end
147
-
148
- def test_to_command_format
149
- filter = 'geo_in_rectangle(location,' +
150
- '"35.73360x139.7394","62614x139.7714") && ' +
151
- '((type == "たいやき" || type == "和菓子")) && ' +
152
- 'keyword @ "たいやき" &! keyword @ "白" &! keyword @ "養殖"'
153
- select = parse("select",
154
- :table => "Users",
155
- :filter => filter)
156
- assert_equal("select " +
157
- "--filter " +
158
- "\"geo_in_rectangle(location," +
159
- "\\\"35.73360x139.7394\\\",\\\"62614x139.7714\\\") && " +
160
- "((type == \\\"たいやき\\\" || " +
161
- "type == \\\"和菓子\\\")) && " +
162
- "keyword @ \\\"たいやき\\\" &! keyword @ \\\"白\\\" &! " +
163
- "keyword @ \\\"養殖\\\"\" " +
164
- "--output_type \"json\" --table \"Users\"",
165
- select.to_command_format)
166
- end
167
- end
168
-
169
- class HTTPSelectCommandParseTest < Test::Unit::TestCase
170
- include SelectCommandParseTests
171
- include SelectCommandParseFilterTests
172
- include HTTPCommandParseTestUtils
173
-
174
- def test_uri_format?
175
- command = parse("status")
176
- assert_predicate(command, :uri_format?)
177
- end
178
-
179
- def test_command_format?
180
- command = parse("status")
181
- assert_not_predicate(command, :command_format?)
182
- end
183
- end
184
-
185
- class CommandLineSelecCommandParseTest < Test::Unit::TestCase
186
- include SelectCommandParseTests
187
- include SelectCommandParseFilterTests
188
- include CommandLineCommandParseTestUtils
189
-
190
- def test_uri_format?
191
- command = parse("status")
192
- assert_not_predicate(command, :uri_format?)
193
- end
194
-
195
- def test_command_format?
196
- command = parse("status")
197
- assert_predicate(command, :command_format?)
198
- end
199
- end
200
-
201
- class StatisticOperationParseTest < Test::Unit::TestCase
202
- def test_context
203
- operations = statistics.first.operations.collect do |operation|
204
- [operation[:name], operation[:context]]
205
- end
206
- expected = [
207
- ["filter", "local_name @ \"gsub\""],
208
- ["filter", "description @ \"string\""],
209
- ["select", nil],
210
- ["sort", "_score"],
211
- ["output", "_key"],
212
- ["drilldown", "name"],
213
- ["drilldown", "class"],
214
- ]
215
- assert_equal(expected, operations)
216
- end
217
-
218
- def test_n_records
219
- operations = statistics.first.operations.collect do |operation|
220
- [operation[:name], operation[:n_records]]
221
- end
222
- expected = [
223
- ["filter", 15],
224
- ["filter", 13],
225
- ["select", 13],
226
- ["sort", 10],
227
- ["output", 10],
228
- ["drilldown", 3],
229
- ["drilldown", 2],
230
- ]
231
- assert_equal(expected, operations)
232
- end
233
-
234
- private
235
- def log
236
- <<-EOL
237
- 2011-06-02 16:27:04.731685|5091e5c0|>/d/select.join?table=Entries&filter=local_name+%40+%22gsub%22+%26%26+description+%40+%22string%22&sortby=_score&output_columns=_key&drilldown=name,class
238
- 2011-06-02 16:27:04.733539|5091e5c0|:000000001849451 filter(15)
239
- 2011-06-02 16:27:04.734978|5091e5c0|:000000003293459 filter(13)
240
- 2011-06-02 16:27:04.735012|5091e5c0|:000000003327415 select(13)
241
- 2011-06-02 16:27:04.735096|5091e5c0|:000000003411824 sort(10)
242
- 2011-06-02 16:27:04.735232|5091e5c0|:000000003547265 output(10)
243
- 2011-06-02 16:27:04.735606|5091e5c0|:000000003921419 drilldown(3)
244
- 2011-06-02 16:27:04.735762|5091e5c0|:000000004077552 drilldown(2)
245
- 2011-06-02 16:27:04.735808|5091e5c0|<000000004123726 rc=0
246
- EOL
247
- end
248
-
249
- def statistics
250
- statistics = []
251
- parser = Groonga::QueryLog::Parser.new
252
- parser.parse(StringIO.new(log)) do |statistic|
253
- statistics << statistic
254
- end
255
- statistics
256
- end
257
- end
258
- end
data/test/test-record.rb DELETED
@@ -1,569 +0,0 @@
1
- # Copyright (C) 2009-2012 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 RecordTest < Test::Unit::TestCase
17
- include GroongaTestUtils
18
-
19
- def setup
20
- setup_database
21
-
22
- setup_addresses_table
23
- setup_users_table
24
- setup_bookmarks_table
25
- setup_indexes
26
- end
27
-
28
- def setup_addresses_table
29
- @addresses = Groonga::Array.create(:name => "Addresses")
30
- @addresses.define_column("mail", "ShortText")
31
- end
32
-
33
- def setup_users_table
34
- @users = Groonga::Hash.create(:name => "Users",
35
- :key_type => "ShortText")
36
- @users.define_column("addresses", @addresses, :type => "vector")
37
- end
38
-
39
- def setup_bookmarks_table
40
- @bookmarks = Groonga::Array.create(:name => "Bookmarks",
41
- :value_type => "Int32")
42
- @bookmarks.define_column("uri", "ShortText")
43
- @bookmarks.define_column("rate", "Int32")
44
- @bookmarks.define_column("comment", "Text")
45
- @bookmarks.define_column("content", "LongText")
46
- @bookmarks.define_column("user", @users)
47
- end
48
-
49
- def setup_indexes
50
- @bookmarks_index = Groonga::PatriciaTrie.create(:name => "BookmarksIndex")
51
- @bookmarks_index.default_tokenizer = "TokenBigram"
52
-
53
- @bookmarks_content_index =
54
- @bookmarks_index.define_index_column("content", @bookmarks,
55
- :with_section => true,
56
- :with_weight => true,
57
- :with_position => true,
58
- :source => "Bookmarks.content")
59
- @bookmarks_index.define_index_column("uri", @bookmarks,
60
- :with_position => true,
61
- :source => "Bookmarks.uri")
62
- end
63
-
64
- def test_column_accessor
65
- groonga = @bookmarks.add
66
-
67
- groonga["uri"] = "http://groonga.org/"
68
- assert_equal("http://groonga.org/", groonga["uri"])
69
-
70
- groonga["comment"] = "fulltext search engine"
71
- assert_equal("fulltext search engine", groonga["comment"])
72
- end
73
-
74
- def test_have_column?
75
- groonga = @bookmarks.add
76
- assert_true(groonga.have_column?(:uri))
77
- assert_false(groonga.have_column?(:nonexistent))
78
- end
79
-
80
- def test_have_column_id
81
- groonga = @bookmarks.add
82
- assert_true(groonga.have_column?(:_id))
83
- end
84
-
85
- def test_have_column_key_hash
86
- mori = @users.add("mori")
87
- assert_true(mori.have_column?(:_key))
88
- end
89
-
90
- def test_have_column_key_array_with_value_type
91
- groonga = @bookmarks.add
92
- assert_true(groonga.have_column?(:_key))
93
- end
94
-
95
- def test_have_column_key_array_without_value_type
96
- groonga_ml = @addresses.add
97
- assert_false(groonga_ml.have_column?(:_key))
98
- end
99
-
100
- def test_have_column_nsubrecs_existent
101
- @users.add("mori")
102
- bookmarks = @users.select do |record|
103
- record.key == "mori"
104
- end
105
- assert_true(bookmarks.to_a.first.have_column?(:_nsubrecs))
106
- end
107
-
108
- def test_have_column_nsubrecs_nonexistent
109
- groonga = @bookmarks.add
110
- assert_false(groonga.have_column?(:_nsubrecs))
111
- end
112
-
113
- def test_get_nonexistent_column
114
- groonga = @bookmarks.add
115
- assert_raise(Groonga::NoSuchColumn) do
116
- groonga["nonexistent"]
117
- end
118
- end
119
-
120
- def test_set_nonexistent_column
121
- groonga = @bookmarks.add
122
- assert_raise(Groonga::NoSuchColumn) do
123
- groonga["nonexistent"] = "value"
124
- end
125
- end
126
-
127
- def test_set_object_id
128
- groonga = @bookmarks.add
129
- daijiro = @users.add("daijiro")
130
- assert_nil(groonga["user"])
131
- groonga["user"] = daijiro
132
- assert_equal(daijiro, groonga["user"])
133
- end
134
-
135
- def test_set_nil
136
- groonga = @bookmarks.add(:content => "groonga")
137
- assert_equal("groonga", groonga["content"])
138
- groonga["content"] = nil
139
- assert_nil(groonga["content"])
140
- end
141
-
142
- def test_set_empty_string
143
- groonga = @bookmarks.add(:content => "groonga")
144
- assert_equal("groonga", groonga["content"])
145
- groonga["content"] = ""
146
- assert_nil(groonga["content"])
147
- end
148
-
149
- def test_set_nil_reference
150
- groonga = @bookmarks.add(:user => "daijiro",
151
- :uri => "http://groonga.org/")
152
- groonga.user = nil
153
- assert_nil(groonga.user)
154
- end
155
-
156
- def test_set_empty_key_reference
157
- groonga = @bookmarks.add(:user => "daijiro",
158
- :uri => "http://groonga.org/")
159
- assert_equal(@users["daijiro"], groonga.user)
160
- groonga["user"] = ""
161
- assert_nil(groonga.user)
162
- end
163
-
164
- def test_set_string_to_integer_column
165
- groonga = @bookmarks.add(:content => "groonga")
166
- groonga.rate = "100"
167
- assert_equal(100, groonga.rate)
168
- end
169
-
170
- def test_delete
171
- bookmark_records = []
172
- bookmark_records << @bookmarks.add
173
- bookmark_records << @bookmarks.add
174
- bookmark_records << @bookmarks.add
175
-
176
- assert_equal(3, @bookmarks.size)
177
- bookmark_records[1].delete
178
- assert_equal(2, @bookmarks.size)
179
- end
180
-
181
- def test_key
182
- documents = Groonga::PatriciaTrie.create(:name => "Documents",
183
- :key_type => "ShortText")
184
- reference = documents.add("reference")
185
- assert_equal("reference", reference.key)
186
- end
187
-
188
- def test_value
189
- bookmark = @bookmarks.add
190
- assert_equal(0, bookmark.value)
191
- bookmark.value = 100
192
- assert_equal(100, bookmark.value)
193
- end
194
-
195
- def test_reference_column?
196
- bookmark = @bookmarks.add
197
- assert_false(bookmark.reference_column?("uri"))
198
- assert_true(bookmark.reference_column?("user"))
199
- end
200
-
201
- def test_index_column?
202
- bookmark = @bookmarks.add
203
- assert_false(bookmark.index_column?("uri"))
204
- index = @bookmarks_index.add("token")
205
- assert_true(index.index_column?("content"))
206
- end
207
-
208
- def test_vector_column?
209
- bookmark = @bookmarks.add
210
- assert_false(bookmark.vector_column?("uri"))
211
- morita = @users.add("morita")
212
- assert_true(morita.vector_column?("addresses"))
213
- end
214
-
215
- def test_scalar_column?
216
- bookmark = @bookmarks.add
217
- assert_true(bookmark.scalar_column?("uri"))
218
- morita = @users.add("morita")
219
- assert_false(morita.scalar_column?("addresses"))
220
- end
221
-
222
- def test_score
223
- groonga = @bookmarks.add
224
- groonga["content"] = "full text search search search engine."
225
-
226
- google = @bookmarks.add
227
- google["content"] = "Web search engine."
228
-
229
- results = @bookmarks_content_index.search("search")
230
- assert_equal([[groonga.id, 3], [google.id, 1]],
231
- results.collect do |record|
232
- [record.id, record.score]
233
- end)
234
- end
235
-
236
- def test_score=
237
- groonga = @bookmarks.add
238
- groonga["content"] = "full text search search search engine."
239
-
240
- google = @bookmarks.add
241
- google["content"] = "Web search engine."
242
-
243
- results = @bookmarks_content_index.search("search")
244
- results.each do |record|
245
- record.score *= 10
246
- end
247
- assert_equal([[groonga.id, 30], [google.id, 10]],
248
- results.collect do |record|
249
- [record.id, record.score]
250
- end)
251
- end
252
-
253
- def test_increment!
254
- groonga = @bookmarks.add
255
- assert_equal(0, groonga["rate"])
256
- groonga.increment!("rate")
257
- assert_equal(1, groonga["rate"])
258
- groonga.increment!("rate", 2)
259
- assert_equal(3, groonga["rate"])
260
- groonga.increment!("rate", -2)
261
- assert_equal(1, groonga["rate"])
262
- end
263
-
264
- def test_decrement!
265
- groonga = @bookmarks.add
266
- assert_equal(0, groonga["rate"])
267
- groonga.decrement!("rate")
268
- assert_equal(-1, groonga["rate"])
269
- groonga.decrement!("rate", 2)
270
- assert_equal(-3, groonga["rate"])
271
- groonga.decrement!("rate", -2)
272
- assert_equal(-1, groonga["rate"])
273
- end
274
-
275
- def test_lock
276
- groonga = @bookmarks.add
277
-
278
- assert_not_predicate(groonga, :locked?)
279
- groonga.lock
280
- assert_predicate(groonga, :locked?)
281
- groonga.unlock
282
- assert_not_predicate(groonga, :locked?)
283
- end
284
-
285
- def test_lock_failed
286
- groonga = @bookmarks.add
287
-
288
- groonga.lock
289
- assert_raise(Groonga::ResourceDeadlockAvoided) do
290
- groonga.lock
291
- end
292
- end
293
-
294
- def test_lock_block
295
- groonga = @bookmarks.add
296
-
297
- assert_not_predicate(groonga, :locked?)
298
- groonga.lock do
299
- assert_predicate(groonga, :locked?)
300
- end
301
- assert_not_predicate(groonga, :locked?)
302
- end
303
-
304
- def test_clear_lock
305
- groonga = @bookmarks.add
306
-
307
- assert_not_predicate(groonga, :locked?)
308
- groonga.lock
309
- assert_predicate(groonga, :locked?)
310
- groonga.clear_lock
311
- assert_not_predicate(groonga, :locked?)
312
- end
313
-
314
- def test_attributes
315
- values = {
316
- "uri" => "http://groonga.org/",
317
- "rate" => 5,
318
- "comment" => "Grate!"
319
- }
320
- groonga = @bookmarks.add(values)
321
- assert_equal(values.merge("_id" => groonga.id,
322
- "content" => nil,
323
- "user" => nil),
324
- groonga.attributes)
325
- end
326
-
327
- def test_recursive_attributes
328
- @bookmarks.define_column("next", @bookmarks)
329
-
330
- top_page_record = @bookmarks.add(top_page)
331
- doc_page_record = @bookmarks.add(doc_page)
332
-
333
- top_page_record["next"] = doc_page_record
334
- doc_page_record["next"] = top_page_record
335
-
336
- expected = {
337
- "_id" => 1,
338
- "user" => nil,
339
- "uri" => "http://groonga.org/",
340
- "rate" => 5,
341
- "next" => {
342
- "_id" => 2,
343
- "user" => nil,
344
- "uri" => "http://groonga.org/document.html",
345
- "rate" => 8,
346
- "content" => nil,
347
- "comment" => "Informative"
348
- },
349
- "content" => nil,
350
- "comment" => "Great!"
351
- }
352
- expected["next"]["next"] = expected
353
-
354
- assert_equal(expected, top_page_record.attributes)
355
- end
356
-
357
- def test_duplicate_records_attributes
358
- @bookmarks.define_column("next1", @bookmarks)
359
- @bookmarks.define_column("next2", @bookmarks)
360
-
361
- top_page_record = @bookmarks.add(top_page)
362
- doc_page_record = @bookmarks.add(doc_page)
363
-
364
- top_page_record["next1"] = doc_page_record
365
- top_page_record["next2"] = doc_page_record
366
- doc_page_record["next1"] = top_page_record
367
-
368
- doc_page_attributes = {
369
- "_id" => 2,
370
- "user" => nil,
371
- "uri" => "http://groonga.org/document.html",
372
- "rate" => 8,
373
- "content" => nil,
374
- "comment" => "Informative",
375
- "next2" => nil
376
- }
377
- top_page_attributes = {
378
- "_id" => 1,
379
- "user" => nil,
380
- "uri" => "http://groonga.org/",
381
- "rate" => 5,
382
- "next1" => doc_page_attributes,
383
- "next2" => doc_page_attributes,
384
- "content" => nil,
385
- "comment" => "Great!"
386
- }
387
- doc_page_attributes["next1"] = top_page_attributes
388
-
389
- actual_records = top_page_record.attributes
390
- assert_equal(top_page_attributes, actual_records)
391
- assert_equal(actual_records["next1"].object_id,
392
- actual_records["next2"].object_id)
393
- end
394
-
395
- def test_select_result_attributes
396
- @bookmarks.add(top_page)
397
- select_result = @bookmarks.select
398
- select_result_result = select_result.first
399
-
400
- expected_attributes = {
401
- "_id" => 1,
402
- "_key" => {
403
- "comment" => "Great!",
404
- "content" => nil,
405
- "_id" => 1,
406
- "rate" => 5,
407
- "uri" => "http://groonga.org/",
408
- "user" => nil
409
- },
410
- "_nsubrecs" => 1,
411
- "_score" => 1,
412
- }
413
-
414
- assert_equal(expected_attributes, select_result_result.attributes)
415
- end
416
-
417
- def test_self_referencing_attributes
418
- @bookmarks.define_column("next", @bookmarks)
419
-
420
- top_page_record = @bookmarks.add(top_page)
421
- top_page_record["next"] = top_page_record
422
-
423
- expected = {
424
- "_id" => 1,
425
- "user" => nil,
426
- "uri" => "http://groonga.org/",
427
- "rate" => 5,
428
- "content" => nil,
429
- "comment" => "Great!"
430
- }
431
- expected["next"] = expected
432
-
433
- assert_equal(expected, top_page_record.attributes)
434
- end
435
-
436
- def test_vector_attributes
437
- @bookmarks.define_column("related_bookmarks", @bookmarks, :type => :vector)
438
-
439
- top_page_record = @bookmarks.add(top_page)
440
- doc_page_record = @bookmarks.add(doc_page)
441
- top_page_record["related_bookmarks"] = [doc_page_record]
442
-
443
- expected = {
444
- "_id" => 1,
445
- "user" => nil,
446
- "uri" => "http://groonga.org/",
447
- "rate" => 5,
448
- "related_bookmarks" => [
449
- {
450
- "_id" => 2,
451
- "comment" => "Informative",
452
- "content" => nil,
453
- "rate" => 8,
454
- "related_bookmarks" => [],
455
- "uri" => "http://groonga.org/document.html",
456
- "user" => nil,
457
- }
458
- ],
459
- "content" => nil,
460
- "comment" => "Great!"
461
- }
462
-
463
- assert_equal(expected, top_page_record.attributes)
464
- end
465
-
466
- def test_self_referencing_vector_attributes
467
- @bookmarks.define_column("related_bookmarks", @bookmarks, :type => :vector)
468
-
469
- top_page_record = @bookmarks.add(top_page)
470
- doc_page_record = @bookmarks.add(doc_page)
471
- top_page_record["related_bookmarks"] = [
472
- top_page_record,
473
- doc_page_record
474
- ]
475
-
476
- top_page_attributes = {
477
- "_id" => 1,
478
- "user" => nil,
479
- "uri" => "http://groonga.org/",
480
- "rate" => 5,
481
- "content" => nil,
482
- "comment" => "Great!"
483
- }
484
- doc_page_attributes = {
485
- "_id" => 2,
486
- "comment" => "Informative",
487
- "content" => nil,
488
- "rate" => 8,
489
- "related_bookmarks" => [],
490
- "uri" => "http://groonga.org/document.html",
491
- "user" => nil,
492
- }
493
- top_page_attributes["related_bookmarks"] = [
494
- top_page_attributes,
495
- doc_page_attributes
496
- ]
497
- assert_equal(top_page_attributes, top_page_record.attributes)
498
- end
499
-
500
- def test_dynamic_accessor
501
- groonga = @bookmarks.add
502
- assert_equal([],
503
- ["uri", "uri="] - groonga.methods.collect {|name| name.to_s})
504
- assert_equal([true, true],
505
- [groonga.respond_to?(:uri),
506
- groonga.respond_to?(:uri=)])
507
- groonga.uri = "http://groonga.org/"
508
- assert_equal("http://groonga.org/", groonga.uri)
509
- end
510
-
511
- def test_method_chain
512
- morita = @users.add("morita")
513
- groonga = @bookmarks.add(:user => morita, :uri => "http://groonga.org")
514
- assert_equal("morita", groonga.user.key)
515
- end
516
-
517
- def test_support_sub_records
518
- morita = @users.add("morita")
519
- assert_not_predicate(morita, :support_sub_records?)
520
- users = @users.select {|record| record.key == "morita"}
521
- assert_predicate(users.to_a[0], :support_sub_records?)
522
- end
523
-
524
- def test_set_record_like_object
525
- kou_at_clear_code = @addresses.add(:mail => "kou@clear-code.com")
526
- record_like_class = Class.new do
527
- attr_reader :record_raw_id
528
- def initialize(record_raw_id)
529
- @record_raw_id = record_raw_id
530
- end
531
- end
532
- record_like_object = record_like_class.new(kou_at_clear_code.record_raw_id)
533
- kou = @users.add("kou")
534
- kou.addresses = [record_like_object]
535
- end
536
-
537
- def test_set_array_like_records
538
- kou_at_clear_code = @addresses.add(:mail => "kou@clear-code.com")
539
- array_like_class = Class.new do
540
- def initialize(records)
541
- @records = records
542
- end
543
-
544
- def to_ary
545
- @records
546
- end
547
- end
548
- array_like_object = array_like_class.new([kou_at_clear_code])
549
- kou = @users.add("kou")
550
- kou.addresses = array_like_object
551
- end
552
-
553
- private
554
- def top_page
555
- {
556
- "uri" => "http://groonga.org/",
557
- "rate" => 5,
558
- "comment" => "Great!",
559
- }
560
- end
561
-
562
- def doc_page
563
- {
564
- "uri" => "http://groonga.org/document.html",
565
- "rate" => 8,
566
- "comment" => "Informative"
567
- }
568
- end
569
- end