[Groonga-commit] groonga/groonga-query-log at 38cd7cb [master] replayer: add Option#target_command_name?

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Sep 24 11:58:40 JST 2013


Kouhei Sutou	2013-09-24 11:58:40 +0900 (Tue, 24 Sep 2013)

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

  Message:
    replayer: add Option#target_command_name?

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

  Modified: lib/groonga/query-log/replayer.rb (+10 -0)
===================================================================
--- lib/groonga/query-log/replayer.rb    2013-09-24 11:47:52 +0900 (7a45a0b)
+++ lib/groonga/query-log/replayer.rb    2013-09-24 11:58:40 +0900 (fa063b1)
@@ -134,6 +134,7 @@ module Groonga
         attr_accessor :protocol
         attr_accessor :n_clients
         attr_writer :request_queue_size
+        attr_accessor :target_command_names
         def initialize
           @host = "127.0.0.1"
           @port = 10041
@@ -143,6 +144,7 @@ module Groonga
           @disable_cache = false
           @requests_path = nil
           @responses_path = nil
+          @target_command_names = ["*"]
         end
 
         def create_client(&block)
@@ -175,6 +177,14 @@ module Groonga
         def disable_cache?
           @disable_cache
         end
+
+        def target_command_name?(name)
+          @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
       end
     end
   end

  Modified: test/test-replayer.rb (+58 -0)
===================================================================
--- test/test-replayer.rb    2013-09-24 11:47:52 +0900 (aed27d8)
+++ test/test-replayer.rb    2013-09-24 11:58:40 +0900 (feab790)
@@ -57,5 +57,63 @@ class ReplayerTest < Test::Unit::TestCase
         end
       end
     end
+
+    class TargetCommandNameTest < self
+      def setup
+        @options = Groonga::QueryLog::Replayer::Options.new
+      end
+
+      def test_default
+        assert_true(@options.target_command_name?("shutdown"))
+      end
+
+      class GlobTest < self
+        def setup
+          super
+          @options.target_command_names = ["se*"]
+        end
+
+        def test_match
+          assert_true(@options.target_command_name?("select"))
+        end
+
+        def test_not_match
+          assert_false(@options.target_command_name?("status"))
+        end
+      end
+
+      class ExtGlobTest < self
+        def setup
+          super
+          @options.target_command_names = ["s{elect,tatus}"]
+          unless File.const_defined?(:FNM_EXTGLOB)
+            omit("File:::FNM_EXTGLOB (Ruby 2.0.0 or later) is required.")
+          end
+        end
+
+        def test_match
+          assert_true(@options.target_command_name?("select"))
+        end
+
+        def test_not_match
+          assert_false(@options.target_command_name?("selectX"))
+        end
+      end
+
+      class ExactMatchTest < self
+        def setup
+          super
+          @options.target_command_names = ["select"]
+        end
+
+        def test_match
+          assert_true(@options.target_command_name?("select"))
+        end
+
+        def test_not_match
+          assert_false(@options.target_command_name?("selectX"))
+        end
+      end
+    end
   end
 end
-------------- next part --------------
HTML����������������������������...
Download 



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