Sha256: fc67586e1ec5365f68eadeb6d9c7c9b896098ecc14ecf3472e494992db023ff5

Contents?: true

Size: 1.42 KB

Versions: 13

Compression:

Stored size: 1.42 KB

Contents

# encoding: utf-8

require "spec_helper"
describe AMQP::ChannelIdAllocator do

  class ChannelAllocator
    include AMQP::ChannelIdAllocator
  end

  describe "#next_channel_id" do
    subject do
      ChannelAllocator.new
    end

    context "when there is a channel id available for allocation" do
      it "returns that channel id" do
        1024.times { subject.next_channel_id }

        subject.next_channel_id.should == 1025
      end
    end

    context "when THERE IS NO a channel id available for allocation" do
      it "raises an exception" do
        (ChannelAllocator::MAX_CHANNELS_PER_CONNECTION - 1).times do
          subject.next_channel_id
        end

        lambda { subject.next_channel_id }.should raise_error
      end
    end
  end


  describe ".release_channel_id" do
    subject do
      ChannelAllocator.new
    end

    it "releases that channel id" do
      1024.times { subject.next_channel_id }
      subject.next_channel_id.should == 1025

      subject.release_channel_id(128)
      subject.next_channel_id.should == 128
      subject.next_channel_id.should == 1026
    end
  end

  describe "each instance gets its own channel IDs" do
    it "has an allocator per instance" do
      one = ChannelAllocator.new
      two = ChannelAllocator.new
      one.next_channel_id.should == 1
      one.next_channel_id.should == 2
      two.next_channel_id.should == 1
      two.next_channel_id.should == 2
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
amqp-1.8.0 spec/unit/amqp/channel_id_allocation_spec.rb
amqp-1.7.0 spec/unit/amqp/channel_id_allocation_spec.rb
amqp-1.6.0 spec/unit/amqp/channel_id_allocation_spec.rb
amqp-1.5.3 spec/unit/amqp/channel_id_allocation_spec.rb
amqp-1.5.2 spec/unit/amqp/channel_id_allocation_spec.rb
amqp-1.5.1 spec/unit/amqp/channel_id_allocation_spec.rb
amqp-1.5.0 spec/unit/amqp/channel_id_allocation_spec.rb
amqp-1.4.2 spec/unit/amqp/channel_id_allocation_spec.rb
amqp-1.4.1 spec/unit/amqp/channel_id_allocation_spec.rb
amqp-1.4.0 spec/unit/amqp/channel_id_allocation_spec.rb
amqp-1.3.0 spec/unit/amqp/channel_id_allocation_spec.rb
amqp-1.2.1 spec/unit/amqp/channel_id_allocation_spec.rb
amqp-1.2.0 spec/unit/amqp/channel_id_allocation_spec.rb