[Groonga-commit] droonga/droonga-engine at d36a989 [master] Implement "status" command

Back to archive index

YUKI Hiroshi null+****@clear*****
Tue Jun 24 17:16:02 JST 2014


YUKI Hiroshi	2014-06-24 17:16:02 +0900 (Tue, 24 Jun 2014)

  New Revision: d36a9898f3dd0d03a50d118a4a9d12b2343f044f
  https://github.com/droonga/droonga-engine/commit/d36a9898f3dd0d03a50d118a4a9d12b2343f044f

  Message:
    Implement "status" command

  Added files:
    lib/droonga/plugins/status.rb
    test/unit/plugins/test_status.rb
  Modified files:
    lib/droonga/dispatcher.rb
    lib/droonga/handler_messenger.rb
    lib/droonga/test/stub_handler_messenger.rb

  Modified: lib/droonga/dispatcher.rb (+5 -1)
===================================================================
--- lib/droonga/dispatcher.rb    2014-06-24 16:12:01 +0900 (3ae7fd1)
+++ lib/droonga/dispatcher.rb    2014-06-24 17:16:02 +0900 (64e5869)
@@ -51,7 +51,7 @@ module Droonga
     def initialize(engine_state, catalog)
       @engine_state = engine_state
       @catalog = catalog
-      @live_nodes = catalog.all_nodes
+      @live_nodes = all_nodes
       @adapter_runners = create_adapter_runners
       @farm = Farm.new(@engine_state.name, @catalog, @engine_state.loop,
                        :dispatcher => self)
@@ -210,6 +210,10 @@ module Droonga
       @engine_state.local_route?(route)
     end
 
+    def all_nodes
+      @catalog.all_nodes
+    end
+
     private
     def farm_path(route)
       @engine_state.farm_path(route)

  Modified: lib/droonga/handler_messenger.rb (+1 -1)
===================================================================
--- lib/droonga/handler_messenger.rb    2014-06-24 16:12:01 +0900 (db78220)
+++ lib/droonga/handler_messenger.rb    2014-06-24 17:16:02 +0900 (9311ad5)
@@ -18,7 +18,7 @@ require "droonga/forwarder"
 
 module Droonga
   class HandlerMessenger
-    attr_reader :database_name
+    attr_reader :database_name, :dispatcher
 
     def initialize(forwarder, message, options={})
       @forwarder = forwarder

  Added: lib/droonga/plugins/status.rb (+51 -0) 100644
===================================================================
--- /dev/null
+++ lib/droonga/plugins/status.rb    2014-06-24 17:16:02 +0900 (12fdde0)
@@ -0,0 +1,51 @@
+# Copyright (C) 2013-2014 Droonga Project
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1 as published by the Free Software Foundation.
+#
+# 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+require "droonga/plugin"
+
+module Droonga
+  module Plugins
+    module Status
+      extend Plugin
+      register("status")
+
+      class Handler < Droonga::Handler
+        action.synchronous = true
+
+        def handle(message)
+          dispatcher =****@messe*****
+
+          live_nodes = dispatcher.live_nodes
+          nodes = {}
+          dispatcher.all_nodes.collect do |identifier|
+            nodes[identifier] = {
+              "live" => live_nodes.include?(identifier),
+            }
+          end
+
+          {
+            "nodes" => nodes,
+          }
+        end
+      end
+
+      define_single_step do |step|
+        step.name = "status"
+        step.handler = Handler
+        step.collector = Collectors::Or
+      end
+    end
+  end
+end

  Modified: lib/droonga/test/stub_handler_messenger.rb (+3 -0)
===================================================================
--- lib/droonga/test/stub_handler_messenger.rb    2014-06-24 16:12:01 +0900 (e8fdeba)
+++ lib/droonga/test/stub_handler_messenger.rb    2014-06-24 17:16:02 +0900 (de0034e)
@@ -17,9 +17,12 @@ module Droonga
   module Test
     class StubHandlerMessenger
       attr_reader :values, :messages
+      attr_accessor :dispatcher
+
       def initialize
         @values = []
         @messages = []
+        @dispatcher = nil
       end
 
       def emit(value)

  Added: test/unit/plugins/test_status.rb (+80 -0) 100644
===================================================================
--- /dev/null
+++ test/unit/plugins/test_status.rb    2014-06-24 17:16:02 +0900 (983d1f3)
@@ -0,0 +1,80 @@
+# Copyright (C) 2013-2014 Droonga Project
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1 as published by the Free Software Foundation.
+#
+# 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+require "droonga/plugins/status"
+
+class StatusHandlerTest < Test::Unit::TestCase
+  def setup
+    setup_handler
+  end
+
+  def teardown
+    teardown_handler
+  end
+
+  private
+  def setup_handler
+    @worker = StubWorker.new
+    @messenger = Droonga::Test::StubHandlerMessenger.new
+    @dispatcher = StubDispatcher.new
+    @messenger.dispatcher = @dispatcher
+    @loop = nil
+    @handler = Droonga::Plugins::Status::Handler.new("name",
+                                                     @worker.context,
+                                                     @messenger,
+                                                     @loop)
+  end
+
+  def teardown_handler
+    @handler = nil
+  end
+
+  def process(request)
+    message = Droonga::Test::StubHandlerMessage.new(request)
+    @handler.handle(message)
+  end
+
+  class StubDispatcher
+    def all_nodes
+      [
+        "127.0.0.1:10031/droonga",
+        "127.0.0.1:10032/droonga",
+      ]
+    end
+
+    def live_nodes
+      [
+        "127.0.0.1:10031/droonga",
+      ]
+    end
+  end
+
+  public
+  def test_request
+    request = {}
+    response = process(request)
+    status = {
+      "nodes" => {
+        "127.0.0.1:10031/droonga" => {
+          "live" => true,
+        },
+        "127.0.0.1:10032/droonga" => {
+          "live" => false,
+        },
+      },
+    }
+    assert_equal(status, response)
+  end
+end
-------------- next part --------------
HTML����������������������������...
다운로드 



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