[Groonga-commit] groonga/fluent-plugin-kotoumi [master] Support startTime and elapsedTime

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Jan 31 14:40:46 JST 2013


Kouhei Sutou	2013-01-31 14:40:46 +0900 (Thu, 31 Jan 2013)

  New Revision: deb995cbead7fa695becd33c461a18ae6b6bf9e2
  https://github.com/groonga/fluent-plugin-kotoumi/commit/deb995cbead7fa695becd33c461a18ae6b6bf9e2

  Log:
    Support startTime and elapsedTime

  Modified files:
    lib/kotoumi/worker.rb
    test/test_worker.rb

  Modified: lib/kotoumi/worker.rb (+6 -0)
===================================================================
--- lib/kotoumi/worker.rb    2013-01-31 14:27:33 +0900 (6c67f0d)
+++ lib/kotoumi/worker.rb    2013-01-31 14:40:46 +0900 (06ef8d9)
@@ -15,6 +15,8 @@
 # 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 "time"
+
 require 'groonga'
 
 module Kotoumi
@@ -48,9 +50,13 @@ module Kotoumi
     end
 
     def search_query(query)
+      start_time = Time.now
       source = @context[query["source"]]
+      elapsed_time = Time.now.to_f - start_time.to_f
       {
         "count" => source.size,
+        "startTime" => start_time.iso8601,
+        "elapsedTime" => elapsed_time,
       }
     end
   end

  Modified: test/test_worker.rb (+26 -2)
===================================================================
--- test/test_worker.rb    2013-01-31 14:27:33 +0900 (a843f5a)
+++ test/test_worker.rb    2013-01-31 14:40:46 +0900 (25fd1d1)
@@ -56,11 +56,35 @@ class WorkerTest < Test::Unit::TestCase
       }
       expected = {
         "sections" => {
+          "startTime" => start_time,
+          "elapsedTime" => elapsed_time,
           "count" => 9,
         }
       }
-      assert_equal(expected,
-                   @worker.process_message(request))
+      actual =****@worke*****_message(request)
+      assert_equal(expected, normalize_result_set(actual))
+    end
+
+    private
+    def start_time
+      "2013-01-31T14:34:47+09:00"
+    end
+
+    def elapsed_time
+      0.01
+    end
+
+    def normalize_result_set(result_set)
+      normalized_result_set = copy_deeply(result_set)
+      normalized_result_set.each do |name, result|
+        result["startTime"] = start_time if result["startTime"]
+        result["elapsedTime"] = elapsed_time if result["elapsedTime"]
+      end
+      normalized_result_set
+    end
+
+    def copy_deeply(object)
+      Marshal.load(Marshal.dump(object))
     end
   end
 end
-------------- next part --------------
HTML����������������������������...
Télécharger 



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