Sha256: 30a2b62465f82d4593fe219e81234dddc7ba45a89cb2a325977de5f194ee989a

Contents?: true

Size: 1.11 KB

Versions: 6

Compression:

Stored size: 1.11 KB

Contents

require 'spec_helper'

describe PulseMeter::CommandAggregator::UDP do
  let(:host){'127.0.0.1'}
  let(:port){33333}
  let(:udp_sock){mock(:socket)}
  before do 
    UDPSocket.stub!(:new).and_return(udp_sock)
    udp_sock.stub!(:fcntl).and_return(nil)
    @ca = described_class.new([[host, port]])
  end

  describe "#multi" do
    it "should accumulate redis commands and send them in a bulk" do
      data = [
        ["set", "xxxx", "zzzz"],
        ["set", "yyyy", "zzzz"]
      ].to_json
      udp_sock.should_receive(:send).with(data, 0, host, port).and_return(0)
      @ca.multi do
        @ca.set("xxxx", "zzzz")
        @ca.set("yyyy", "zzzz")
      end
    end

    it "should ignore standard exceptions" do
      udp_sock.should_receive(:send).and_raise(StandardError)
      @ca.multi do
        @ca.set("xxxx", "zzzz")
      end
    end
  end

  describe "any other redis instance method" do
    it "should send data imediately" do
      data = [
        ["set", "xxxx", "zzzz"]
      ].to_json
      udp_sock.should_receive(:send).with(data, 0, host, port).and_return(0)
      @ca.set("xxxx", "zzzz")
    end
  end

end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
pulse_meter_core-0.5.2 spec/pulse_meter/command_aggregator/udp_spec.rb
pulse_meter_core-0.5.1 spec/pulse_meter/command_aggregator/udp_spec.rb
pulse_meter_core-0.5.0 spec/pulse_meter/command_aggregator/udp_spec.rb
pulse_meter_core-0.4.13 spec/pulse_meter/command_aggregator/udp_spec.rb
pulse-meter-0.4.9 spec/pulse_meter/command_aggregator/udp_spec.rb
pulse-meter-0.4.8 spec/pulse_meter/command_aggregator/udp_spec.rb