groonga-query-log 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a90caf244ba39ca7b7ba11c85821185a693e4d3e
4
- data.tar.gz: b51489a8a105f9c8f5ea348e7a804193b1abcd71
3
+ metadata.gz: 05b507ee733fc255cabbb5cf09e7d050460ed282
4
+ data.tar.gz: 18b939521cb5c1568f7a3cb7d5cce3aee9042bd8
5
5
  SHA512:
6
- metadata.gz: 1e5bf6c8af15419ea6383172cdab9b439a772106368607f219ee2653f5a1e813edb55d26d2aa3705ec5ee29e25a0b0b2274c9dc40227e742247c91f2b6e07b8d
7
- data.tar.gz: 2e1317950786b1018c1fa4b5eb9444354ff9447d7d401a99a8a220ccf69be384db19283a6da8c7a465b4d3fcfd497d8df3d4e85a19b28852f81510180805f6fa
6
+ metadata.gz: 102d611f9a0ca59eaef084a138849cd4ee13cf9b7e7fca2ee9921b3cbe3a9b33fd0024aaa6b3ce80e9996ab9f3e8c0e948d1fd081b1e60fe74f237f6bd9be3ad
7
+ data.tar.gz: 5e59087eca3bda7a8488be18c9b747ef08e90ad47bc2a24f22fee0d71ebdf78a249f3da4030ee04893f189600cc2343ac860a26643506fd39e257bd613a3f839
data/doc/text/news.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # News
2
2
 
3
+ ## 1.0.4: 2014-02-09
4
+
5
+ ### Improvements
6
+
7
+ * groonga-query-log-verify-server: Supported reading input from the
8
+ standard input.
9
+ * groonga-query-log-verify-server: Supported logging error on
10
+ connecting server.
11
+ * groonga-query-log-verify-server: Supported random sort select.
12
+ * groonga-query-log-verify-server: Added `--abort-on-exception` debug option.
13
+
3
14
  ## 1.0.3: 2014-01-06
4
15
 
5
16
  ### Improvements
@@ -31,9 +31,13 @@ module Groonga
31
31
  def run(*command_line)
32
32
  input_paths = create_parser.parse(*command_line)
33
33
  verifier = ServerVerifier.new(@options)
34
- input_paths.each do |input_path|
35
- File.open(input_path) do |input|
36
- verifier.verify(input)
34
+ if input_paths.empty?
35
+ verifier.verify($stdin)
36
+ else
37
+ input_paths.each do |input_path|
38
+ File.open(input_path) do |input|
39
+ verifier.verify(input)
40
+ end
37
41
  end
38
42
  end
39
43
  end
@@ -124,6 +128,14 @@ module Groonga
124
128
  "[stdout]") do |path|
125
129
  @options.output_path = path
126
130
  end
131
+
132
+ parser.separator("Debug options:")
133
+ parser.separator("")
134
+
135
+ parser.on("--abort-on-exception",
136
+ "Abort on exception in threads") do
137
+ Thread.abort_on_exception = true
138
+ end
127
139
  end
128
140
  end
129
141
  end
@@ -0,0 +1,70 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2014 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 as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+
19
+ module Groonga
20
+ module QueryLog
21
+ class ResponseComparer
22
+ def initialize(command, response1, response2)
23
+ @command = command
24
+ @response1 = response1
25
+ @response2 = response2
26
+ end
27
+
28
+ def same?
29
+ case @command.name
30
+ when "select"
31
+ same_select_response?
32
+ else
33
+ same_response?
34
+ end
35
+ end
36
+
37
+ private
38
+ def same_response?
39
+ @response1 == @response2
40
+ end
41
+
42
+ def same_select_response?
43
+ if random_sort?
44
+ records_result1 = @response1[0] || []
45
+ records_result2 = @response2[0] || []
46
+ records_result1.size == records_result2.size and
47
+ records_result1[0..1] == records_result2[0..1]
48
+ else
49
+ same_response?
50
+ end
51
+ end
52
+
53
+ def random_score?
54
+ @command.scorer == "_score=rand()"
55
+ end
56
+
57
+ def random_sort?
58
+ random_score? and score_sort?
59
+ end
60
+
61
+ def score_sort?
62
+ sort_items = (@command.sortby || "").split(/\s*,\s*/)
63
+ normalized_sort_items = sort_items.collect do |item|
64
+ item.gsub(/\A[+-]/, "")
65
+ end
66
+ normalized_sort_items.include?("_score")
67
+ end
68
+ end
69
+ end
70
+ end
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
- # Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
3
+ # Copyright (C) 2013-2014 Kouhei Sutou <kou@clear-code.com>
4
4
  #
5
5
  # This library is free software; you can redistribute it and/or
6
6
  # modify it under the terms of the GNU Lesser General Public
@@ -22,6 +22,7 @@ require "thread"
22
22
  require "groonga/client"
23
23
 
24
24
  require "groonga/query-log/parser"
25
+ require "groonga/query-log/response-comparer"
25
26
 
26
27
  module Groonga
27
28
  module QueryLog
@@ -59,8 +60,15 @@ module Groonga
59
60
  def run_consumers
60
61
  @options.n_clients.times.collect do
61
62
  Thread.new do
62
- loop do
63
- break if run_consumer
63
+ begin
64
+ loop do
65
+ break if run_consumer
66
+ end
67
+ rescue Groonga::Client::Connection::Error
68
+ # TODO: add error log mechanism
69
+ $stderr.puts(Time.now.iso8601)
70
+ $stderr.puts($!.raw_error.message)
71
+ $stderr.puts($!.raw_error.backtrace)
64
72
  end
65
73
  end
66
74
  end
@@ -108,18 +116,15 @@ module Groonga
108
116
  command["cache"] = "no" if @options.disable_cache?
109
117
  response1 = groonga1_client.execute(command)
110
118
  response2 = groonga2_client.execute(command)
111
- unless same_response?(response1, response2)
119
+ comparer = ResponseComparer.new(command, response1.body, response2.body)
120
+ unless comparer.same?
112
121
  @different_results.push([command, response1, response2])
113
122
  end
114
123
  end
115
124
 
116
- def same_response?(response1, response2)
117
- response1.body == response2.body
118
- end
119
-
120
125
  def report_result(output, result)
121
126
  command, response1, response2 = result
122
- output.puts("command: #{command.original_format}")
127
+ output.puts("command: #{command.original_source}")
123
128
  output.puts("response1: #{response1.body}")
124
129
  output.puts("response2: #{response2.body}")
125
130
  end
@@ -129,6 +134,7 @@ module Groonga
129
134
  attr_reader :groonga2
130
135
  attr_accessor :n_clients
131
136
  attr_writer :request_queue_size
137
+ attr_writer :disable_cache
132
138
  attr_accessor :target_command_names
133
139
  attr_accessor :output_path
134
140
  def initialize
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
- # Copyright (C) 2012-2013 Kouhei Sutou <kou@clear-code.com>
3
+ # Copyright (C) 2012-2014 Kouhei Sutou <kou@clear-code.com>
4
4
  #
5
5
  # This library is free software; you can redistribute it and/or
6
6
  # modify it under the terms of the GNU Lesser General Public
@@ -18,6 +18,6 @@
18
18
 
19
19
  module Groonga
20
20
  module QueryLog
21
- VERSION = "1.0.3"
21
+ VERSION = "1.0.4"
22
22
  end
23
23
  end
@@ -0,0 +1,123 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2014 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 as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+
19
+ class ResponseComparerTest < Test::Unit::TestCase
20
+ private
21
+ def comparer(response1, response2)
22
+ Groonga::QueryLog::ResponseComparer.new(@command, response1, response2)
23
+ end
24
+
25
+ def same?(response1, response2)
26
+ comparer(response1, response2).same?
27
+ end
28
+
29
+ class SelectTest < self
30
+ def setup
31
+ @command = Groonga::Command::Select.new("select", {})
32
+ end
33
+
34
+ class ScorerTest < self
35
+ class RandTest < self
36
+ def setup
37
+ super
38
+ @command["scorer"] = "_score=rand()"
39
+ @command["sortby"] = "_score"
40
+ end
41
+
42
+ def test_different_order
43
+ assert_true(same?([[[3], [["_id", "UInt32"]], [1], [2], [3]]],
44
+ [[[3], [["_id", "UInt32"]], [3], [2], [1]]]))
45
+ end
46
+
47
+ def test_different_attributes
48
+ assert_false(same?([[[3], [["_id", "UInt32"]], [1], [2], [3]]],
49
+ [[[3], [["age", "UInt32"]], [1], [2], [3]]]))
50
+ end
51
+
52
+ def test_different_n_records
53
+ assert_false(same?([[[3], [["_id", "UInt32"]], [1], [2]]],
54
+ [[[3], [["_id", "UInt32"]], [1], [2], [3]]]))
55
+ end
56
+ end
57
+
58
+ class DetectRandTest < self
59
+ def test_rand_only
60
+ assert_true(random_score?("_score=rand()"))
61
+ end
62
+
63
+ private
64
+ def random_score?(scorer)
65
+ @command["scorer"] = scorer
66
+ comparer([], []).send(:random_score?)
67
+ end
68
+ end
69
+ end
70
+
71
+ class SortbyTest < self
72
+ class DetectScoreSortTest < self
73
+ private
74
+ def score_sort?(sortby)
75
+ @command["sortby"] = sortby
76
+ comparer([], []).send(:score_sort?)
77
+ end
78
+
79
+ class NoScoreTest < self
80
+ def test_nil
81
+ assert_false(score_sort?(nil))
82
+ end
83
+
84
+ def test_empty
85
+ assert_false(score_sort?(""))
86
+ end
87
+ end
88
+
89
+ class ScoreOnly < self
90
+ def test_no_sign
91
+ assert_true(score_sort?("_score"))
92
+ end
93
+
94
+ def test_plus
95
+ assert_true(score_sort?("+_score"))
96
+ end
97
+
98
+ def test_minus
99
+ assert_true(score_sort?("-_score"))
100
+ end
101
+ end
102
+
103
+ class MultipleItemsTest < self
104
+ def test_no_space
105
+ assert_true(score_sort?("_id,_score,_key"))
106
+ end
107
+
108
+ def test_have_space
109
+ assert_true(score_sort?("_id, _score, _key"))
110
+ end
111
+
112
+ def test_plus
113
+ assert_true(score_sort?("_id,+_score,_key"))
114
+ end
115
+
116
+ def test_minus
117
+ assert_true(score_sort?("_id,-_score,_key"))
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: groonga-query-log
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kouhei Sutou
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-06 00:00:00.000000000 Z
11
+ date: 2014-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: groonga-command-parser
@@ -154,11 +154,11 @@ description: ''
154
154
  email:
155
155
  - kou@clear-code.com
156
156
  executables:
157
- - groonga-query-log-analyze
158
157
  - groonga-query-log-detect-memory-leak
158
+ - groonga-query-log-verify-server
159
+ - groonga-query-log-analyze
159
160
  - groonga-query-log-replay
160
161
  - groonga-query-log-extract
161
- - groonga-query-log-verify-server
162
162
  extensions: []
163
163
  extra_rdoc_files: []
164
164
  files:
@@ -167,52 +167,54 @@ files:
167
167
  - Gemfile
168
168
  - groonga-query-log.gemspec
169
169
  - lib/groonga/query-log.rb
170
- - lib/groonga/query-log/parser.rb
170
+ - lib/groonga/query-log/version.rb
171
171
  - lib/groonga/query-log/extractor.rb
172
- - lib/groonga/query-log/command-line-utils.rb
173
- - lib/groonga/query-log/command/detect-memory-leak.rb
174
172
  - lib/groonga/query-log/command/verify-server.rb
173
+ - lib/groonga/query-log/command/detect-memory-leak.rb
175
174
  - lib/groonga/query-log/command/replay.rb
176
- - lib/groonga/query-log/version.rb
177
- - lib/groonga/query-log/server-verifier.rb
178
175
  - lib/groonga/query-log/memory-leak-detector.rb
176
+ - lib/groonga/query-log/parser.rb
179
177
  - lib/groonga/query-log/analyzer.rb
178
+ - lib/groonga/query-log/response-comparer.rb
179
+ - lib/groonga/query-log/command-line-utils.rb
180
+ - lib/groonga/query-log/server-verifier.rb
180
181
  - lib/groonga/query-log/replayer.rb
181
- - lib/groonga/query-log/analyzer/sized-grouped-operations.rb
182
- - lib/groonga/query-log/analyzer/streamer.rb
183
182
  - lib/groonga/query-log/analyzer/statistic.rb
183
+ - lib/groonga/query-log/analyzer/streamer.rb
184
+ - lib/groonga/query-log/analyzer/sized-statistics.rb
185
+ - lib/groonga/query-log/analyzer/sized-grouped-operations.rb
186
+ - lib/groonga/query-log/analyzer/reporter.rb
184
187
  - lib/groonga/query-log/analyzer/reporter/console.rb
185
- - lib/groonga/query-log/analyzer/reporter/html.rb
186
188
  - lib/groonga/query-log/analyzer/reporter/json.rb
187
- - lib/groonga/query-log/analyzer/reporter.rb
188
- - lib/groonga/query-log/analyzer/sized-statistics.rb
189
+ - lib/groonga/query-log/analyzer/reporter/html.rb
189
190
  - doc/text/news.md
190
191
  - doc/text/lgpl-2.1.txt
191
192
  - .yardopts
192
- - test/run-test.rb
193
- - test/test-extractor.rb
194
- - test/command/test-select.rb
195
- - test/test-analyzer.rb
196
193
  - test/test-replayer.rb
197
- - test/test-parser.rb
198
- - test/fixtures/no-report-summary.expected
199
- - test/fixtures/order/elapsed.expected
194
+ - test/command/test-select.rb
195
+ - test/test-response-comparer.rb
196
+ - test/groonga-query-log-test-utils.rb
197
+ - test/test-extractor.rb
198
+ - test/run-test.rb
199
+ - test/fixtures/n_entries.expected
200
+ - test/fixtures/other-query.log
201
+ - test/fixtures/multi.expected
200
202
  - test/fixtures/order/-start-time.expected
203
+ - test/fixtures/order/elapsed.expected
201
204
  - test/fixtures/order/start-time.expected
202
205
  - test/fixtures/order/-elapsed.expected
203
- - test/fixtures/n_entries.expected
204
- - test/fixtures/other-query.log
206
+ - test/fixtures/no-report-summary.expected
207
+ - test/fixtures/query.log
205
208
  - test/fixtures/reporter/json.expected
206
- - test/fixtures/reporter/console.expected
207
209
  - test/fixtures/reporter/html.expected
208
- - test/fixtures/multi.expected
209
- - test/fixtures/query.log
210
- - test/groonga-query-log-test-utils.rb
211
- - bin/groonga-query-log-analyze
210
+ - test/fixtures/reporter/console.expected
211
+ - test/test-analyzer.rb
212
+ - test/test-parser.rb
212
213
  - bin/groonga-query-log-detect-memory-leak
214
+ - bin/groonga-query-log-verify-server
215
+ - bin/groonga-query-log-analyze
213
216
  - bin/groonga-query-log-replay
214
217
  - bin/groonga-query-log-extract
215
- - bin/groonga-query-log-verify-server
216
218
  homepage: https://github.com/groonga/groonga-query-log
217
219
  licenses:
218
220
  - LGPLv2.1+
@@ -241,23 +243,24 @@ summary: Groonga-query-log is a collection of library and tools to process [groo
241
243
  as a library. You can analyze your groonga's queries and test with your groonga's
242
244
  query log by using groonga-query-log as a tool.
243
245
  test_files:
244
- - test/run-test.rb
245
- - test/test-extractor.rb
246
- - test/command/test-select.rb
247
- - test/test-analyzer.rb
248
246
  - test/test-replayer.rb
249
- - test/test-parser.rb
250
- - test/fixtures/no-report-summary.expected
251
- - test/fixtures/order/elapsed.expected
247
+ - test/command/test-select.rb
248
+ - test/test-response-comparer.rb
249
+ - test/groonga-query-log-test-utils.rb
250
+ - test/test-extractor.rb
251
+ - test/run-test.rb
252
+ - test/fixtures/n_entries.expected
253
+ - test/fixtures/other-query.log
254
+ - test/fixtures/multi.expected
252
255
  - test/fixtures/order/-start-time.expected
256
+ - test/fixtures/order/elapsed.expected
253
257
  - test/fixtures/order/start-time.expected
254
258
  - test/fixtures/order/-elapsed.expected
255
- - test/fixtures/n_entries.expected
256
- - test/fixtures/other-query.log
259
+ - test/fixtures/no-report-summary.expected
260
+ - test/fixtures/query.log
257
261
  - test/fixtures/reporter/json.expected
258
- - test/fixtures/reporter/console.expected
259
262
  - test/fixtures/reporter/html.expected
260
- - test/fixtures/multi.expected
261
- - test/fixtures/query.log
262
- - test/groonga-query-log-test-utils.rb
263
+ - test/fixtures/reporter/console.expected
264
+ - test/test-analyzer.rb
265
+ - test/test-parser.rb
263
266
  has_rdoc: