Sha256: 43f01444ffed532832066d922787c78092d9cfda3d8cc5c910220ae5de005550

Contents?: true

Size: 1.48 KB

Versions: 16

Compression:

Stored size: 1.48 KB

Contents

require 'spec_helper'

describe PulseMeter::CommandAggregator::Async do
  let(:ca){PulseMeter.command_aggregator}
  let(:redis){PulseMeter.redis}

  describe "#multi" do
    it "should accumulate redis command and execute in a bulk" do
      ca.multi do
        ca.set("xxxx", "zzzz")
        ca.set("yyyy", "zzzz")
        sleep 0.1
        redis.get("xxxx").should be_nil
        redis.get("yyyy").should be_nil
      end
      ca.wait_for_pending_events
      redis.get("xxxx").should == "zzzz"
      redis.get("yyyy").should == "zzzz"
    end
  end

  describe "any other redis instance method" do
    it "should be delegated to redis" do
      ca.set("xxxx", "zzzz")
      ca.wait_for_pending_events
      redis.get("xxxx").should == "zzzz"
    end

    it "should be aggregated if queue is not overflooded" do
      redis.set("x", 0)
      ca.max_queue_length.times{ ca.incr("x") }
      ca.wait_for_pending_events
      redis.get("x").to_i.should == ca.max_queue_length
    end

    it "should not be aggregated if queue is overflooded" do
      redis.set("x", 0)
      (ca.max_queue_length * 2).times{ ca.incr("x") }
      ca.wait_for_pending_events
      redis.get("x").to_i.should < 2 * ca.max_queue_length
    end
  end

  describe "#wait_for_pending_events" do
    it "should pause execution until aggregator thread sends all commands ro redis" do
      ca.set("xxxx", "zzzz")
      redis.get("xxxx").should be_nil
      ca.wait_for_pending_events
      redis.get("xxxx").should == "zzzz"
    end
  end

end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
pulse_meter_core-0.5.3 spec/pulse_meter/command_aggregator/async_spec.rb
pulse_meter_core-0.5.2 spec/pulse_meter/command_aggregator/async_spec.rb
pulse_meter_core-0.5.1 spec/pulse_meter/command_aggregator/async_spec.rb
pulse_meter_core-0.5.0 spec/pulse_meter/command_aggregator/async_spec.rb
pulse_meter_core-0.4.13 spec/pulse_meter/command_aggregator/async_spec.rb
pulse-meter-0.4.9 spec/pulse_meter/command_aggregator/async_spec.rb
pulse-meter-0.4.8 spec/pulse_meter/command_aggregator/async_spec.rb
pulse-meter-0.4.7 spec/pulse_meter/command_aggregator/async_spec.rb
pulse-meter-0.4.6 spec/pulse_meter/command_aggregator/async_spec.rb
pulse-meter-0.4.5 spec/pulse_meter/command_aggregator/async_spec.rb
pulse-meter-0.4.4 spec/pulse_meter/command_aggregator/async_spec.rb
pulse-meter-0.4.3 spec/pulse_meter/command_aggregator/async_spec.rb
pulse-meter-0.4.2 spec/pulse_meter/command_aggregator/async_spec.rb
pulse-meter-0.4.1 spec/pulse_meter/command_aggregator/async_spec.rb
pulse-meter-0.4.0 spec/pulse_meter/command_aggregator/async_spec.rb
pulse-meter-0.3.2 spec/pulse_meter/command_aggregator/async_spec.rb