[Groonga-commit] groonga/groonga-query-log at 8a3ed86 [master] verify-server: support column order by output_columns=*

Back to archive index

Kouhei Sutou null+****@clear*****
Fri May 16 17:13:06 JST 2014


Kouhei Sutou	2014-05-16 17:13:06 +0900 (Fri, 16 May 2014)

  New Revision: 8a3ed865aad773d33a4c790d14ba311faff52a6d
  https://github.com/groonga/groonga-query-log/commit/8a3ed865aad773d33a4c790d14ba311faff52a6d

  Message:
    verify-server: support column order by output_columns=*

  Modified files:
    lib/groonga/query-log/response-comparer.rb
    test/test-response-comparer.rb

  Modified: lib/groonga/query-log/response-comparer.rb (+53 -4)
===================================================================
--- lib/groonga/query-log/response-comparer.rb    2014-05-12 17:12:08 +0900 (3de158b)
+++ lib/groonga/query-log/response-comparer.rb    2014-05-16 17:13:06 +0900 (c026c50)
@@ -57,10 +57,10 @@ module Groonga
 
       def same_select_response?
         if random_sort?
-          records_result1 =****@respo*****[0] || []
-          records_result2 =****@respo*****[0] || []
-          records_result1.size == records_result2.size and
-            records_result1[0..1] == records_result2[0..1]
+          same_random_sort_response?
+        elsif all_output_columns?
+
+          same_all_output_columns?
         else
           same_response?
         end
@@ -81,6 +81,55 @@ module Groonga
         end
         normalized_sort_items.include?("_score")
       end
+
+      def same_random_sort_response?
+        records_result1 =****@respo*****[0] || []
+        records_result2 =****@respo*****[0] || []
+        records_result1.size == records_result2.size and
+          records_result1[0..1] == records_result2[0..1]
+      end
+
+      def all_output_columns?
+        @command.output_columns == "*"
+      end
+
+      def same_all_output_columns?
+        records_result1 =****@respo*****[0] || []
+        records_result2 =****@respo*****[0] || []
+        return false if records_result1.size != records_result2.size
+
+        n_hits1 = records_result1[0]
+        n_hits2 = records_result2[0]
+        return false if n_hits1 != n_hits2
+
+        columns1 = records_result1[1]
+        columns2 = records_result2[1]
+        return false if columns1.sort_by(&:first) != columns2.sort_by(&:first)
+
+        column_to_index1 = make_column_to_index_map(columns1)
+        column_to_index2 = make_column_to_index_map(columns2)
+
+        records1 = records_result1[2..-1]
+        records2 = records_result2[2..-1]
+        records1.each_with_index do |record1, record_index|
+          record2 = records2[record_index]
+          column_to_index1.each do |name, column_index1|
+            value1 = record1[column_index1]
+            value2 = record2[column_to_index2[name]]
+            return false if value1 != value2
+          end
+        end
+
+        true
+      end
+
+      def make_column_to_index_map(columns)
+        map = {}
+        columns.each_with_index do |(name, _), i|
+          map[name] = i
+        end
+        map
+      end
     end
   end
 end

  Modified: test/test-response-comparer.rb (+59 -0)
===================================================================
--- test/test-response-comparer.rb    2014-05-12 17:12:08 +0900 (a6fd266)
+++ test/test-response-comparer.rb    2014-05-16 17:13:06 +0900 (e87b564)
@@ -138,6 +138,65 @@ class ResponseComparerTest < Test::Unit::TestCase
       end
     end
 
+    class OutputColumnsTest < self
+      class AllTest < self
+        def setup
+          super
+          @command["output_columns"] = "*"
+        end
+
+        def test_different_order
+          assert_true(same?([
+                              [
+                                [3],
+                                [["_id", "UInt32"], ["_key", "ShortText"]],
+                                [1, "1"],
+                                [2, "2"],
+                                [3, "3"],
+                              ],
+                            ],
+                            [
+                              [
+                                [3],
+                                [["_key", "ShortText"], ["_id", "UInt32"]],
+                                ["1", 1],
+                                ["2", 2],
+                                ["3", 3],
+                              ],
+                            ]))
+        end
+
+        def test_different_record
+          assert_false(same?([
+                               [
+                                 [1],
+                                 [["_id", "UInt32"], ["_key", "ShortText"]],
+                                 [1, "1"],
+                               ],
+                             ],
+                             [
+                               [
+                                 [1],
+                                 [["_key", "ShortText"], ["_id", "UInt32"]],
+                                 [2, "2"],
+                               ],
+                             ]))
+        end
+      end
+
+      class DetectAllTest < self
+        def test_all_output_columns
+          assert_true(all_output_columns?("*"))
+        end
+
+        private
+        def all_output_columns?(output_columns)
+          @command["output_columns"] = output_columns
+          comparer([[[0]]], [[[0]]]).send(:all_output_columns?)
+        end
+      end
+    end
+
     class ErrorTest < self
       def test_with_location
         response1_header = [
-------------- next part --------------
HTML����������������������������...
Télécharger 



More information about the Groonga-commit mailing list
Back to archive index