rroonga 5.0.1 → 5.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/ext/groonga/rb-grn.h CHANGED
@@ -101,7 +101,7 @@ RB_GRN_BEGIN_DECLS
101
101
 
102
102
  #define RB_GRN_MAJOR_VERSION 5
103
103
  #define RB_GRN_MINOR_VERSION 0
104
- #define RB_GRN_MICRO_VERSION 1
104
+ #define RB_GRN_MICRO_VERSION 2
105
105
 
106
106
  #define RB_GRN_QUERY_DEFAULT_MAX_EXPRESSIONS 32
107
107
 
@@ -18,7 +18,18 @@
18
18
  module Groonga
19
19
  class QueryLogger
20
20
  module Flags
21
+ NAMES = {
22
+ :none => NONE,
23
+ :command => COMMAND,
24
+ :result_code => RESULT_CODE,
25
+ :destination => DESTINATION,
26
+ :cache => CACHE,
27
+ :size => SIZE,
28
+ :score => SCORE,
29
+ }
30
+
21
31
  LABELS = {
32
+ NONE => "none",
22
33
  COMMAND => "command",
23
34
  RESULT_CODE => "result_code",
24
35
  DESTINATION => "destination",
@@ -28,9 +39,43 @@ module Groonga
28
39
  }
29
40
 
30
41
  class << self
31
- def parse(input, base_flags)
32
- # TODO
33
- base_flags
42
+ # TODO: Document me.
43
+ def parse(input, base_flags=nil)
44
+ base_flags |= Flags::NONE
45
+ case input
46
+ when nil
47
+ base_flags
48
+ when Integer
49
+ input | base_flags
50
+ when String, Symbol
51
+ value = NAMES[input.to_sym]
52
+ if value.nil?
53
+ message =
54
+ "flag name must be one of #{NAMES.keys.inspect}: " +
55
+ "<#{input.inspect}>"
56
+ raise ArgumentError, message
57
+ end
58
+ value | base_flags
59
+ when ::Array
60
+ input.inject(base_flags) do |flags, sub_input|
61
+ parse(sub_input, flags)
62
+ end
63
+ when ::Hash
64
+ flags = base_flags
65
+ input.each do |key, use_key|
66
+ if use_key
67
+ flags = parse(key, flags)
68
+ else
69
+ flags &= ~parse(key, 0)
70
+ end
71
+ end
72
+ flags
73
+ else
74
+ message =
75
+ "flags value must be nil, Integer, names, " +
76
+ "Array of flag or Hash of name and boolean: <#{input.inspect}>"
77
+ raise ArgumentError, message
78
+ end
34
79
  end
35
80
 
36
81
  def label(flags)
@@ -1209,8 +1209,16 @@ module Groonga
1209
1209
  # @private
1210
1210
  def table_type
1211
1211
  type = @options[:type]
1212
+ if type.nil?
1213
+ if @options[:key_type]
1214
+ type = :hash
1215
+ else
1216
+ type = :array
1217
+ end
1218
+ end
1219
+
1212
1220
  case type
1213
- when :array, nil
1221
+ when :array
1214
1222
  Groonga::Array
1215
1223
  when :hash
1216
1224
  Groonga::Hash
@@ -1219,8 +1227,13 @@ module Groonga
1219
1227
  when :double_array_trie
1220
1228
  Groonga::DoubleArrayTrie
1221
1229
  else
1222
- supported_types = [nil, :array, :hash, :patricia_trie,
1223
- :double_array_trie]
1230
+ supported_types = [
1231
+ nil,
1232
+ :array,
1233
+ :hash,
1234
+ :patricia_trie,
1235
+ :double_array_trie,
1236
+ ]
1224
1237
  raise UnknownTableType.new(type, supported_types)
1225
1238
  end
1226
1239
  end
data/rroonga-build.rb CHANGED
@@ -20,15 +20,15 @@ module RroongaBuild
20
20
  module RequiredGroongaVersion
21
21
  MAJOR = 5
22
22
  MINOR = 0
23
- MICRO = 2
23
+ MICRO = 3
24
24
  VERSION = [MAJOR, MINOR, MICRO]
25
- RELEASED_DATE = Time.utc(2015, 2, 9)
25
+ RELEASED_DATE = Time.utc(2015, 3, 31)
26
26
  end
27
27
 
28
28
  module LatestGroongaVersion
29
29
  MAJOR = 5
30
30
  MINOR = 0
31
- MICRO = 2
31
+ MICRO = 3
32
32
  VERSION = [MAJOR, MINOR, MICRO]
33
33
  end
34
34
 
data/test/test-logger.rb CHANGED
@@ -18,12 +18,12 @@ class LoggerTest < Test::Unit::TestCase
18
18
 
19
19
  def setup
20
20
  @default_log_path = Groonga::Logger.path
21
- @default_query_log_path = Groonga::QueryLogger.path
21
+ @default_rotate_threshold_size = Groonga::Logger.rotate_threshold_size
22
22
  end
23
23
 
24
24
  def teardown
25
25
  Groonga::Logger.path = @default_log_path
26
- Groonga::QueryLogger.path = @default_query_log_path
26
+ Groonga::Logger.rotate_threshold_size = @default_rotate_threshold_size
27
27
  end
28
28
 
29
29
  def test_reopen
@@ -36,4 +36,99 @@ class LoggerTest < Test::Unit::TestCase
36
36
  Groonga::Logger.reopen
37
37
  assert_true(@log_path.exist?)
38
38
  end
39
+
40
+ sub_test_case ".log" do
41
+ test "no options" do
42
+ messages = []
43
+ Groonga::Logger.register do |event, level, time, title, message, location|
44
+ messages << message
45
+ end
46
+ Groonga::Logger.log("1")
47
+ Groonga::Logger.log("2")
48
+ Groonga::Logger.log("3")
49
+ assert_equal(["1", "2", "3"],
50
+ messages)
51
+ end
52
+
53
+ test ":level" do
54
+ levels = []
55
+ Groonga::Logger.register(:max_level => :dump) do |event, level, *rest|
56
+ levels << level
57
+ end
58
+ Groonga::Logger.log("default")
59
+ Groonga::Logger.log("debug", :level => :debug)
60
+ assert_equal([:notice, :debug],
61
+ levels)
62
+ end
63
+
64
+ test "default location" do
65
+ locations = []
66
+ Groonga::Logger.register do |event, level, time, title, message, location|
67
+ locations << location
68
+ end
69
+ Groonga::Logger.log("message"); line = __LINE__
70
+ function = caller_locations(0, 1)[0].label
71
+ assert_equal([
72
+ "#{Process.pid} #{__FILE__}:#{line} #{function}()",
73
+ ],
74
+ locations)
75
+ end
76
+
77
+ test ":file" do
78
+ locations = []
79
+ Groonga::Logger.register do |event, level, time, title, message, location|
80
+ locations << location
81
+ end
82
+ Groonga::Logger.log("message", :file => "file.rb")
83
+ locations = locations.collect do |location|
84
+ location.gsub(/\A(\d+) (.*?):(\d+) (.*?)\(\)\z/,
85
+ "0 \\2:0 function()")
86
+ end
87
+ assert_equal([
88
+ "0 file.rb:0 function()",
89
+ ],
90
+ locations)
91
+ end
92
+
93
+ test ":line" do
94
+ locations = []
95
+ Groonga::Logger.register do |event, level, time, title, message, location|
96
+ locations << location
97
+ end
98
+ Groonga::Logger.log("message", :line => 100)
99
+ locations = locations.collect do |location|
100
+ location.gsub(/\A(\d+) (.*?):(\d+) (.*?)\(\)\z/,
101
+ "0 test.rb:\\3 function()")
102
+ end
103
+ assert_equal([
104
+ "0 test.rb:100 function()",
105
+ ],
106
+ locations)
107
+ end
108
+
109
+ test ":function" do
110
+ locations = []
111
+ Groonga::Logger.register do |event, level, time, title, message, location|
112
+ locations << location
113
+ end
114
+ Groonga::Logger.log("message", :function => "method_name")
115
+ locations = locations.collect do |location|
116
+ location.gsub(/\A(\d+) (.*?):(\d+) (.*?)\(\)\z/,
117
+ "0 test.rb:0 \\4()")
118
+ end
119
+ assert_equal([
120
+ "0 test.rb:0 method_name()",
121
+ ],
122
+ locations)
123
+ end
124
+ end
125
+
126
+ def test_rotate_threshold_size
127
+ Groonga::Logger.unregister
128
+ Groonga::Logger.path = @log_path.to_s
129
+ Groonga::Logger.rotate_threshold_size = 10
130
+ assert_equal([], Dir.glob("#{@log_path}.*"))
131
+ Groonga::Logger.log("Hello")
132
+ assert_not_equal([], Dir.glob("#{@log_path}.*"))
133
+ end
39
134
  end
data/test/test-plugin.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2011 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2011-2015 Kouhei Sutou <kou@clear-code.com>
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -35,6 +35,10 @@ class PluginTest < Test::Unit::TestCase
35
35
  end
36
36
  end
37
37
 
38
+ def test_ruby_suffix
39
+ assert_equal(".rb", Groonga::Plugin.ruby_suffix)
40
+ end
41
+
38
42
  class UnregisterTest < self
39
43
  def test_by_name
40
44
  context.register_plugin("token_filters/stop_word")
@@ -0,0 +1,149 @@
1
+ # Copyright (C) 2015 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
+
16
+ class QueryLoggerTest < Test::Unit::TestCase
17
+ include GroongaTestUtils
18
+
19
+ def setup
20
+ @default_log_path = Groonga::QueryLogger.path
21
+ @default_rotate_threshold_size = Groonga::QueryLogger.rotate_threshold_size
22
+ end
23
+
24
+ def teardown
25
+ Groonga::QueryLogger.path = @default_log_path
26
+ Groonga::QueryLogger.rotate_threshold_size = @default_rotate_threshold_size
27
+ end
28
+
29
+ def test_reopen
30
+ Groonga::QueryLogger.unregister
31
+ Groonga::QueryLogger.path = @query_log_path.to_s
32
+ if @query_log_path.exist?
33
+ FileUtils.mv(@query_log_path, "#{@query_log_path}.old")
34
+ end
35
+ assert do
36
+ not @query_log_path.exist?
37
+ end
38
+ Groonga::QueryLogger.reopen
39
+ assert do
40
+ @query_log_path.exist?
41
+ end
42
+ end
43
+
44
+ sub_test_case ".parse" do
45
+ def parse(input, base_flags=nil)
46
+ base_flags ||= Groonga::QueryLogger::Flags::NONE
47
+ Groonga::QueryLogger::Flags.parse(input, base_flags)
48
+ end
49
+
50
+ test "nil" do
51
+ assert_equal(Groonga::QueryLogger::Flags::NONE,
52
+ parse(nil))
53
+ end
54
+
55
+ test "Integer" do
56
+ assert_equal(Groonga::QueryLogger::Flags::COMMAND,
57
+ parse(Groonga::QueryLogger::Flags::COMMAND))
58
+ end
59
+
60
+ test "String" do
61
+ assert_equal(Groonga::QueryLogger::Flags::COMMAND,
62
+ parse("command"))
63
+ end
64
+
65
+ test "Symbol" do
66
+ assert_equal(Groonga::QueryLogger::Flags::COMMAND,
67
+ parse(:command))
68
+ end
69
+
70
+ test "Array" do
71
+ assert_equal(Groonga::QueryLogger::Flags::COMMAND |
72
+ Groonga::QueryLogger::Flags::RESULT_CODE,
73
+ parse([:command, :result_code]))
74
+ end
75
+
76
+ test "Hash" do
77
+ assert_equal(Groonga::QueryLogger::Flags::COMMAND |
78
+ Groonga::QueryLogger::Flags::DESTINATION,
79
+ parse({
80
+ :command => true,
81
+ :result_code => false,
82
+ :destination => true,
83
+ },
84
+ Groonga::QueryLogger::Flags::COMMAND |
85
+ Groonga::QueryLogger::Flags::RESULT_CODE))
86
+ end
87
+ end
88
+
89
+ sub_test_case ".log" do
90
+ test "no options" do
91
+ messages = []
92
+ Groonga::QueryLogger.register do |action, flag, timestamp, info, message|
93
+ messages << message
94
+ end
95
+ Groonga::QueryLogger.log("1")
96
+ Groonga::QueryLogger.log("2")
97
+ Groonga::QueryLogger.log("3")
98
+ assert_equal(["1", "2", "3"],
99
+ messages)
100
+ end
101
+
102
+ test ":flags" do
103
+ infos = []
104
+ Groonga::QueryLogger.register do |action, flag, timestamp, info, message|
105
+ infos << info
106
+ end
107
+ Groonga::QueryLogger.log("default")
108
+ Groonga::QueryLogger.log("flags", :flags => "command")
109
+ normalized_infos = infos.collect do |info|
110
+ info = info.gsub(/\A0x[a-f\d]+\|/,
111
+ "context_id|")
112
+ info.gsub(/\|[\d]+ \z/,
113
+ "|timestamp ")
114
+ end
115
+ assert_equal([
116
+ "context_id|timestamp ",
117
+ "context_id|",
118
+ ],
119
+ normalized_infos)
120
+ end
121
+
122
+ test ":mark" do
123
+ infos = []
124
+ Groonga::QueryLogger.register do |action, flag, timestamp, info, message|
125
+ infos << info
126
+ end
127
+ Groonga::QueryLogger.log("default")
128
+ Groonga::QueryLogger.log("mark", :mark => ":")
129
+ normalized_infos = infos.collect do |info|
130
+ info.gsub(/\A0x[a-f\d]+\|([^\d])?[\d]+ \z/,
131
+ "context_id|\\1timestamp ")
132
+ end
133
+ assert_equal([
134
+ "context_id|timestamp ",
135
+ "context_id|:timestamp ",
136
+ ],
137
+ normalized_infos)
138
+ end
139
+ end
140
+
141
+ def test_rotate_threshold_size
142
+ Groonga::QueryLogger.unregister
143
+ Groonga::QueryLogger.path = @query_log_path.to_s
144
+ Groonga::QueryLogger.rotate_threshold_size = 10
145
+ assert_equal([], Dir.glob("#{@query_log_path}.*"))
146
+ Groonga::QueryLogger.log("command")
147
+ assert_not_equal([], Dir.glob("#{@query_log_path}.*"))
148
+ end
149
+ end
data/test/test-schema.rb CHANGED
@@ -71,6 +71,25 @@ class SchemaTest < Test::Unit::TestCase
71
71
  end
72
72
  end
73
73
 
74
+ sub_test_case "define table" do
75
+ sub_test_case ":key_type" do
76
+ test "exist" do
77
+ Groonga::Schema.create_table("Posts",
78
+ :key_type => :short_text) do |table|
79
+ end
80
+ posts = context["Posts"]
81
+ assert_kind_of(Groonga::Hash, posts)
82
+ end
83
+
84
+ test "not exist" do
85
+ Groonga::Schema.create_table("Posts") do |table|
86
+ end
87
+ posts = context["Posts"]
88
+ assert_kind_of(Groonga::Array, posts)
89
+ end
90
+ end
91
+ end
92
+
74
93
  class DefineHashTest < self
75
94
  def test_default
76
95
  Groonga::Schema.create_table("Posts", :type => :hash) do |table|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rroonga
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.1
4
+ version: 5.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kouhei Sutou
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2015-04-15 00:00:00.000000000 Z
15
+ date: 2015-05-18 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: pkg-config
@@ -219,8 +219,6 @@ files:
219
219
  - bin/groonga-database-inspect
220
220
  - bin/groonga-index-dump
221
221
  - doc/images/sample-schema.png
222
- - doc/text/install.textile
223
- - doc/text/tutorial.textile
224
222
  - example/bookmark.rb
225
223
  - example/index-html.rb
226
224
  - ext/groonga/extconf.rb
@@ -334,6 +332,7 @@ files:
334
332
  - test/test-patricia-trie.rb
335
333
  - test/test-plugin.rb
336
334
  - test/test-procedure.rb
335
+ - test/test-query-logger.rb
337
336
  - test/test-record.rb
338
337
  - test/test-remote.rb
339
338
  - test/test-schema-create-table.rb
@@ -435,6 +434,7 @@ test_files:
435
434
  - test/test-token-regexp.rb
436
435
  - test/test-table-dumper.rb
437
436
  - test/test-database.rb
437
+ - test/test-query-logger.rb
438
438
  - test/test-variable-size-column.rb
439
439
  - test/test-table-select-mecab.rb
440
440
  - test/test-expression-builder.rb