Kouhei Sutou
null+****@clear*****
Wed Jan 15 19:01:06 JST 2014
Kouhei Sutou 2014-01-15 19:01:06 +0900 (Wed, 15 Jan 2014) New Revision: 05583ced7b239f6972b3856d8cb9d57032c8f303 https://github.com/groonga/groonga-query-log/commit/05583ced7b239f6972b3856d8cb9d57032c8f303 Message: server-verifier: support random sort case Added files: lib/groonga/query-log/response-comparer.rb test/test-response-comparer.rb Modified files: lib/groonga/query-log/server-verifier.rb Added: lib/groonga/query-log/response-comparer.rb (+63 -0) 100644 =================================================================== --- /dev/null +++ lib/groonga/query-log/response-comparer.rb 2014-01-15 19:01:06 +0900 (c3c8453) @@ -0,0 +1,63 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2014 Kouhei Sutou <kou �� clear-code.com> +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +module Groonga + module QueryLog + class ResponseComparer + def initialize(command, response1, response2) + @command = command + @response1 = response1 + @response2 = response2 + end + + def same? + case****@comma***** + when "select" + same_select_response? + else + same_response? + end + end + + private + def same_response? + @response1 == @response2 + end + + def same_select_response? + if random_sort? + records_result1 = @response1[0] || [] + records_result2 = @response2[0] || [] + records_result1.size == records_result2.size and + records_result1[0..1] == records_result2[0..1] + else + same_response? + end + end + + def random_score? + @command.scorer == "_score=rand()" + end + + def random_sort? + random_score? and + (@command.sortby || "").split(/\s*,\s*/).include?("_score") + end + end + end +end Modified: lib/groonga/query-log/server-verifier.rb (+4 -6) =================================================================== --- lib/groonga/query-log/server-verifier.rb 2014-01-07 16:17:16 +0900 (6c73e78) +++ lib/groonga/query-log/server-verifier.rb 2014-01-15 19:01:06 +0900 (914a8bb) @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright (C) 2013 Kouhei Sutou <kou �� clear-code.com> +# Copyright (C) 2013-2014 Kouhei Sutou <kou �� clear-code.com> # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -22,6 +22,7 @@ require "thread" require "groonga/client" require "groonga/query-log/parser" +require "groonga/query-log/response-comparer" module Groonga module QueryLog @@ -115,15 +116,12 @@ module Groonga command["cache"] = "no" if****@optio*****_cache? response1 = groonga1_client.execute(command) response2 = groonga2_client.execute(command) - unless same_response?(response1, response2) + comparer = ResponseComparer(command, response1, response2) + unless comparer.same? @different_results.push([command, response1, response2]) end end - def same_response?(response1, response2) - response1.body == response2.body - end - def report_result(output, result) command, response1, response2 = result output.puts("command: #{command.original_source}") Added: test/test-response-comparer.rb (+71 -0) 100644 =================================================================== --- /dev/null +++ test/test-response-comparer.rb 2014-01-15 19:01:06 +0900 (5cb8d8a) @@ -0,0 +1,71 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2014 Kouhei Sutou <kou �� clear-code.com> +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +class ResponseComparerTest < Test::Unit::TestCase + private + def comparer(response1, response2) + Groonga::QueryLog::ResponseComparer.new(@command, response1, response2) + end + + def same?(response1, response2) + comparer(response1, response2).same? + end + + class SelectTest < self + def setup + @command = Groonga::Command::Select.new("select", {}) + end + + class ScorerTest < self + class RandTest < self + def setup + super + @command["scorer"] = "_score=rand()" + @command["sortby"] = "_score" + end + + def test_different_order + assert_true(same?([[[3], [["_id", "UInt32"]], [1], [2], [3]]], + [[[3], [["_id", "UInt32"]], [3], [2], [1]]])) + end + + def test_different_attributes + assert_false(same?([[[3], [["_id", "UInt32"]], [1], [2], [3]]], + [[[3], [["age", "UInt32"]], [1], [2], [3]]])) + end + + def test_different_n_records + assert_false(same?([[[3], [["_id", "UInt32"]], [1], [2]]], + [[[3], [["_id", "UInt32"]], [1], [2], [3]]])) + end + end + + class DetectRandTest < self + def test_rand_only + assert_true(random_score?("_score=rand()")) + end + + private + def random_score?(scorer) + @command["scorer"] = scorer + comparer([], []).send(:random_score?) + end + end + end + end +end -------------- next part -------------- HTML����������������������������...Download