[Groonga-commit] groonga/groonga-query-log at b354d4b [master] Fix indent

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Jun 13 17:23:29 JST 2018


Kouhei Sutou	2018-06-13 17:23:29 +0900 (Wed, 13 Jun 2018)

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

  Message:
    Fix indent

  Modified files:
    lib/groonga-query-log/command/verify-server.rb
    lib/groonga-query-log/server-verifier.rb

  Modified: lib/groonga-query-log/command/verify-server.rb (+112 -112)
===================================================================
--- lib/groonga-query-log/command/verify-server.rb    2018-06-13 17:23:01 +0900 (86967da)
+++ lib/groonga-query-log/command/verify-server.rb    2018-06-13 17:23:29 +0900 (ba85ea6)
@@ -19,143 +19,143 @@ require "optparse"
 require "groonga-query-log"
 
 module GroongaQueryLog
-    module Command
-      class VerifyServer
-        def initialize
-          @options = ServerVerifier::Options.new
-        end
-
-        def run(command_line, &callback)
-          input_paths = create_parser.parse(command_line)
-          same = true
-          verifier = ServerVerifier.new(@options)
-          if input_paths.empty?
-            same = verifier.verify($stdin, &callback)
-          else
-            input_paths.each do |input_path|
-              File.open(input_path) do |input|
-                unless verifier.verify(input, &callback)
-                  same = false
-                end
+  module Command
+    class VerifyServer
+      def initialize
+        @options = ServerVerifier::Options.new
+      end
+
+      def run(command_line, &callback)
+        input_paths = create_parser.parse(command_line)
+        same = true
+        verifier = ServerVerifier.new(@options)
+        if input_paths.empty?
+          same = verifier.verify($stdin, &callback)
+        else
+          input_paths.each do |input_path|
+            File.open(input_path) do |input|
+              unless verifier.verify(input, &callback)
+                same = false
               end
             end
           end
-          same
         end
+        same
+      end
 
-        private
-        def create_parser
-          parser = OptionParser.new
-          parser.version = VERSION
-          parser.banner += " QUERY_LOG1 QUERY_LOG2 ..."
+      private
+      def create_parser
+        parser = OptionParser.new
+        parser.version = VERSION
+        parser.banner += " QUERY_LOG1 QUERY_LOG2 ..."
 
-          parser.separator("")
-          parser.separator("Options:")
+        parser.separator("")
+        parser.separator("Options:")
 
-          available_protocols = [:gqtp, :http]
-          available_protocols_label = "[#{available_protocols.join(', ')}]"
+        available_protocols = [:gqtp, :http]
+        available_protocols_label = "[#{available_protocols.join(', ')}]"
 
-          parser.on("--groonga1-host=HOST",
-                    "Host name or IP address of Groonga server 1",
-                    "[#{@options.groonga1.host}]") do |host|
-            @options.groonga1.host = host
-          end
+        parser.on("--groonga1-host=HOST",
+                  "Host name or IP address of Groonga server 1",
+                  "[#{@options.groonga1.host}]") do |host|
+          @options.groonga1.host = host
+        end
 
-          parser.on("--groonga1-port=PORT", Integer,
-                    "Port number of Groonga server 1",
-                    "[#{@options.groonga1.port}]") do |port|
-            @options.groonga1.port = port
-          end
+        parser.on("--groonga1-port=PORT", Integer,
+                  "Port number of Groonga server 1",
+                  "[#{@options.groonga1.port}]") do |port|
+          @options.groonga1.port = port
+        end
 
-          parser.on("--groonga1-protocol=PROTOCOL", available_protocols,
-                    "Protocol of Groonga server 1",
-                    available_protocols_label) do |protocol|
-            @options.groonga1.protocol = protocol
-          end
+        parser.on("--groonga1-protocol=PROTOCOL", available_protocols,
+                  "Protocol of Groonga server 1",
+                  available_protocols_label) do |protocol|
+          @options.groonga1.protocol = protocol
+        end
 
-          parser.on("--groonga2-host=HOST",
-                    "Host name or IP address of Groonga server 2",
-                    "[#{@options.groonga2.host}]") do |host|
-            @options.groonga2.host = host
-          end
+        parser.on("--groonga2-host=HOST",
+                  "Host name or IP address of Groonga server 2",
+                  "[#{@options.groonga2.host}]") do |host|
+          @options.groonga2.host = host
+        end
 
-          parser.on("--groonga2-port=PORT", Integer,
-                    "Port number of Groonga server 2",
-                    "[#{@options.groonga2.port}]") do |port|
-            @options.groonga2.port = port
-          end
+        parser.on("--groonga2-port=PORT", Integer,
+                  "Port number of Groonga server 2",
+                  "[#{@options.groonga2.port}]") do |port|
+          @options.groonga2.port = port
+        end
 
-          parser.on("--groonga2-protocol=PROTOCOL", available_protocols,
-                    "Protocol of Groonga server 2",
-                    available_protocols_label) do |protocol|
-            @options.groonga2.protocol = protocol
-          end
+        parser.on("--groonga2-protocol=PROTOCOL", available_protocols,
+                  "Protocol of Groonga server 2",
+                  available_protocols_label) do |protocol|
+          @options.groonga2.protocol = protocol
+        end
 
-          parser.on("--n-clients=N", Integer,
-                    "The max number of concurrency",
-                    "[#{@options.n_clients}]") do |n_clients|
-            @options.n_clients = n_clients
-          end
+        parser.on("--n-clients=N", Integer,
+                  "The max number of concurrency",
+                  "[#{@options.n_clients}]") do |n_clients|
+          @options.n_clients = n_clients
+        end
 
-          parser.on("--request-queue-size=SIZE", Integer,
-                    "The size of request queue",
-                    "[auto]") do |size|
-            @options.request_queue_size = size
-          end
+        parser.on("--request-queue-size=SIZE", Integer,
+                  "The size of request queue",
+                  "[auto]") do |size|
+          @options.request_queue_size = size
+        end
 
-          parser.on("--disable-cache",
-                    "Add 'cache=no' parameter to request",
-                    "[#{@options.disable_cache?}]") do
-            @options.disable_cache = true
-          end
+        parser.on("--disable-cache",
+                  "Add 'cache=no' parameter to request",
+                  "[#{@options.disable_cache?}]") do
+          @options.disable_cache = true
+        end
 
-          parser.on("--target-command-name=NAME",
-                    "Add NAME to target command names",
-                    "You can specify this option zero or more times",
-                    "See also --target-command-names") do |name|
-            @options.target_command_names << name
-          end
+        parser.on("--target-command-name=NAME",
+                  "Add NAME to target command names",
+                  "You can specify this option zero or more times",
+                  "See also --target-command-names") do |name|
+          @options.target_command_names << name
+        end
 
-          target_command_names_label =****@optio*****_command_names.join(", ")
-          parser.on("--target-command-names=NAME1,NAME2,...", Array,
-                    "Replay only NAME1,NAME2,... commands",
-                    "You can use glob to choose command name",
-                    "[#{target_command_names_label}]") do |names|
-            @options.target_command_names = names
-          end
+        target_command_names_label =****@optio*****_command_names.join(", ")
+        parser.on("--target-command-names=NAME1,NAME2,...", Array,
+                  "Replay only NAME1,NAME2,... commands",
+                  "You can use glob to choose command name",
+                  "[#{target_command_names_label}]") do |names|
+          @options.target_command_names = names
+        end
 
-          parser.on("--no-care-order",
-                    "Don't care order of select response records") do
-            @options.care_order = false
-          end
+        parser.on("--no-care-order",
+                  "Don't care order of select response records") do
+          @options.care_order = false
+        end
 
-          parser.on("--output=PATH",
-                    "Output results to PATH",
-                    "[stdout]") do |path|
-            @options.output_path = path
-          end
+        parser.on("--output=PATH",
+                  "Output results to PATH",
+                  "[stdout]") do |path|
+          @options.output_path = path
+        end
 
-          parser.on("--[no-]verify-cache",
-                    "Verify cache for each query.",
-                    "[#{@options.verify_cache?}]") do |verify_cache|
-            @options.verify_cache = verify_cache
-          end
+        parser.on("--[no-]verify-cache",
+                  "Verify cache for each query.",
+                  "[#{@options.verify_cache?}]") do |verify_cache|
+          @options.verify_cache = verify_cache
+        end
 
-          parser.on("--ignore-drilldown-key=KEY",
-                    "Don't compare drilldown result for KEY",
-                    "You can specify multiple drilldown keys by",
-                    "specifying this option multiple times") do |key|
-            @options.ignored_drilldown_keys << key
-          end
+        parser.on("--ignore-drilldown-key=KEY",
+                  "Don't compare drilldown result for KEY",
+                  "You can specify multiple drilldown keys by",
+                  "specifying this option multiple times") do |key|
+          @options.ignored_drilldown_keys << key
+        end
 
-          parser.separator("Debug options:")
-          parser.separator("")
+        parser.separator("Debug options:")
+        parser.separator("")
 
-          parser.on("--abort-on-exception",
-                    "Abort on exception in threads") do
-            Thread.abort_on_exception = true
-          end
+        parser.on("--abort-on-exception",
+                  "Abort on exception in threads") do
+          Thread.abort_on_exception = true
         end
       end
     end
+  end
 end

  Modified: lib/groonga-query-log/server-verifier.rb (+182 -182)
===================================================================
--- lib/groonga-query-log/server-verifier.rb    2018-06-13 17:23:01 +0900 (e5715cd)
+++ lib/groonga-query-log/server-verifier.rb    2018-06-13 17:23:29 +0900 (6158cbd)
@@ -23,232 +23,232 @@ require "groonga-query-log/parser"
 require "groonga-query-log/response-comparer"
 
 module GroongaQueryLog
-    class ServerVerifier
-      def initialize(options)
-        @options = options
-        @queue = SizedQueue.new(@options.request_queue_size)
-        @different_results = Queue.new
-      end
+  class ServerVerifier
+    def initialize(options)
+      @options = options
+      @queue = SizedQueue.new(@options.request_queue_size)
+      @different_results = Queue.new
+    end
 
-      def verify(input, &callback)
-        @same = true
-        producer = run_producer(input, &callback)
-        reporter = run_reporter
-        producer.join
-        @different_results.push(nil)
-        reporter.join
-        @same
-      end
+    def verify(input, &callback)
+      @same = true
+      producer = run_producer(input, &callback)
+      reporter = run_reporter
+      producer.join
+      @different_results.push(nil)
+      reporter.join
+      @same
+    end
 
-      private
-      def run_producer(input, &callback)
-        Thread.new do
-          consumers = run_consumers
-
-          parser = Parser.new
-          n_commands = 0
-          callback_per_n_commands = 100
-          parser.parse(input) do |statistic|
-            command = statistic.command
-            next if command.nil?
-            next unless target_command?(command)
-            n_commands += 1
-            @queue.push(statistic)
-
-            if callback and (n_commands % callback_per_n_commands).zero?
-              @options.n_clients.times do
-                @queue.push(nil)
-              end
-              consumers.each(&:join)
-              callback.call
-              consumers = run_consumers
+    private
+    def run_producer(input, &callback)
+      Thread.new do
+        consumers = run_consumers
+
+        parser = Parser.new
+        n_commands = 0
+        callback_per_n_commands = 100
+        parser.parse(input) do |statistic|
+          command = statistic.command
+          next if command.nil?
+          next unless target_command?(command)
+          n_commands += 1
+          @queue.push(statistic)
+
+          if callback and (n_commands % callback_per_n_commands).zero?
+            @options.n_clients.times do
+              @queue.push(nil)
             end
+            consumers.each(&:join)
+            callback.call
+            consumers = run_consumers
           end
-          @options.n_clients.times do
-            @queue.push(nil)
-          end
-          consumers.each(&:join)
         end
+        @options.n_clients.times do
+          @queue.push(nil)
+        end
+        consumers.each(&:join)
       end
+    end
 
-      def run_consumers
-        @options.n_clients.times.collect do
-          Thread.new do
-            loop do
-              break if run_consumer
-            end
+    def run_consumers
+      @options.n_clients.times.collect do
+        Thread.new do
+          loop do
+            break if run_consumer
           end
         end
       end
+    end
 
-      def run_consumer
-        @options.groonga1.create_client do |groonga1_client|
-          @options.groonga2.create_client do |groonga2_client|
-            loop do
-              statistic =****@queue*****
-              return true if statistic.nil?
-
-              original_source = statistic.command.original_source
+    def run_consumer
+      @options.groonga1.create_client do |groonga1_client|
+        @options.groonga2.create_client do |groonga2_client|
+          loop do
+            statistic =****@queue*****
+            return true if statistic.nil?
+
+            original_source = statistic.command.original_source
+            begin
+              verify_command(groonga1_client, groonga2_client,
+                             statistic.command)
+            rescue
+              log_client_error($!) do
+                $stderr.puts(original_source)
+              end
+              return false
+            end
+            if****@optio*****_cache?
               begin
                 verify_command(groonga1_client, groonga2_client,
-                               statistic.command)
+                               Groonga::Command::Status.new)
               rescue
                 log_client_error($!) do
-                  $stderr.puts(original_source)
+                  $stderr.puts("status after #{original_source}")
                 end
                 return false
               end
-              if****@optio*****_cache?
-                begin
-                  verify_command(groonga1_client, groonga2_client,
-                                 Groonga::Command::Status.new)
-                rescue
-                  log_client_error($!) do
-                    $stderr.puts("status after #{original_source}")
-                  end
-                  return false
-                end
-              end
             end
           end
         end
       end
+    end
 
-      def run_reporter
-        Thread.new do
-          @options.create_output do |output|
-            loop do
-              result = @different_results.pop
-              break if result.nil?
-              report_result(output, result)
-            end
+    def run_reporter
+      Thread.new do
+        @options.create_output do |output|
+          loop do
+            result = @different_results.pop
+            break if result.nil?
+            report_result(output, result)
           end
         end
       end
+    end
 
-      def target_command?(command)
-        @options.target_command_name?(command.command_name)
-      end
+    def target_command?(command)
+      @options.target_command_name?(command.command_name)
+    end
 
-      def verify_command(groonga1_client, groonga2_client, command)
-        command["cache"] = "no" if****@optio*****_cache?
-        command["output_type"] = "json"
-        response1 = groonga1_client.execute(command)
-        response2 = groonga2_client.execute(command)
-        compare_options = {
-          :care_order => @options.care_order,
-          :ignored_drilldown_keys => @options.ignored_drilldown_keys,
-        }
-        comparer = ResponseComparer.new(command, response1, response2,
-                                        compare_options)
-        unless comparer.same?
-          @different_results.push([command, response1, response2])
-        end
+    def verify_command(groonga1_client, groonga2_client, command)
+      command["cache"] = "no" if****@optio*****_cache?
+      command["output_type"] = "json"
+      response1 = groonga1_client.execute(command)
+      response2 = groonga2_client.execute(command)
+      compare_options = {
+        :care_order => @options.care_order,
+        :ignored_drilldown_keys => @options.ignored_drilldown_keys,
+      }
+      comparer = ResponseComparer.new(command, response1, response2,
+                                      compare_options)
+      unless comparer.same?
+        @different_results.push([command, response1, response2])
       end
+    end
 
-      def report_result(output, result)
-        @same = false
-        command, response1, response2 = result
-        command_source = command.original_source || command.to_uri_format
-        output.puts("command: #{command_source}")
-        output.puts("response1: #{response1.body.to_json}")
-        output.puts("response2: #{response2.body.to_json}")
-      end
+    def report_result(output, result)
+      @same = false
+      command, response1, response2 = result
+      command_source = command.original_source || command.to_uri_format
+      output.puts("command: #{command_source}")
+      output.puts("response1: #{response1.body.to_json}")
+      output.puts("response2: #{response2.body.to_json}")
+    end
 
-      def log_client_error(error)
-        $stderr.puts(Time.now.iso8601)
-        yield if block_given?
-        if error.respond_to?(:raw_error)
-          target_error = error.raw_error
-        else
-          target_error = error
-        end
-        $stderr.puts("#{target_error.class}: #{target_error.message}")
-        $stderr.puts(target_error.backtrace)
+    def log_client_error(error)
+      $stderr.puts(Time.now.iso8601)
+      yield if block_given?
+      if error.respond_to?(:raw_error)
+        target_error = error.raw_error
+      else
+        target_error = error
       end
+      $stderr.puts("#{target_error.class}: #{target_error.message}")
+      $stderr.puts(target_error.backtrace)
+    end
 
-      class Options
-        attr_reader :groonga1
-        attr_reader :groonga2
-        attr_accessor :n_clients
-        attr_writer :request_queue_size
-        attr_writer :disable_cache
-        attr_accessor :target_command_names
-        attr_accessor :output_path
-        attr_accessor :care_order
-        attr_writer :verify_cache
-        attr_accessor :ignored_drilldown_keys
-        def initialize
-          @groonga1 = GroongaOptions.new
-          @groonga2 = GroongaOptions.new
-          @n_clients = 8
-          @request_queue_size = nil
-          @disable_cache = false
-          @output_path = nil
-          @target_command_names = [
-            "io_flush",
-            "logical_count",
-            "logical_range_filter",
-            "logical_shard_list",
-            "logical_select",
-            "normalize",
-            "object_exist",
-            "select",
-            "status",
-          ]
-          @care_order = true
-          @verify_cache = false
-          @ignored_drilldown_keys = []
-        end
+    class Options
+      attr_reader :groonga1
+      attr_reader :groonga2
+      attr_accessor :n_clients
+      attr_writer :request_queue_size
+      attr_writer :disable_cache
+      attr_accessor :target_command_names
+      attr_accessor :output_path
+      attr_accessor :care_order
+      attr_writer :verify_cache
+      attr_accessor :ignored_drilldown_keys
+      def initialize
+        @groonga1 = GroongaOptions.new
+        @groonga2 = GroongaOptions.new
+        @n_clients = 8
+        @request_queue_size = nil
+        @disable_cache = false
+        @output_path = nil
+        @target_command_names = [
+          "io_flush",
+          "logical_count",
+          "logical_range_filter",
+          "logical_shard_list",
+          "logical_select",
+          "normalize",
+          "object_exist",
+          "select",
+          "status",
+        ]
+        @care_order = true
+        @verify_cache = false
+        @ignored_drilldown_keys = []
+      end
 
-        def request_queue_size
-          @request_queue_size || @n_clients * 3
-        end
+      def request_queue_size
+        @request_queue_size || @n_clients * 3
+      end
 
-        def disable_cache?
-          @disable_cache
-        end
+      def disable_cache?
+        @disable_cache
+      end
 
-        def verify_cache?
-          @verify_cache
-        end
+      def verify_cache?
+        @verify_cache
+      end
 
-        def target_command_name?(name)
-          return false if name.nil?
+      def target_command_name?(name)
+        return false if name.nil?
 
-          @target_command_names.any? do |name_pattern|
-            flags = 0
-            flags |= File::FNM_EXTGLOB if File.const_defined?(:FNM_EXTGLOB)
-            File.fnmatch(name_pattern, name, flags)
-          end
+        @target_command_names.any? do |name_pattern|
+          flags = 0
+          flags |= File::FNM_EXTGLOB if File.const_defined?(:FNM_EXTGLOB)
+          File.fnmatch(name_pattern, name, flags)
         end
+      end
 
-        def create_output(&block)
-          if @output_path
-            FileUtils.mkdir_p(File.dirname(@output_path))
-            File.open(@output_path, "w", &block)
-          else
-            yield($stdout)
-          end
+      def create_output(&block)
+        if @output_path
+          FileUtils.mkdir_p(File.dirname(@output_path))
+          File.open(@output_path, "w", &block)
+        else
+          yield($stdout)
         end
       end
+    end
 
-      class GroongaOptions
-        attr_accessor :host
-        attr_accessor :port
-        attr_accessor :protocol
-        def initialize
-          @host     = "127.0.0.1"
-          @port     = 10041
-          @protocol = :gqtp
-        end
+    class GroongaOptions
+      attr_accessor :host
+      attr_accessor :port
+      attr_accessor :protocol
+      def initialize
+        @host     = "127.0.0.1"
+        @port     = 10041
+        @protocol = :gqtp
+      end
 
-        def create_client(&block)
-          Groonga::Client.open(:host     => @host,
-                               :port     => @port,
-                               :protocol => @protocol,
-                               &block)
-        end
+      def create_client(&block)
+        Groonga::Client.open(:host     => @host,
+                             :port     => @port,
+                             :protocol => @protocol,
+                             &block)
       end
     end
+  end
 end
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180613/b87a4d96/attachment-0001.htm 



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