From a7d7c763eb9e507af7535a146c69b9028b6cc851 Mon Sep 17 00:00:00 2001 From: Colin Surprenant Date: Mon, 19 Dec 2011 14:40:01 -0500 Subject: [PATCH] fix issue #10 - Fields grouping must be declared with strings, not symbols --- lib/red_storm/simple_topology.rb | 4 +- spec/red_storm/simple_topology_spec.rb | 69 ++++++++++++++++++++++++-- 2 files changed, 68 insertions(+), 5 deletions(-) diff --git a/lib/red_storm/simple_topology.rb b/lib/red_storm/simple_topology.rb index 121a0f8..6f203dc 100644 --- a/lib/red_storm/simple_topology.rb +++ b/lib/red_storm/simple_topology.rb @@ -36,10 +36,10 @@ def source(source_id, grouping) def define_grouping(declarer) @sources.each do |source_id, grouping| grouper, params = grouping.first - + # declarer.fieldsGrouping(source_id, Fields.new()) case grouper when :fields - declarer.fieldsGrouping(source_id, Fields.new(*params)) + declarer.fieldsGrouping(source_id, Fields.new(*([params].flatten.map(&:to_s)))) when :global declarer.globalGrouping(source_id) when :shuffle diff --git a/spec/red_storm/simple_topology_spec.rb b/spec/red_storm/simple_topology_spec.rb index 96a3daa..a8c98a6 100644 --- a/spec/red_storm/simple_topology_spec.rb +++ b/spec/red_storm/simple_topology_spec.rb @@ -68,12 +68,12 @@ class BoltClass2; end bolt_definition = RedStorm::SimpleTopology::BoltDefinition.new(BoltClass1, "bolt_class1", 1) RedStorm::SimpleTopology::BoltDefinition.should_receive(:new).with(BoltClass1, "bolt_class1", 1).and_return(bolt_definition) bolt_definition.should_receive(:source).with(1, {:fields => ["f1"]}) - class TopologyBolt1 < RedStorm::SimpleTopology + class Topology1 < RedStorm::SimpleTopology bolt BoltClass1 do source 1, :fields => ["f1"] end end - TopologyBolt1.bolts.should == [bolt_definition] + Topology1.bolts.should == [bolt_definition] end it "should parse single bolt with options" do @@ -106,6 +106,30 @@ class Topology1 < RedStorm::SimpleTopology Topology1.bolts.should == [bolt_definition1, bolt_definition2] end + it "should parse single symbolic fields" do + bolt_definition = RedStorm::SimpleTopology::BoltDefinition.new(BoltClass1, "bolt_class1", 1) + RedStorm::SimpleTopology::BoltDefinition.should_receive(:new).with(BoltClass1, "bolt_class1", 1).and_return(bolt_definition) + bolt_definition.should_receive(:source).with(1, {:fields => :g1}) + class Topology1 < RedStorm::SimpleTopology + bolt BoltClass1 do + source 1, :fields => :g1 + end + end + Topology1.bolts.should == [bolt_definition] + end + + it "should parse symbolic fields array" do + bolt_definition = RedStorm::SimpleTopology::BoltDefinition.new(BoltClass1, "bolt_class1", 1) + RedStorm::SimpleTopology::BoltDefinition.should_receive(:new).with(BoltClass1, "bolt_class1", 1).and_return(bolt_definition) + bolt_definition.should_receive(:source).with(1, {:fields => [:g1, :g2]}) + class Topology1 < RedStorm::SimpleTopology + bolt BoltClass1 do + source 1, :fields => [:g1, :g2] + end + end + Topology1.bolts.should == [bolt_definition] + end + end describe "configure statement" do @@ -295,7 +319,7 @@ class Topology1 < RedStorm::SimpleTopology RedStorm::StormSubmitter.should_receive("submitTopology").with("topology1", "config", "topology") end - it "should support fields" do + it "should support single string fields" do class Topology1 < RedStorm::SimpleTopology spout SpoutClass1, :id => 1 bolt BoltClass1 do @@ -308,6 +332,45 @@ class Topology1 < RedStorm::SimpleTopology Topology1.new.start("base_path", :cluster) end + it "should support single symbolic fields" do + class Topology1 < RedStorm::SimpleTopology + spout SpoutClass1, :id => 1 + bolt BoltClass1 do + source 1, :fields => :s1 + end + end + + RedStorm::Fields.should_receive(:new).with("s1").and_return("fields") + @declarer.should_receive("fieldsGrouping").with('1', "fields") + Topology1.new.start("base_path", :cluster) + end + + it "should support string array fields" do + class Topology1 < RedStorm::SimpleTopology + spout SpoutClass1, :id => 1 + bolt BoltClass1 do + source 1, :fields => ["f1", "f2"] + end + end + + RedStorm::Fields.should_receive(:new).with("f1", "f2").and_return("fields") + @declarer.should_receive("fieldsGrouping").with('1', "fields") + Topology1.new.start("base_path", :cluster) + end + + it "should support symbolic array fields" do + class Topology1 < RedStorm::SimpleTopology + spout SpoutClass1, :id => 1 + bolt BoltClass1 do + source 1, :fields => [:s1, :s2] + end + end + + RedStorm::Fields.should_receive(:new).with("s1", "s2").and_return("fields") + @declarer.should_receive("fieldsGrouping").with('1', "fields") + Topology1.new.start("base_path", :cluster) + end + it "should support shuffle" do class Topology1 < RedStorm::SimpleTopology spout SpoutClass1, :id => 1