本文整理汇总了Python中haigha.channel_pool.ChannelPool._get_channel方法的典型用法代码示例。如果您正苦于以下问题:Python ChannelPool._get_channel方法的具体用法?Python ChannelPool._get_channel怎么用?Python ChannelPool._get_channel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类haigha.channel_pool.ChannelPool
的用法示例。
在下文中一共展示了ChannelPool._get_channel方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_channel_when_two_free_and_one_closed
# 需要导入模块: from haigha.channel_pool import ChannelPool [as 别名]
# 或者: from haigha.channel_pool.ChannelPool import _get_channel [as 别名]
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)
示例2: test_get_channel_when_none_free
# 需要导入模块: from haigha.channel_pool import ChannelPool [as 别名]
# 或者: from haigha.channel_pool.ChannelPool import _get_channel [as 别名]
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 )
示例3: test_get_channel_when_one_free_and_not_closed
# 需要导入模块: from haigha.channel_pool import ChannelPool [as 别名]
# 或者: from haigha.channel_pool.ChannelPool import _get_channel [as 别名]
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)
示例4: test_get_channel_returns_new_when_none_free_and_at_limit
# 需要导入模块: from haigha.channel_pool import ChannelPool [as 别名]
# 或者: from haigha.channel_pool.ChannelPool import _get_channel [as 别名]
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)
示例5: test_get_channel_returns_new_when_none_free_and_not_at_limit
# 需要导入模块: from haigha.channel_pool import ChannelPool [as 别名]
# 或者: from haigha.channel_pool.ChannelPool import _get_channel [as 别名]
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)
示例6: test_get_channel_when_two_free_and_all_closed
# 需要导入模块: from haigha.channel_pool import ChannelPool [as 别名]
# 或者: from haigha.channel_pool.ChannelPool import _get_channel [as 别名]
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 )
示例7: test_get_channel_when_two_free_and_all_closed
# 需要导入模块: from haigha.channel_pool import ChannelPool [as 别名]
# 或者: from haigha.channel_pool.ChannelPool import _get_channel [as 别名]
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)