Exemplo n.º 1
0
    def test_get_channel_when_two_free_and_one_closed(self):
        # Because we can't mock builtins ....
        class Set(set):

            def pop(self):
                pass

        conn = mock()
        ch1 = mock()
        ch1.closed = True
        ch2 = mock()
        ch2.closed = False
        cp = ChannelPool(conn)
        cp._free_channels = Set([ch1, ch2])
        cp._channels = 2

        # Because we want them in order
        expect(cp._free_channels.pop).returns(
            ch1).side_effect(super(Set, cp._free_channels).pop)
        expect(cp._free_channels.pop).returns(
            ch2).side_effect(super(Set, cp._free_channels).pop)

        self.assertEquals(ch2, cp._get_channel())
        self.assertEquals(set(), cp._free_channels)
        assert_equals(2, cp._channels)
Exemplo n.º 2
0
  def test_get_channel_when_none_free(self):
    conn = mock()
    cp = ChannelPool(conn)

    expect(conn.channel).returns( 'channel' )
    
    self.assertEquals( 'channel', cp._get_channel() )
    self.assertEquals( set(), cp._free_channels )
Exemplo n.º 3
0
  def test_get_channel_when_none_free(self):
    conn = mock()
    cp = ChannelPool(conn)

    expect(conn.channel).returns( 'channel' )
    
    self.assertEquals( 'channel', cp._get_channel() )
    self.assertEquals( set(), cp._free_channels )
Exemplo n.º 4
0
    def test_get_channel_when_one_free_and_not_closed(self):
        conn = mock()
        ch = mock()
        ch.closed = False
        cp = ChannelPool(conn)
        cp._free_channels = set([ch])

        self.assertEquals(ch, cp._get_channel())
        self.assertEquals(set(), cp._free_channels)
Exemplo n.º 5
0
    def test_get_channel_returns_new_when_none_free_and_at_limit(self):
        conn = mock()
        cp = ChannelPool(conn, 1)
        cp._channels = 1

        stub(conn.channel)

        self.assertEquals(None, cp._get_channel())
        self.assertEquals(set(), cp._free_channels)
Exemplo n.º 6
0
    def test_get_channel_returns_new_when_none_free_and_not_at_limit(self):
        conn = mock()
        cp = ChannelPool(conn)
        cp._channels = 1

        with expect(conn.channel).returns(mock()) as newchannel:
            expect(newchannel.add_close_listener).args(cp._channel_closed_cb)
            self.assertEquals(newchannel, cp._get_channel())
        self.assertEquals(set(), cp._free_channels)
        assert_equals(2, cp._channels)
Exemplo n.º 7
0
  def test_get_channel_when_two_free_and_all_closed(self):
    conn = mock()
    ch1 = mock()
    ch1.closed = True
    ch2 = mock()
    ch2.closed = True
    cp = ChannelPool(conn)
    cp._free_channels = set([ch1,ch2])

    expect(conn.channel).returns('channel')

    self.assertEquals( 'channel', cp._get_channel() )
    self.assertEquals( set(), cp._free_channels )
Exemplo n.º 8
0
  def test_get_channel_when_two_free_and_all_closed(self):
    conn = mock()
    ch1 = mock()
    ch1.closed = True
    ch2 = mock()
    ch2.closed = True
    cp = ChannelPool(conn)
    cp._free_channels = set([ch1,ch2])

    expect(conn.channel).returns('channel')

    self.assertEquals( 'channel', cp._get_channel() )
    self.assertEquals( set(), cp._free_channels )
Exemplo n.º 9
0
    def test_get_channel_when_two_free_and_all_closed(self):
        conn = mock()
        ch1 = mock()
        ch1.closed = True
        ch2 = mock()
        ch2.closed = True
        cp = ChannelPool(conn)
        cp._free_channels = set([ch1, ch2])
        cp._channels = 2

        with expect(conn.channel).returns(mock()) as newchannel:
            expect(newchannel.add_close_listener).args(cp._channel_closed_cb)
            self.assertEquals(newchannel, cp._get_channel())

        self.assertEquals(set(), cp._free_channels)
        assert_equals(3, cp._channels)