require "./spec_helper" describe Crystal::Scatter do it "add elements to RingGraphs" do rg = Crystal::Scatter::RingGraph.new 0 rg.add(UInt64.new(1),[0,0,0,0,0,0],"OSD0") rg.add(UInt64.new(1),[0,0,0,0,0,1],"OSD1") rg.add(UInt64.new(1),[0,0,0,0,1,0],"OSD2") rg.get_weight.should eq(3) rg.generate_ring(BigRational.new(1)) rg.first.first.first.first.first.first.range_effector.not_nil!.[0].should eq(0) rg.last.last.last.last.last.last.range_effector.not_nil!.[1].should eq(UInt64::MAX) end it "slices data into multiple pods" do mr = Crystal::Scatter::MetaRing.new(3) mr.add Crystal::Scatter::Daemon.new(1,[0,0,0,0,0,0],"OSD0") mr.add [Crystal::Scatter::Daemon.new(1,[0,0,0,0,0,1],"OSD1"),Crystal::Scatter::Daemon.new(1,[0,0,0,0,0,2],"OSD2")] (1..1000).each do |numb| slices = mr.get_slices_for(numb.to_s) slices_history = mr.get_slices_for(numb.to_s,2) set = Set(String).new slices.each do |sl| set< (hash_nb/1000*4/5)) end slice_array.each do |v| good_slice&=(v > (hash_nb/1000*4/5)) end good_mod.should be_true good_slice.should be_true end end