1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
# 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
|