[Groonga-commit] droonga/fluent-plugin-droonga at 61fe1b0 [master] Indent

Back to archive index

YUKI Hiroshi null+****@clear*****
Thu Nov 28 11:06:15 JST 2013


YUKI Hiroshi	2013-11-28 11:06:15 +0900 (Thu, 28 Nov 2013)

  New Revision: 61fe1b049b753dbe60e6db84940527da9f7d9737
  https://github.com/droonga/fluent-plugin-droonga/commit/61fe1b049b753dbe60e6db84940527da9f7d9737

  Message:
    Indent

  Modified files:
    test/unit/plugin/distributor/test_search.rb

  Modified: test/unit/plugin/distributor/test_search.rb (+327 -327)
===================================================================
--- test/unit/plugin/distributor/test_search.rb    2013-11-28 11:05:16 +0900 (d40c7ff)
+++ test/unit/plugin/distributor/test_search.rb    2013-11-28 11:06:15 +0900 (6eebb48)
@@ -29,385 +29,385 @@ class SearchDistributorTest < Test::Unit::TestCase
   end
 
   class MultipleQueriesTest < SearchDistributorTest
-  def test_distribute
-    envelope = {
-      "type" => "search",
-      "dataset" => "Droonga",
-      "body" => {
-        "queries" => {
-          "query1" => {
-            "source" => "User",
-            "output" => {
-              "format" => "complex",
-              "elements" => ["count", "records"],
-              "offset" => 0,
-              "limit" => 10,
+    def test_distribute
+      envelope = {
+        "type" => "search",
+        "dataset" => "Droonga",
+        "body" => {
+          "queries" => {
+            "query1" => {
+              "source" => "User",
+              "output" => {
+                "format" => "complex",
+                "elements" => ["count", "records"],
+                "offset" => 0,
+                "limit" => 10,
+              },
             },
-          },
-          "query2" => {
-            "source" => "User",
-            "output" => {
-              "format" => "complex",
-              "elements" => ["count", "records"],
-              "offset" => 0,
-              "limit" => 20,
+            "query2" => {
+              "source" => "User",
+              "output" => {
+                "format" => "complex",
+                "elements" => ["count", "records"],
+                "offset" => 0,
+                "limit" => 20,
+              },
             },
-          },
-          "query3" => {
-            "source" => "User",
-            "output" => {
-              "format" => "complex",
-              "elements" => ["count", "records"],
-              "offset" => 0,
-              "limit" => 30,
+            "query3" => {
+              "source" => "User",
+              "output" => {
+                "format" => "complex",
+                "elements" => ["count", "records"],
+                "offset" => 0,
+                "limit" => 30,
+              },
             },
           },
         },
-      },
-    }
+      }
 
-    @plugin.process("search", envelope)
+      @plugin.process("search", envelope)
 
-    message = []
+      message = []
 
-    message << {
-      "type" => "reduce",
-      "body" => {
-        "query1" => {
-          "query1_reduced" => {
-            "count" => {
-              "type" => "sum",
-            },
-            "records" => {
-              "type" => "sort",
-              "order" => ["<"],
-              "offset" => 0,
-              "limit" => 10,
+      message << {
+        "type" => "reduce",
+        "body" => {
+          "query1" => {
+            "query1_reduced" => {
+              "count" => {
+                "type" => "sum",
+              },
+              "records" => {
+                "type" => "sort",
+                "order" => ["<"],
+                "offset" => 0,
+                "limit" => 10,
+              },
             },
           },
         },
-      },
-      "inputs" => ["query1"],
-      "outputs" => ["query1_reduced"],
-    }
-    message << {
-      "type" => "reduce",
-      "body" => {
-        "query2" => {
-          "query2_reduced" => {
-            "count" => {
-              "type" => "sum",
-            },
-            "records" => {
-              "type" => "sort",
-              "order" => ["<"],
-              "offset" => 0,
-              "limit" => 20,
+        "inputs" => ["query1"],
+        "outputs" => ["query1_reduced"],
+      }
+      message << {
+        "type" => "reduce",
+        "body" => {
+          "query2" => {
+            "query2_reduced" => {
+              "count" => {
+                "type" => "sum",
+              },
+              "records" => {
+                "type" => "sort",
+                "order" => ["<"],
+                "offset" => 0,
+                "limit" => 20,
+              },
             },
           },
         },
-      },
-      "inputs" => ["query2"],
-      "outputs" => ["query2_reduced"],
-    }
-    message << {
-      "type" => "reduce",
-      "body" => {
-        "query3" => {
-          "query3_reduced" => {
-            "count" => {
-              "type" => "sum",
-            },
-            "records" => {
-              "type" => "sort",
-              "order" => ["<"],
-              "offset" => 0,
-              "limit" => 30,
+        "inputs" => ["query2"],
+        "outputs" => ["query2_reduced"],
+      }
+      message << {
+        "type" => "reduce",
+        "body" => {
+          "query3" => {
+            "query3_reduced" => {
+              "count" => {
+                "type" => "sum",
+              },
+              "records" => {
+                "type" => "sort",
+                "order" => ["<"],
+                "offset" => 0,
+                "limit" => 30,
+              },
             },
           },
         },
-      },
-      "inputs" => ["query3"],
-      "outputs" => ["query3_reduced"],
-    }
-
-    gatherer = {
-      "type" => "gather",
-      "body" => {
-        "query1_reduced" => "query1",
-        "query2_reduced" => "query2",
-        "query3_reduced" => "query3",
-      },
-      "inputs" => [
-        "query1_reduced",
-        "query2_reduced",
-        "query3_reduced",
-      ],
-      "post" => true,
-    }
-    message << gatherer
-
-    searcher = {
-      "type" => "broadcast",
-      "command" => "search",
-      "dataset" => "Droonga",
-      "body" => {
-        "queries" => {
-          "query1" => {
-            "source" => "User",
-            "output" => {
-              "format" => "complex",
-              "elements" => ["count", "records"],
-              "offset" => 0,
-              "limit" => 10,
+        "inputs" => ["query3"],
+        "outputs" => ["query3_reduced"],
+      }
+
+      gatherer = {
+        "type" => "gather",
+        "body" => {
+          "query1_reduced" => "query1",
+          "query2_reduced" => "query2",
+          "query3_reduced" => "query3",
+        },
+        "inputs" => [
+          "query1_reduced",
+          "query2_reduced",
+          "query3_reduced",
+        ],
+        "post" => true,
+      }
+      message << gatherer
+
+      searcher = {
+        "type" => "broadcast",
+        "command" => "search",
+        "dataset" => "Droonga",
+        "body" => {
+          "queries" => {
+            "query1" => {
+              "source" => "User",
+              "output" => {
+                "format" => "complex",
+                "elements" => ["count", "records"],
+                "offset" => 0,
+                "limit" => 10,
+              },
             },
-          },
-          "query2" => {
-            "source" => "User",
-            "output" => {
-              "format" => "complex",
-              "elements" => ["count", "records"],
-              "offset" => 0,
-              "limit" => 20,
+            "query2" => {
+              "source" => "User",
+              "output" => {
+                "format" => "complex",
+                "elements" => ["count", "records"],
+                "offset" => 0,
+                "limit" => 20,
+              },
             },
-          },
-          "query3" => {
-            "source" => "User",
-            "output" => {
-              "format" => "complex",
-              "elements" => ["count", "records"],
-              "offset" => 0,
-              "limit" => 30,
+            "query3" => {
+              "source" => "User",
+              "output" => {
+                "format" => "complex",
+                "elements" => ["count", "records"],
+                "offset" => 0,
+                "limit" => 30,
+              },
             },
           },
         },
-      },
-      "outputs" => [
-        "query1",
-        "query2",
-        "query3",
-      ],
-      "replica" => "random",
-    }
-    message << searcher
-
-    assert_equal(message, @posted.last.last)
-  end
+        "outputs" => [
+          "query1",
+          "query2",
+          "query3",
+        ],
+        "replica" => "random",
+      }
+      message << searcher
+
+      assert_equal(message, @posted.last.last)
+    end
   end
 
   class SingleQueryTest < SearchDistributorTest
-  def test_no_output
-    envelope = {
-      "type" => "search",
-      "dataset" => "Droonga",
-      "body" => {
-        "queries" => {
-          "no_output" => {
-            "source" => "User",
+    def test_no_output
+      envelope = {
+        "type" => "search",
+        "dataset" => "Droonga",
+        "body" => {
+          "queries" => {
+            "no_output" => {
+              "source" => "User",
+            },
           },
         },
-      },
-    }
+      }
 
-    @plugin.process("search", envelope)
+      @plugin.process("search", envelope)
 
-    message = []
-    message << gatherer(envelope, :no_output => true)
-    message << searcher(envelope, :no_output => true)
-    assert_equal(message, @posted.last.last)
-  end
+      message = []
+      message << gatherer(envelope, :no_output => true)
+      message << searcher(envelope, :no_output => true)
+      assert_equal(message, @posted.last.last)
+    end
 
-  def test_no_records_element
-    envelope = {
-      "type" => "search",
-      "dataset" => "Droonga",
-      "body" => {
-        "queries" => {
-          "no_records" => {
-            "source" => "User",
-            "output" => {
-              "elements" => ["count"],
+    def test_no_records_element
+      envelope = {
+        "type" => "search",
+        "dataset" => "Droonga",
+        "body" => {
+          "queries" => {
+            "no_records" => {
+              "source" => "User",
+              "output" => {
+                "elements" => ["count"],
+              },
             },
           },
         },
-      },
-    }
-
-    @plugin.process("search", envelope)
-
-    message = []
-    message << reducer(envelope, {
-      "count" => {
-        "type" => "sum",
-      },
-    })
-    message << gatherer(envelope)
-    message << searcher(envelope, :output_limit => 0)
-    assert_equal(message, @posted.last.last)
-  end
+      }
 
+      @plugin.process("search", envelope)
 
-  def test_no_output_limit
-    envelope = {
-      "type" => "search",
-      "dataset" => "Droonga",
-      "body" => {
-        "queries" => {
-          "no_limit" => {
-            "source" => "User",
-            "output" => {
-              "format" => "complex",
-              "elements" => ["count", "records"],
+      message = []
+      message << reducer(envelope, {
+        "count" => {
+          "type" => "sum",
+        },
+      })
+      message << gatherer(envelope)
+      message << searcher(envelope, :output_limit => 0)
+      assert_equal(message, @posted.last.last)
+    end
+
+
+    def test_no_output_limit
+      envelope = {
+        "type" => "search",
+        "dataset" => "Droonga",
+        "body" => {
+          "queries" => {
+            "no_limit" => {
+              "source" => "User",
+              "output" => {
+                "format" => "complex",
+                "elements" => ["count", "records"],
+              },
             },
           },
         },
-      },
-    }
-
-    @plugin.process("search", envelope)
-
-    message = []
-    message << reducer(envelope, {
-      "count" => {
-        "type" => "sum",
-      },
-      "records" => {
-        "type" => "sort",
-        "order" => ["<"],
-        "offset" => 0,
-        "limit" => 0,
-      },
-    })
-    message << gatherer(envelope)
-    message << searcher(envelope, :output_offset => 0,
-                                  :output_limit => 0)
-    assert_equal(message, @posted.last.last)
-  end
+      }
+
+      @plugin.process("search", envelope)
+
+      message = []
+      message << reducer(envelope, {
+        "count" => {
+          "type" => "sum",
+        },
+        "records" => {
+          "type" => "sort",
+          "order" => ["<"],
+          "offset" => 0,
+          "limit" => 0,
+        },
+      })
+      message << gatherer(envelope)
+      message << searcher(envelope, :output_offset => 0,
+                                    :output_limit => 0)
+      assert_equal(message, @posted.last.last)
+    end
 
 
-  def test_have_records
-    envelope = {
-      "type" => "search",
-      "dataset" => "Droonga",
-      "body" => {
-        "queries" => {
-          "have_records" => {
-            "source" => "User",
-            "output" => {
-              "format" => "complex",
-              "elements" => ["count", "records"],
-              "attributes" => ["_key", "name", "age"],
-              "offset" => 1,
-              "limit" => 2,
+    def test_have_records
+      envelope = {
+        "type" => "search",
+        "dataset" => "Droonga",
+        "body" => {
+          "queries" => {
+            "have_records" => {
+              "source" => "User",
+              "output" => {
+                "format" => "complex",
+                "elements" => ["count", "records"],
+                "attributes" => ["_key", "name", "age"],
+                "offset" => 1,
+                "limit" => 2,
+              },
             },
           },
         },
-      },
-    }
-
-    @plugin.process("search", envelope)
-
-    message = []
-    message << reducer(envelope, {
-      "count" => {
-        "type" => "sum",
-      },
-      "records" => {
-        "type" => "sort",
-        "order" => ["<"],
-        "offset" => 1,
-        "limit" => 2,
-      },
-    })
-    message << gatherer(envelope)
-    message << searcher(envelope, :output_offset => 0,
-                                  :output_limit => 3)
-    assert_equal(message, @posted.last.last)
-  end
+      }
 
-  # XXX we should write cases for...
-  #  - sortBy(simple)
-  #  - sortBy(rich)
-  #  - sortBy(rich) with offset
-  #  - sortBy(rich) with limit
-  #  - sortBy(rich) with offset and limit
-  #  - sortBy(simple) + output(limit, offset)
-  #  - sortBy(rich)
-  #    + output(limit, offset)
-  #  - sortBy(rich) with offset
-  #    + output(limit, offset)
-  #  - sortBy(rich) with limit
-  #    + output(limit, offset)
-  #  - sortBy(rich) with offset and limit
-  #    + output(limit, offset)
-  # and, we have to write cases for both unlimited and limited cases...
-
-  private
-  def reducer(search_request_envelope, reducer_body)
-    queries = search_request_envelope["body"]["queries"]
-    query_name = queries.keys.first
-
-    reducer = {
-      "type" => "reduce",
-      "body" => {
-        query_name => {
-          "#{query_name}_reduced" => reducer_body,
+      @plugin.process("search", envelope)
+
+      message = []
+      message << reducer(envelope, {
+        "count" => {
+          "type" => "sum",
+        },
+        "records" => {
+          "type" => "sort",
+          "order" => ["<"],
+          "offset" => 1,
+          "limit" => 2,
         },
-      },
-      "inputs" => [query_name],
-      "outputs" => ["#{query_name}_reduced"],
-    }
+      })
+      message << gatherer(envelope)
+      message << searcher(envelope, :output_offset => 0,
+                                    :output_limit => 3)
+      assert_equal(message, @posted.last.last)
+    end
 
-    reducer
-  end
+    # XXX we should write cases for...
+    #  - sortBy(simple)
+    #  - sortBy(rich)
+    #  - sortBy(rich) with offset
+    #  - sortBy(rich) with limit
+    #  - sortBy(rich) with offset and limit
+    #  - sortBy(simple) + output(limit, offset)
+    #  - sortBy(rich)
+    #    + output(limit, offset)
+    #  - sortBy(rich) with offset
+    #    + output(limit, offset)
+    #  - sortBy(rich) with limit
+    #    + output(limit, offset)
+    #  - sortBy(rich) with offset and limit
+    #    + output(limit, offset)
+    # and, we have to write cases for both unlimited and limited cases...
+
+    private
+    def reducer(search_request_envelope, reducer_body)
+      queries = search_request_envelope["body"]["queries"]
+      query_name = queries.keys.first
+
+      reducer = {
+        "type" => "reduce",
+        "body" => {
+          query_name => {
+            "#{query_name}_reduced" => reducer_body,
+          },
+        },
+        "inputs" => [query_name],
+        "outputs" => ["#{query_name}_reduced"],
+      }
 
-  def gatherer(search_request_envelope, options={})
-    queries = search_request_envelope["body"]["queries"]
-    query_name = queries.keys.first
-
-    gatherer = {
-      "type" => "gather",
-      "body" => {
-      },
-      "inputs" => [
-      ],
-      "post" => true,
-    }
-
-    unless options[:no_output]
-      gatherer["body"]["#{query_name}_reduced"] = query_name
-      gatherer["inputs"] << "#{query_name}_reduced"
+      reducer
     end
 
-    gatherer
-  end
+    def gatherer(search_request_envelope, options={})
+      queries = search_request_envelope["body"]["queries"]
+      query_name = queries.keys.first
 
-  def searcher(search_request_envelope, options={})
-    searcher = search_request_envelope.dup
+      gatherer = {
+        "type" => "gather",
+        "body" => {
+        },
+        "inputs" => [
+        ],
+        "post" => true,
+      }
 
-    queries = searcher["body"]["queries"]
-    query_name = queries.keys.first
-    if options[:sort_offset]
-      queries[query_name]["sortBy"]["offset"] = options[:sort_offset]
-    end
-    if options[:sort_limit]
-      queries[query_name]["sortBy"]["limit"] = options[:sort_limit]
-    end
-    if options[:output_offset]
-      queries[query_name]["output"]["offset"] = options[:output_offset]
-    end
-    if options[:output_limit]
-      queries[query_name]["output"]["limit"] = options[:output_limit]
-    end
+      unless options[:no_output]
+        gatherer["body"]["#{query_name}_reduced"] = query_name
+        gatherer["inputs"] << "#{query_name}_reduced"
+      end
 
-    outputs = []
-    outputs << query_name unless options[:no_output]
+      gatherer
+    end
 
-    searcher["type"] = "broadcast"
-    searcher["command"] = "search"    
-    searcher["outputs"] = outputs
-    searcher["replica"] = "random"
-    searcher
-  end
+    def searcher(search_request_envelope, options={})
+      searcher = search_request_envelope.dup
+
+      queries = searcher["body"]["queries"]
+      query_name = queries.keys.first
+      if options[:sort_offset]
+        queries[query_name]["sortBy"]["offset"] = options[:sort_offset]
+      end
+      if options[:sort_limit]
+        queries[query_name]["sortBy"]["limit"] = options[:sort_limit]
+      end
+      if options[:output_offset]
+        queries[query_name]["output"]["offset"] = options[:output_offset]
+      end
+      if options[:output_limit]
+        queries[query_name]["output"]["limit"] = options[:output_limit]
+      end
+
+      outputs = []
+      outputs << query_name unless options[:no_output]
+
+      searcher["type"] = "broadcast"
+      searcher["command"] = "search"    
+      searcher["outputs"] = outputs
+      searcher["replica"] = "random"
+      searcher
+    end
   end
 end
-------------- next part --------------
HTML����������������������������...
Download 



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