spec/lib/rhcf/timeseries/redis_spec.rb in rhcf-timeseries-0.0.3 vs spec/lib/rhcf/timeseries/redis_spec.rb in rhcf-timeseries-0.0.4

- old
+ new

@@ -1,46 +1,44 @@ require 'spec_helper' require 'timecop' require 'redis' -require 'micon' require 'rhcf/timeseries/redis' require 'benchmark' require 'logger' -micon.register(:logger){Logger.new('/dev/null')} -#micon.register(:logger){Logger.new(STDOUT)} -micon.register(:redis_connection){Redis.new} - describe Rhcf::Timeseries::Redis do + let(:null_logger){Logger.new('/dev/null')} + let(:redis_connection){Redis.new} + subject{Rhcf::Timeseries::Redis.new(null_logger, redis_connection)} before(:each) do Timecop.return subject.flush! end it "should be fast to store and read" do subject.flush! total = 0 start_time = Time.now - + bench = Benchmark.measure { - 10000.times do - total +=1 - subject.store("a", {"b" => 1} ) #, time) - end + 10000.times do + total +=1 + subject.store("a", {"b" => 1} ) #, time) + end } - -#pp subject.find("a", start_time - 11100, Time.now + 11100).points(:second) + + #pp subject.find("a", start_time - 11100, Time.now + 11100).points(:second) qbench = Benchmark.measure { subject.find("a", start_time - 11100, Time.now + 11100).total['b'].to_i.should == total } qbench_year = Benchmark.measure { subject.find("a", start_time - 100000, Time.now + 100000).total(:year)['b'].to_i.should == total } - + puts "Write speed %d points/seg | points:%d, duration:%0.3fs | query_time %0.3fs" % [speed = (1.0 * total / (bench.total + 0.00000001)), total, bench.total, qbench.total] speed.should > 400 end @@ -60,30 +58,30 @@ Timecop.travel(15.minutes) #00:00:45 subject.store("views/product/15", {"web/ie/6" => 2}) Timecop.travel(15.minutes) #00:00:00 subject.store("views/product/11", {"web/ie/5" => 2}) - + Timecop.travel(15.minutes) #00:00:15 subject.store("views/product/11", {"web/chrome/11"=> 4}) Timecop.travel(15.minutes) #00:00:30 subject.store("views/product/11", {"web/chrome/11"=> 2}) subject.find("views/product", start_time, start_time + 55.minutes).total(:ever).should == { - "web" => 16.0, + "web" => 16.0, "web/chrome" => 6.0, "web/chrome/11" => 6.0, "web/firefox" => 3.0, "web/firefox/3" => 3.0, "web/ie" => 7.0, "web/ie/5" => 2.0, "web/ie/6" => 5.0 } subject.find("views/product", start_time, start_time + 55.minutes).total(:year).should == { - "web" => 16.0, + "web" => 16.0, "web/chrome" => 6.0, "web/chrome/11" => 6.0, "web/firefox" => 3.0, "web/firefox/3" => 3.0, "web/ie" => 7.0, @@ -125,42 +123,42 @@ {:moment=>"2000-01-01T00:30", :values=>{"web"=>3, "web/ie/6"=>3, "web/ie"=>3}}, {:moment=>"2000-01-01T00:45", :values=>{"web"=>2, "web/ie/6"=>2, "web/ie"=>2}} ] subject.find("views", start_time).points(:hour).should == [{:moment=>"2000-01-01T00", - :values=> - {"web/ie"=>5.0, - "web"=>8.0, - "web/firefox"=>3.0, - "web/ie/6"=>5.0, - "web/firefox/3"=>3.0}}, - {:moment=>"2000-01-01T01", - :values=> - {"web/ie"=>2.0, - "web/chrome"=>6.0, - "web/chrome/11"=>6.0, - "web"=>8.0, - "web/ie/5"=>2.0}}] + :values=> + {"web/ie"=>5.0, + "web"=>8.0, + "web/firefox"=>3.0, + "web/ie/6"=>5.0, + "web/firefox/3"=>3.0}}, + {:moment=>"2000-01-01T01", + :values=> + {"web/ie"=>2.0, + "web/chrome"=>6.0, + "web/chrome/11"=>6.0, + "web"=>8.0, + "web/ie/5"=>2.0}}] end - it "causes no stack overflow" do - params_hash = { - sender_domain: 'example.com', - realm: 'realm', - destination_domain: 'lvh.me', - mail_server: 'aserver', - bind_interface: '11.1.1.11' - } + it "causes no stack overflow" do + params_hash = { + sender_domain: 'example.com', + realm: 'realm', + destination_domain: 'lvh.me', + mail_server: 'aserver', + bind_interface: '11.1.1.11' + } - { - 'sender_domain' => '%{sender_domain}', - 'realm_and_sender_domain' => '%{realm}/%{sender_domain}', - 'mail_server_and_interface' => '%{mail_server}/%{bind_interface}', - 'realm_and_destination_domain' => '%{realm}/%{destination_domain}', - 'destination_domain' => '%{destination_domain}' - }.each do |known, unknown| - subject.store(known % params_hash, {[(unknown % params_hash),'sent'].join('/') => 1}) + { + 'sender_domain' => '%{sender_domain}', + 'realm_and_sender_domain' => '%{realm}/%{sender_domain}', + 'mail_server_and_interface' => '%{mail_server}/%{bind_interface}', + 'realm_and_destination_domain' => '%{realm}/%{destination_domain}', + 'destination_domain' => '%{destination_domain}' + }.each do |known, unknown| + subject.store(known % params_hash, {[(unknown % params_hash),'sent'].join('/') => 1}) end end end